Timeline for Single Line Statements & Good Practices
Current License: CC BY-SA 3.0
4 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Nov 17, 2022 at 12:30 | comment | added | Ciaran Gallagher | It's not easier to read something horizontally - we read code from top to bottom. It's common for developers to split the code window vertically when working on multiple files, which introduces an issue was developers are then forced to scroll horizontally in order to read a line of code. | |
| Jul 15, 2014 at 17:58 | comment | added | supercat | Further, if a small piece of a line changes, a "diff" will regard that as a change to the whole line. If the line should behave functionally as a unit, that would be a good thing. Otherwise, if a semantic operation is split among multiple lines, changes to some lines might affect the operation in ways which would not be apparent. | |
| Jul 15, 2014 at 17:54 | comment | added | supercat | Some of the "cons" may at times be pros. For example, suppose a piece of code has eight consecutive operations of the form if (x > maxX) {x=maxX; peggedAny = true;}. If each such operation will fit easily on a single line, I would rather have eight lines like that than dozens of lines which split out the statements. If such comparisons were used in enough places, four statements of the form peggedAny |= pegValueMinMax(ref x, minX, maxX); might be better, but someone reading that would have to read pegValueMinMax to see what it does. | |
| Aug 30, 2011 at 16:22 | history | answered | MaR | CC BY-SA 3.0 |