Re: Best practices of using const

2019-06-22 Thread Bart via Digitalmars-d-learn
On Wednesday, 13 February 2019 at 16:40:18 UTC, H. S. Teoh wrote: So ironically, the iron-clad semantics of D's const system turns out to be also its own downfall. Such things are not ironic. There is always a trade off. You get nothing for free in this universe. Physics tells us this.

Re: Best practices of using const

2019-06-22 Thread Yatheendra via Digitalmars-d-learn
On Saturday, 22 June 2019 at 05:10:14 UTC, Yatheendra wrote: It feels disingenous to want to call a caching object even "logically" const. There has to be a scaffolding-based but hopefully generic compromise. I haven't yet tested this belief, but I believe "physical" const is of good use

Re: Best practices of using const

2019-06-21 Thread Yatheendra via Digitalmars-d-learn
It feels disingenous to want to call a caching object even "logically" const. There has to be a scaffolding-based but hopefully generic compromise. I haven't yet tested this belief, but I believe "physical" const is of good use wherever it can be applied. On Friday, 21 June 2019 at 23:39:20

Re: Best practices of using const

2019-06-21 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Jun 21, 2019 at 06:32:33PM +, Yatheendra via Digitalmars-d-learn wrote: [...] >struct CostlyComputeResult { > ... // data fields > // constructor takes compute results, no postblit >} > >struct Wrapper { > const (CostlyComputeResult) *cachee = 0; >

Re: Best practices of using const

2019-06-21 Thread Yatheendra via Digitalmars-d-learn
That is a comprehensive reply. No pointers to other material required :-) On Friday, 21 June 2019 at 16:35:50 UTC, H. S. Teoh wrote: On Fri, Jun 21, 2019 at 06:07:59AM +, Yatheendra via Digitalmars-d-learn wrote: Actually, optimizers work best when there is minimal mutation *in the

Re: Best practices of using const

2019-06-21 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Jun 21, 2019 at 06:07:59AM +, Yatheendra via Digitalmars-d-learn wrote: > Am I mistaken in saying that we are conflating: >"anything that is logically const should be declared const" No, not in D. D does not have logical const; it has "physical" const, which is a strict subset

Re: Best practices of using const

2019-06-21 Thread Yatheendra via Digitalmars-d-learn
Am I mistaken in saying that we are conflating: "anything that is logically const should be declared const" // makes perfect sense // e.g. the lowest 2, and some branches of the 3rd and 4th, levels // of members (and a subset of the overall methods) in a 5-deep type hierarchy are

Re: Best practices of using const

2019-02-20 Thread drug via Digitalmars-d-learn
On 20.02.2019 11:05, Kagamin wrote: On Tuesday, 19 February 2019 at 16:38:17 UTC, drug wrote: The same I can say about properties - for example I use them in meta programming to detect what to serialize/process - I skip methods but serialize properties and for me this is a nice language

Re: Best practices of using const

2019-02-20 Thread Kagamin via Digitalmars-d-learn
On Tuesday, 19 February 2019 at 16:38:17 UTC, drug wrote: The same I can say about properties - for example I use them in meta programming to detect what to serialize/process - I skip methods but serialize properties and for me this is a nice language feature. Serialization of arbitrary

Re: Best practices of using const

2019-02-19 Thread drug via Digitalmars-d-learn
On 19.02.2019 19:19, Kagamin wrote: On Tuesday, 19 February 2019 at 15:30:22 UTC, Atila Neves wrote: I keep hearing how const is nigh unusable in D, and except for ranges I litter my code with const everywhere, pretty much just as often as I used in C++. I once spent a good amount of effort

Re: Best practices of using const

2019-02-19 Thread Kagamin via Digitalmars-d-learn
On Tuesday, 19 February 2019 at 15:30:22 UTC, Atila Neves wrote: I keep hearing how const is nigh unusable in D, and except for ranges I litter my code with const everywhere, pretty much just as often as I used in C++. I once spent a good amount of effort to annotate my code with pure and

Re: Best practices of using const

2019-02-19 Thread Atila Neves via Digitalmars-d-learn
On Wednesday, 13 February 2019 at 16:40:18 UTC, H. S. Teoh wrote: On Wed, Feb 13, 2019 at 11:32:46AM +, envoid via Digitalmars-d-learn wrote: [...] Const in D is very restrictive because it's supposed to provide real compiler guarantees, i.e., it's statically verifiable that the data

Re: Best practices of using const

2019-02-17 Thread Marco de Wild via Digitalmars-d-learn
On Wednesday, 13 February 2019 at 16:40:18 UTC, H. S. Teoh wrote: On Wed, Feb 13, 2019 at 11:32:46AM +, envoid via Digitalmars-d-learn wrote: Unfortunately, that guarantee also excludes a lot of otherwise useful idioms, like objects that cache data -- a const object cannot cache data

Re: Best practices of using const

2019-02-14 Thread envoid via Digitalmars-d-learn
Thank you for such a comprehensive answer.

Re: Best practices of using const

2019-02-13 Thread psycha0s via Digitalmars-d-learn
On Wednesday, 13 February 2019 at 11:32:46 UTC, envoid wrote: Is there an article that explains best practices of using const in D? You can find some information here: https://dlang.org/articles/const-faq.html

Re: Best practices of using const

2019-02-13 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Feb 13, 2019 at 11:32:46AM +, envoid via Digitalmars-d-learn wrote: > In C++ we have const correctness in some way. A compiler can make > optimizations whenever it doesn't find a const_cast and the mutable > specifier marks members that aren't a part of the object state. Of > course,

Re: Best practices of using const

2019-02-13 Thread XavierAP via Digitalmars-d-learn
On Wednesday, 13 February 2019 at 11:32:46 UTC, envoid wrote: Is there an article that explains best practices of using const in D? Chapter 8 of Andrei Alexandrescu's book The D Programming Language.

Re: Best practices of using const

2019-02-13 Thread Alex via Digitalmars-d-learn
On Wednesday, 13 February 2019 at 11:32:46 UTC, envoid wrote: Is there an article that explains best practices of using const in D? http://jmdavisprog.com/articles/why-const-sucks.html

Re: Best practices of using const

2019-02-13 Thread Kagamin via Digitalmars-d-learn
D has immutable data, const allows to consume both mutable and immutable data.