This blog has moved. Please update your bookmarks.

Code Defensively

If there's one single thing that new programmers should learn, as quickly as possible, it is to code defensively.

That means: Expect that things go wrong. Expect that things will fail, spectacularly, at random occasions. Expect to get garbage over the serial port. Expect random disconnects over the network. Expect programs to get access violations. Expect houses to burn down, presidents to get assassinated and large meteors to come crashing into the server hall.

Always think "what if I get garbage on the serial port". Never say "oh, that can't happen". Never append an input buffer with incoming data and then checking for STX in the first byte only.

So, here goes.


Your grandchildren will thank you for it.


Post a Comment

<< Home


Blog contents copyright © 2005 Mats Gefvert. All rights reserved.