More constants in std.string?
Jonathan M Davis
jmdavisprog at gmail.com
Mon Aug 9 18:15:46 PDT 2010
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
More information about the Digitalmars-d-learn
mailing list