Live data from Hacker News

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

news.ycombinator.com

51–60 of 267 posts

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

#51
post #9

I generally admire the architecture and and some nice and elegant tricks on my past code, but not the code itself. I always feel like things could be cleaner, with better names, with a more consistent coding style (I am quite severe to my self on this point). Much older code is generally neither smart neither beautiful though.

well, that's the path to coding enlightenment! hahaha, just keep climbing for a few years more

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

#52
What I like better is when you are bumbling through code you wrote a while ago trying to figure something out and there it is, a golden comment from past you, telling future you why you wrote shit this way. Usually it's some corner case or weirdness in an API you're calling.

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

#53

What I like better is when you are bumbling through code you wrote a while ago trying to figure something out and there it is, a golden comment from past you, telling future you why you wrote shit this way. Usually it's some corner case or weirdness in an API you're calling.

I call writing these comments "being kind to my future self". It's easier to take the time to justify writing these when I think of doing my future self -- or the poor person who has to maintain my code -- a kindness.

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

#54
post #41
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 wrote the following, completely innocently: return when.all(promises).yield(true);

Except for the return to happen when that's true, you'd need an await. At least in JS.

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

#55
post #22

Not entirely mine but beautiful nonetheless: @dataclass class Node: id: str children: List[Node] = field(default_factory=list) # beautiful Python: traverse a tree depth-first, pre-order (stack based) def __iter__(self): stack = [self] while stack: node = stack.pop() yield node stack = node.children + stack

You should really use deque for the stack

Why?

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

#56
post #41

Earlier quoted context omitted.

I wrote the following, completely innocently: return when.all(promises).yield(true);

Except for the return to happen when that's true, you'd need an await. At least in JS.

Not if it's returned by an async function. In JS, async functions automatically await promises that are returned.

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

#57
It will pass :) And you're looking at the code right after you wrote it.

If you look at your own code months or years later (some applications do need maintenance), you'll hate it or be ashamed of it. But you should know better than improving it by then.

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

#59
post #8

Yes. Early on in my career, I needed a function that produced a range of dates, given a start and end date. After it was all said and done, it boiled out like so: def daterange(start,end): while start Though simplistic and straightforward, I admire the solution. I am sure there may be “better” ways to achieve the same result, and posting this here may result in cowboys trashing it or pointing out a fallacy - oh well.…

I'm struggling to understand how this is special... isn't it basically just the normal 2-argument range function, but with date instead of int?

    def range(start, end):
     while start 
Or is it more about the beauty of the algorithm than this specific code?
Post reply on HN