You are a stupid programmer, you can't have that

Dukc ajieskola at gmail.com
Sat Aug 7 13:05:33 UTC 2021


On Saturday, 7 August 2021 at 12:15:15 UTC, IGotD- wrote:
> The question is, do you think language designers go to far when 
> trying to "save" programmers from misuse or not?
> Do you think there can be approaches that both prevent bugs at 
> the same time do not limit the language?

I think that a tool should not prevent unrecommended uses 
completely, but it should make them harder so it won't be done by 
mistake or because it's easier than the right way. Well, that's 
my standard philosophy to this issue anyway, but perhaps there 
are cases where that approach is too idealistic. But IMO it's 
what D usually does. Examples:

String mixins. They can be used to do anything the C preprocessor 
can do (and more!), but the syntax is ugly so it's nicer to use 
normal templates, manifest constants, aliases or at least 
template mixins when they can do the job.

`version` declarations. They do not allow expressions in them, 
but if one really needs expressions, `static if` will work around 
the problem.

Default initialization. The shortest syntax will not introduce 
heisenbugs, but if performance is really that important there's 
still `=void`.

Floats default initialized to NaN instead of 0. One can still 
initialize them to anything, but this forces to think about it.


More information about the Digitalmars-d mailing list