More constants in std.string?

simendsjo simen.endsjo at pandavre.com
Mon Aug 9 18:21:21 PDT 2010


On 10.08.2010 03:15, Jonathan M Davis wrote:
> On Monday, August 09, 2010 18:00:44 simendsjo wrote:
>> I agree. I really don't thing it makes a difference or not.. '\r' is
>> always that symbol no matter if it's a iPhone, embedded device or
>> supercomputer. It's more that it's more error prone to write it than CR
>> (ooops! compiler error!). If I wrote '\e' in a large switch and haven't
>> tested all code paths.. Yes, shame on me, but I really meant \r! A
>> constant gives me an at once. D is all about removing common, stupid
>> programmer errors like I do, right? :)
>>
>> It's just nitpicking and not a big deal at all. I can only remember once
>> I've been bitten by one of these (not in D), but I quickly found the
>> source.
>
> You might be less likely to mistype CR as something valid, but the compiler
> won't care whether you write CR or "\e". It's just going to replace CR with "\r"
> everywhere anyway. You can only do so much to save the programmer from their own
> stupidity and carelessness. Using constants as an attempt to reduce typos is not
> a good move IMHO. The language itself does try and reduce the opportunity for
> stupid programming errors, but it doesn't protect against everything, and I
> think that it's generally only in the cases where it's obviously a benefit that
> it actually tries to protect you from yourself.
>
> - Jonathan M Davis

Yeah, I know. I'm really just pointing out very small things here as I 
try to learn the language and library. Still.. I do think that static 
checking is a very good way of eliminating many common bugs. This might 
have been a bad example. I've coded several non-trivial applications in 
scripting languages, and more often than not, I _know_ what kind of 
objects my functions accepts... Why a runtime error when you can have a 
compile time error?


More information about the Digitalmars-d-learn mailing list