Hacker News new | past | comments | ask | show | jobs | submit login
Show HN: Two Kilo – A curses-based text editor in 2kb of code (0x0.st)
67 points by earenndil 14 days ago | hide | past | web | favorite | 44 comments

It has some promise, however:

* The code generates a number of warnings when compiled with '-Wall -Wpedantic'. Look at IOCCC entries; a number of them take pride in having no warnings whatsoever, even with full warnings enabled.

* The code does not include instructions. Even a 12-line 900 character obfuscated program can include basic usage instructions.

* Most importantly, the code does not work. When I compiled it with GCC on Cygwin (gcc -o zolW zolW.c -lncurses), then ran 'touch foo ; ./zolW foo', I almost immediately got a core dump.

So, yes, this is a good first attempt, but I would like to see this get revised. Fix all compile time warnings; make sure it works with both GCC and CLANG. Add test cases. Add documentation.

Shameless plug: Yes, I have made a small, 900 character 12 line program which does not generate compile-time warnings, does not generate core dumps (even going so far as to fix a core dump which only happened after running the code for over an hour and generating 16 gigabytes of data), has a usage manual, has test cases, and even has basic usage information in the code. So I know it can be done. See https://github.com/samboy/rg32hash/blob/master/C/tinyrg32.md and scroll down for the actual obfuscated C code.

Segfault: I know of a segfault when you try to run it on a file with nothing in the first line, which I'm working on. Beyond that, though, I'd have to do some rearchitecturing in order to get the char-count low enough that I'd have space for more documentation.

P.S. there is documentation already. Try ./two_kilo -h or with no args.

Where is the manual for this program? Every IOCCC winner has a "hint" file which explains what the program does and how to run it.

On the subject of small code: embedded folk have to do this sort of thing all the time. Put a wifi AP and client on a tiny processor with 1Mb of flash/256K of RAM. Host a web site so the user can configure the device. Contact a cloud server for continuous IoT provisioning. And perform whatever function the device does.

OTOH, the embedded context is kind of special in that you can hyper-optimize for each device, right?

For example: a program that runs on a desktop may have to take into account many edge-cases, but if an embedded device has quirks then they always apply for that device, so you can remove the "non-edge case" code from the binary.

Further: there are 'board support packages' or BSPs that are tailored to the processor, support chips and package that you're coding too. They work exactly for that configuration and no other. It'd be impossible to fit much in there otherwise!

Off Topic: Google translate thinks it's Welsh.

Probably has a small-enough document distance to famous welsh names like: llanfairpwllgwyngyllgogerychwyrndrobwlll

Is that an actual Welsh name or did you just jam your knuckles into the keyboard?

Thats actually the name of a village: https://en.wikipedia.org/wiki/Llanfairpwllgwyngyll

"St Mary's church of the pool of the white hazels near the pool"

But, its also kind of a cheat, since the name was established in order to be the village with the longest name for British railway station. - Some early tourist attraction-thingy. The isle of Anglessey has many natural and cultural sites, that are more interesting than railway station with a really long names though.

Llanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogogoch is also a "real" word in Welsh.

There is a youtube video out there with locals pronouncing it :D

Good submission for http://ioccc.org ?

To compile: gcc -o zolW zolW.c -lncurses

For those who missed it, I assume this was somewhat inspired by this project, which is building a small text editor without curses.


Nope, I was more inspired by the challenge to make a videogame that could fit on a business card.

This crashes almost immediately on my machine :(

The same. It does strlen(0) somewhere

  $ dtrace -n 'pid$target::strlen:entry { print(arg0) }' -c './a.out 2'
  CPU     ID                    FUNCTION:NAME
    4  22139                     strlen:entry int64_t 0

It requires a file with a nonblank first line. I'm working on that...

Did you give it a file to edit on the cmd line?


I don’t get it it’s telling me to F off. Maybe HN is sending too much traffic, but this seems rude.

This is the second small code snippet I've seen on HN this week that is intentionally unreadable. What is the draw in obfuscating code to make some silly "art"? I'm far less likely to compile and run it when I can't read it.

It’s art.

You might as well ask of painting and drawing artwork what its purpose is.

I would say it is more "craftsmanship" than "art": it is the proof of an ability, not something made to please.

Of course, this is just debatable. But the normal person will not be awed or simply pleased seeing the code. Only a good craftsman will appreciate it, which is its purpose.

I can clearly read it on my phone. Says "TWO KİLO".

If you think this is unreadable you should look at what "normal" APL code looks like. Then consider there are people who work with such code every day, being very productive in it, and to which normally-formatted C would appear excessively verbose. That really changes your perspective...

Agree. It's not art but an unfounded fear that one might steal/fork the source and get more credits.

I disagree that this is a likely reason. There's nothing novel about the implementation except the size of the source code.

If I wanted to do that I'd just not release any source. And--credits for what? Making a basic line texteditor? Those are a dime a dozen.

Really buggy sadly

It needs to be run on a file with a nonblank first line (which I'm working on), are there other bugs you've noticed?


"If you wish to make an apple pie from scratch, you must first invent the universe" - Carl Sagan

What is a good place to draw the line? Kernel? BIOS? Microcode? Hardware?

I say hardware and that 1072 bytes beats the shit out of that:


pfft, you aren't counting the megabytes of intel microcode that emulate this

I really don't understand why more people in this generation don't run their own strip mining operations for processor fabrication anymore. It's incredibly helpful in both understanding just how many man hours go into a single google search as well as teaching one how to get the most performance out of every last electron.

I'm even fine with OpenGL if the functionality is impressive. (Generated textures, models, great visuals etc.) A text noneditor is not.

Aye, in my day we had to smelt the ore first, but before we could do that we had to ... (drifts off)

In my day we had to invent tools first, but before we could do that we had to evolve from unicellular microbes.

But someone else has already tested that code.


Time to write a text editor in a shader, I guess.

or with a cellular automata (bonus if one writes a brainfuck to cellular automata compiler)

Applications are open for YC Summer 2019

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