Live data from Hacker News

Learn a Programming Language Faster by Copying Unix

rodrigoalvesvieira.com

21–30 of 110 posts

Re: Learn a Programming Language Faster by Copying Unix

#21
I write a unit testing framework in every new language I learn. I find it's a great workout because making it usable for yourself is immediately assessable, and it often forces you into deeper areas of the language, including reflection and meta-programming.

Re: Learn a Programming Language Faster by Copying Unix

#22
post #17

For a purely functional language like Haskell, this would not be a very good advice. Any kind of I/O would involve monads and other imperative constructs. Better implement an algorithm involving trees or graphs to better appreciate a functional language.

main = interact id This is a slightly crude implementation of cat in Haskell. As you can see, it is replete with scary monad plumbing that gets in the way of the actual functionality (copying stdin to stdout). I would explain further and implement more than what the blog post suggested but there's already a book (Real World Haskell) that does this with a number of other Unix commands.

In the post I only suggested cat and tree for examples. Other nice tools would be: ls, touch, rm, mkdir, rmdir and even cal.

I just made a few more suggestions. I can't count how many neat, small tools are provided by Unix. It's a large ground to play in!

Re: Learn a Programming Language Faster by Copying Unix

#23

I write a unit testing framework in every new language I learn. I find it's a great workout because making it usable for yourself is immediately assessable, and it often forces you into deeper areas of the language, including reflection and meta-programming.

That's nice.

Re: Learn a Programming Language Faster by Copying Unix

#24
post #17

For a purely functional language like Haskell, this would not be a very good advice. Any kind of I/O would involve monads and other imperative constructs. Better implement an algorithm involving trees or graphs to better appreciate a functional language.

Not at all. You can start doing I/O in Haskell without knowing anything at all about monads by just treating the do-syntax as an imperative DSL.

In fact, Bryan O'Sullivan (who wrote Real World Haskell) just held a tutorial session on Haskell a couple of weeks ago where people completely new to the language implemented simple Unix tools like "wc". I don't think monads were mentioned at all.

Re: Learn a Programming Language Faster by Copying Unix

#27
post #26

The advantage and disadvantage of this approach: you have to already know Unix commands. Inevitably all programmers learn Unix commands - but probably a rough approach for beginners. Although, I'm guessing this advice isn't really aimed at beginners anyway.

Other side of the coin: you'll learn unix commands in a very non-superficial way.

Re: Learn a Programming Language Faster by Copying Unix

#28
I feel like this approach might get boring after a couple of languages.

I think most people here could skim through the language intro, and then just start working on a new project in that language (picking up more of the language as they go).

This is the approach I usually use, and it seems more fun than porting the same tools. Just my opinion though :)

Re: Learn a Programming Language Faster by Copying Unix

#29

For those who want a very clear, concise set of userland code to try translating for practice, consider using 9base: http://tools.suckless.org/9base It's not quite Unix, but it's still quite lovely and it's rather succinct: "It also contains the Plan 9 libc, libbio, libregexp, libfmt and libutf. The overall SLOC is about 66kSLOC, so this userland + all libs is much smaller than, e.g. bash (duh!)."

in the same spirit: unixv6 https://github.com/guilleiguaran/xv6
Post reply on HN