Re: Article: Why Const Sucks

2018-03-11 Thread joe via Digitalmars-d-announce
On Thursday, 8 March 2018 at 15:13:09 UTC, Steven Schveighoffer wrote: On 3/8/18 9:58 AM, joe wrote: On Monday, 5 March 2018 at 10:57:35 UTC, Jonathan M Davis wrote: Here's something I wrote up on const: /snip May be not entirely related, but a little gotcha. given: interface XY {} class

Re: Article: Why Const Sucks

2018-03-09 Thread Nathan S. via Digitalmars-d-announce
On Monday, 5 March 2018 Jonathan M Davis wrote at http://jmdavisprog.com/articles/why-const-sucks.html: What Java has instead is `final`, which IMHO is borderline useless In Java `final` is extremely useful for efficient threadsafe code.

Re: Article: Why Const Sucks

2018-03-08 Thread Steven Schveighoffer via Digitalmars-d-announce
On 3/8/18 9:58 AM, joe wrote: On Monday, 5 March 2018 at 10:57:35 UTC, Jonathan M Davis wrote: Here's something I wrote up on const: /snip May be not entirely related, but a little gotcha. given: interface XY {} class Foo: XY {} class Bar: XY {} void doSomething(in XY sth) {   auto foo =

Re: Article: Why Const Sucks

2018-03-08 Thread joe via Digitalmars-d-announce
On Monday, 5 March 2018 at 10:57:35 UTC, Jonathan M Davis wrote: Here's something I wrote up on const: /snip May be not entirely related, but a little gotcha. given: interface XY {} class Foo: XY {} class Bar: XY {} void doSomething(in XY sth) { auto foo = cast(Foo)sth; // error in @safe

Re: Article: Why Const Sucks

2018-03-07 Thread Simen Kjærås via Digitalmars-d-announce
On Tuesday, 6 March 2018 at 17:41:42 UTC, H. S. Teoh wrote: Yeah, Andrei has admitted before that this is probably what he would do today, if he were given a second chance to design ranges. But at the time, the landscape of D was rather different, and certain language features didn't exist

Re: Article: Why Const Sucks

2018-03-06 Thread Martin Nowak via Digitalmars-d-announce
On Monday, 5 March 2018 at 17:38:52 UTC, H. S. Teoh wrote: struct Container { auto opSlice() const { static struct Result { private Container impl; private int n; // internal mutable

Re: Article: Why Const Sucks

2018-03-06 Thread Jonathan M Davis via Digitalmars-d-announce
On Tuesday, March 06, 2018 19:06:25 Martin Nowak via Digitalmars-d-announce wrote: > On Tuesday, 6 March 2018 at 18:17:58 UTC, Jonathan M Davis wrote: > > I'm not actually convinced that killing auto-decoding is really > > much better. > > I don't think the problem is auto-decoding in string

Re: Article: Why Const Sucks

2018-03-06 Thread Martin Nowak via Digitalmars-d-announce
On Tuesday, 6 March 2018 at 18:17:58 UTC, Jonathan M Davis wrote: I'm not actually convinced that killing auto-decoding is really much better. I don't think the problem is auto-decoding in string range adapters, but repeated validation. https://issues.dlang.org/show_bug.cgi?id=14519#c32 If

Re: Article: Why Const Sucks

2018-03-06 Thread Jonathan M Davis via Digitalmars-d-announce
On Tuesday, March 06, 2018 10:47:36 H. S. Teoh via Digitalmars-d-announce wrote: > On Tue, Mar 06, 2018 at 01:31:39PM -0500, Steven Schveighoffer via Digitalmars-d-announce wrote: > > On 3/6/18 10:39 AM, Jonathan M Davis wrote: > > > Yeah. If you're dealing with generic code rather than a

Re: Article: Why Const Sucks

2018-03-06 Thread H. S. Teoh via Digitalmars-d-announce
On Tue, Mar 06, 2018 at 01:31:39PM -0500, Steven Schveighoffer via Digitalmars-d-announce wrote: > On 3/6/18 10:39 AM, Jonathan M Davis wrote: > > Yeah. If you're dealing with generic code rather than a specific > > range type that you know is implicitly saved when copied, you have > > to use

Re: Article: Why Const Sucks

2018-03-06 Thread Steven Schveighoffer via Digitalmars-d-announce
On 3/6/18 10:39 AM, Jonathan M Davis wrote: Yeah. If you're dealing with generic code rather than a specific range type that you know is implicitly saved when copied, you have to use save so often that it's painful, and almost no one does it. e.g. equal(lhs.save, rhs.save) or immutable

Re: Article: Why Const Sucks

2018-03-06 Thread H. S. Teoh via Digitalmars-d-announce
On Tue, Mar 06, 2018 at 11:20:56AM -0700, Jonathan M Davis via Digitalmars-d-announce wrote: > On Tuesday, March 06, 2018 09:41:42 H. S. Teoh via Digitalmars-d-announce > wrote: > > As they say, hindsight is always 20/20. But it wasn't so easy to > > foresee the consequences at the time when

Re: Article: Why Const Sucks

2018-03-06 Thread Jonathan M Davis via Digitalmars-d-announce
On Tuesday, March 06, 2018 09:41:42 H. S. Teoh via Digitalmars-d-announce wrote: > As they say, hindsight is always 20/20. But it wasn't so easy to > foresee the consequences at the time when the very concept of ranges was > still brand new. Except that even worse, I'd argue that hindsight

Re: Article: Why Const Sucks

2018-03-06 Thread Jonathan M Davis via Digitalmars-d-announce
On Tuesday, March 06, 2018 09:36:43 H. S. Teoh via Digitalmars-d-announce wrote: > Andrei has said before, and probably on more than one occasion, that if > he were to redesign ranges today, one of the things he would do > differently was to change the definition of forward range so that .save >

Re: Article: Why Const Sucks

2018-03-06 Thread H. S. Teoh via Digitalmars-d-announce
On Mon, Mar 05, 2018 at 10:21:47PM -0500, Nick Sabalausky (Abscissa) via Digitalmars-d-announce wrote: > On 03/05/2018 12:38 PM, H. S. Teoh wrote: > > > > This broke the by-value assumption inherent in much of Phobos code, > > Wait, seriously? Phobos frequently passes ranges by value? I

Re: Article: Why Const Sucks

2018-03-06 Thread H. S. Teoh via Digitalmars-d-announce
On Tue, Mar 06, 2018 at 08:39:41AM -0700, Jonathan M Davis via Digitalmars-d-announce wrote: [...] > Yeah. If you're dealing with generic code rather than a specific range > type that you know is implicitly saved when copied, you have to use > save so often that it's painful, and almost no one

Re: Article: Why Const Sucks

2018-03-06 Thread jmh530 via Digitalmars-d-announce
On Tuesday, 6 March 2018 at 15:39:41 UTC, Jonathan M Davis wrote: [snip] How well Phobos has done with this has improved over time as more and better testing has been added (testing for reference type ranges is probably the most critical to finding this particular problem), but I doubt that

Re: Article: Why Const Sucks

2018-03-06 Thread Jonathan M Davis via Digitalmars-d-announce
On Tuesday, March 06, 2018 15:23:52 Adam D. Ruppe via Digitalmars-d-announce wrote: > On Tuesday, 6 March 2018 at 03:21:47 UTC, Nick Sabalausky > > (Abscissa) wrote: > > Wait, seriously? Phobos frequently passes ranges by value? > > You *should* pass most ranges by value, just like how you should

Re: Article: Why Const Sucks

2018-03-06 Thread Adam D. Ruppe via Digitalmars-d-announce
On Tuesday, 6 March 2018 at 03:21:47 UTC, Nick Sabalausky (Abscissa) wrote: Wait, seriously? Phobos frequently passes ranges by value? You *should* pass most ranges by value, just like how you should rarely use `ref T[]` or `T[]*`. Ranges, like slices, are typically already small references

Re: Article: Why Const Sucks

2018-03-06 Thread Meta via Digitalmars-d-announce
On Tuesday, 6 March 2018 at 10:02:10 UTC, Radu wrote: On Monday, 5 March 2018 at 10:57:35 UTC, Jonathan M Davis wrote: Here's something I wrote up on const: http://jmdavisprog.com/articles/why-const-sucks.html I suppose that it's not exactly the most positive article, but I feel that it's

Re: Article: Why Const Sucks

2018-03-06 Thread Dukc via Digitalmars-d-announce
On Tuesday, 6 March 2018 at 12:05:26 UTC, Dukc wrote: I think we have a bug here. I believe postblits should behave like constructors in both events. https://issues.dlang.org/show_bug.cgi?id=18561

Re: Article: Why Const Sucks

2018-03-06 Thread Steven Schveighoffer via Digitalmars-d-announce
On 3/6/18 1:49 AM, Jonathan M Davis wrote: Regardless, I doubt that the design of ranges is going to be changed at this point given the amount of code that would break as a result, and these sort of changes are not backwards compatible. I sometimes think we would be better off to drop

Re: Article: Why Const Sucks

2018-03-06 Thread Dukc via Digitalmars-d-announce
On Tuesday, 6 March 2018 at 11:03:24 UTC, Nemanja Boric wrote: title = title.dup;// doesn't work anymore Strange! You're right it does not when the type declares a member as const, yet: On Monday, 5 March 2018 at 10:57:35 UTC, Jonathan M Davis wrote (in the article): And if an

Re: Article: Why Const Sucks

2018-03-06 Thread Nemanja Boric via Digitalmars-d-announce
On Tuesday, 6 March 2018 at 10:49:48 UTC, Dukc wrote: On Monday, 5 March 2018 at 10:57:35 UTC, Jonathan M Davis wrote (in the article): The problem is that the entire object must be fully initialized before the body of the postblit constructor is run. That means that any member variables which

Re: Article: Why Const Sucks

2018-03-06 Thread Dukc via Digitalmars-d-announce
On Monday, 5 March 2018 at 10:57:35 UTC, Jonathan M Davis wrote (in the article): The problem is that the entire object must be fully initialized before the body of the postblit constructor is run. That means that any member variables which are const or immutable are stuck at whatever they

Re: Article: Why Const Sucks

2018-03-06 Thread Radu via Digitalmars-d-announce
On Monday, 5 March 2018 at 10:57:35 UTC, Jonathan M Davis wrote: Here's something I wrote up on const: http://jmdavisprog.com/articles/why-const-sucks.html I suppose that it's not exactly the most positive article, but I feel that it's accurate. - Jonathan M Davis Spot on article, and

Re: Article: Why Const Sucks

2018-03-06 Thread Guillaume Piolat via Digitalmars-d-announce
On Monday, 5 March 2018 at 13:59:02 UTC, Adam D. Ruppe wrote: On Monday, 5 March 2018 at 10:57:35 UTC, Jonathan M Davis wrote: Here's something I wrote up on const: And then, of course, like you said "don't use it" is the solution to most of the const system's flaws anyway which seems

Re: Article: Why Const Sucks

2018-03-06 Thread aberba via Digitalmars-d-announce
On Monday, 5 March 2018 at 10:57:35 UTC, Jonathan M Davis wrote: Here's something I wrote up on const: http://jmdavisprog.com/articles/why-const-sucks.html I suppose that it's not exactly the most positive article, but I feel that it's accurate. - Jonathan M Davis Its amazing how typed

Re: Article: Why Const Sucks

2018-03-05 Thread Jonathan M Davis via Digitalmars-d-announce
On Monday, March 05, 2018 22:21:47 Nick Sabalausky via Digitalmars-d- announce wrote: > On 03/05/2018 12:38 PM, H. S. Teoh wrote: > > This broke the by-value > > assumption inherent in much of Phobos code, > > Wait, seriously? Phobos frequently passes ranges by value? I sincerely > hope that's

Re: Article: Why Const Sucks

2018-03-05 Thread Nick Sabalausky (Abscissa) via Digitalmars-d-announce
On 03/05/2018 12:38 PM, H. S. Teoh wrote: This broke the by-value assumption inherent in much of Phobos code, Wait, seriously? Phobos frequently passes ranges by value? I sincerely hope that's only true for class-based ranges and forward-ranges (and more specifically, only forward ranges

Re: Article: Why Const Sucks

2018-03-05 Thread Arun Chandrasekaran via Digitalmars-d-announce
On Monday, 5 March 2018 at 13:48:23 UTC, Adam D. Ruppe wrote: Just a semantic note, it is "straitjacket". "straight" is like a non-wiggly line. "strait" means narrow or constricted. Thus, the straitjacket is a jacket that constricts your movement. Of course, using "straight" is such a common

Re: Article: Why Const Sucks

2018-03-05 Thread Me via Digitalmars-d-announce
On Monday, 5 March 2018 at 13:48:23 UTC, Adam D. Ruppe wrote: Just a semantic note, it is "straitjacket". "straight" is like a non-wiggly line. "strait" means narrow or constricted. Thus, the straitjacket is a jacket that constricts your movement. Of course, using "straight" is such a common

Re: Article: Why Const Sucks

2018-03-05 Thread Me via Digitalmars-d-announce
On Monday, 5 March 2018 at 13:48:23 UTC, Adam D. Ruppe wrote: Just a semantic note, it is "straitjacket". "straight" is like a non-wiggly line. "strait" means narrow or constricted. Thus, the straitjacket is a jacket that constricts your movement. Of course, using "straight" is such a common

Re: Article: Why Const Sucks

2018-03-05 Thread H. S. Teoh via Digitalmars-d-announce
On Mon, Mar 05, 2018 at 11:04:49AM -0700, Jonathan M Davis via Digitalmars-d-announce wrote: > On Monday, March 05, 2018 09:38:52 H. S. Teoh via Digitalmars-d-announce > wrote: > > Eventually, I discovered that the underlying problem was that > > Result, as defined above, was a struct with a

Re: Article: Why Const Sucks

2018-03-05 Thread Jonathan M Davis via Digitalmars-d-announce
On Monday, March 05, 2018 09:38:52 H. S. Teoh via Digitalmars-d-announce wrote: > Eventually, I discovered > that the underlying problem was that Result, as defined above, was a > struct with a const member, and therefore it was illegal to assign it to > a variable of the same type outside of

Re: Article: Why Const Sucks

2018-03-05 Thread Jonathan M Davis via Digitalmars-d-announce
On Monday, March 05, 2018 17:35:28 ShadoLight via Digitalmars-d-announce wrote: > Very interesting and well written! Jonathan, your experiences > with const in C++/Java just about matches my experiences with it. > I also feel that the situation in D is less than ideal in this > regard. > > First,

Re: Article: Why Const Sucks

2018-03-05 Thread ShadoLight via Digitalmars-d-announce
Very interesting and well written! Jonathan, your experiences with const in C++/Java just about matches my experiences with it. I also feel that the situation in D is less than ideal in this regard. First, a small (for sure copy-pasta) typo in your article: const(int[]) arr1 = getArray();

Re: Article: Why Const Sucks

2018-03-05 Thread H. S. Teoh via Digitalmars-d-announce
On Mon, Mar 05, 2018 at 03:57:35AM -0700, Jonathan M Davis via Digitalmars-d-announce wrote: > Here's something I wrote up on const: > > http://jmdavisprog.com/articles/why-const-sucks.html > > I suppose that it's not exactly the most positive article, but I feel > that it's accurate. [...]

Re: Article: Why Const Sucks

2018-03-05 Thread joe via Digitalmars-d-announce
On Monday, 5 March 2018 at 10:57:35 UTC, Jonathan M Davis wrote: Here's something I wrote up on const: http://jmdavisprog.com/articles/why-const-sucks.html I suppose that it's not exactly the most positive article, but I feel that it's accurate. - Jonathan M Davis Interesting read and it

Re: Article: Why Const Sucks

2018-03-05 Thread bauss via Digitalmars-d-announce
On Monday, 5 March 2018 at 10:57:35 UTC, Jonathan M Davis wrote: Here's something I wrote up on const: http://jmdavisprog.com/articles/why-const-sucks.html I suppose that it's not exactly the most positive article, but I feel that it's accurate. - Jonathan M Davis Great read for a Monday.

Re: Article: Why Const Sucks

2018-03-05 Thread Adam D. Ruppe via Digitalmars-d-announce
On Monday, 5 March 2018 at 10:57:35 UTC, Jonathan M Davis wrote: Here's something I wrote up on const: So as to the main thrust, I generally agree. In fact, I think const is almost useless even if you want to use it fully: you said immutable is better in many places, and yes, but in

Re: Article: Why Const Sucks

2018-03-05 Thread SimonN via Digitalmars-d-announce
On Monday, 5 March 2018 at 10:57:35 UTC, Jonathan M Davis wrote: Here's something I wrote up on const: Excellent read! I enjoyed the history of proposed solutions. I've run into the trouble with annotated opEquals in classes several times. I believe an empty/nonexistant Object class is the

Re: Article: Why Const Sucks

2018-03-05 Thread Jonathan M Davis via Digitalmars-d-announce
On Monday, March 05, 2018 11:38:05 Atila Neves via Digitalmars-d-announce wrote: > I used to use `immutable`, but gradually came around to only > using it if I have to send data to another thread, otherwise it's > too much of a hassle. Aside from the whole std.concurrency situation, I generally

Re: Article: Why Const Sucks

2018-03-05 Thread Dejan Lekic via Digitalmars-d-announce
On Monday, 5 March 2018 at 10:57:35 UTC, Jonathan M Davis wrote: Here's something I wrote up on const: http://jmdavisprog.com/articles/why-const-sucks.html I suppose that it's not exactly the most positive article, but I feel that it's accurate. - Jonathan M Davis Brilliant article,

Re: Article: Why Const Sucks

2018-03-05 Thread Atila Neves via Digitalmars-d-announce
On Monday, 5 March 2018 at 10:57:35 UTC, Jonathan M Davis wrote: Here's something I wrote up on const: http://jmdavisprog.com/articles/why-const-sucks.html I suppose that it's not exactly the most positive article, but I feel that it's accurate. - Jonathan M Davis My biggest issues with

Article: Why Const Sucks

2018-03-05 Thread Jonathan M Davis via Digitalmars-d-announce
Here's something I wrote up on const: http://jmdavisprog.com/articles/why-const-sucks.html I suppose that it's not exactly the most positive article, but I feel that it's accurate. - Jonathan M Davis