News for hackers. Stuff that matters.
Re:Understandability in software by dfabulich on Tuesday June 09, 2020 @07:35PM (#23472185)
This article would be significantly better if it suggested any way to measure the "understandability" of code.

Even just proposing standard language for a survey question, like Net Promoter Score, would help.

As of today, it seems inappropriate to call understandability a "metric." What's a metric that can't be measured?

Re:Understandability in software by Alex3917 on Tuesday June 09, 2020 @07:48PM (#23472278)
> if it suggested any way to measure the "understandability" of code.

There's no reason to measure it, just don't let people merge difficult-to-understand code into the codebase. The best comment you can leave on a PR is always, "I don't understand this, please rewrite it." People hate hearing it, they'd much prefer it if you'd show them some new trick or something, but that's not nearly as valuable to the company or whatever.

Re:Understandability in software by frankandstein on Tuesday June 09, 2020 @08:01PM (#23472393)
I’d be really annoyed if someone said “I don’t understand this” and immediately jumped to the conclusion of “rewrite it”.

It’s reasonable to assume there are times that complex problems require complex solutions. Saying “this code feels like it could be simpler, have you tried x?” would accomplish the same goal without the aggressive and lazy tone imo.

Re:Understandability in software by Alex3917 on Tuesday June 09, 2020 @08:12PM (#23472469)
I get your point. Obviously you shouldn't gratuitously be a dick to people, and I was being a little bit flippant with my phrasing. On the other hand, being able to understand the code is an extremely low bar, and if you're writing code that other people can't understand then at best it shows a lack of basic respect for your coworkers, and at worst it's a form of employee theft from your employer.

If you sent in an article to a magazine as a freelancer and the editors didn't understand what you were trying to say, then you probably wouldn't even get a response. And if you did it repeatedly they'd probably block your email address.

Obviously no one is going to immediately intuitively understand a 1,000 character regex. But I'm sure we've all seen people who have treated basic CRUD apps like obfuscated C competitions.

Re:Understandability in software by RcouF1uZ4gsC on Tuesday June 09, 2020 @08:03PM (#23472409)
> There's no reason to measure it, just don't let people merge difficult-to-understand code into the codebase.

The problem is that it ends up saying more about the maintainer than about understandability.

Is object oriented program hard to understand?

Is C with manual memory management hard to understand?

Are genetics hard to understand?

Is functional style programming hard to understand?

Is SIMD hard to understand?

Is code that uses linear algebra hard to understand?

Different people, and even the same person over time, will have different answers to these questions.

Re:Understandability in software by AnimalMuppet on Tuesday June 09, 2020 @08:06PM (#23472435)
All true. But given a team with some mix of backgrounds and talents, some code is going to be easier to understand than other code. Write the code the way that is easier for the team to understand. Write it for the team you have, not for posterity or to impress random people on message boards on the internet.
Re:Understandability in software by waheoo on Tuesday June 09, 2020 @08:17PM (#23472509)
Code complexity is a thing. It doesnt describe understandability but its a pretty decent proxy in my experience.

> In 1976, Thomas McCabe Snr proposed a metric for calculating code complexity, called Cyclomatic Complexity.

https://blog.codacy.com/an-in-depth-explanation-of-code-comp...

There is also likely some simple metrics you could get by looking at names of things alone.

Common substrings, length, and diversity of names are probably decent indicators.

Re:Understandability in software by flukus on Tuesday June 09, 2020 @09:36PM (#23472936)
Understandability here is more of an umbrella term for the system as a whole, cyclomatic complexity is generally only useful for much more isolated chunks of code. Reducing CC can also make the the system as a whole less understandable, moving an inner loop into it's own function for a simple example will reduce the cyclomatic complexity of the outer function yet the complexity hasn't really changed and now there is more indirection for the developer to deal with. It's a good tool for telling you how complicated a piece of code is, but generally there aren't many options to reduce it other than hacking the metric and making the system as a whole more complicated and less understandable.
Re:Understandability in software by waheoo on Tuesday June 09, 2020 @10:40PM (#23473338)
I wonder if there is any comprehension metrics we could use in its place, similar how you can measure reading comprehension levels of certain text?