Live data from Hacker News

Don't be clever

stitcher.io

1–10 of 231 posts

Re: Don't be clever

#5
I think these stories and aversion to "clever" code end up hurting programmers overall. I wish we spent more time teaching how to choose the correct time and place to be clever instead. Searching for ways to make things better instead of mindlessly copy pasting how it was done by the person before me is how I learned my most valuable skills.

Re: Don't be clever

#6
post #2

It seems like every coder needs to learn this the hard way at some point. “I’ll save so much time!”

I don't think this particular person would have learned the lesson.

> Yes, I had failed to see the proper solution: a class generator — so that I didn't have to manually copy code again. It actually existed back then, I simply didn't know about it, no one told me about it, and I wasn't smart enough to question myself once I started going down a certain path.

I shudder for the next gig where they get to apply ^

Re: Don't be clever

#7
post #2

It seems like every coder needs to learn this the hard way at some point. “I’ll save so much time!”

I think this is because most literature focusses on exactly those things. Design patterns to be one step ahead of some obscure future usage of your API, FP patterns to abstract your API into a 'something' that you could not just use to aggregate customer account balances in the database but, say, merge arbitrary lists as well etc.

It's rare to find literature that tells you -not- to use new frameworks or design patterns, and if it exists, if probably doesn't sell very well because it's just not sexy.

Re: Don't be clever

#8
To expand on the article from my personal experience, sometimes, there's a very thin line between "clever code" as in "overengineered", and "clever code" as in "I don't understand it, so I don't like it".

Imagine situation where a team of Java developers need to create a component in Python. No problem!

We come to the following code:

```

list_of_resources = method_a()

if not list_of_resources:

  handle_empty_list()
```

Now, is the code above "clever", or not? As Java developers, you could get into arguments like "we should use `len(list_of_resources) == 0` instead" vs "it's not Pythonic and there's no reason to use len instead truth/falsey-ness".

Of course, the whole problem gets exacerbated by unit testing, where `list_of_resources` can be a MagicMock, and therefore `if not list_of_resources` will never trigger.

Of course, probably nobody will argue that the above snipped of code is overengineered. But, somehow, the same logic of "clever code bites you back" applies to more situations than just insane class hierarchies. And it's those very tiny fragments that seems so simple yet there are hidden issues that I find the most interesting to focus on.

Re: Don't be clever

#9
Yeah, like me (DevOps) writing our dev environment manager tool in Python when all the devs write nodejs. Then not being able to just ask them how to solve a problem in node, instead having to spend far longer figuring stuff out myself.

Good for learning, bad for velocity. Although I do know a buttload more Python now.

Yeah, clever! As my old man said, so sharp you cut yourself.

Re: Don't be clever

#10
> Yes, I had failed to see the proper solution… It actually existed back then, I simply didn't know about it, no one told me about it, and I wasn't smart enough to question myself once I started going down a certain path.

And there’s your problem right there: Assuming that nobody has ever tried to solve this problem before so not bothering to look around at existing solutions.

This is a failure of lack of context, in two ways:

1. The author lacked knowledge about the various possible solutions and the strengths and weaknesses of each one.

2. The author lacked knowledge of the context into which the solution would be applied, e.g. a sophisticated solution might not make sense for an unsophisticated team to maintain.

Post reply on HN