Live data from Hacker News

Learn a Programming Language Faster by Copying Unix

rodrigoalvesvieira.com

61–70 of 110 posts

Re: Learn a Programming Language Faster by Copying Unix

#63
post #8

My favourite way to learn new languages & platforms was implementing a du-like ('disk usage') tool. It was also the exercise I proposed to my students. It doesn't require complex algorithms but touches a lot of the basics: recursion, filesystems, command line parsing, output formatting, etc.

I am taking Operating Systems at Auburn University, and my professor had us work on the Linux kernel source, learn how to define and implement our own system calls using the SYSCALL_DEFINE[0-6] macro and then implement our own memory snapshot tool. It is similar to /proc//statm. We had to get other info on major and minor page faults as well. I learn a lot doing things like this.

Re: Learn a Programming Language Faster by Copying Unix

#65
post #31

Your ruby version of cat implements none of the command line switches. I learned C by going through the FreeBSD code and helping with POSIX compliance. For fun I would implement a lot of the commands in Python. You get the most out of learning both the language and UNIX by implementing all the command line options.

And you get a better grounding in the Unix philosophy if you omit the command line switches and make small utilities to handle those cases, because as the paper said, cat -v is harmful ( http://harmful.cat-v.org/cat-v/unix_prog_design.pdf ).

The Unix philosophy is somewhat of a myth. http://cm.bell-labs.com/cm/cs/who/dmr/man12.pdf shows that that same first edition already had a -t option on ls. Surely, that should have been some | sort, but AFAICT, they did not bother to write that until some later time.

Re: Learn a Programming Language Faster by Copying Unix

#66
post #65

Earlier quoted context omitted.

And you get a better grounding in the Unix philosophy if you omit the command line switches and make small utilities to handle those cases, because as the paper said, cat -v is harmful ( http://harmful.cat-v.org/cat-v/unix_prog_design.pdf ).

The Unix philosophy is somewhat of a myth. http://cm.bell-labs.com/cm/cs/who/dmr/man12.pdf shows that that same first edition already had a -t option on ls. Surely, that should have been some | sort, but AFAICT, they did not bother to write that until some later time.

[deleted]

Re: Learn a Programming Language Faster by Copying Unix

#67

Can someone give a non-expert way of going about this learning method? For instance, what are your options on Windows or Mac? And are the languages you can do this with limited to Ruby, Python, or Javascript?

Mac is Unix under the hood.

On Windows you can install Linux in a virtual machine, or you can install Cygwin (which is basically an almost complete POSIX system on Windows).

You can use your preferred programming language to implement any of these tools: Ruby, Python, Perl, Scheme, Common Lisp, C, C++ ... The original Unix implementation of these tools was done in C.

Re: Learn a Programming Language Faster by Copying Unix

#69
post #9

The example code for cat is only half of cat, which reminds me of Rob Pike's criticism of "cat -v"---Unix programs are often more complicated than they arguably should be, are "reimplementing" Unix programs often means implementing a small subset of the features. Or, look up the manpage for your locally installed "tree" and see how many non-standard options and features have been bolted on. I think it would be helpfu…

Even if you ignore all of the bolted on options, his simple implementation of cat doesn't even handle "cat -" so I would say less than half. I think this is still a good exercise if you don't dig deep into the plumbing of all the tools you're reimplementing, but it's even better if you do.

Re: Learn a Programming Language Faster by Copying Unix

#70
A few years back I remember submitting the implementation of a couple of Unix tools in Perl. The idea was to implement as many of the standard tools as possible, in perl.

The project seems to be sleeping, although there are many contributions:

  http://search.cpan.org/dist/ppt/
Post reply on HN