Over here, Kristian Dupont Knudsen gives his top ten pieces of programming advice which you shouldn’t follow.
I’m heartily in agreement with most, but there’s a couple I take issue with. I’ll say why here, lest I forget.
9) "Use unsigned integers for values that can only be positive"
Kristian thinks that people use unsigned because it makes them feel safer. Perhaps some people do that, but I use unsigned (where possible) for a different reason:
When I see signed types where the range of values which could be stored is really unsigned, I wonder in what circumstances a negative value could be encountered, or should be given. I then have to investigate.
3) "Be tolerant with input and strict with output"
I completely agree that this is at odds with the ‘fail fast’ principle, and that principle should generally win out, but there are circumstances where you really do want to be as tolerant with input as possible.
To give a concrete example: Some years ago I wrote an Internet radio playing application. When the user chooses a station, the program connects to a server and requests a stream. If the headers given by the server (or one to which the program is redirected) aren’t completely standard-compliant, the user doesn’t need to know. They just want to hear the radio station. There’s no point giving them a message box saying that the server is non-standards-compliant! In cases such as this, if it’s at all possible to continue, you should.
The web, too, being thanks to certain pathetic tools and lackadaisical publishers, requires some ‘give’. As Jeremy Hopkin says, “If you weren’t tolerant with input browsers would only show 1% of web pages”.