Ask HN: The most fun and beautiful code you know of?
11–20 of 23 posts
Re: Ask HN: The most fun and beautiful code you know of?
#12Re: Ask HN: The most fun and beautiful code you know of?
#13http://www.amazon.com/Programming-Pearls-2nd-ACM-Press/dp/02...
Re: Ask HN: The most fun and beautiful code you know of?
#14 if (c > (6 * b)); // head
while (b) *(s++) = 0x80 | ((c >> (6 * --b)) & 0x3F); // payload
}Re: Ask HN: The most fun and beautiful code you know of?
#15Re: Ask HN: The most fun and beautiful code you know of?
#16Funny seeing this, because I was at my local Borders earlier and decided to give that Beautiful Code book a shot. I've seen it on the shelf for quite a while, but those books don't tend to turn my crank, so to speak, so I had never before really considered it. I only read the first and the third essay, but I must say, wow! The third essay, for instance, takes a simple 12 line implementation of quicksort in C (which i…
Re: Ask HN: The most fun and beautiful code you know of?
#17* Doesn't repeat itself. This includes languages which involve marking out blocks of code once for the interpreter and the second time for humans.
* Is short, because it doesn't reinvent common modules, and modularizes out general logic.
* Uses descriptive names, including using dictionary keys rather than vague list element numbers. A good test is if you can show the code to someone who doesn't work in computing and have them understand it. ZS had a talk on this where he showed lawyers SOx code and received feedback on the rules, changes to the order, etc.
* Uses tree structures for tree structured data (eg, etrees and xpath) rather than treating such data as strings and using RegExs.
* Has docstrings.
Re: Ask HN: The most fun and beautiful code you know of?
#18Re: Ask HN: The most fun and beautiful code you know of?
#19Re: Ask HN: The most fun and beautiful code you know of?
#20My own code... (Not because it's perfect and beautiful, but just because I wrote it and understand it.)
Report writers, data base update objects, data formatting routines, form processors, string & array handlers, special logic algorithms, and especially, code generators.
The more I read these, the better I know them.
The better I know them, the easier to improve and extend them.
The more I extend them, the better my software gets and the less of it I have to write to get anything done. Leverage.
I literally have a folder of all this stuff on my nightstand or in my backpack all the time.