What should I code to learn a given language?
October 14, 2008 10:49 AM   Subscribe

Let's say I want to learn a few (more) programming languages. What application/solution would it be best to try to create in order to really "learn" a given language?

I don't tend to respond well to standard tutorials, especially since with few exceptions most of them in the beginning look very similar (hello world, etc). I'm much more interested in jumping into the middle of things and figuring out how the language works by building something that actually does something.

With this in mind, what solutions should I build for a given language of choice.

To give an example: I'm fairly familiar with web programming, and I would guess the best app to use to learn a web programming language/framework (Ruby on Rails, PHP, ColdFusion, etc) would be to create a web-based messaging system. That would allow yourself to gain familiarity in database calls, file processing and management (maybe even image processing), interacting with mail servers, parsing text, and display.

I'm interest in any and all languages, although I'm leaning more towards languages that are strongly supported/used in the open source community, although I am also interested in languages normally employed in academic settings (ML comes to mind). Finally, I'd also be interested in knowing this answer for common programming technologies/formats (Ant/XML/XSLT) and miscellaneous (projects at Apache come to mind)
posted by Deathalicious to Computers & Internet (17 answers total) 32 users marked this as a favorite
 
If I were in your position, I'd grab the python interpreter and start tackling some of these Project Euler problems.

Of course, if Python's not your thing, you can do the same with any language of your choice.

I just happen to appreciate the utility of Python, and there's one big advantage with it -- these data-structure-oriented problems let you really explore the strongpoints of Python, which is more-or-less a truly object-oriented language. Another advantage is that it has plenty of solid documentation and online resources.
posted by spiderskull at 11:10 AM on October 14, 2008


It depends on the programming language. You probably don't want to write a high performance compression library in Python or a natural language processing system in Fortran.

You should probably figure out what kind of programs you want to learn how to write and then use a tool that helps you to write that type of program.
posted by demiurge at 11:15 AM on October 14, 2008 [1 favorite]


Hello World is the basic, not so much because printing strings is complex, but because it's an introduction into how to write the most basic of programs. I struggled with my Java-based Hello World, because I'd never used Java at all.

It depends a lot on what you do... A game developer would have a completely different set of skills than a web developer, or example. What I do think is helpful is to make an effort to do the same thing different ways... I just wrote some really simple code yesterday, but it was a pain because I'm trying to get myself more familiar with foreach() in PHP: I've always used for(). The code you write to learn should be something related to the "real" code you write, of course.

For the example you give, how about a webmail client? You could have a script connect to a POP3/IMAP server and retrieve mail, parse the headers, and so forth. And then you can write the sending half of it, that connects to an SMTP server to send mail. Or a simple photo gallery, or a simple forum/blog/message board. There are lots of programs that already do that, of course, but it'd be a good way to learn, and half of the existing products are pretty crappy, really. ;)
posted by fogster at 11:18 AM on October 14, 2008


From checking out the various books and tutorials, lately, it looks like developing a blogging platform seems to be the most common example.

It's certainly featured prominently in the ruby and grails books I've seen lately. It lets you exercise the full stack (presentation tier down to database), and everyone has a pretty good mental model of the core functionality. You also have to deal with issues like authentication and persistence pretty early in the development cycle, but the functionality isn't very big.
posted by jenkinsEar at 11:19 AM on October 14, 2008


Write a command-line program that reads records from an XML file, sorts them according to some user input, and writes them to a text file. Then add a GUI to it, either web- or desktop-based. If you know a couple of programming languages already then you're familiar with all the necessary concepts (sorting algorithms, file and user I/O, library linkage, presentation) but not how to implement them, so the learning curve is a bit lower than it'd be otherwise.

If you're on Linux and use Rhythmbox as your music player, you could start with the playlist XML file. Show all your friends what you've been listening to lately.
posted by xbonesgt at 11:19 AM on October 14, 2008


For C: write a simple web server. This will give you an understanding of structures, threading, networking, file i/o, memory management, etc.

For C++: write a simple raytracer. The math is not too hard, and a well-designed implementation will make good use of object-oriented programming, threading, memory management, and file i/o.

For Lisp (or another functional language): Implement some basic AI techniques, like k-means, k-nearest neighbor, or (for a bit of a stretch) a neural network.

For C++/Java (or any language with the appropriate bindings): Write a non-trivial program with a GUI. One possibility would be a front-end to your raytracing engine. For best results: include threading so that the GUI does not freeze while the raytracer is busy.

You can use Ant to manage the build for just about any of these, and use XML for the configuration files for your web server or raytracer. You could also experiment with using XML for the input files for your raytracer and use XSLT to perform simple transformations on those files (e.g., use XSLT to add wireframe bounding boxes to all of the objects in an input file).
posted by jedicus at 11:21 AM on October 14, 2008 [2 favorites]


The right training application would, of course, vary depending on the language, but I think the following criteria should apply in all cases:

1. The application should use a wide variety of features your target language takes advantage of.
2. The application should be simple enough that you'll see it to completion. I've found that some technologies have nuances and pitfalls that become apparent only after the application has been launched and used by others.
3. The application should be something you're interested in, for the same reason as #2. This is probably the most important criteria. I've found that if my chosen project is something I'm really excited about, I'll learn the language much faster than if it's something I need to force myself to pay attention to.

My last two projects have been games, because writing games are fun and for the technologies I was interested in, appropriate. They also have the advantage that because people like to play games, it's easier to find testers than if I were writing some kind of CMS.
posted by justkevin at 11:23 AM on October 14, 2008


In general terms, I think it's best to begin with something that you are familiar with as a user. This enables you to clearly visualize your target, which is important, especially if you're not inclined to write up a detailed design document at the start.

However, make it something that you haven't actually written before (to make yourself work out the core problems of that solution rather than falling back on past experience). I learned PHP by writing a relatively simple blog, and by the time I was done I had gained a wide range of language-specific ability in areas like image handling, date/time formats, XML, and basic security.

Seconding justkevin on keeping it simple. I find that every time I start out with a project that's too ambitious, I lose interest before it's completed. Maybe start with something that can be considered "complete" in a basic state but is highly expandable. The suggestion for a webmail client is a good one; you can have something basic put together (using your language's preferred mail-handling library) that lets you read/write mail in a fairly short time frame, but the opportunities to expand into other areas (handling attachments, multiple users, spam prevention just to name a few) are nearly endless.

I agree entirely that not all languages are suited for all tasks, but on the other hand, don't regard a new language as being necessarily suited only for what made it popular. Ruby is best known for Rails, but writing GUI applications with Shoes is a great way to learn Ruby: it's simple, fun, highly idiomatic, and comes with a wealth of straightforward programs written by other people, complete with source code.

After choosing your project, you'll want to find a decent online reference to that language's standard library. This is something to keep open in a browser tab the entire time you're coding. (Examples: PHP Quick Reference, Java API, Python Standard Library)

Final thought: even though you dislike tutorials, if you're interested in Ruby you should check out Why's (Poignant) Guide to Ruby. It's simply the most entertaining (and least tutorial-like) programming tutorial ever written.
posted by [user was fined for this post] at 12:08 PM on October 14, 2008


Write a lisp interpreter.
posted by phrontist at 12:49 PM on October 14, 2008


In addition to a CMS/blogging system, a cleaner clone of evite would work. A clone of Metafilter done in something modern like Rails or Django might be interesting.

As an aside, I too struggle with ideas for smallish practical web apps that could be developed in a new technology for learning.
posted by mmascolino at 1:22 PM on October 14, 2008


2nding Project Euler.

Also SICP exercises
posted by swapspace at 2:12 PM on October 14, 2008


3rding Project Euler.

Alternatively, look around and you can probably find some cool tutorials that aren't your standard "Hello World" ones. I found this one for Haskell (you said academic!) which has you learn Haskell by writing a Scheme interpreter. Hey, learn two languages for the price of one!
posted by losvedir at 2:48 PM on October 14, 2008 [1 favorite]


I read this question today and decided to play with learning Scala via Project Euler questions. I think they would be adequate for learning some of a functional language like ML, but not nearly enough to get comfortable with Java or C/C++. For those you need a larger-scale project, something that will force you to think about the object model, data structures, and interactions between several pieces of the system. It is going to be very hard to be a good contributor to an open-source project without a general idea of how moderately large software systems are put together.

I recently took a class through work emphasizing object-oriented design, and we implemented a simple monopoly game. This is actually not a bad way to pull together the elements I mentioned above, and when I taught (and upon recollection, took) intro to Java the major final project was also building a game. You might consider looking at lecture notes and assignments for college courses online, like perhaps this Java course from MIT, and poke around other university's websites to see what you can find in terms of assignments, because the hardest part for me trying to learn a language is thinking up all the details of a sample project to code. Games are fun because you can take it as far as you want: implement simple logic and text output, or go the full nine yards and put some graphics and a gui in.
posted by ch1x0r at 7:21 PM on October 14, 2008


Have a look at Crunchy, written using Python (and some javascript) and design a new plugin for it. Python takes a static html page and transforms it into an interactive Python session within your browser.

Some ideas for plugins: designing interactive elements for other programming language. The obvious extension is to design an interactive javascript plugin. The next obvious one is for html. Less obvious plugins would allow interactive ruby sessions within the browser.

You could look at doing this using Silverlight (Moonlight on Linux).
posted by aroberge at 8:54 PM on October 14, 2008


If I were in your position, I'd grab the python interpreter and start tackling some of these Project Euler problems.

Actually, for me this is the opposite of what I'd want right now. I really want the only difficulty to be the language itself, not puzzling out brain teasers. Although goodness knows I could stand to exercise my brain more.

I will be going over all these responses and start thinking about my next project.

Thanks!
posted by Deathalicious at 9:08 PM on October 14, 2008


You should probably figure out what kind of programs you want to learn how to write and then use a tool that helps you to write that type of program.

Well, to be honest aside from (obviously) my work and the random shell script, there hasn't really been a time when there wasn't already an existing application that did most of what I wanted to do, and I imagine that'll always be the case. This is really just for play and learning, so the whole point is to choose a random language and code an application that's suited for it. In fact, that was the very point of this question.
posted by Deathalicious at 9:11 PM on October 14, 2008


I just found an intriguing tutorial for Haskell in which you use the language to write an interpreter for Scheme. I'm just starting the tutorial now, but it looks like it should be a fun way to learn Haskell (and some Scheme as well).
posted by Deathalicious at 5:14 PM on April 26, 2009


« Older Reverting to a previous version of iTunes?   |   Get where from here? Newer »
This thread is closed to new comments.