4 ms·
Serious question: why is this on HN front page? Am I missing something?
by aiur3la 10y ago
Serious question: why is this on HN front page? Am I missing something?
- pavlov 10y agoI feel it's kind of interesting as a minimal Unix program that does something useful without linking to the C library, just with syscalls. Even for echo, this one is extremely minimalist: first argument only, and a maximum of 255 characters.
- gens 10y agoI don't understand why it is limited to 255 chars. The kernel copies the string(s) into the programs memory so it would be a kernel bug if the program got a non null-terminated or too long string. More importantly this program has a bug in that it doesn't check if there is an argument passed to it at all. Good effort but can improve a lot. I would praise the documentation but it is rather imprecise. All in all i wouldn't put it on the front page of HN yet.
- pavlov 10y agoMaybe the 255-char limit is a feature? If this "fast echo" is meant to be used in a script that writes entries to a log where you wouldn't want long text anyway, or something like that... So having a known upper bound for the output size can be useful.
- deleted 10y ago[deleted]
- cyphar 10y ago> I don't understand why it is limited to 255 chars. The kernel copies the string(s) into the programs memory so it would be a kernel bug if the program got a non null-terminated or too long string. But you can also pass arguments to execve(2) which are not null-terminated.
- gens 10y agoThe kernel copies the strings you pass in the array of pointers. (haven't checked though, but it is better then the alternative of not copying and dealing with the mess)
- cyphar 10y agoThe memory mapping is the same before and after execve(2), so I don't think it needs to be copied. I'll take a look though.
- gens 10y agoMaybe only a few pages remain as programs don't inherit memory from their parents. It could be done for those strings but consider that mappings are in 4k pages (so the rest of the page would have to be cleared to 0).
- kelseyhightower 10y agoThis is great feedback, which I plan to use to improve the echo program. I'm just learning (on my own), and I figured I would just post my progress and I would get some feedback; it worked! echo is far from finished, and it's safe to say "I don't know what the hell I'm doing", but hey, I gotta start somewhere.
- unixbhaskar 10y agoThat's the spirit Kelsey! keep it up.
- activatedgeek 10y agoI think this is a pretty interesting piece of code. Something trivial via non-trivial (something that we don't do everyday) set of calls.
- Bladtman 10y agoSerious answer: Because many developers regard assembly as some sort deep magic only understood by elder gods. This, of course, comes from some vague (and not entirely correct) understanding of "assembly" running beneath everything else, and thus being fundamental, yet not immediately useful to a large category of developers today. Hence it seems important but archaic. Archaic + difficult = elder knowledge.
- userbinator 10y agoI've actually had a few coworkers think I'm some sort of elder god when I find the root cause of subtle bugs that would've either required deep knowledge of the C++ standard, or not-as-deep knowledge of Asm. These are bugs that others have spent many hours staring at the source and stepping through in a debugger without any better idea of why they occur, but are solved in minutes by a glance at the Asm. IMHO if you are working with native code at all, it's a very useful skill to have.
- ycmbntrthrwaway 10y agoEveryone who works with native code, not just C or C++, should at least understand how linkers and loaders work.
- ycmbntrthrwaway 10y agoOnce you are tired being praised, teach them some valgrind. It will solve most of their problems.
- userbinator 10y agoI'm pretty sure the bugs I found would not have been valgrind-able as they were unrelated to memory errors.
- ycmbntrthrwaway 10y agoFrom my experience most of the hard to trace errors come from uninitialized variables and they are usually valgrindable. It is VM-based so it can cache jumps and other conditions that depend one uninitialized vars via taint analysis.
- cshep 10y agoYes. From experience, many developers, namely newly-graduated college students from not-so-rigorous programs, have little idea of Assembly. The same applies with theoretical computer science (Turing Machines, FSMs, PDAs etc.), algorithmic analysis and fundamentals of computing hardware (flip-flops, half/full adders, basic CPU design).
- ZeljkoS 10y agoI agree, nothing special. For comparison, "colpinsky" draws color changing Sierpinski Triangle in only 16 bytes, less than this echo :D https://www.youtube.com/watch?v=Qw5WLk9IeX0 https://www.youtube.com/watch?v=Qw5WLk9IeX0 https://www.pouet.net/prod.php?which=62079 https://www.pouet.net/prod.php?which=62079