tag:blogger.com,1999:blog-1368731483244051508.post5153775472880539796..comments2007-06-20T09:44:39.661+10:00Comments on while(nan): You can't touch this.Dkhttp://www.blogger.com/profile/02909587337938463354noreply@blogger.comBlogger6125tag:blogger.com,1999:blog-1368731483244051508.post-30559979624752386852007-06-20T09:44:00.000+10:002007-06-20T09:44:00.000+10:00Tyler: Well, at least I'm closer than Terry Pratch...Tyler: Well, at least I'm closer than Terry Pratchett was in Going Postal; he used 3.<BR/><BR/>Tomas: Anything's possible with enough casting. However, unlike C++, casting away constness and then changing something has undefined behaviour. Also, you <EM>can</EM> have member functions marked as "const" that prohibit you from changing an object through its this reference.Dkhttp://www.blogger.com/profile/02909587337938463354noreply@blogger.comtag:blogger.com,1999:blog-1368731483244051508.post-11337926482986890272007-06-20T06:05:00.000+10:002007-06-20T06:05:00.000+10:00Good explanation. I like this disambiguation betwe...Good explanation. I like this disambiguation between different usages of const. C++ does not provide immutable storage, and does not differentiate between the other two uses of const.<BR/><BR/>Will D allow one to call functions on a reference const value that mutate the object, or is there a way to mark functions as non-mutating (as in C++). I feel much of the value of const is lost without this.Tomashttp://www.blogger.com/profile/14474896952223748449noreply@blogger.comtag:blogger.com,1999:blog-1368731483244051508.post-63388843221353476672007-06-20T02:40:00.000+10:002007-06-20T02:40:00.000+10:00Funny that you say no one wants to change the valu...Funny that you say no one wants to change the value of pi, because that is precisely what you did.<BR/><BR/>"storage const" PI = 3.1415926535897931;<BR/><BR/>That last value should be a 2 ;)<BR/><BR/>I'm just poking fun though. This was a good article, very informative.Tyler Pretehttp://www.tylerprete.comnoreply@blogger.comtag:blogger.com,1999:blog-1368731483244051508.post-49880598998102328602007-06-20T00:41:00.000+10:002007-06-20T00:41:00.000+10:00Just a general comment: now that D 2.0 has been re...Just a general comment: now that D 2.0 has been released with the shiny new const stuff, it seems that what I wrote here is still true (go me!)<BR/><BR/>That said, I urge everyone interested in D's const system to download the new compiler from the DigitalMars website and play with it. Reading about it is all well and good, but nothing beats being able to poke it with a stick...<BR/><BR/>Jesse: when I first started drafting this, I used the actual keywords. A lot of people will see the word "const" and think "I bet it works just like it does in C++!" In some ways it does, but in others it doesn't. It's simpler to just beat people over the head with "it's not C++; don't try comparing it because I'm sick of splitting hairs on this" than not.<BR/><BR/>Also, I never said that storage const wasn't part of the type system: I said it's not part of a variable's type. That taking the address of a storage const variable gives you a reference immutable type is kind of a side-effect of the addressof operator.<BR/><BR/>Finally, on immutability, there are two schools of thought at the moment: that it's really good to have, or that it's totally useless. I suppose we'll soon find out which is more correct.Dkhttp://www.blogger.com/profile/02909587337938463354noreply@blogger.comtag:blogger.com,1999:blog-1368731483244051508.post-25736825600838682892007-06-20T00:21:00.000+10:002007-06-20T00:21:00.000+10:00You say this is nothing like _const_ in C/C++, but...You say this is nothing like _const_ in C/C++, but then the first two things you introduce are! A "storage const" int ** is "int ** const" in C, and a "reference const" int ** is just "int const * const *" in C. I've always found the C syntax for this appealing, but I realize that many people don't. Is the goal here to reduce confusion, because it's nothing new.<BR/><BR/>Also, you say that storage const-ness isn't part of the type system, but certainly if you have a storage const int a, then &a must be a reference const int *. There's something type-y going on there.<BR/><BR/>On the other hand, immutability is a nice feature to have, and I agree that's nothing like C(++) const. (Though there is some kind of relationship between const, invarient, and volatile, eh?)Jesse Tovhttp://www.blogger.com/profile/05394743293033983187noreply@blogger.comtag:blogger.com,1999:blog-1368731483244051508.post-34572696425944726082007-06-09T13:28:00.000+10:002007-06-09T13:28:00.000+10:00Wow, thanks. That really cleared this up for me, I...Wow, thanks. That really cleared this up for me, I've been spending way too much time trying to piece it all together lurking in the NG.Danhttp://www.blogger.com/profile/11694980728276672755noreply@blogger.com