News for hackers. Stuff that matters.
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.