Live data from Hacker News

Interesting C code

a1k0n.net

11–20 of 31 posts

Re: Interesting C code

#12
post #3

"in six lines of C" I'm not impressed. It could be done in 1 line of C when he left out the line-breaks. I don't think obfuscated code is interesting. It's unreadable. And therefore it's hard to learn something from it. But it's nice he is explaining the code. Now that is interesting!

"It could be done in 1 line of C when he left out the line-breaks." Yeah, exactly. It's incredibly silly when people "count" lines of code like this. If you want to talk about lines of code in any kind of practical way, the code you're referring to really needs to be at least somewhat sanely formatted according to the conventions of whatever language you're in. Otherwise, any given sample of code can be in {1,2,3,...,# of characters in program} lines of code. You should just count characters (which is the more appropriate thing to do when you're trying to write a compressed program anyway). A metric of lines of code = ceil(characters/80) is weird because a) it's relatively arbitrary (in that it has nothing to do with languages but with the conventions of terminals), and b) it goes against the more common understanding of "lines of code".

/rant

I think compressed (edit: golfed - new word of the day :) code in general is pretty cool, though.

Re: Interesting C code

#13
post #2

Interesting indeed. But weird that he uses obfuscated code when doing a piece of explaining how it's done. Or do people actually write for loops like those? :P

This is basically the a C equivalent of a JAPH. A JAPH is a usually short bit of perl code that prints "Just Another Perl Hacker", but it isn't obvious that that's what it does. Trying to figure out how it works without cheating is part of the fun.

Re: Interesting C code

#14
post #8
post #3

"in six lines of C" I'm not impressed. It could be done in 1 line of C when he left out the line-breaks. I don't think obfuscated code is interesting. It's unreadable. And therefore it's hard to learn something from it. But it's nice he is explaining the code. Now that is interesting!

Obfuscation alone is not interesting, but 'code compression' (to achieve something using as few characters as possible) is a very interesting puzzle for the brain I think.

It's called "code golf", and from what I can tell, perl is the undisputed king of golfing languages.

Someone ought to make a quiz page - "is this perl golf, or a cat walking on a keyboard".

Re: Interesting C code

#15
post #8

Earlier quoted context omitted.

Obfuscation alone is not interesting, but 'code compression' (to achieve something using as few characters as possible) is a very interesting puzzle for the brain I think.

It's called "code golf", and from what I can tell, perl is the undisputed king of golfing languages. Someone ought to make a quiz page - "is this perl golf, or a cat walking on a keyboard".

,[.,] is /bin/cat in brainfuck. Though, brainfuck fails miserably at most golfing challenges.

Re: Interesting C code

#17
post #3

"in six lines of C" I'm not impressed. It could be done in 1 line of C when he left out the line-breaks. I don't think obfuscated code is interesting. It's unreadable. And therefore it's hard to learn something from it. But it's nice he is explaining the code. Now that is interesting!

I could have said "in 454 characters of C" but that wouldn't have been as linkbaity. Thanks for clicking!

Yes, the aim was compression (golfing), not obfuscation. Compression of silly ASCII things has been sort of a hobby of mine for a while and I intend to blog about that in particular. Another little compressed snippet is my "email signature" at the bottom of my site root. Try clicking on it.

Re: Interesting C code

#18
post #3

"in six lines of C" I'm not impressed. It could be done in 1 line of C when he left out the line-breaks. I don't think obfuscated code is interesting. It's unreadable. And therefore it's hard to learn something from it. But it's nice he is explaining the code. Now that is interesting!

Agreed.
Post reply on HN