What is the shortest and most effective code ever written?

Quora runs the question, that by now has plenty of awesome answers.  But this one is my favorite so far:

The ‘true’ program in Unix from the 1970s was an empty file. The shell interpreted that as a shell script which ran and resulted in no error status, so the result was zero. Zero is the shell exit code value that represents ‘success’ or ‘true’ within if and while clauses.

So, no program can be shorter than that. And it was entirely effective at meeting its specification.

False was much longer, being

exit 1

Once lawers got in, both programs were sullied with plenty of copyrights. BSD also eventually established a format for identifying shell scripts explicitly, and those codes got added to the file too. Eventually, ‘true’ stretched to hundreds of bytes of copyrights on top of the shell script format intro code. Now, annoyingly, Linux and Mac OS have made it a compiled binary program. In Ubuntu, it is a 22K binary with an 18K code size. Ugh.

At least writing a correct C program for true can be very short. It is one of the few C programs that should require no #include files, and can be simply:

int main(void){return 0;}

Of course make sure to add lots of copyright notices.

An Interview with Brian Kernighan

An Interview with Brian Kernighan

John Wait: Many popular newer programming languages trace their roots to C. Unix has had direct and indirect influence on many newer operating systems. To what do you attribute the longevity and popularity of both C and Unix?

Brian Kernighan: Both C and Unix strike a very good balance among expressiveness, efficiency and economy of means. That means that they are a good base to build on: the good ideas are worth stealing and the efficiency sets a standard of comparison.  It’s also easier for people to make a transition from something familiar than to make a big change, so a language or system that has significant elements of familiarity is more likely to be a success.

Via LWN.