"the older I get the more I am enjoying dumb verbose code, over fancy concise code" via @samsaffron
@codinghorror @samsaffron yes plz, totally agree -- let me use my brain cells for something other than decrypting your boolean expression masterpiece :)
@codinghorror @tjmahr @samsaffron The vast majority of software should be written with other software devs as the target audience -- not a computer.
@codinghorror @samsaffron I work on the fact that we read code dozens, if not hundreds, more times than we ever write it. So the focus is to write code that's easy to read first. Speed and size is secondary and only when absolutely essential.
@codinghorror @samsaffron Younglings need to understand that a code is written once and read hundreds of time. Hence we must "optimize" for reads.
@codinghorror @samsaffron I’ve been fighting for short-circuiting over nesting my whole career
@codinghorror @samsaffron I like how he stubbornly refuses to insert the last return statement because it's ruby after all
@codinghorror @samsaffron What language is this? I really like the way exiting early reads with the result defined first.
@codinghorror @samsaffron I tend to call this style "bookish". The logic is lined up for easy scanning. You can also easily tell the order of eval. first example had you jumping back and forth to find matching (). adding a new line is super easy. exit early makes code look less like lisp ftw
@codinghorror @shanecelis @samsaffron The second one is horrible too.
@codinghorror @samsaffron I honestly don't understand why people write code like shown on the top. Its awful.
@codinghorror @rsms @samsaffron Is this python? That `return () if` syntax is pretty elegant.
@codinghorror @samsaffron I agree with the idea, but I would say the clarity comes mostly from the ordering of the conditionals and the fact that it is a conjunction of disjunctions, not the use of early returns per se. In other words, this is still readable:
@codinghorror @samsaffron return early is always easy to read
@codinghorror @samsaffron @andrzejkrzywda You will like this one
@codinghorror @samsaffron The first CTO I worked for had a rule of one return statement per function. And his were not small functions. I knew it was dumb even back then. Simplicity and clarity > "cleverness" every single time.
@codinghorror @samsaffron just call it something fancy like "expedited exist theroem" or "guard clause" and then everyone will accept it. #marketing
@codinghorror @samsaffron I wouldn't call the bottom code "dumb". Obviously, the person is familiar with concept of "gurads", for instance. This is more "high level" concept.
@codinghorror @samsaffron I'm not sure if you didn't add so much negated logic if it wouldn't be more clear.
@codinghorror @samsaffron Were these meant to be the same? They accept much different conditions.
@codinghorror @samsaffron Both is barely understandable. If you have conditions that complex, modulize the logic.
@codinghorror @ValentinHervieu @samsaffron “Any fool can write code that a computer can understand. Good programmers write code that humans can understand.”
@codinghorror @samsaffron Old boring code with lots of comments and one statement per line of code gets things done!
@codinghorror @samsaffron The problem there is mixed levels of abstraction. If those tests have meaning at that level, they need good names and an appropriate place in the namespace
@codinghorror @samsaffron Agreed. I'm all for Readability > concise
@codinghorror @samsaffron It's the "old developer" in me that decided to collect my thoughts on how we can name things better too: namingthings.donedone.com
@codinghorror @samsaffron I think the second one is more readable and easiest to write tests by far, but I'm listening Sonarqube crying because of the multiple return statements.
@codinghorror @samsaffron I like to write dumb, concise code def can_accept_answer?(topic, post) return true # sure, why not? 🤷♂️ end
@codinghorror @samsaffron Early returns are just faster
@codinghorror @samsaffron Whowever wrote the tip part is either showing off, a total noob or just dumb in my book.
@codinghorror @KFMolli @samsaffron As long as you wrote proper tests for all the cases, I'll write those first since is you code documentation. Then...how you wrote the code...I don't really care. But still, there is a correlation between lines of code and bugs so I'd still suggest you to go with version 1.
@codinghorror @dreamquest @samsaffron With age comes wisdom
@codinghorror @samsaffron Agreed. If the job allows it, my main priorities are readability, maintainability, and testability. Everything else tends to just happen if these are in place.