I just got it! (invariant/const)

Lionello Lunesu lionello at lunesu.remove.com
Wed Apr 9 01:58:23 PDT 2008


After reading Walter's posts these last weeks and Andrei's PDF, I think the 
D 2.0 invariant/const make a lot of sense, and I can see the how it opens up 
new possibilities.

I was a bit worried for a performance penalty because of the need for 
"idup"s, but then I realized that you only .idup when you use "invariant()" 
when you actually don't care about it being invariant or not. So converting 
all D 1.0 "char[]" to D 2.0 "string" might not be such a good idea.

One thing that I like is that suddenly C++ "const &" construction can be 
standardized and made safe at the same time! Because of invariant, "in" can 
safely pass the arguments by ref, instead of by value.

Sorry for repeating what most probably already know, but it just felt like a 
revelation that I had to share :-)  A bit slow perhaps, but I'm pretty sure 
I'm not the last one to /get it/.

Thanks Walter, Andrei for explaining this invariant/const thing over and 
over again, in different forms.

Now I'll have to change Phobos 2.0 to get "foreach(string s; new 
BufferedFile(..))" working ;-)

L.





More information about the Digitalmars-d mailing list