4 Comments
User's avatar
Lucien Bill's avatar

As a beginner, I wrote simple code because I wanted to understand it.

Then as my skills grew, I wrote some one liners in my code because I thought it was more efficient... Until I had to maintain some of it and realised it was just painful 🤣

Now, I write simple code because I want to understand it... And I want it to be as easy to understand as possible for as many people as possible.

I use the same approach with abstractions: I only create them when they bring more advantages that what they cost in complexity and cognitive load.

Expand full comment
Jordan Cutler's avatar

This is one of the few times I would use the "Request changes" button 😂 if someone submitted that for code review

Expand full comment
Tim McKenna's avatar

Programming is communication between ONE HUMAN BEING and ANOTHER HUMAN BEING. -- Don Schenck. (maybe the same human being much later in time)

Dense code does not run any faster than simple code once compiled. It's almost always a similar number of machine instructions. Want it to run faster? Turn on the compiler's optimizer. Pay for more cycles.

75% of software development is maintenance.

Dense code is not written faster than simple code and, as Lucien says, it's painful. And the rest of what Lucien says, too. And what Ryan said. Many thanks.

The most important part of maintainable code is not the code, it's the comments.

But if you are reading this, I'm preaching to the choir.

Expand full comment
ishaan's avatar

This doesn't have much to do with Leetcode really, rather just code golf, and this is kind of just a one-off bad example. Stefan notoriously likes to golf.

FWIW, I've done 2000 Leetcode questions, and write all my solutions with aim to be practical and clean (sometimes will shorten variable names if it's just me reading it).

I think the general message of favoring readable and durable code is good, and I agree that Leetcode != SWE (often the opposite!), I'm just not sure the example does any favors.

>1000 of my LC solutions (mostly older ones): https://github.com/ishaanbuildsthings/leetcode/tree/main/patterns

Expand full comment