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.
Ask HN: Do you ever go back and admire a piece of code you wrote?
51–60 of 267 posts
Re: Ask HN: Do you ever go back and admire a piece of code you wrote?
#52Re: Ask HN: Do you ever go back and admire a piece of code you wrote?
#53What 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?
#54The 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);
Re: Ask HN: Do you ever go back and admire a piece of code you wrote?
#55Not 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
Re: Ask HN: Do you ever go back and admire a piece of code you wrote?
#56Earlier 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.
Re: Ask HN: Do you ever go back and admire a piece of code you wrote?
#57If 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?
#58Re: Ask HN: Do you ever go back and admire a piece of code you wrote?
#59Yes. 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.…
def range(start, end):
while start
Or is it more about the beauty of the algorithm than this specific code?Re: Ask HN: Do you ever go back and admire a piece of code you wrote?
#60 amountFulfilled = isFulfilledOnSite * quantity
yes, isFulfilledOnSite is a boolean