What are (dis)advantages of using pure and immutable by default?

2015-09-07 Thread Bahman Movaqar via Digitalmars-d-learn
It seems to me a good practice to mark all functions that I write as `pure` and define all the variables as `immutable`, unless there is a reason not to. I can see some serious advantages of this, most notable of which is minimum side-effect and predictability of the code. However I suppose

Re: What are (dis)advantages of using pure and immutable by default?

2015-09-07 Thread anonymous via Digitalmars-d-learn
On Monday 07 September 2015 13:12, Bahman Movaqar wrote: > I was under the impression that when a variable, that is declared > as `immutable`, is passed to a function, a copy of the value is > passed. > > However based on "marks" I can imagine that since the data is > marked as `immutable`

Re: What are (dis)advantages of using pure and immutable by default?

2015-09-07 Thread Bahman Movaqar via Digitalmars-d-learn
On Monday, 7 September 2015 at 11:49:32 UTC, anonymous wrote: void f(int a) {} void g(int* a) {} void main() { int xm; immutable int xi; f(xm); /* ok, obviously */ f(xi); /* ok */ int* ym = immutable int* yi = g(ym); /* ok, obviously */ g(yi); /* doesn't

Re: What are (dis)advantages of using pure and immutable by default?

2015-09-07 Thread anonymous via Digitalmars-d-learn
On Monday 07 September 2015 12:40, Bahman Movaqar wrote: > It seems to me a good practice to mark all functions that I write > as `pure` and define all the variables as `immutable`, unless > there is a reason not to. I agree. > I can see some serious advantages of this, most notable of which

Re: What are (dis)advantages of using pure and immutable by default?

2015-09-07 Thread Bahman Movaqar via Digitalmars-d-learn
On Monday, 7 September 2015 at 10:55:13 UTC, anonymous wrote: On Monday 07 September 2015 12:40, Bahman Movaqar wrote: I can see some serious advantages of this, most notable of which is minimum side-effect and predictability of the code. However I suppose it's going to impact the performance