News for hackers. Stuff that matters.
Re:Simple Code, High Performance [video] by werner1886 on Saturday October 30, 2021 @03:49AM (#29046889)
He measures code 'simplicity' by how much work it makes CPU do, and not some made up metric like 'readability'.
Re:Simple Code, High Performance [video] by philosopher1234 on Saturday October 30, 2021 @04:18AM (#29047029)
How exactly is readability made up?
Re:Simple Code, High Performance [video] by matiasmolinari on Saturday October 30, 2021 @05:04AM (#29047237)
This is a good question to ask, if not rhetorical.

When practicing rigorous measuring, quantities need to be quantifiable aspects of the world. For example, you can quantify how much physical space your code or compiled output takes up in memory, and use these quantities as base units to derive others. By branching from a quantifiable root, you can derive metrics such as lines of code or number of CPU instructions, and they’d still retain those quantifiable aspects. Meaning there’s a clear path to the quantifiable root.

Needless to say, readability, as a metric, is not branched from quantifiable aspects of the world. So in a sense, it is still a “made up” metric because (as of today), there’s no way to trace it down to the quantifiable measurements.

Re:Simple Code, High Performance [video] by Zababa on Saturday October 30, 2021 @11:37AM (#29049615)
> Needless to say, readability, as a metric, is not branched from quantifiable aspects of the world. So in a sense, it is still a “made up” metric because (as of today), there’s no way to trace it down to the quantifiable measurements.

It is, actually. "Readability" for me means "how long it takes to someone that didn't write the code to be able to understand it, make changes, add features". It's a more fuzzy metric of course, as anything involving humans is, but that's also usually the kind of metrics that matters a lot.

That also means that it's not a binary readable/non-readable thing. A way of measuring "readability" could be: assuming all other variables are equal, what percentage of the new hires are able to add new features after 1 month?

Re:Simple Code, High Performance [video] by meheleventyone on Saturday October 30, 2021 @05:42AM (#29047394)
I’d note that because something is hard to measure doesn’t make it “made-up” or unimportant. And that concentrating on things that are easy to measure doesn’t make them more important and in fact can bias things badly.
Re:Simple Code, High Performance [video] by dsego on Saturday October 30, 2021 @07:39AM (#29048000)
I think the poster is using the term “made-up” in a stricter sense to categorize it, not just to be dismissive.
Re:Simple Code, High Performance [video] by MikeDelta on Saturday October 30, 2021 @07:06AM (#29047843)
Readability can be quantified and it done by static code analyzers into a metric known as cognitive complexity [0], which measures things like amount of branches in your function. The thing is, you can make code of low complexity but still hard to read.

[0] https://tomasvotruba.com/blog/2018/05/21/is-your-code-readab...

Re:Simple Code, High Performance [video] by ratww on Sunday October 31, 2021 @04:20AM (#29055387)
Cyclomatic complexity is a good metric for local readability, but for considering the readability and ease of modification of whole programs or even for single files, it's far from good enough.

For an extreme example: you can turn all the methods of a complex program into one-liners, and all your classes into one-method classes. But doing that will definitely make your program harder to read.

Re:Simple Code, High Performance [video] by matiasmolinari on Saturday October 30, 2021 @02:24PM (#29051101)
Sure. You can trace branches to quantifiable roots, but you can’t trace readability. To me, readability means something different than what it means to the author of that article.
Re:Simple Code, High Performance [video] by RedShift1 on Saturday October 30, 2021 @04:57AM (#29047197)
Simple example: I love the ternary operator and use it quite a lot in simple "if/then" scenarios. However some people hate them because they consider them harder to read than the fully written out if/then form. Those people would judge my code less readable.
Re:Simple Code, High Performance [video] by dsego on Saturday October 30, 2021 @07:44AM (#29048022)
Ternary operators are better for expressions, which yield a result, since you don't have to declare or initialize a variable with a dummy value first. If/else is better for general branching. Using ternary without assigning or passing the expression would imho be misleading. I've seen ternaries used for branching and it's a smell imho, they're not really meant for that use case.
Re:Simple Code, High Performance [video] by flohofwoe on Saturday October 30, 2021 @06:09AM (#29047532)
Code readability is at least extremely subjective, one person's highly readable code is another person's incomprehensible mess.
Re:Simple Code, High Performance [video] by generichuman on Saturday October 30, 2021 @04:59AM (#29047208)
It is not made up but different people can have different opinions on what's readable and what's not.

If the metric is supposed to be objective, then number of CPU cycles used is probably the simplest metric there is for computers.

Re:Simple Code, High Performance [video] by meheleventyone on Saturday October 30, 2021 @05:56AM (#29047458)
Right it’s a communication problem because calling code simple conjures different ideas in people heads. Code that is simple for computers (principle of least work) is not necessarily simple (principle of comprehension?) for humans.
Re:Simple Code, High Performance [video] by flohofwoe on Saturday October 30, 2021 @06:15AM (#29047559)
There is a high overlap though, it's often harder to understand how highly abstracted code actually works than 'unrolled' verbose code composed from simple operations (which is closer to machine code - thus the 'overlap').

It might be easier to understand the 'intent' of highly abstracted code, but this doesn't mean the code behaves as intended, and IMHO 'readability' is about understanding what the code actually does, not what it is supposed to do.

Re:Simple Code, High Performance [video] by meheleventyone on Saturday October 30, 2021 @08:14AM (#29048185)
I think all these things are aspects that are interrelated. A principle of abstraction is another good one. Others I can think of are principle of least surprise and principle of least work done by the compiler (lol “zero cost” abstractions).
Re:Simple Code, High Performance [video] by werner1886 on Saturday October 30, 2021 @04:38AM (#29047123)
We might be thinking about different things here, so let me first ask this: What do you want to measure?
Re:Simple Code, High Performance [video] by bruce343434 on Saturday October 30, 2021 @06:33AM (#29047652)
How can you objectively quantify it?