Thanks a lot for taking the time and replying in that much detail!
On Saturday, 11 March 2023 at 21:07:18 UTC, H. S. Teoh wrote:
> I also came from a C/C++ background. The GC turned me off D for a long time, until one day I decided to just give it a try to see if it was all as bad as people made it sound. [...]
That is actually not my issue at all. While I see the benefits of "manual" memory management, these quickly go away when it's done badly, and in my day job I am actually maintaining a project where it is a mess and just using a garbage collected language would have been a much better choice. Because guess what, if you go for manually managing your memory, you actually have to do the management properly.
> Why am I saying all this? Because to be frank, you haven't really used D if you've been avoiding its standard library like the plague.
Again, I'm afraid this is a bit of a misunderstanding. I'm not trying to avoid the standard library, in fact I wanted to use it and thought I couldn't because I'm also using a @nogc library. But turns out I was just doing it wrong. :)
> As for implicit type conversions: I don't know where you got your information from, but D's implicit conversions are a WHOLE different world from C++.
I am still a complete noob in D, at this point very little of my information comes from practical experience, but mostly what I've read in "Programming in D" by Ali Cehreli (yeah, I still kinda like books, I'm weird that way).
As for the conversion, it might not be as bad as in C++ where it will just silently construct new objects as long as there's a ctor with a matching parameter list somewhere, but it will still implicitly cast an enum
to its underlying type, or a bool
to an int
.
Now you may call me too strict about this, or point out that it will never be a problem in any real world use case, but if you take this classic example (which happens to actually be in the book as well, p. 20):
(30 > 20) > 10
, equals false
.
Well at least you have to use the parantheses, which is an improvement I guess, but still, this is something that I hate to see in any language that calls itself type safe.
You see, the second language I ever learned was Pascal, and while that has many issues of it's own, it irks me how so many modern languages do things wrong that Pascal did right as early as 1970. And to me, one of those things is that above code should not even compile.
"True" should not be comparable to 10, because "True" is not a number. And it should not be treated as such just because of how it is stored internally, as this is, after all, just an implementation detail. When you ask someone on the street if "True" plus two was three, he would call you a fool, and so should your compiler.
> Otherwise in practice it's not even an issue IME.
Yeah, probably right. Actually very few people have ever agreed with me on that one. Maybe I'm weird. :)
> For-loop syntax: I can't remember the last time I wrote one in D. Maybe I did like 1 or 2 times (across my 20+ D projects) when I really needed to do something weird with my loops.
As I wrote, I expected as much. So it's not so much a real problem as a general concept that I dislike; even if something is rarely (if ever) used: when you put it into your language, why do it in such a weird and ugly way just to have it look similar to C? I don't get it, is all. But I also didn't get it in JavaScript or any other language that adopted the C syntax, so it's not D specific.
> Again, not something you'll understand if you never tried to use D in a serious way.
Completely true. Again, I'm totally new to D and my criticism is kinda academic. I know that.
> I recommend actually trying to write D, not as transplanted C++, but the way D code is meant to be written.
But this is actually my point. Since D is not C++, it should not have adapted the for
or switch
syntax in almost exactly the same weird way. And saying that I shouldn't bother because I can always choose to not use it just seems like a very bad argument to me, sorry. It's kinda like saying that C++ wasn't a bad language when you just ignore 50% of it, which most people actually do. :)
> As for const: I hardly ever use it. It's useful occasional for low-level code, but not much beyond that. My advice: don't bother. Just pretend it doesn't exist, and your life will be happier. [...]
Same here. I have no problem with stuff in a language that I don't want to use, after all I guess you'll have that in every language. Still, especially as a beginner, I think it is legitimate to wonder why it was put in. const
has always gotten a lot of heat by C++ programmers, so what is the reasoning behind putting an even stricter version of it into a language that aspires to be a cleaner and better version of C++?
And again, I'm not trying to be the smartass who could have done it better, I'm just trying to understand it.
Taking your first steps into a new language, you just stumble across these things.
Thanks again for your time!