News for hackers. Stuff that matters.
Re:John Carmack on Inlined Code (2014) by scarface74 on Tuesday January 22, 2019 @01:37AM (#18966432)
Even with using a switch statement, how would it be less readable to put each part of the statement in a function?
Re:John Carmack on Inlined Code (2014) by iainmerrick on Tuesday January 22, 2019 @04:01AM (#18967008)
Imagine there are two or three key variables, and a bunch of repeated blocks of code that modify some or all of the variables. (That sounds messy but it’s the kind of thing that could easily come up in an embedded controller.)

If you turn all those code blocks into functions, it’s no longer easy to visually inspect the code to see all the places where variable X is modified. It might not be a net win for readibility.

Personally, I wouldn’t define a function purely to contain a repeated block of code; I only do it if the code is related, i.e. all operating on the same data.

In my first example, before trying to wrap things in functions, I’d try to figure out if some of those variables can be tied together into a single object with a nice clear interface.

Re:John Carmack on Inlined Code (2014) by scarface74 on Tuesday January 22, 2019 @10:31AM (#18968930)
If you turn all those code blocks into functions, it’s no longer easy to visually inspect the code to see all the places where variable X is modified. It might not be a net win for readibility.

This goes back to not modifying global (or class global) variables and using a functional style. If you need to pass four or five variables put them in your languages equivalent of a pass by value struct.

In the case of my favorite IDE, Extract Method and creating a struct/class from a parameter list is an automated, guaranteed safe refactor.

Re:John Carmack on Inlined Code (2014) by maxxxxx on Tuesday January 22, 2019 @09:05AM (#18968285)
Good explanation. Thanks?