4 ms·
In my experience, it's the size of individual methods/functions that determine the number of bugs. >50 or 75 lines of code per routine greatly reduces its main
by codeslush 15y ago
In my experience, it's the size of individual methods/functions that determine the number of bugs. >50 or 75 lines of code per routine greatly reduces its maintainability and increases the number of bugs (often difficult bugs to track down).
- mrb 15y agoAt my school (Epita, France) our C coding style standard mandated that all functions be <= 25 lines. Even though some lines didn't count (like those containing a single curly brace), it was very tough, but always possible. This applied to all projects, small and large. They made us write mostly Unix apps, like an FTP server, a command-line NNTP client, a POSIX shell (I still remember how meticulous you had to be when reading all the man pages to implement process control and terminal control correctly!). Plus the code had to be portable across all 3 Unix OS running at the school: NetBSD, Solaris, Digital Unix. This was in 2000-2001. For example I just checked the FTP server I wrote for one of the assignments (I still have a copy): 3123 lines and all the functions are <= 25 lines of code. Such rigorousness definitely shaped the quality of the code I now write professionally, 10 years later...
- codeslush 15y agoThat's awesome! I'm guessing it fits within what I defined - you look at the starting line number and the ending line number for code points in a function and the number should be <50 to 75 LOC. That includes inline comments (noticeably not function definition comments). Code clarity should also be prevalent - meaning, nothing fancy! ;-) Don't cheat the system with single line if statements (for example). It's a really, really simple rule that works! People have argued with me, saying they needed more LOC for a routine, but not once has that proven to be true - at least not in the code I reviewed. And I'm, by far, not the sharpest tool in the shed. If I can do it, anyone can!
- mrb 15y agoOur coding standard was very strict. It was not possible to cheat and save lines by writing, eg: if (func()) a = 1; You had to write: if (func()) a = 1; Writing very complex C programs with functions <= 25 lines is definitely possible. All Epita students were routinely doing it!
- codeslush 15y agoI was thinking more along the lines of: if (func()) { a=1; } /* curly braces didn't count in your allocation of LOC, but they would in mine. */
- deleted 15y ago[deleted]