Is there any real reason to use "const"?

rempas rempas at tutanota.com
Mon Jan 24 17:38:45 UTC 2022


On Monday, 24 January 2022 at 17:30:26 UTC, Ali Çehreli wrote:
> Yeah, that thought disappears once one realizes that humans are 
> mistake-making machines. :)
>

Yeah, really working towards accepting that but I'm getting 
closer and closer each day...

> 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...
>
> Ali

Yeah, that's classic! Tbh, either force your users to use curly 
brackets or find a python like system that will not cause these 
types of errors. In my language this will be:

```
for i in 0..2:
  // foo()

bar()
```

Ending up having an empty "for" statement and executing "bar()" 
only once.


More information about the Digitalmars-d mailing list