Ask HN: Do you ever go back and admire a piece of code you wrote?
21–30 of 267 posts
Re: Ask HN: Do you ever go back and admire a piece of code you wrote?
#22 @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 + stackRe: Ask HN: Do you ever go back and admire a piece of code you wrote?
#23Regardless of comments.
Re: Ask HN: Do you ever go back and admire a piece of code you wrote?
#24The only thing I have ever gone back and admired is when I wrote the following snippet of code: long time; // no see
Re: Ask HN: Do you ever go back and admire a piece of code you wrote?
#25Not 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
Re: Ask HN: Do you ever go back and admire a piece of code you wrote?
#26Re: Ask HN: Do you ever go back and admire a piece of code you wrote?
#27Yes. 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.…
Re: Ask HN: Do you ever go back and admire a piece of code you wrote?
#28Otherwise code can always be made better.
Re: Ask HN: Do you ever go back and admire a piece of code you wrote?
#29Yes. 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.…
dt = timedelta(days=1)
outside the loop and using it inside would make it a bit more efficient.Re: Ask HN: Do you ever go back and admire a piece of code you wrote?
#30I immediately think of my very simple 17-line constraint satisfaction problem solver which has saved me so much work.