Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

#define op operator

#define rt return

Then replacing the corresponding inline tokens shaves off another 25 bytes from the source without affecting the output or (arguably) the readability.

Sorry, my inner obfuscator couldn't resist :-)

Beautiful bit of coding, btw.



Thanks, glad you liked it!

Yes, it's true that even more could have been shaved off and I did explore some #defines. As I recall, there were also some other changes I could have made to shave off yet more. Ultimately, I decided against them for two main reasons. First, they'd need to occupy lines by themselves which I felt created a bigger gap at the top that ruined the aesthetics somewhat. I wanted something that would look nice and roughly fill the 1.75 aspect ratio of a typical US business card. Secondly, as noted in my reply to matthew-wegner below, I'd noticed the file size that I had achieved.


#defines have to be one to a line, though - in this case, where you're optimising for layout rather than bytes, i'm not sure it would be a net win. counting, there are 5 instances of "operator", so that's a saving of 36 chars versus 40 taken up by the #define (including the whitespace at the end). there are 10 "return"s, so saving 40 chars there just about draws you even.


>Then replacing the corresponding inline tokens shaves off another 25 bytes from the source

I dunno, I kinda like the current size.


Can you pastebin.com it so we can see what it looks like ?


http://pastebin.com/ktukPBHE

I reformatted it so it would justify right like the original but for some reason Pastebin likes to reflow things.

It turns out the single-character tokens 'u' and 'w' were not being used so repurposing them for the #defines leads to a saving of 46 characters at the cost of an extra line. There are a few other recurring tokens but you hit a point of diminishing return.

One should not, however, lose sight of what an awesomely clever hack the whole thing is. Reminds me of some of the text-flow layouts in old illuminated manuscripts, or the more modern variations here (like the one with the light-bulb): http://www.smashingmagazine.com/2008/02/11/award-winning-new...




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: