Live data from Hacker News

What can you do in 2k LOC of C?

h4ck3r.net

21–30 of 110 posts

Re: What can you do in 2k LOC of C?

#21
post #18

How much memory does the code the blog poster described leak? How does it respond to edge cases and invalid input? Finally, is it portable beyond one specific OS? Beyond POSIX or Windows-based systems? Those questions are especially pertinent in C.

The only dependencies are the C standard libraries (this is even mentioned in the blog post). So unless there's some terrible hackery going on (and skimming the source files, it doesn't look like there is), these are going to be more portable than most of the mega-libs you'd be choosing instead.

What makes you so incredulous about this?

Re: What can you do in 2k LOC of C?

#22
Shocked that silentbicycle hasn't mentioned it already, but Arthur Whitney whipped up the first prototype/inspiration for the J language in a short bit of macro heavy C over the course of an afternoon.

42 lines?

http://pastebin.com/s2usuqDq

If this interests you at all, absolutely worth reading Roger Hui's retrospective on the subject (more about J + Ken Iverson, but definitely fascinating) http://keiapl.org/rhui/

Re: What can you do in 2k LOC of C?

#23
post #16

$ git show e83c5163316f89bfbde7d9ab23ca2e25604af290 --stat commit e83c5163316f89bfbde7d9ab23ca2e25604af290 Author: Linus Torvalds Date: Thu Apr 7 15:13:13 2005 -0700 Initial revision of "git", the information manager from hell Makefile | 40 +++++++++ README | 168 ++++++++++++++++++++++++++++++++++++ cache.h | 93 ++++++++++++++++++++ cat-file.c | 23 +++++ commit-tree.c | 172 +++++++++++++++++++++++++++++++++++++ init-…

To be fair, that's 1244 _lines_, not bytes :)

Re: What can you do in 2k LOC of C?

#25
post #23
post #16

$ git show e83c5163316f89bfbde7d9ab23ca2e25604af290 --stat commit e83c5163316f89bfbde7d9ab23ca2e25604af290 Author: Linus Torvalds Date: Thu Apr 7 15:13:13 2005 -0700 Initial revision of "git", the information manager from hell Makefile | 40 +++++++++ README | 168 ++++++++++++++++++++++++++++++++++++ cache.h | 93 ++++++++++++++++++++ cat-file.c | 23 +++++ commit-tree.c | 172 +++++++++++++++++++++++++++++++++++++ init-…

To be fair, that's 1244 _lines_, not bytes :)

So is what the OP is talking about :o (lines vs. bytes)

Re: What can you do in 2k LOC of C?

#27

Shocked that silentbicycle hasn't mentioned it already, but Arthur Whitney whipped up the first prototype/inspiration for the J language in a short bit of macro heavy C over the course of an afternoon. 42 lines? http://pastebin.com/s2usuqDq If this interests you at all, absolutely worth reading Roger Hui's retrospective on the subject (more about J + Ken Iverson, but definitely fascinating) http://keiapl.org/rhui/

That's interesting, but damn is that some ugly code. Slightly obfuscated on purpose? Though of course it wouldn't win the IOCCC.

On the other hand, it's notable that many IOCCC submissions happen to pack a lot of functionality in often less than 2k. I remember reading a few descriptions of some the winning entries, but I can't find that now. Here's a glimpse though: http://cboard.cprogramming.com/brief-history-cprogramming-co...

Re: What can you do in 2k LOC of C?

#28
post #27

Shocked that silentbicycle hasn't mentioned it already, but Arthur Whitney whipped up the first prototype/inspiration for the J language in a short bit of macro heavy C over the course of an afternoon. 42 lines? http://pastebin.com/s2usuqDq If this interests you at all, absolutely worth reading Roger Hui's retrospective on the subject (more about J + Ken Iverson, but definitely fascinating) http://keiapl.org/rhui/

That's interesting, but damn is that some ugly code. Slightly obfuscated on purpose? Though of course it wouldn't win the IOCCC. On the other hand, it's notable that many IOCCC submissions happen to pack a lot of functionality in often less than 2k. I remember reading a few descriptions of some the winning entries, but I can't find that now. Here's a glimpse though: http://cboard.cprogramming.com/brief-history-cprogr…

Nevermind the comment about it being slightly obfuscated. Have to realize that this is the creator of J we're talking about. He probably saw it as highly expressive code (much meaning in as few characters as possible). Though I can't agree, it is definitely amazing that something so small could be the start of something like J.

Re: What can you do in 2k LOC of C?

#29
post #27

Shocked that silentbicycle hasn't mentioned it already, but Arthur Whitney whipped up the first prototype/inspiration for the J language in a short bit of macro heavy C over the course of an afternoon. 42 lines? http://pastebin.com/s2usuqDq If this interests you at all, absolutely worth reading Roger Hui's retrospective on the subject (more about J + Ken Iverson, but definitely fascinating) http://keiapl.org/rhui/

That's interesting, but damn is that some ugly code. Slightly obfuscated on purpose? Though of course it wouldn't win the IOCCC. On the other hand, it's notable that many IOCCC submissions happen to pack a lot of functionality in often less than 2k. I remember reading a few descriptions of some the winning entries, but I can't find that now. Here's a glimpse though: http://cboard.cprogramming.com/brief-history-cprogr…

Having spent a lot of time meditating on it (as sofuture mentioned), it isn't "slightly obfuscated" so much as "stubbornly written like APL rather than C".

If you become inexplicably fascinated by that code and want help unraveling it, my contact info is in my profile.

I don't consider it noteworthy as a useful program under 2kloc (on modern hardware it usually just crashes, it's quite cavalier with pointer casting, and clearly a quick prototype either way), but it's like a pink space laser beam of insight about the APL mindset. Real APLs take more than a page, but not that much more. Eliding loops does that.

A lot of the IOCCC code is also delightfully perverse, too. Highly recommended.

Re: What can you do in 2k LOC of C?

#30
post #28
post #27

Earlier quoted context omitted.

That's interesting, but damn is that some ugly code. Slightly obfuscated on purpose? Though of course it wouldn't win the IOCCC. On the other hand, it's notable that many IOCCC submissions happen to pack a lot of functionality in often less than 2k. I remember reading a few descriptions of some the winning entries, but I can't find that now. Here's a glimpse though: http://cboard.cprogramming.com/brief-history-cprogr…

Nevermind the comment about it being slightly obfuscated. Have to realize that this is the creator of J we're talking about. He probably saw it as highly expressive code (much meaning in as few characters as possible). Though I can't agree, it is definitely amazing that something so small could be the start of something like J.

It was actually written by Arthur Whitney, the author of K (not J), though Roger Hui (of J) studied it beforehand.

I do recommend studying it, though. Their APL dialects are really something; I wish there were good fully open-source implementations, and writing one is on my queue. Kona (http://github.com/kevinlawler/kona), an open-source implementation of K 3.2, is also coming along.

Just be warned that APLer C is usually nasty, brutish, and short. :)

FWIW, the best thing I've seen for getting the J mindset is _J for C Programmers_ - as Henry Rich says, to do J you must "think big" - don't think "for each part of this list, do this, then this, then this...", think, "apply this operation over these.". That scales up to multiple dimensions, and can often be run in parallel. :)

Post reply on HN