News for hackers. Stuff that matters.
Re:Size is the best predictor of code quality (2011) by stephc_int13 on Friday November 11, 2022 @08:02PM (#33568874)
The experiment should be pretty straightforward to test.

X lines of simple code containing a bug vs X lines of complex code also containing a bug.

How long does it take for average joe coder to find it in both cases? Is the experiment really needed?

Re:Size is the best predictor of code quality (2011) by TeMPOraL on Friday November 11, 2022 @08:31PM (#33569085)
It's not so easy. In my experience, most bugs that aren't extremely trivial are not obvious locally. A function, whether simple or complex, will look totally fine, but it's in fact buggy, because it violates the implied expectation of the caller, or makes the caller violate implied expectations of their caller, etc. Decoding a complex line of code isn't the hard part here - narrowing down the mismatched expectations and identifying where to apply the fix is.
Re:Size is the best predictor of code quality (2011) by nyanpasu64 on Saturday November 12, 2022 @12:26AM (#33570241)
Splitting code into functions isolates blocks of their context of what situations they are called in and what parameters are passed in. In my experience, Transcribing code into notes, where struct fields are inlined as indented blocks into their surrounding types, and function calls' interiors are inlined as indented blocks into their call sites, restores this context, places lines on-screen in the order they execute, and enables casual reasoning. (You still won't know data invariants without asking the original programmers, but you can guess and check at this point.) http://number-none.com/blow/john_carmack_on_inlined_code.htm... advocates for a style where code is inlined in the actual source code whenever possible.
Re:Size is the best predictor of code quality (2011) by TeMPOraL on Sunday November 13, 2022 @02:49AM (#33580947)
I'm heavily in favor of inlining over tiny little functions, and the transcribing you describe is something that should, IMO, be done automatically by your IDE, on the fly, as a different rendering mode. It's unfortunate that there's no such feature for any of the languages I know.
Re:Size is the best predictor of code quality (2011) by lmm on Sunday November 13, 2022 @05:30PM (#33588065)
I don't think that's a valid way of framing things, beacuse it's not like the amount of review time available is proportional to the number of lines of code.