What Toy Apps would you write in order to learn a language?
Let's say I wanted to learn Lisp, Haskell, Scala, Clojure, Javascript and Ruby. What set of toy applications would I have to write in order to say I have a good feel for the capabilities of the language and largely understand it?
For example maybe: Quicksort, Directory structure read/store/search, ping pong game?
I would guess that this question might be too general and should be broken down into sub sections, what do you think?
(
43 comments
| 43 points
| on HN
)
* Write a program that does a recursive directory traversal doing something with each file. Once without using any considerable library support (only open directory, list directory, etc.), and once trying to find a library to do it (such as the os.walk call in Python)
* Write a small recursive-descent parser for arithmetic expressions, with a regex-based lexer.
* Create a simple GUI with a few buttons and boxes
* Create a small multi-threaded application using producer/consumer or something else.
* Write a simple socket client-server pair and let them talk on localhost. Then rewrite it using a popular library for the language.
* Find out how to create a distributable .exe for Windows in this language
* Find out how to call functions from a C DLL in this language.
From a game development perspective, it's perhaps a bit too minimal (given that the spec can be implemented with static HTML), but it does serve as a sort of hello world for GUI interaction.
For me, the best way is to solve a few problems from Project Euler and then just dive into whatever I want to use the language for.
http://projecteuler.net/
Phew, sorry for the flame. Had to get it off my chest. PE is sometimes a knee-jerk reaction to programming queries, and this is wrong IMHO.
E.g. in Java, you would probably solve problem 1 with a for loop, while you could use a generator expression in Python.
http://www.hxa.name/minilight/
Here's the full article http://weblog.jamisbuck.org/2010/12/27/maze-generation-recur...
http://weblog.jamisbuck.org/2011/2/7/maze-generation-algorit...
* URL handling
* OAuth
* The HTTP client module the language uses
* The storage model
And other common webby things.
As an exemple a lot of people know how to make a blog in rails but only a part of them really understand what's a class variable.
I'm not saying it doesn't work, just that you could ending up knowing a framework not a language.
I agree I'm blurring the lines a little, but when I talk about liking 'Python' or 'Javascript' I mean not just the syntax, but the libraries, the package managers, and other parts of the surrounding toolset.
There are some languages with great syntax, but small communities and little library support. Checking the whole, bigger picture gives me a feel as to whether it's something I'd like to use in production.
Unlike the people you speak of, someone trying to learn the language would stop and learn what a class variable is. This is exactly how I learned Rails and the Ruby language. I just dove in to Rails and went to Ruby references along the way.
http://stackoverflow.com/questions/3247812/toy-projects-for-...
I will try that out in Python and let you know how it is going :D
A fresh take on a basic tool.
It could have started as a generic to-do list. That's how I'd begin.
And for me to say
> I have a good feel for the capabilities of the language and largely understand it?
I would need to have built, deployed, maintained, rewrote version 2.0, etc of a production app with actual users. Anything else is "Academic Knowledge".
* Go through any of the main tutorials or walkthroughs to get a basic understanding.
* Have a read of the API docs.
* Gain an understanding of concurrency, bounds checking and memory management by writing simple apps to test each.
* Write a program to execute another program
* Write a program to access core system info (e.g. registry etc.)
* Write a program that uses sockets or network connectivity (normally a client and server)
Making a calculator forces one to learn how to work with the user interface framework. Making a sophisticated calculator forces one to learn more about the language and the math libraries available.
That should provide a good feel for the basic language constructs, and the essentials of the standard library.
Why do you care to learn said language?
When I started learning F#, I tried these traditional suggestions: write some data structures and algorithms, go through Project Euler problems. I probably wrote close to a few hundred lines of F#. You know what ended up happening? I can't remember a lick of F#. How could that have happened?
I had no palpable reason to learn F#. I like writing web applications, and the ones that I do like to write have very little use for concurrency or functional programming (also the reason why I'm having trouble getting motivated to write any Haskell/Erlang).
Compare this with Ruby (Rails). I had an idea for a web app. I work on the .NET stack during the day and I wanted to learn another language. I heard that Python and Ruby were the best ones to pick up, and since they are so similar in terms of end goal, I chose Ruby because it simply intrigued me more. I've written close to a few thousand lines of Ruby and I'm at the point where I could write it ad hoc and make something off the top of my head. So what worked this time around?
The keywords here are "idea" and "intrigue."
The number one thing that will help you learn a new language is to have an idea of something you want to build.
It doesn't have to be a new idea. Maybe you want to try cloning ThreeWords.me. Maybe you want to automate picking stocks (a personal favorite). Whatever it is, you have to have an idea of something you want to build, not only because it helps you define the language you should use (and thus give you a compelling reason to learn X instead of Y), but also because it will give you the intrinsic motivation to retain that knowledge after you've executed on your idea. You'll feel like the language has a purpose in your life, an actual tool you can use from the proverbial programmer's toolbox.
The other piece, as I mentioned, is intrigue. You have to want to learn the language to really get any benefit from it. As I mentioned earlier, it ultimately came down to a gut feeling as to why I chose Ruby/Rails over Python/Django(/Pylons/Web2py). This is so important, because ultimately if you're already trying to learn a language outside of work, you've got an internal motivator that isn't driven by profit or work; it's driven by excitement and fun. So follow through on that promise to yourself to have fun by picking a language that makes coding fun! If Haskell bores you but Erlang gets you going, even if Haskell is considered to be a more hardcore functional language...WHO CARES! You're doing this for fun, NOT with a gun to your head or a job on the line. You need to do what's right for you. I don't think I've ever met an individual who said "I picked the wrong language to learn, I'm dumber than I was before!"
TLDR: You need to have a reason to learn said language(s) by first having something to build. That will help you choose a subset of languages you'll actually want to learn. When filtering down between similar languages, go with your gut and choose the one that excites you the most. You simply can't go wrong, and there's no better way to learn a language faster than by building something you've always wanted to make.