Live data from Hacker News

Ask HN: Do you ever go back and admire a piece of code you wrote?

news.ycombinator.com

231–240 of 267 posts

Re: Ask HN: Do you ever go back and admire a piece of code you wrote?

#231
I find that some ideas gestate on the backburner "I wish I had time to implement feature X".

Then upon going into the code I realize the basic framework already exists to implement the feature.

One of the more pleasant experiences in our code base.

The negative experiences of "Did I write this?!?" tend to be driven by performance bottlenecks and profiling.

Re: Ask HN: Do you ever go back and admire a piece of code you wrote?

#232
post #156

Earlier quoted context omitted.

I find it's not useful to have comments in code that you are actively working on since they quickly get out of date. They are best added when one finishes work on a block of code.

I’ll do comments first and then code. It’s a lot faster for me to keep a flow and pseudocode and then write the code in between. If the comments are two pedestrian afterwards (increment i), I will erase the comments. I started this technique early in my career back in the late 90s after reading “Code Complete”. It also helps me to pick back up faster if I get interrupted.

This sounds a lot like TDD, but with comments instead of tests. It's an interesting technique I never heard of.

Do you ever get back to code you wrote and find a lot of misleading comments that you simply forgot to delete/update? Or are you always updating the comments before you try a new approach if the first one didn't work out?

Re: Ask HN: Do you ever go back and admire a piece of code you wrote?

#233
post #43

I do sometimes go back and stare at this wonder I crafted once: s=>s[0]+/.*( .|z)|...s.s?|T..|M[i-t]+|[AFINOUW][^o]v?|.*/.exec(s)[0].slice(-1).toUpperCase() It does something pretty useful, that has surely been written many times over. But unlikely ever as succinctly as this. :)

Alright, I'll bite - what does it do?

It takes the name of a state in the United States and returns its two letter abbreviation.

EDIT: I swear I didn't look at the CodeGolf link. :(

Re: Ask HN: Do you ever go back and admire a piece of code you wrote?

#235
post #96

Earlier quoted context omitted.

100%. It's amazing how many GitHub repos have little to no comments, not even file or function overview comments. The amount of time save by potential contributors reading and having to interpret the code is way longer than it would take for the author to write the comments in the first place. To each their own, but comments are generally a positive addition to code.

I think there are levels: Level 1: Garbage code with no or bad comment. Level 2: Garbage code with good comments. Level 3: Good code with comments Level 4: Code good enough that it doesn't need comments, with rare exceptions. Each level is better than the previous. You can't level up directly from 1 to 4. Still, 4 is the best level. I know it sounds weird if you haven't seen it.

I don't think level 4 exists. There is no code for problems of sufficient complexity that are self-explanatory. There are too many hidden assumptions and foreknowledge and tradeoffs and decisions baked into a block of code that, unless it's trivial, there's no way code itself can reflect it adequately.

Re: Ask HN: Do you ever go back and admire a piece of code you wrote?

#236
post #12
post #11

The only thing I have ever gone back and admired is when I wrote the following snippet of code: long time; // no see

I came across this gem recently: catch (Exception up) { throw up; } Truly genius code

Or in Python:

  except Exception as the_roof:
      raise the_roof

Re: Ask HN: Do you ever go back and admire a piece of code you wrote?

#237
Sometimes-- but most of the time when I look at code I wrote and was proud of but 6months or a year later-- I'm like, what was I thinking- I would of done it differently now. I call it programmers remorse. Since we're always learning and patterns change over time based on technology I think that most programmers live in a constant state of embarassment over things they previously had done.

However-- sometimes (with increasing rate into my 15 year carreer) I need to modify something and had not touche the code in a long time-- only to find to my supprise I already had that feature or ability coded into it... I then have to say "Thanks Past Jon- This is Future Jon (to you) and noice forward thinking"

While in isolation due to gobal things... it's a good time to make sure Past you and Future you get along-- Present you (third state) is both past and future but leave some notes for Future [yourname] and make sure if you find notes from Past [yourname] you remember to appreciate their work.

Re: Ask HN: Do you ever go back and admire a piece of code you wrote?

#238

My number one favorite time is after I sold a company. Two years later, the company contacted me as the old CTO and asked me about some piece of core technology. They asked me to take them through it and show them what was going on since they wanted to migrate it into something else. My first question was, "Haven't the other developers ever touched it." They said no. This core piece of technology scaled to way more u…

Wow. You should be proud indeed. Turned out you maintained enough corner cases right there.

Re: Ask HN: Do you ever go back and admire a piece of code you wrote?

#239

All the time. The old joke is about us looking at code we wrote six months ago, and being horrified at what we see. And I've had more than my share of that. But what's ALSO happened, many times, is I look at old code I wrote... and I'm IMPRESSED. Just blown away by the beautiful elegance and power of the abstractions I came up with, the sheer intelligence of the approach, the insight and lucidity oozing from the code…

> But what's ALSO happened, many times, is I look at old code I wrote... and I'm IMPRESSED. Just blown away by the beautiful elegance and power of the abstractions I came up with, the sheer intelligence of the approach, the insight and lucidity oozing from the code. > "Wow, I wrote THAT?!" Because I was deep in a coding trance when I wrote it. So deep "in the zone", that when I come out, it's not easy to recapture wh…

I responded without reading anyone else's comments-- I'm so happy that my Past [name], Future [name], dialogue is something other people do! You're "other me" is the same as my "Past Jon"

haha-- Remember to thank your "other me" and you should make sure to drop little notes addressed to your future self-- beacuse it is REALLY rewarding to find a note you left addressing your future self like "Hey, Future Self-- If you're looking for the actual module that does the communication-- it's: [location]"

And if a year later you are doing EXACTLY that-- trying to track down that thing-- and you start with something you know -- and find that note- It's hard to not exclaim- "Thanks Past Self, you just saved me some searching- hats off to you sir"

Re: Ask HN: Do you ever go back and admire a piece of code you wrote?

#240
There's one particular piece of code I'm especially proud of, coming from a side project. It's a non-trivial amount of code, and it's not the cleanest code, and it has bugs and missing functionality. However, as a library it hits the sweet spot of:

1. Zero dependencies

2. Lightweight abstraction

3. API enforces correctness in usage

4. API covers the problem space well enough that the API hasn't changed since a couple months after initial release (it's been 3-4 years)

5. Library does something all of the individual pieces of software using it couldn't have done individually - not easily anyway.

When I first started working on the code, I guessed (correctly, in retrospect) that for technical reasons changing the API after version 1.0 would be a struggle, so I reached out to 3 of the more prolific developers in the space who needed what I was working on and collaborated with them early to rapidly iterate on the API. I declared 1.0 a couple weeks later once it felt like we were all pretty happy with the product.

I wasn't the only person working on that specific problem. In fact IIRC my solution was the third "to market". However, by really pushing to get through multiple iteration cycles in collaboration with my intended users, the bunch of us managed to converge onto a simple and durable design which ended up becoming the de facto standard.

It's not my most elegant code, but it solved a specific in-demand problem and did a clean job of it.

Post reply on HN