Is there any real reason to use "const"?

Patrick Schluter Patrick.Schluter at bbox.fr
Mon Jan 24 20:31:36 UTC 2022


On Monday, 24 January 2022 at 17:30:26 UTC, Ali Çehreli wrote:
> On 1/24/22 04:31, Dennis wrote:
>
> > I never understood the idea of people always including {}
> braces in
> > if-statements and for-loops.
> [...]
> > What idiot would write something like that,
>
> Yeah, that thought disappears once one realizes that humans are 
> mistake-making machines. :)
>
> > One day I had a single-line for-loop
> > body, and to fix an error I quickly added an `import`
> statement above
> > it, pushing the for-loop body outside the for-loop scope.
> Oops.
>
> I've done its counterpart just two days ago by commenting out 
> one line (in somebody else's code):
>
>   foreach(i; 0..2)
>     // foo();
>
>   bar();
>
> Oops! Now bar() is executed multiple times.
>
> I am saddened with this skipped-braces "optimization" because 
> all that risk for just to skip writing two characters! Wow! 
> Now... that's... interesting... :) Humans are really 
> interesting...
>
Not really a problem in my experience (25 years of C + 5 years of 
D) it happened only a couple of times and it is quickly found 
when it happens. I'm an extremly minimalistic programmer, I avoid 
unecessary parenthesis and brackets whenever I can.




More information about the Digitalmars-d mailing list