вс, 1 авг. 2021 г., 14:22 Serhii Smirnov <free.smile...@gmail.com>:

> instead of defining constants like:
> const FOO = 'FOO';
>
> they could be defined like:
> autoconst FOO; // defines a constant FOO with the value 'FOO'


Sorry, but I'm not a fan of this proposal. Features should not be aiming at
minor savings of keystrokes at the expense of readability and
maintainability. Remember, we write code once but afterwards it might end
up being read hundreds of times. This proposal makes code less readable,
and unintuitively works differently from enums where cases without explicit
values don't default to anything.

Also, modifiers could be useful:
> autoconst uppercase foo; // defines a constant foo with value 'FOO'
> autoconst lowercase FOO; // defines a constant FOO with value 'foo';
>
> and maybe:
> autoconst camelcase FOO_BAR; // defines a constant FOO_BAR with value
> 'fooBar'
> autoconst snakecase fooBar; // defines a constant fooBar with value
> 'foo_bar'
>

This one saves even fewer keystrokes and harms maintainability even more:
imagine you're debugging your program and you've dumped some value. You see
"MyConstant". Now you search the code for the source of that value but find
nothing because instead of MyConstant there's only MY_CONSTANT.

>

Reply via email to