News for hackers. Stuff that matters.
Re:Thank You, Guido by notkaiho on Wednesday October 30, 2019 @10:28AM (#21398110)
"“When asked, I would give people my opinion that maintainable code is more important than clever code,” he said. “If I encountered clever code that was particularly cryptic, and I had to do some maintenance on it, I would probably rewrite it. So I led by example, and also by talking to other people.”"

This is very sage advice.

Re:Thank You, Guido by doc_gunthrop on Wednesday October 30, 2019 @12:46PM (#21399722)
That coincides with the following:

> Code is read many more times than it is written. Writing code costs something, but over time the cost of reading is often higher. Anyone who ever looks at a piece of code has to invest brain-power into figuring out what it does.[1]

This is also noted in PEP8:

> One of Guido's key insights is that code is read much more often than it is written. The guidelines provided here are intended to improve the readability of code and make it consistent across the wide spectrum of Python code. As PEP 20 says, "Readability counts".[2]

[1]: https://www.sandimetz.com/blog/2017/6/1/the-half-life-of-cod... [2]: https://www.python.org/dev/peps/pep-0008/#a-foolish-consiste...

Re:Thank You, Guido by hinkley on Wednesday October 30, 2019 @03:57PM (#21401856)
I’m finding that one of the biggest time sinks is code that looks like it’s doing something other than what it’s actually doing.

Code smells draw the eye when debugging. Your brain wants the problem to be in the code that’s clearly “wrong”. So smelly code anywhere near common code paths has a huge cost compared to smelly code in some leaf function in an obscure feature.

One of the wisdoms of XP, I think. The code you touch the most should be the sanest.

Re:Thank You, Guido by jodrellblank on Wednesday October 30, 2019 @09:34PM (#21404870)
> Code is read many more times than it is written

I'm really curious how true this is. Partly because, if it really was read more than it is written, people would optimize to /write less/ of it - if you have to pick up everything you put on the floor ten times over, it will incentivize you to put fewer things on the floor in future. And people would say things about code which people say about writing, such as "you have to write for your audience", instead of the more common "it's either boolean readable or unreadable".

And partly because I suspect code is /skimmed over/ more than it is read; that is, people assume what it does, glance at its shape, then if there's no surprise triggered, move on.

I would be interested to know if anyone has studied what it means for code to be read, but my suspicions are that most code which works is almost never read, and most code which is read, is read because it doesn't work and therefore it will be self-selected to be poor code in some regard.

But then, I'm not a programmer working on a large codebase. Those of you who are, how much of it have you read in enough detail that you verified how it works - and no assuming that a method does what its name implies, or assuming that if it passes tests it must work, but actually verifying by studying it that it does what it should and that you understand it?

Re:Thank You, Guido by RaiseProfits on Wednesday October 30, 2019 @01:22PM (#21400149)
Who would have thought the best argument against an 80 character cap in pep8 would come from guido himself?
Re:Thank You, Guido by icebraining on Wednesday October 30, 2019 @04:35PM (#21402360)
Anyone who charitably reads what he writes.
Re:Thank You, Guido by Alex3917 on Wednesday October 30, 2019 @12:40PM (#21399639)
> This is very sage advice.

I mean in real life (when you don't have Guido to do it for you), if people are writing code you can't understand then you need to tell them to fix it. And many people don't like being told they need to rewrite their code because you can't understand it, so it leads to conflict and eventually you often need to fire people.

So yes, it's good advice, but by cleaning up engineering debt you're often going to take on a lot of team debt.

Re:Thank You, Guido by Aperocky on Wednesday October 30, 2019 @01:19PM (#21400120)
There's a delicate balance that often lies in hiring process.

There are people who simply refuse to understand generics and/or stream APIs. Which are to (most) programmers more readable then the same logic being drawn out in a loop.

Meanwhile some other programmer would just write code golf and brag about it.

At the end of the day, it should be about enforcing a coding style that defines what you can or can't do. Adding final to all variable that can be final for instance is a great start.

Re:Thank You, Guido by trilinearnz on Wednesday October 30, 2019 @04:13PM (#21402050)
We have reached a middle ground in our organisation (not a tech company, so there is less code and a slower pace). We don't require rewrites, but simply recommend that next time the code be written in a more lenient style. The education aspect is a good lens through which to view the issue also, sometimes resistance to an unfamiliar style is due to a fixed mindset around a known set of language functionality. It could be an opportunity to learn something new which is genuinely useful.
Re:Thank You, Guido by skellera on Wednesday October 30, 2019 @11:29AM (#21398796)
You’d think it would be common sense when writing something that other people will read. We don’t see people writing books in acronyms or omitting words.

How come so many people try to use code to show how smart they are?

Re:Thank You, Guido by wutbrodo on Wednesday October 30, 2019 @12:55PM (#21399835)
Honestly, if you're smart, it's just really fun to make things dense and logically concise. Think of it like a minor form of code golf.

My first CL at my first job out of college was writing a state machine at Google. I remember collapsing it into this dense, elegant representation by hinging on a couple of bits of state. It took me an extra half day, but I was really proud of the end result, and I remember being mildly put off by the request that I unroll it and make it explicit. Upon thinking about it for a bit, I decided it was entirely reasonable, and after a few more years at Google, I transformed into the kind of engineer insisting that every bit of code prioritize readability over everything else, in the absence of constraints like performance. Across the tech orgs and teams that I've run since, this has paid huge dividends. I'm writing a lot of tensorflow and C++ at a very fast-moving company working on a complex problem, and I don't know how anyone on my team would be productive at all without strictly prioritizing readability.

Being good at coding and having good engineering habits aren't the same skill, and the latter is about discipline and patience (and occasionally thinking like a dumber person), which are inherently less fun than unfettered technical challenges.

Re:Thank You, Guido by hinkley on Wednesday October 30, 2019 @04:09PM (#21401996)
My best friend in college was a writer, pursuing a BA in Literature.

I’ve been thinking again lately about little bits I picked up via osmosis and my own early creative writing experiences. In fact I was just noting a couple weeks ago how refactoring resembles an exploratory writing exercise.

I think we need to embrace the creative writing similarities. Would we ever celebrate an author who published efficient, dense and cryptic text? Rarely.

One of the things we do want is someone who paints a clear picture in a few well chosen words. Another is to be inspired. Tricked or bored are not on that list.

Re:Thank You, Guido by jodrellblank on Wednesday October 30, 2019 @09:48PM (#21404933)
Readability isn't just the inverse of code golf, but that's how it's often talked about. We want a clear picture in a few well chosen words, but writing padded with low effort filler is not clear, it's a drag. Whatever the answer is, it's not "shortest code possible" but it's also not "longest code possible". Given that, it seems quite plausible that the answer is "whatever you have learned to read is readable, and what you haven't, isn't".

We have ideas of a "grade 6 reading level", do we have such a scale for code? If not, why not?

Re:Thank You, Guido by therealdrag0 on Wednesday October 30, 2019 @04:40PM (#21402425)
Love the analogy. I'm a SE with a English degree. Maybe that is why I care so much (more than those around me) about editing code and finding the readability sweet spot.
Re:Thank You, Guido by egypturnash on Wednesday October 30, 2019 @04:49PM (#21402527)
Hemmingway.
Re:Thank You, Guido by pdonis on Wednesday October 30, 2019 @11:46AM (#21398980)
> How come so many people try to use code to show how smart they are?

Writing clever code doesn't mean it's being done for that reason. As the article notes, Guido himself agreed that in the early stages of developing a piece of software, such as in an early stage startup, it probably makes sense to write clever code, because you can get it done faster and therefore iterate faster on improving the code to meet user needs. At this stage very few people are working on the code (often just one), so communicating with other developers is not a big issue.

The need for making it maintainable comes later, when the product is mature and many more people are working on the code, so the need for clear communication becomes much stronger.

Re:Thank You, Guido by Grue3 on Wednesday October 30, 2019 @12:20PM (#21399380)
We don't use code to show how smart we are. We just assume that other developers are as smart as we are.

>We don’t see people writing books in acronyms or omitting words.

Math books written for mathematicians do this all the time.

Re:Thank You, Guido by Rychard on Wednesday October 30, 2019 @01:07PM (#21399978)
> We don't use code to show how smart we are. We just assume that other developers are as smart as we are.

I think it would be more accurate to say that we assume that other developers have the same amount of context about the problem as we do.

Going back and reading my own code from even a few months ago makes this very evident, as I frequently realize that I'd made various assumptions that required a much deeper level of understanding than I anticipated. The difficulty in providing a sufficient amount of context is readily apparent to me as I go back and fill in the gaps I unknowingly left.

Re:Thank You, Guido by hinkley on Wednesday October 30, 2019 @04:17PM (#21402109)
Oh, I’ve definitely worked with people who really enjoy being clever.

And telling them their cleverness is hurting other people can be traumatic, for one or both parties.

I like being clever too. I’ve just sublimated that into more beneficial things like human factors.

Re:Thank You, Guido by robocat on Wednesday October 30, 2019 @05:00PM (#21402664)
> We just assume that other developers are as smart as we are.

I think that excuse falls over when you look at some old code you yourself wrote, and you find that you can't understand it.

That's presuming your smartness doesn't change much over time.

Re:Thank You, Guido by rurp on Wednesday October 30, 2019 @01:06PM (#21399975)
I didn't take the comment to mean that other developers can't understand clever code, rather that writing overly clever code just isn't the best approach when a more plain solution will do. Writing code that takes another developer an hour to read through and understand wastes a lot of time compared to code that can be read and understood at a glance.
Re:Thank You, Guido by hinkley on Wednesday October 30, 2019 @04:24PM (#21402200)
This is most important when scanning code.

When I’m trying to add functionality of fix a bug, I’m going to read dozens and dozens of functions to winnow down to a handful of candidates.

Simple code can be filtered quickly and cheaply. Clever code requires contemplation. Which clears working memory.

Yes, I can understand your code. But I shouldn’t have to work for it.

Re:Thank You, Guido by mathgladiator on Wednesday October 30, 2019 @01:10PM (#21400011)
The key difference being operational ownership and business continuity. If all mathematicians (and I say this as a mathematician and math lover) just up and had a heart attack, then the world would probably not notice (as a whole).

If a critical service is experiencing growth and built on cryptic stuff, then the world may notice if no one can maintain it and it falls over.

Re:Thank You, Guido by aksx on Wednesday October 30, 2019 @11:49AM (#21399024)
Sometimes it's not about show how smart they are, developers aren't clear about the code they are writing.

when I write code for a concept i don't understand completely, it tends to be complex and cryptic. I'll go back to it after trying to understand the problem and the problem space more and be able to write simpler code.

Re:Thank You, Guido by Cthulhu_ on Wednesday October 30, 2019 @11:47AM (#21399003)
You say that, but then there's more advanced writings like scientific papers which will freely use domain-specific terms and / or maths; I'm not saying that's bad, it's just that because I'm not at home with these terms and / or subjects I won't invest the time in trying to decipher it. Also because unlike with code, I don't actually have to of course.
Re:Thank You, Guido by hinkley on Wednesday October 30, 2019 @04:01PM (#21401900)
I’ve ratcheted this up a notch with jr devs.

When are you having fun reading someone else’s code? You’re usually there trying to solve a problem. Your plans for the day have gotten away from you. You may even be having a Bad Day. And this is at least doubly true for failing tests.

Take pity on the person.

Re:Thank You, Guido by marktangotango on Wednesday October 30, 2019 @04:27PM (#21402235)
I've also begun to stress this in code reviews and mentoring interaction but the question is; how to present this idea in a way that "early in their career" developers (and not so early) can appreciate? Simply admonishing them about "keep it readable!" isn't effective in my experience.

An example that frequently occurrs is decomposing a large method into smaller methods. Okay, there are now more lines of code (due to adding method declarations), but what was really gained? The gain that can be had is identifying common use cases and factoring some of those methods out to utility classes that can be referenced from the same source file and others. This can be difficult to identify unless one learns to really look for these oppurtunities.

The approach I've been taking recently is presenting the idea as there's always a minimal level of abstraction, and code should try to achieve it. I'm interested to hear what others think about this.

Re:Thank You, Guido by mark-r on Wednesday October 30, 2019 @05:07PM (#21402743)
One of the things I love most about Python is the ease of decomposing functions. The ability to return an arbitrary number of objects at the same time makes it really easy.

Python not caring about the type of a parameter makes it easy to share code too.

Re:Thank You, Guido by cytzol on Wednesday October 30, 2019 @12:24PM (#21399430)
> How come so many people try to use code to show how smart they are?

It's tricky, isn't it? The original quote was about "clever code" versus "maintainable code", but they are not orthogonal: it's possible to write code that's more maintainable (because it's harder to use incorrectly) at the cost of being more clever (because you need to learn more of the language or standard library to understand it). One person's "more maintainable" is going to be another person's "too clever" — you're going to get a bunch of different opinions on where the line lies. Not everybody is trying to show off their brains.

Re:Thank You, Guido by dwaltrip on Wednesday October 30, 2019 @03:22PM (#21401494)
People enjoy doing something clever. It takes experience and careful reflection to realize the downsides of being overly clever. It takes maturity to not give in to the guilty pleasure. It can also stem from boredom or insecurity.
Re:Thank You, Guido by quaquaqua1 on Wednesday October 30, 2019 @11:43AM (#21398952)
It's terrible. People use deliberate crypticness to flex on everyone who hasn't seen x subniche of programming style before. They designed it to be like this to be the gatekeeper at their organization.
Re:Thank You, Guido by chipgap98 on Wednesday October 30, 2019 @11:49AM (#21399017)
That metaphor doesn't hold up. Literature is full of allegories, figures of speech, allusion, and other forms of imagery.

I agree that code should be as straightforward as possible, but I don't think books follow that rule.

Re:Thank You, Guido by skywhopper on Wednesday October 30, 2019 @05:10PM (#21402777)
Much of 18th century English-language literature was an attempt to show how smart the authors were...
Re:Thank You, Guido by notkaiho on Wednesday October 30, 2019 @02:15PM (#21400747)
This is a really good comparison and one I'm going to use going forward. Thank you.
Re:Thank You, Guido by vkat on Wednesday October 30, 2019 @11:49AM (#21399019)
I think this is what experience teaches. Sometimes I have the itch to write clever code but then more often than not it ends up being cryptic to other developers. If you really have to write clever code, wrap it up in a well defined interface and write a bunch of tests.
Re:Thank You, Guido by rstupek on Wednesday October 30, 2019 @12:17PM (#21399341)
I've found it also becomes cryptic to your future self who will have to figure out how to maintain it going forward
Re:Thank You, Guido by huhtenberg on Wednesday October 30, 2019 @01:15PM (#21400060)
The third option, of course, is to just comment your clever code to make it less cryptic.

Yes, you can have your pie and eat it :)

Re:Thank You, Guido by nomel on Wednesday October 30, 2019 @01:35PM (#21400295)
Unless there’s a real and needed benefit, why complicate it?

I’ve seen clever code that was 300% faster, half the lines, completely unreadable, and called once per session, for a total the time of 10ms in a workflow that was minutes long.

No amount of commenting could justify it.

Re:Thank You, Guido by bagacrap on Wednesday October 30, 2019 @03:11PM (#21401370)
The compiler doesn't care about comments, so in my experience comments quickly go out of date as others change the code and ignore comments.

There's nothing to say code can't be performant and legible. In fact I'm a bit confused what "clever" means here. Writing performant but illegible code does not take more cleverness than performant while legible.

Re:Thank You, Guido by streetcat1 on Wednesday October 30, 2019 @12:15PM (#21399318)
probably would help if he added static typing from the get go.
Re:Thank You, Guido by tyingq on Wednesday October 30, 2019 @11:03AM (#21398484)
Interesting in the context of Dropbox, as they ship the client code as obfuscated and encrypted pyc files and a custom runtime that's pretty "clever": https://anvilventures.com/blog/looking-inside-the-box.html

Edit. Yes I get the difference and the reasons they do this. The wordplay crossover (cryptic, clever, etc) was notable to me, and reminded me of the link I posted above.

Re:Thank You, Guido by _coveredInBees on Wednesday October 30, 2019 @11:27AM (#21398766)
That has zero bearing on the point Guido was making. He is talking about development practices. The client code is not being sent to users for them to develop code and contribute to the Dropbox codebase.
Re:Thank You, Guido by caseysoftware on Wednesday October 30, 2019 @11:12AM (#21398594)
We're not the intended audience for the code. We're just the consumers.
Re:Thank You, Guido by jamestenglish on Wednesday October 30, 2019 @11:30AM (#21398809)
Just because the outcome of the code (i.e. obfuscated code) is "clever" doesn't mean that the code that does the obfuscation is clever