Live data from Hacker News

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

news.ycombinator.com

121–130 of 267 posts

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

#121
post #90
post #67

Earlier quoted context omitted.

It's unfortunate that the younger generation of coders took "comments are code smell" idealogy to heart and are actively against writing comments.

Too many comments explain what is going on. That should be obvious from well-written code. But comments why it's done that way can be extremely valuable. And sometimes there is indeed something wrong with the code. In those cases, a comment saying so can save a lot of time analyzing what's wrong with the code.

The counter-argument I've heard is that commit messages are a better tool for those kinds of annotations, especially if there are multiple points across the codebase where a change was made for the same reason.

That's exactly what commit messages are designed to do, too.

I've seen plenty of comments in code that say "handle case X because of behavior in place Y", that's tied to changes in place Y. I find it more meaningful when I see all those changes together, bundled in a commit diff, with a message on why.

In an especially good editor you can even have the title of the commit rendered into the blank space on the end of the line, which I find useful if I'm trying to figure out the past motivation behind a piece of code.

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

#122

Everyone's talking about code, but I do this with carpentry. Right now, I'm working as a trim carpenter in residential construction, and I pride myself on doing as good a job as I can. As a result, when I come back to a job to install door hardware after everything is painted, I sometimes just wander around the house and admire my work. Especially tricky details that took a bit of thinking to get right, even if no-on…

I do this with almost everything I make. The act of creating is an act of achieving an aesthetic you developed in your mind's eye, so it seems reasonable to want to spend some time admiring that aesthetic once achieved.

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

#124
Yes, absolutely.

More fulfilling for me however is not the code itself, but significant results. I have captured/framed a few graphs in my career that look like a "sudden jump" or a "sudden drop", which were caused by deploying a more elegant solution to a problem or pain point.

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

#125

Earlier quoted context omitted.

When I started my first programming job the CEO told me that programming is 59 minutes of feeling like an idiot and 1 minute of feeling like a genius. It's really stuck with me, and has so far proven true.

59:1 is pretty good. Sometimes debugging gets me really down

That's when you hack and slash and debug by friction. : p

Forging ahead thoughtfully, incrementally, and modularly balances the ratio a lo--oh hey a foreign codebase designed in an overengineered byzantine Lovecraftian fractal of thought death. 9999999:1

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

#126
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

Remember timecube guy? Seen on a 16-bit DSP... struct timecube { uint16_t millisecond_of_minute; uint16_t minute_of_month; uint16_t month_and_year; };

That's clever. I might steal that at some point. Or combine into a millisecond_of_month on a 32 bit processor.

For people that don't play with bits often: Unsigned 16-bit integers have their max as 65,536. Storing data often wastes most of the bits, since a field that goes from 0-1000 doesn't fit in an 8-bit integer, and C doesn't have native integers between 8 and 16 bits long. (You can mask out relevant fields, but that's annoying.)

So there are 1000 * 60 = 60,000 milliseconds in a minute, which is an impressively good use of the space available. There are also a max of 60 * 24 * 31 = 44,640 minutes in a month, which is pretty good usage of the second value as well. The final 16 bits are probably 4 bits for month and 12 bits for the year, going up to 4096. Alternatively it could be using it as something like month_of_common_era to get it out to year 65536/12 = 5461.

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

#127

Earlier quoted context omitted.

59:1 is pretty good. Sometimes debugging gets me really down

That's when you hack and slash and debug by friction. : p Forging ahead thoughtfully, incrementally, and modularly balances the ratio a lo--oh hey a foreign codebase designed in an overengineered byzantine Lovecraftian fractal of thought death. 9999999:1

I find it reassuring to read these accounts. Even though I've been in the industry for years, I still have times (like this week), where I spend way too much time trying to do something that I feel shouldn't be that hard to do and imposter syndrome kicks in hard. A lot of what I see on hacker news is people at the top of their game, so it's nice to see people talking about actually struggling.

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

#128
I have an old A* pathfinder I wrote in C about 13 years ago that I revisit with surprising frequency. Every now and then I'll have a glass of whisky and pull up the .h and .c files and smile.

The code is good, but something about the simplicity of the language and the bareness of the algorithm that makes that header and source file pair so meaningful for me.

Post reply on HN