Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are some functions extremely long? (ideas needed for an academic research!) [closed]

I am writing a small academic research project about extremely long functions. Obviously, I am not looking for examples for bad programming, but for examples of 100, 200 and 600 lines long functions which makes sense.

I will be investigating the Linux kernel source using a script written for a Master's degree written in the Hebrew University, which measures different parameters like number of lines of code, function complexity (measured by MCC) and other goodies. By the way, It's a neat study about code analysis, and a recommended reading material.

I am interested if you can think of any good reason why any function should be exceptionally long? I'll be looking into C, but examples and arguments from any language would be of great use.

like image 504
Adam Matan Avatar asked Jul 14 '09 19:07

Adam Matan


2 Answers

I may catch flak for this, but readability. A highly serial, but independent execution that could be broken up into N function calls (of functions that are used nowhere else) doesn't really benefit from decomposition. Unless you count meeting an arbitrary maximum on function length as a benefit.

I'd rather scroll through N function sized blocks of code in order than navigate the whole file, hitting N functions.

like image 146
patros Avatar answered Oct 12 '22 06:10

patros


Lots of values in a switch statement?

like image 33
smcameron Avatar answered Oct 12 '22 04:10

smcameron