Why D const is annoying

Mehrdad wfunction at hotmail.com
Sat Dec 10 01:37:18 PST 2011


I just thought I'd give D another try, after having given up on it for a 
while.

Lo and behold... the same old kind of problem from a year ago is still 
here. :(

Simple stuff like this:

     import std.algorithm;
     void main() {
         const arr = [1, 2, 3];
         reduce!"a*b"(arr);   // You'd think it'd work...
     }

Results in ridiculously annoying errors like:
     // algorithm.d(728): Error: can only initialize const member 
_field_field_0 inside constructor

I **HIGHLY** suggest that priority be given to simple problems like 
these, instead of OMG-so-cool-libraries. It really doesn't matter if 
there is an uber-awesome collections/CURL/whatever library out there, 
when problems like these exist. If a 2-line piece of code needs a 
workaround, then (IMO) people simply won't care about anything else 
that's more complicated.

I'll post more as I find them. (I'd found plenty a few months ago, now I 
just need to find them again.)
Too lazy/busy studying to post as a bug. And it feels a bit better when 
I add the complaint. :P

(Sorry for being so critical but at least I tried to make it 
constructive...)


More information about the Digitalmars-d mailing list