News for hackers. Stuff that matters.
Re:Simple Ways of Reducing the Cognitive Load in Code by pimlottc on Tuesday June 28, 2016 @10:25AM (#11994026)
Using intermediate variables is one of the most underrated tools to make code more understandable. It's the definition of something completely unnecessary from a technical standpoint that is all about conveying meaning and clarity to other programmers. And it can be used to help group and "modularize" chunks of code within a routine without necessarily going to the extreme of pulling out a separate subroutine, which can be overkill in some circumstances.
Re:Simple Ways of Reducing the Cognitive Load in Code by jboy on Tuesday June 28, 2016 @11:15AM (#11994395)
Agreed about using intermediate variables.

What's better than comments to describe what the code does? CODE that describes what the code does. (Let the code describe WHAT the code does, and if necessary, the comments describe WHY the code does it like that.)

In C++, if I use an intermediate variable to decompose a complicated expression into easier-to-understand sub-expressions, I like to make the intermediate variable `const` to emphasize that it's an intermediate component.

Re:Simple Ways of Reducing the Cognitive Load in Code by amirouche on Tuesday June 28, 2016 @01:17PM (#11995550)
beautiful has it's value too. I prefer a code that creates paragraphs using an extra line break. A single comment can explain what each paragraph means. Reading (simply) a file is "open it, use it, close it", in my code it's three paragraph of code.
Re:Simple Ways of Reducing the Cognitive Load in Code by Chris2048 on Wednesday June 29, 2016 @08:41AM (#12001251)
I hear this a lot, often in the for "Good code doesn't need comments", but I'm more than a little skeptical of this view.

I need actual examples to get on board, and not just the usual "idiot" programmer strawmen - actual examples that aren't obviously unreasonable.

My main reason for skepticism - Full, proper English sentences are capable of a lot more nuance, and precise semantics than whatever the programming-language syntax might support. I agree code can be written with more clarity, but it cannot substitute actual text, i.e. Code is not documentation.

Re:Simple Ways of Reducing the Cognitive Load in Code by chimprich on Tuesday June 28, 2016 @12:11PM (#11994922)
I agree, intermediate variables are a highly underrated technique that can make code more understandable at a glance. What is annoying is that quite a few IDEs flag intermediate values that can be removed as a possible error, which probably discourages quite a few beginners from using them.
Re:Simple Ways of Reducing the Cognitive Load in Code by lmm on Tuesday June 28, 2016 @12:26PM (#11995075)
I think people underestimate the cost of vertical length. It's less obvious in small examples, but there's a huge difference in readability between a class or function that fits on one page and one that doesn't, so it's well worth making individual lines a bit less readable if it means you need less of them.
Re:Simple Ways of Reducing the Cognitive Load in Code by pyre on Tuesday June 28, 2016 @03:25PM (#11996735)
The question here is with is "a bit less readable"? Many people with run with that advice and start playing code golf on a production codebase.
Re:Simple Ways of Reducing the Cognitive Load in Code by amirouche on Tuesday June 28, 2016 @01:18PM (#11995564)
> so it's well worth making individual lines a bit less readable if it means you need less of them

What does it mean?

Re:Simple Ways of Reducing the Cognitive Load in Code by effie on Tuesday June 28, 2016 @03:29PM (#11996768)
Our teacher of programming told us something like this: if your program has so many lines it cannot fit on one screen, it contains at least one bug, so don't make them, keep them short. I try to make all projects made of small files, where each one can fit on one screen. Great for comprehensibility and productivity (less scrolling). Sometimes, a procedure gets longer than one screen, so what one needs to do is to put as much source as possible on a line, so that the entire thing fits into one screen.
Re:Simple Ways of Reducing the Cognitive Load in Code by lmm on Wednesday June 29, 2016 @04:14AM (#12000198)
Making individual lines a bit less readable is well worth it if making individual lines a bit less readable means you need less of them. ("Worth it" is a construct I don't really understand the grammar of - I'm a native English speaker)
Re:Simple Ways of Reducing the Cognitive Load in Code by zenojevski on Tuesday June 28, 2016 @03:40PM (#11996876)
Intermediate functions :)