Why do we have transitive const, again?

Mehrdad wfunction at hotmail.com
Fri Sep 23 22:24:37 PDT 2011


Also, another problem I remembered about const:

If you have a const object, you can't have an invariant() that calls 
something impure (or something like that -- I forget the details, it was 
a while ago). Which was pretty darn annoying when I was trying to use 
D's DBC features, which seemed to again conflict with the the 
transitivity of const.

I'll post more issues as I remember them. There certainly wasn't just 1.

See below for inline reply.

-------------------

On 9/23/2011 8:08 PM, Jonathan M Davis wrote:
> Many, many people _never_ try and lazy load or cache variables like 
> you're trying to do. So, there are many, many people that this will 
> never affect 
Oh... was the purpose of D to appeal to /those/ kinds of people? If so, 
then please ignore this entire post; it was my mistake.

> Obviously, it _will_ affect people but not enough that it would 
> cripple D's chances of catching on.
That's what we hope and keep our fingers crossed for, but something 
tells me that isn't quite enough. YMMV.

> Also, since all you have to do to work around the issue is to not use 
> const in this particular case (and there are already tons of 
> programmers who never use const and have no interest in it),and you're 
> fine, I don't see how this can be a showstopper for adopting the language.
"If it doesn't work then just don't use it"? I find it funny that you 
find this reasoning convincing, since I don't (and I don't think others 
do either).

> Yes, it's annoying, but there's a workaround which doesn't affect 
> performance at all,
Was const introduced for performance, or for code verifiability? I don't 
see how that's relevant, because honestly, the word "performance" wasn't 
even in my /mind/ when I was thinking about this problem. All I wanted 
was to _compile_ *verifiably correct* code, which failed pretty darn 
miserably, due to the const issues. I couldn't care less about 
performance when I was writing my code.

> and if something like this is all it takes for you to decide that 
> you're not going to use a particular language, then it's going to be 
> hard to get you to use _any_ language.
I personally know that's not true, but why bother convincing you 
otherwise? Feel free to believe that, if it makes sense with your reasoning.

> They _all_ have issues of one sort or another, if nothing else because 
> every language makes its own share of tradeoffs based on its goals.
NO! I think this is where you're missing the critical point. D's 
tradeoffs are NOT like other languages' tradeoffs.

Widely-used languages (C++, Python, C#, whatever) do NOT have half-baked 
(or even 95%-baked) features. They have features that work 100% of the 
time. Sure, they may be incomplete and they certainly have more room for 
improvement, but _what they *already* have_ works in EVERY situation. If 
you ever wondered what people meant on programmers.se when they said 
"C++ has a better thought-out type system", I hope you now know why. 
They did NOT mean that it has better features. Or that the compilers are 
of better quality. They were saying that the rules are self-consistent 
and they *work*. That is, _regardless_ of the compiler quality, the 
features of the *language* itself work in EVERY situation.

D, on the other hand, tries to appeal to everyone but instead has 
supposedly awesome features (e.g. transitive const) that DON'T work 100% 
of the time. They only work 95% of the time. You might refuse to believe 
this, but I'm convinced that this **IS** the reason why it's not being 
adopted as fast as you'd want it to be. You can continue to justify it 
as "but it works for 95% of people!" but the fact of the matter is that 
we've seen otherwise. Believe me, I want to see D get adopted too, but 
my brain is telling me that there HAS to be a reason it hasn't -- and 
that reason isn't the compiler bugs or anything of that sort, but the 
language itself.


P.S. I really hope people don't take this as a C++ fanboy ranting about 
D... not only am I not a fan of C++ (I pretty much hate the language), 
and it should be obvious (if not from my previous posts, at least from 
how much I've tried to promote D on StackOverflow) that I indeed do like 
D, and I've tried to suggest it to people as often as I've been able to. 
But over time, I've come to realize some of the reasons people like C++ 
as opposed to D, so I'm trying to point them out here so that they might 
be helpful. Hopefully they make sense.


More information about the Digitalmars-d mailing list