by gorgoiler · 4y ago · 0 comments
Writing a computer program serves two separate purposes: to communicate a set of functions to the machine, but also to communicate the purpose of these functions to a human. The former is for execution and the latter is for code review and, later, debugging.
Any old clown can get a computer to do something approximating a solution to the problem at hand. If it has bugs then the author — or more likely some other poor sap down the line — will be on the hook to first understand the intent, and then make the code match the intent.
In a professional shop you will have code review where this “debugging” step happens first. Your reviewer will read your code to infer your intent and upon agreeing with that, check your style and composition for inconsistencies or lack of clarity.
To that extent, a large codebase is akin to a mathematical proof where each new module and function represents a lemma on which the final proof depends. No serious scientist would present their thesis without a progression of isolated and carefully laid out lemmas and corollaries, and no serious programmer throws up a thousand line function with 15 arguments, global state, and — if in a dynamic language like Python — inconsistent return types.
Your code is a proof to your reviewer that you are on the right track. The fact that it happens to execute without bugs and produces the correct output is far less important than the code being readable, comprehensible, and consistent as part of the larger system.
It's more important that a function looks good, than that it actually works?
I'm sorry, but that sounds stupid. A computer is a functioning machine first.
If it worked from the start, it wouldn't need to be fixed later.
You can always study someone's work to figure out how it works. There's no point studying a system that doesn't.
True. But you ignore the fact that NO SOFTWARE IS EVER DONE. Software always has bugs, and even if it didn't, it will bitrot as the business needs change.
In theory, it's better to have 100% working software. In practice, that never happens (or only happens for a few weeks at best). Eventually the software needs to be changed. In that case, software that is "written for humans" will always be easier to change than "software that used to work, but now we need to change it, but nobody understands it".
On that note, Zawinski's Law:
“Every program attempts to expand until it can read mail. Those programs which cannot so expand are replaced by ones which can.”
This is mostly true, but it does not have to be. :(
"Software is never rewritten. Projects last longer than expected; programmers get bored or burned out; management moves on the newer challenges. The attitude of ‘good enough’ reflects reality.
Instead of being rewritten, software has features added. And becomes more complex. So complex that no one dares change it, or improve it, for fear of unintended consequences. But adding to it seems relatively safe. We need dedicated programmers who commit their careers to single applications. Rewriting them over and over until they’re perfect. Such people will never exist. The world is too full of more interesting things to do.
The only hope is to abandon complex software. Embrace simple. Forget backward compatibility." - Chuck MooreI love this.
Software in practice needs to run to classify. Without that it's just a .txt file that won't compile.
Otherwise you're talking about a standard, a protocol, a document with no program. Instructions for humans how to program computers.
that is just false. I've seen plenty of one-use software - made specifically for trade shows, exhibitions, etc. which were never reused again because the entire software was the logic specific to that particuliar exhibition.
there is also a few thousand gigabytes of old game ROMs and abandonware on the internet which are all perfectly done software.
So yeah: code readability becomes the deciding factor for both what to accept: and what will be (most importantly) the most efficient use of development hours on fixing…
Or a better way of putting it… We are monkeys that bribed rocks and copper to think for us with electricity: design code and systems that even a monkey could maintain.
It is not stupid - just counter-intuitive, which should give us a pause to think. You say, "A computer is a functioning machine first" - yes - but consider why SICP says, "Programs are meant to be read by humans and only incidentally for computers to execute." (see a discussion on the quote https://news.ycombinator.com/item?id=16431701).
A silly thing to say while sitting at the top of the tower of abstraction, ignoring the fact that programs that actually work provide the foundation for the entire system.
Computer programs were originally intended for humans. Entire office buildings of humans with the job title "computer" would examine paper documents and carry out instructions therewithin.
Your linked quote talks about efficiency and style of code, which is a far cry from "execute without bugs and produce correct output" - an unavoidable necessity for a functioning computer.
Once the software is done, sure, throw away the source code entirely (if you dare).
I highly recommend reading the previous article to this one posted (Pragmatism in Programming Proverbs) to get a better understanding of what I am expressing, since "The Essence of Programming" is a sequel to that article. I originally wanted to write the previous article in normal prose article, regarding the topic of "Pragmatism in Programming", however I thought I’d experiment in style by writing in a proverbial style.
> The fact that it happens to execute without bugs and produces the correct output is far less important than the code being readable, comprehensible, and consistent as part of the larger system.
I partially disagree with this. If the code executes without bugs (very rare) and produces the correct output, then that code solves the problem. The next task is to make it readable, comprehensible, and easy to maintain whilst not trying to introduce other bugs.
I recommend reading Casey Muratori's article on "Semantic Compression" https://caseymuratori.com/blog_0015
This article is a good overview of the idea I am trying to express in this reply. It's very important to get things working BUT then actually improve it, don't just stop there!
a large codebase is akin to a mathematical proof iff you are using something like an lcf/λc environment; the curry-howard isomorphism does not yield meaningful programmer-level insights about the average monad transformer lens abomination implementing a rest api endpoint
mathematicians do not have to worry about dependency hell in their proofs, or whether they should be importing wiles's proof of fermat's last theorem at version 3.8.21-rc2 or -rc3
if i write a window manager, its source does not primarily function as some indication that i am on the right track to competently wrangling the x11 protocol, unless i am trying to impress a headhunter from red hat. it is, in fact, primarily meant to produce a program that competently wrangles the x11 protocol. making the code clean and sensible is akin to the courtesy demonstrated by not rendering the blueprints to an air conditioner in chicken scratch with a crayon, and ensuring that part sheets are easy to follow to the assembly
framing code as in the service of the reviewer or debugger takes what is a self-evident prerequisite for getting anywhere, and promotes it to a counterproductive mind game
“oh i'll break this function out into multiple that are called exactly once, even though all that does is make the reader scroll a bunch to follow the logic, because i know jeff is gonna get this one, and jeff is a cargo cultist who thinks robert martin is the second coming of christ”
> Any old clown can get a computer to do something approximating a solution to the problem at hand.
in my experience, far more clowns are capable foremost of endless bikeshedding -- they adore giving off the impression that they are contributing something to the effort, and in the absence of insight, they substitute a performance. “hah, bet you're glad you had me to tell you to write every item in this array on its own line” (the items in question are numbers averaging two digits)
yes, code is for human beings to read, but experience has made me wary of anyone who shows up to passionately insist to that effect
> Make it work, Make it right, Make it fast
Make it work, [take a break], Make it right, [push it for code review, gather feedback, make changes, push to master], Make it fast.
I looked for a reference just now and couldn't find one. This mentions it:
> Dijkstra was famous for his general rejection of personal computers. Instead of typing papers out using a word processor, he printed everything in longhand.
https://www.mentalfloss.com/article/49520/retrobituaries-eds...
> That's like saying being an expert cook but not wanting to taste food.
Oh ho! Don't let him hear you say that, eh? You'd get a scolding. He's the one who said, "Computer science is no more about computers than astronomy is about telescopes" and "Calling it computer science is like calling surgery knife science."
The analogy would be more like "an expert chef who refused to eat frozen dinners" maybe? :)
In principle, the suitability function would be evaluated over the entire lattice; in practice, that function, whether explicitly or implicitly, includes a strong weight for "distance from existing solutions". In either case, this split in focus between the interior and the boundaries of the solution space means that programmers are often highly concerned with specific details that do not even appear (because they have been abstracted away) in the objects with which informaticians work.
As an example: theory people love to use 1-ary trees (induction steps cost nothing in proofs, but cases are expensive) and they will use 2-ary trees (sometimes even without pressure to sympathize with the machine) but systems people and programmers use k-ary trees (where, if it's been determined by measurement and not by compatibility, k depends upon "the" bandwidth-delay product between the storage hierarchy levels for which the tree is optimized ... or at least what the bandwidth-delay product had been at the time of writing).
There is a reason it is called COMPUTER science while astronomy is not "telescope science". The analogy is faulty as well:
>> "Computer science is no more about computers than astronomy is about telescopes":
You can't compare astronomy to CS--astronomy needs both computers and telescopes and spaceships--but in CS, the computer is the central figure. If not, can you think of ANY other tool that represents CS?
>> "Calling it computer science is like calling surgery knife science." is another faulty analogy. The knife does not have the same amount of critical importance both as a mean and an end in surgery, as does the computer for CS; in other words, a knife is merely a means to an end in surgery, but in CS, the computer is both the mean and the end: in the latter case, the computer is a sort of representative of all the knowledge and practice in CS, in a given time. The sophistication of the computer and what it can do, represent, to a large extent, what we have achieved in CS--but you can't say the same about a knife vs. surgery. Capisch?