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.
Ask HN: Do you ever go back and admire a piece of code you wrote?
261–267 of 267 posts
Re: Ask HN: Do you ever go back and admire a piece of code you wrote?
#262When I was ~15 I wrote this: $c=`clear`;for(`tail -c+324 $0|zcat`){if(/^p/){print@l;@l=()}elsif(/^d(.+)/){select$u,$u,$u,$1/10}elsif(/^s(.)/){$s=9;$e=-30;$m=-1;if('o'eq$1){$s=-30;$e=9;$m=1}for($i=$s;$i!=$e;$i+=$m){$j=0;for(@l){print substr($_,$i+$j++>0?($i+$j) 2:0,-1)."\n"}select$u,$u,$u,.1;print$c}}elsif(/^c/){print$c;@l=()}else{push@l,$_}}__END__ Which (with ~1.5KB of binary data appended, total under 2KB) creates…
(Also, leave a blank line before your code and indent each line of it by two spaces to make it formatted like code.)
Re: Ask HN: Do you ever go back and admire a piece of code you wrote?
#263Earlier quoted context omitted.
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?
#264Earlier quoted context omitted.
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.
1. I did allow for "rare exceptions". Some things do need to be explained outside of the code. Maybe we're not so different after all :)
2. There are a number of techniques to write such code. Before I learned them, I had NO IDEA. One is to take what would have been comments and use them as variable or function names. This includes (and I had real resistance before I accepted this) breaking out a variable of function only in order to give it an informative name. "Level 4" doesn't just happen. You work at it for a long time and sharpen your skills in that area.
3. To me, much of the art of writing software is to find ways to divide a complex problem into simple pieces. If my code is real complex, I look for simpler way to write it. And I look hard.
Re: Ask HN: Do you ever go back and admire a piece of code you wrote?
#265Earlier quoted context omitted.
I have, and I do use it for projects (and plan on using it for more). But I also need C for things that require certain performance I'm unable to get out of Go.
Use Rust, then. Rust is like Go, except its binaries are small and fast (except string formatting, which is very runtime, horribly bloated and merely "fast-ish"). Anything C can do, Rust can do better (the string formatting excepted).
It's so weird to me.
Re: Ask HN: Do you ever go back and admire a piece of code you wrote?
#266When I was ~15 I wrote this: $c=`clear`;for(`tail -c+324 $0|zcat`){if(/^p/){print@l;@l=()}elsif(/^d(.+)/){select$u,$u,$u,$1/10}elsif(/^s(.)/){$s=9;$e=-30;$m=-1;if('o'eq$1){$s=-30;$e=9;$m=1}for($i=$s;$i!=$e;$i+=$m){$j=0;for(@l){print substr($_,$i+$j++>0?($i+$j) 2:0,-1)."\n"}select$u,$u,$u,.1;print$c}}elsif(/^c/){print$c;@l=()}else{push@l,$_}}__END__ Which (with ~1.5KB of binary data appended, total under 2KB) creates…
That's really neat. I'm guessing this is Lemonade? https://github.com/shish/lemonade (Also, leave a blank line before your code and indent each line of it by two spaces to make it formatted like code.)
Re: Ask HN: Do you ever go back and admire a piece of code you wrote?
#267Earlier quoted context omitted.
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…
IIRC, month and year was a 4-bit and 12-bit bitfield just as you describe.