Click here to Skip to main content
16,018,318 members

Survey Results

What most improves the readability of source code?   [Edit]

Survey period: 24 Mar 2008 to 31 Mar 2008

Reviewing or even learning someone else's code can be hard work. What's the best way to make code easily approachable for someone else?

OptionVotes% 
Obvious and intuitive names for variables, classes and methods64238.31
Clear and useful comments29417.54
Wise use of Whitespace945.61
Correct Spelling and grammar60.36
Limits on file, class and method sizes281.67
Clear and concise code logic and structure39323.45
The use of common coding patterns and practices1649.79

View optional text answers (58 answers)


 
GeneralHard to pick just one PinPopular
PIEBALDconsult24-Mar-08 7:33
mvePIEBALDconsult24-Mar-08 7:33 
GeneralRe: Hard to pick just one Pin
Don Driskell24-Mar-08 9:31
Don Driskell24-Mar-08 9:31 
GeneralRe: Hard to pick just one Pin
PIEBALDconsult24-Mar-08 11:26
mvePIEBALDconsult24-Mar-08 11:26 
GeneralRe: Hard to pick just one Pin
Owen3725-Mar-08 7:58
Owen3725-Mar-08 7:58 
GeneralRe: Hard to pick just one Pin
squeek25-Mar-08 11:33
squeek25-Mar-08 11:33 
GeneralRe: Hard to pick just one Pin
PIEBALDconsult25-Mar-08 13:15
mvePIEBALDconsult25-Mar-08 13:15 
GeneralRe: Hard to pick just one Pin
Draugnar27-Mar-08 8:01
Draugnar27-Mar-08 8:01 
GeneralNarrative Pin
Shog924-Mar-08 7:16
sitebuilderShog924-Mar-08 7:16 
I've been thinking about this a lot lately while doing code reviews... The most readable code seems to use these three practices:
  1. Descriptive names for functions, objects, methods, variables... I'm not sure whether or not that falls under "obvious and intuitive"; depending on intuition always makes me rather nervous. IMHO, names for variables, complex objects and high-level methods should describe an intended purpose, while low-level functions and simple types should describe what they do / are: StringArray entryColumns rather than StringArray strings, LogFileWriter rather than CSVWithTimestampWriterLogFileWriter::FlushLog() rather than LogFileWriter::WriteUnsavedEntriesToDisk()SplitCSV() rather than ParseLogFileLineIntoColumns(), StringArray rather than ParsedLogEntryColumns...
  2. Short secondary branches within functions / methods. I don't have a problem with the odd 200-line function here and there, provided those 200 lines amount to a mundate description of a linear process. But when it involves numerous non-trivial branches, it becomes a headache. If there is no else to an if, then the body should be a separate function. If the <span style="font-weight: bold;"><span style="font-weight: bold;"></span></span>else amounts to "indicate an error and leave the function" or an implicit "get to the end of the function without doing anything", then the test should be reversed and the function should be exited as quickly as possible, allowing me to skip past failure/no-op modes when i want to read the code that actually accomplishes something, and avoid digging into the function's logic when i'm analyzing failure modes. Pendantic "one return per function" people should be taken out back and beaten with a sack of gotos. Wink | ;) And of course, if both branches are non-trivial, they should each be split into separate functions.
  3. Judicious use of "Why" comments. This has to be the most-preached, least-practiced recommendation i've ever encountered. The only thing worse than a confusing bit of code with no comments explaining why it is necessary is a confusing bit of code littered with comments describing things that are perfectly obvious from reading the code itself, but none explaining why it is necessary in the first place.




GeneralRe: Narrative Pin
PIEBALDconsult24-Mar-08 7:32
mvePIEBALDconsult24-Mar-08 7:32 
GeneralRe: Narrative Pin
Shog924-Mar-08 7:43
sitebuilderShog924-Mar-08 7:43 
GeneralRe: Narrative Pin
Gary Wheeler25-Mar-08 7:22
Gary Wheeler25-Mar-08 7:22 
GeneralRe: Narrative Pin
Shog925-Mar-08 7:29
sitebuilderShog925-Mar-08 7:29 
GeneralRe: Narrative Pin
Gary Wheeler25-Mar-08 7:36
Gary Wheeler25-Mar-08 7:36 
GeneralRe: Narrative Pin
firegryphon25-Mar-08 7:40
firegryphon25-Mar-08 7:40 
GeneralRe: Narrative Pin
Steve Echols24-Mar-08 10:52
Steve Echols24-Mar-08 10:52 
GeneralRe: Narrative Pin
Blake Miller24-Mar-08 11:54
Blake Miller24-Mar-08 11:54 
GeneralRe: Narrative Pin
Shog924-Mar-08 13:57
sitebuilderShog924-Mar-08 13:57 
GeneralRe: Narrative Pin
Chris Maunder24-Mar-08 19:44
cofounderChris Maunder24-Mar-08 19:44 
GeneralRe: Narrative Pin
Shog925-Mar-08 7:36
sitebuilderShog925-Mar-08 7:36 
GeneralRe: Narrative Pin
firegryphon25-Mar-08 7:48
firegryphon25-Mar-08 7:48 
GeneralRe: Narrative Pin
Tim Yen25-Mar-08 13:12
Tim Yen25-Mar-08 13:12 
GeneralA lost art: Clear and concise code logic and structure Pin
Nemanja Trifunovic24-Mar-08 3:57
Nemanja Trifunovic24-Mar-08 3:57 
GeneralRe: A lost art: Clear and concise code logic and structure Pin
Shog924-Mar-08 6:47
sitebuilderShog924-Mar-08 6:47 
GeneralRe: A lost art: Clear and concise code logic and structure Pin
Alan Balkany25-Mar-08 3:21
Alan Balkany25-Mar-08 3:21 
GeneralRe: A lost art: Clear and concise code logic and structure Pin
Shog925-Mar-08 7:37
sitebuilderShog925-Mar-08 7:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.