Learn a Programming Language Faster by Copying Unix
21–30 of 110 posts
Re: Learn a Programming Language Faster by Copying Unix
#22For 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.
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
#23I 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
#24For 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.
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
#25 puts ARGF.read
I know it's besides the point, However I couldn't resist :)Re: Learn a Programming Language Faster by Copying Unix
#26Re: Learn a Programming Language Faster by Copying Unix
#27The 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.
Re: Learn a Programming Language Faster by Copying Unix
#28I 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
#29For 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!)."
Re: Learn a Programming Language Faster by Copying Unix
#30On a side note, a more concise version of cat in ruby is: puts ARGF.read I know it's besides the point, However I couldn't resist :)