Peter Marklund

Peter Marklund's Home

Fri Aug 08 2003 05:00:00 GMT+0000 (Coordinated Universal Time)

Linus on Coding Conventions

I was browsing Jeff Davis's homepage and came across Linus Torvald's coding conventions. I particularly like how Linus stresses the importance of keeping functions short and cohesive. I'll try to keep the following rule in mind when writing my own code:

Another measure of the function is the number of local variables. They shouldn't exceed 5-10, or you're doing something wrong. Re-think the function, and split it into smaller pieces. A human brain can generally easily keep track of about seven different things, anything more and it gets confused. You know you're brilliant, but maybe you'd like to understand what you did two weeks from now.