D2.0: an example of use-case for casting invariant away

James Dennett jdennett at acm.org
Sun Jun 24 17:40:10 PDT 2007


Jason House wrote:
> James Dennett wrote:
>> Jason House wrote:
>>> Don Clugston wrote:
>>>> int* d = cast(break const) b;
>>>>
>>>> IMHO, we want something that looks really nasty.
>>> Based on all the discussion in this thread, I like this alternative
>>> best.  I'd only insist that if someone did int *d = cast(int*) b; that
>>> the compiler would issue an error saying to use cast(break const)
>>> instead
>>
>> Interesting: my experience suggests that it shouldn't do so.
>> Those who know enough to use cast(break const) appropriately
>> will find out how to do so.  Others would just read the error
>> message and blindly do what it said, pausing only briefly to
>> wonder why the compiler issued an error message if it knew
>> exactly how to "fix" the code.  Far too many programmers'
>> first reaction to type warnings/errors is to add casts and
>> mask the problem rather than addressing root cause.
>>
>> -- James
> 
> ... And what about those programmers who know what they're doing but
> don't know the ins and outs of the language perfectly? 

They'll know what to do.  This isn't obscure; knowing how to
handle issues such as constness is basic to any language which
supports such a notion.  Programmers who "Know what they're
doing" know what they're doing.  They're just in the minority.

> Should they
> start scouring the documentation and news groups to find the proper fix?

Even if they didn't know, it shouldn't take much to find the
answer.  Typing the error message into Google would likely do
the job.

> IMHO, error messages should be as helpful as possible.  Besides giving a
> new syntax with "break const" embedded within it.  I don't think there's
> really anything else we can do to stop crazy programmers who'll do
> anything to get their code to function. 

You can't stop people writing bad code, but you can avoid
making the bad code easier to write than the good code in
many cases.

-- James



More information about the Digitalmars-d mailing list