Re: thoughts on immutability in D

2011-09-28 Thread Marco Leise
Am 24.09.2011, 07:28 Uhr, schrieb Mehrdad : On 9/23/2011 8:11 PM, Jonathan M Davis wrote: On Friday, September 23, 2011 19:42:24 Walter Bright wrote: On 9/23/2011 6:55 PM, Jonathan M Davis wrote: True, but it doesn't just happen. You have to choose to make a variable mutable. Which you *mus

Re: thoughts on immutability in D

2011-09-26 Thread Rainer Schuetze
On 26.09.2011 16:14, Steven Schveighoffer wrote: On Sat, 24 Sep 2011 04:46:07 -0400, Rainer Schuetze wrote: On 9/24/2011 9:30 AM, Andrei Alexandrescu wrote: On 9/24/11 1:12 CDT, Rainer Schuetze wrote: On 9/22/2011 4:10 PM, Andrei Alexandrescu wrote: On 9/22/11 3:02 AM, Peter Alexander

Re: thoughts on immutability in D

2011-09-26 Thread Rainer Schuetze
On 26.09.2011 08:32, Jonathan M Davis wrote: On Monday, September 26, 2011 08:14:31 Rainer Schuetze wrote: Which finally brings us back to the original question: What does immutable guarantee in the face of non-pure property getter functions? immutable guarantees that when an object is immut

Re: thoughts on immutability in D

2011-09-26 Thread Steven Schveighoffer
On Fri, 23 Sep 2011 20:05:16 -0400, Walter Bright wrote: On 9/23/2011 3:46 PM, Peter Alexander wrote: On 23/09/11 6:48 AM, Walter Bright wrote: On 9/22/2011 4:39 AM, bearophile wrote: Walter: "logical const" in C++ is faith-based programming. I think you're exaggerating it's uselessness

Re: thoughts on immutability in D

2011-09-26 Thread Steven Schveighoffer
On Fri, 23 Sep 2011 20:13:39 -0400, Walter Bright wrote: On 9/23/2011 4:13 PM, Jonathan M Davis wrote: But while C++'s const is not as good as D's const, it's still very worthwhile IMHO. To me it's like buffer overflows. 99% of C/C++ code doesn't have buffer overflows, and is perfectly

Re: thoughts on immutability in D

2011-09-26 Thread Steven Schveighoffer
On Sat, 24 Sep 2011 04:46:07 -0400, Rainer Schuetze wrote: On 9/24/2011 9:30 AM, Andrei Alexandrescu wrote: On 9/24/11 1:12 CDT, Rainer Schuetze wrote: On 9/22/2011 4:10 PM, Andrei Alexandrescu wrote: On 9/22/11 3:02 AM, Peter Alexander wrote: On 22/09/11 7:04 AM, Andrei Alexandrescu w

Re: thoughts on immutability in D

2011-09-25 Thread Jonathan M Davis
On Monday, September 26, 2011 08:14:31 Rainer Schuetze wrote: > Which finally brings us back to the original question: What does > immutable guarantee in the face of non-pure property getter functions? immutable guarantees that when an object is immutable, none of its member variables will _ever_

Re: thoughts on immutability in D

2011-09-25 Thread Rainer Schuetze
On 25.09.2011 04:25, Peter Alexander wrote: On 24/09/11 4:47 PM, Rainer Schuetze wrote: Sorry for the bad example, here's one that is not thread-safe, and where the invariant can fail in a multi-threaded environment: shared(int) globId; class C { invariant() { assert((globId & 1) == 0); } @p

Re: thoughts on immutability in D

2011-09-25 Thread Peter Alexander
On 25/09/11 4:49 AM, Walter Bright wrote: On 9/24/2011 6:03 AM, Peter Alexander wrote: I only use const/immutable for concurrency. Nothing else. How do you avoid race conditions when setting logical const values? You can't and don't. That's not what logical const is for. That's what physica

Re: thoughts on immutability in D

2011-09-24 Thread dame
Walter Bright wrote: > On 9/24/2011 11:00 PM, dame wrote: >> Walter Bright wrote: >>> On 9/24/2011 6:03 AM, Peter Alexander wrote: I only use const/immutable for concurrency. Nothing else. >>> >>> How do you avoid race conditions when setting logical const values? >> >> Is that important? > >

Re: thoughts on immutability in D

2011-09-24 Thread Walter Bright
On 9/24/2011 11:00 PM, dame wrote: Walter Bright wrote: On 9/24/2011 6:03 AM, Peter Alexander wrote: I only use const/immutable for concurrency. Nothing else. How do you avoid race conditions when setting logical const values? Is that important? If you have a concurrent data structure, it

Re: thoughts on immutability in D

2011-09-24 Thread dame
Walter Bright wrote: > On 9/24/2011 6:03 AM, Peter Alexander wrote: >> I only use const/immutable for concurrency. Nothing else. > > How do you avoid race conditions when setting logical const values? Is that important?

Re: thoughts on immutability in D

2011-09-24 Thread Walter Bright
On 9/24/2011 6:03 AM, Peter Alexander wrote: I only use const/immutable for concurrency. Nothing else. How do you avoid race conditions when setting logical const values?

Re: thoughts on immutability in D

2011-09-24 Thread Peter Alexander
On 24/09/11 4:47 PM, Rainer Schuetze wrote: Sorry for the bad example, here's one that is not thread-safe, and where the invariant can fail in a multi-threaded environment: shared(int) globId; class C { invariant() { assert((globId & 1) == 0); } @property int id() immutable { globId = globId +

Re: thoughts on immutability in D

2011-09-24 Thread Rainer Schuetze
On 9/24/2011 6:42 PM, Peter Alexander wrote: On 24/09/11 2:39 PM, Rainer Schuetze wrote: Is c.id thread-safe? no! Is it constant? no! How does this help in multi-threaded applications that access c? It is thread safe. globId is a thread-local variable. sorry, I noticed this mistake in my e

Re: thoughts on immutability in D

2011-09-24 Thread Timon Gehr
On 09/24/2011 01:34 AM, Mehrdad wrote: On 9/23/2011 4:13 PM, Jonathan M Davis wrote: On Friday, September 23, 2011 15:58 Andrej Mitrovic wrote: On 9/24/11, Peter Alexander wrote: On 23/09/11 6:48 AM, Walter Bright wrote: On 9/22/2011 4:39 AM, bearophile wrote: Walter: "logical const" in C++

Re: thoughts on immutability in D

2011-09-24 Thread Peter Alexander
On 24/09/11 2:39 PM, Rainer Schuetze wrote: Is c.id thread-safe? no! Is it constant? no! How does this help in multi-threaded applications that access c? It is thread safe. globId is a thread-local variable. sorry, I noticed this mistake in my example too late. Using shared(int) still compile

Re: thoughts on immutability in D

2011-09-24 Thread Rainer Schuetze
On 9/24/2011 3:00 PM, Peter Alexander wrote: On 24/09/11 9:46 AM, Rainer Schuetze wrote: On 9/24/2011 9:30 AM, Andrei Alexandrescu wrote: On 9/24/11 1:12 CDT, Rainer Schuetze wrote: On 9/22/2011 4:10 PM, Andrei Alexandrescu wrote: On 9/22/11 3:02 AM, Peter Alexander wrote: On 22/09/11 7

Re: thoughts on immutability in D

2011-09-24 Thread Peter Alexander
On 23/09/11 11:58 PM, Andrej Mitrovic wrote: On 9/24/11, Peter Alexander wrote: On 23/09/11 6:48 AM, Walter Bright wrote: On 9/22/2011 4:39 AM, bearophile wrote: Walter: "logical const" in C++ is faith-based programming. I think you're exaggerating it's uselessness. It's faith-based as mu

Re: thoughts on immutability in D

2011-09-24 Thread Peter Alexander
On 24/09/11 9:46 AM, Rainer Schuetze wrote: On 9/24/2011 9:30 AM, Andrei Alexandrescu wrote: On 9/24/11 1:12 CDT, Rainer Schuetze wrote: On 9/22/2011 4:10 PM, Andrei Alexandrescu wrote: On 9/22/11 3:02 AM, Peter Alexander wrote: On 22/09/11 7:04 AM, Andrei Alexandrescu wrote: The initial

Re: thoughts on immutability in D

2011-09-24 Thread Rainer Schuetze
On 9/24/2011 9:30 AM, Andrei Alexandrescu wrote: On 9/24/11 1:12 CDT, Rainer Schuetze wrote: On 9/22/2011 4:10 PM, Andrei Alexandrescu wrote: On 9/22/11 3:02 AM, Peter Alexander wrote: On 22/09/11 7:04 AM, Andrei Alexandrescu wrote: The initial submission got junked so I resubmitted: http

Re: thoughts on immutability in D

2011-09-24 Thread Andrei Alexandrescu
On 9/24/11 1:12 CDT, Rainer Schuetze wrote: On 9/22/2011 4:10 PM, Andrei Alexandrescu wrote: On 9/22/11 3:02 AM, Peter Alexander wrote: On 22/09/11 7:04 AM, Andrei Alexandrescu wrote: The initial submission got junked so I resubmitted: http://www.reddit.com/r/programming/comments/knn5p/thoug

Re: thoughts on immutability in D

2011-09-24 Thread Jonathan M Davis
On Saturday, September 24, 2011 08:12:17 Rainer Schuetze wrote: > On 9/22/2011 4:10 PM, Andrei Alexandrescu wrote: > > On 9/22/11 3:02 AM, Peter Alexander wrote: > >> On 22/09/11 7:04 AM, Andrei Alexandrescu wrote: > >>> The initial submission got junked so I resubmitted: > >>> > >>> http://www.re

Re: thoughts on immutability in D

2011-09-24 Thread Rainer Schuetze
On 9/22/2011 4:10 PM, Andrei Alexandrescu wrote: On 9/22/11 3:02 AM, Peter Alexander wrote: On 22/09/11 7:04 AM, Andrei Alexandrescu wrote: The initial submission got junked so I resubmitted: http://www.reddit.com/r/programming/comments/knn5p/thoughts_on_immutability_in_d/ Andrei Thanks

Re: thoughts on immutability in D

2011-09-23 Thread Mehrdad
On 9/23/2011 8:11 PM, Jonathan M Davis wrote: On Friday, September 23, 2011 19:42:24 Walter Bright wrote: On 9/23/2011 6:55 PM, Jonathan M Davis wrote: True, but it doesn't just happen. You have to choose to make a variable mutable. Which you *must* do for logical const. And, of course, anythi

Re: thoughts on immutability in D

2011-09-23 Thread Jonathan M Davis
On Friday, September 23, 2011 19:42:24 Walter Bright wrote: > On 9/23/2011 6:55 PM, Jonathan M Davis wrote: > > True, but it doesn't just happen. You have to choose to make a variable > > mutable. > > Which you *must* do for logical const. And, of course, anything beyond the > first level is not c

Re: thoughts on immutability in D

2011-09-23 Thread Walter Bright
On 9/23/2011 6:55 PM, Jonathan M Davis wrote: True, but it doesn't just happen. You have to choose to make a variable mutable. Which you *must* do for logical const. And, of course, anything beyond the first level is not const at all, and there's NO WAY to say it is const. _Some_ effort mu

Re: thoughts on immutability in D

2011-09-23 Thread Jonathan M Davis
On Friday, September 23, 2011 18:39:19 Walter Bright wrote: > On 9/23/2011 5:31 PM, Jonathan M Davis wrote: > > I have to specifically circumvent the compiler to be > > able to alter const stuff. > > Nope, not with 'mutable' you don't have to circumvent anything. Just change > it. True, but it do

Re: thoughts on immutability in D

2011-09-23 Thread Walter Bright
On 9/23/2011 5:31 PM, Jonathan M Davis wrote: I have to specifically circumvent the compiler to be able to alter const stuff. Nope, not with 'mutable' you don't have to circumvent anything. Just change it.

Re: thoughts on immutability in D

2011-09-23 Thread Jonathan M Davis
On Friday, September 23, 2011 17:13 Walter Bright wrote: > On 9/23/2011 4:13 PM, Jonathan M Davis wrote: > > But while C++'s const is not as good as D's const, it's still very > > worthwhile IMHO. > > To me it's like buffer overflows. 99% of C/C++ code doesn't have buffer > overflows, and is perfe

Re: thoughts on immutability in D

2011-09-23 Thread Walter Bright
On 9/23/2011 4:13 PM, Jonathan M Davis wrote: But while C++'s const is not as good as D's const, it's still very worthwhile IMHO. To me it's like buffer overflows. 99% of C/C++ code doesn't have buffer overflows, and is perfectly reliable. But if someone hands you a 1,000,000 line program and

Re: thoughts on immutability in D

2011-09-23 Thread Walter Bright
On 9/23/2011 3:46 PM, Peter Alexander wrote: On 23/09/11 6:48 AM, Walter Bright wrote: On 9/22/2011 4:39 AM, bearophile wrote: Walter: "logical const" in C++ is faith-based programming. I think you're exaggerating it's uselessness. It's faith-based as much as 'walking down the street assumi

Re: thoughts on immutability in D

2011-09-23 Thread Jonathan M Davis
On Friday, September 23, 2011 16:34 Mehrdad wrote: > So far, the 5% of the code it breaks has made it 95% worthless for me, > though I'm not sure about others (would love to hear otherwise)... But _what_ does it break? The lack of logical const is definitely limiting, but at the moment, I can't t

Re: thoughts on immutability in D

2011-09-23 Thread Andrei Alexandrescu
On 09/23/11 17:46, Peter Alexander wrote: On 23/09/11 6:48 AM, Walter Bright wrote: On 9/22/2011 4:39 AM, bearophile wrote: Walter: "logical const" in C++ is faith-based programming. I think you're exaggerating it's uselessness. It's faith-based as much as 'walking down the street assuming

Re: thoughts on immutability in D

2011-09-23 Thread Mehrdad
On 9/23/2011 4:13 PM, Jonathan M Davis wrote: On Friday, September 23, 2011 15:58 Andrej Mitrovic wrote: On 9/24/11, Peter Alexander wrote: On 23/09/11 6:48 AM, Walter Bright wrote: On 9/22/2011 4:39 AM, bearophile wrote: Walter: "logical const" in C++ is faith-based programming. I think y

Re: thoughts on immutability in D

2011-09-23 Thread Jonathan M Davis
On Friday, September 23, 2011 15:58 Andrej Mitrovic wrote: > On 9/24/11, Peter Alexander wrote: > > On 23/09/11 6:48 AM, Walter Bright wrote: > >> On 9/22/2011 4:39 AM, bearophile wrote: > >>> Walter: > >> "logical const" in C++ is faith-based programming. > > > > I think you're exaggerating it's

Re: thoughts on immutability in D

2011-09-23 Thread Andrej Mitrovic
On 9/24/11, Peter Alexander wrote: > On 23/09/11 6:48 AM, Walter Bright wrote: >> On 9/22/2011 4:39 AM, bearophile wrote: >>> Walter: >> "logical const" in C++ is faith-based programming. > > I think you're exaggerating it's uselessness. > > It's faith-based as much as 'walking down the street ass

Re: thoughts on immutability in D

2011-09-23 Thread Peter Alexander
On 23/09/11 6:48 AM, Walter Bright wrote: On 9/22/2011 4:39 AM, bearophile wrote: Walter: "logical const" in C++ is faith-based programming. I think you're exaggerating it's uselessness. It's faith-based as much as 'walking down the street assuming that the next person won't stab you' is fa

Re: thoughts on immutability in D

2011-09-23 Thread Christophe
bearophile , dans le message (digitalmars.D:145005), a écrit : > So with a lconst array you are allowed to change its contents, but not > reassign it or change its length. A lconst doesn't implicitly cast to > immutable. A solution to your problems could be to use a headconst keyword or librar

Re: thoughts on immutability in D

2011-09-22 Thread Walter Bright
On 9/22/2011 4:39 AM, bearophile wrote: Walter: You're right. Logical const is only a convention, since it cannot be enforced by the compiler. Even if it can't be enforced in 100% of the cases, I think it's still useful. So you need to look at the situation from a bit wider point of view. I

Re: thoughts on immutability in D

2011-09-22 Thread Peter Alexander
On 22/09/11 1:34 PM, Vladimir Panteleev wrote: On Thu, 22 Sep 2011 11:02:27 +0300, Peter Alexander wrote: Thanks for the reddit'ing. I launched up google analytics this morning and noticed a sudden spike. That could only mean one thing :-) I tried adding your blog to Planet D, but I can't fi

Re: thoughts on immutability in D

2011-09-22 Thread Peter Alexander
On 22/09/11 12:39 PM, bearophile wrote: Andrei Alexandrescu: The initial submission got junked so I resubmitted: http://www.reddit.com/r/programming/comments/knn5p/thoughts_on_immutability_in_d/ A logical const can coexist beside the other two (three) kinds of const of D. For simplicity I u

Re: thoughts on immutability in D

2011-09-22 Thread Andrei Alexandrescu
On 9/22/11 3:02 AM, Peter Alexander wrote: On 22/09/11 7:04 AM, Andrei Alexandrescu wrote: The initial submission got junked so I resubmitted: http://www.reddit.com/r/programming/comments/knn5p/thoughts_on_immutability_in_d/ Andrei Thanks for the reddit'ing. I launched up google analytics t

Re: thoughts on immutability in D

2011-09-22 Thread Vladimir Panteleev
On Thu, 22 Sep 2011 11:02:27 +0300, Peter Alexander wrote: Thanks for the reddit'ing. I launched up google analytics this morning and noticed a sudden spike. That could only mean one thing :-) I tried adding your blog to Planet D, but I can't figure out how to get an RSS feed of the D catego

Re: thoughts on immutability in D

2011-09-22 Thread bearophile
Andrei Alexandrescu: > The initial submission got junked so I resubmitted: > > http://www.reddit.com/r/programming/comments/knn5p/thoughts_on_immutability_in_d/ A logical const can coexist beside the other two (three) kinds of const of D. For simplicity I use the "lconst" keyword. lconst works

Re: thoughts on immutability in D

2011-09-22 Thread Peter Alexander
On 22/09/11 7:04 AM, Andrei Alexandrescu wrote: The initial submission got junked so I resubmitted: http://www.reddit.com/r/programming/comments/knn5p/thoughts_on_immutability_in_d/ Andrei Thanks for the reddit'ing. I launched up google analytics this morning and noticed a sudden spike. That

thoughts on immutability in D

2011-09-21 Thread Andrei Alexandrescu
The initial submission got junked so I resubmitted: http://www.reddit.com/r/programming/comments/knn5p/thoughts_on_immutability_in_d/ Andrei