Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> Introduce intermediate variables with meaningful names

Abstracting chunks of compound conditionals into easy-to-read variables is one of my favorite techniques. Underrated.

> isValid = val > someConstant

> isAllowed = condition2 || condition3

> isSecure = condition4 && !condition5

> if isValid && isAllowed && isSecure { //...



I treat it a lot like english. Run-on sentences, too much technical jargon, and too many fragmented short sentences all make it harder to read. There's analogies to writing code.


> Abstracting chunks of compound conditionals into easy-to-read variables is one of my favorite techniques. Underrated.

Same. Or alternatively I will just put the English version in comments above each portion of the conditional, makes it easy to read and understand.


So you like procedural code.

I mean, at least western people seem to think in recipes, todo lists, or numbered instructions. Which is what procedural code is.

Dogma will chop up those blocks into sometimes a dozen functions, and that's in stuff like Java, functional is even worse for "function misdirection / short term memory overload".

I don't really mind the hundred line method if that thing is doing the real meat of the work. I find stepping through code to be helpful, and those types of methods/functions/code are easy to track. Lots of functions? You have to set breakpoints or step into the functions, and who knows if you are stepping into a library function or a code-relevant function.

Of course a thousand line method may be a bit much too, but the dogma for a long time was "more than ten lines? subdivide into more functions" which was always weird to me.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: