In my previous post about simulating the Ising model with the Metropolis algorithm in NetLogo, I said that I would return and and give a walk-through of the amazingly succint NetLogo code. Actually, I’m not going to do that; NetLogo code is sufficiently readable, and the documentation is sufficiently comprehensive, that there’s no real point.
Instead I want to discuss to what extent NetLogo can be considered a “real” programming language, suitable for work beyond its roots in education. The short answer is that it looks to me like quite a competitive language, which will make a particularly excellent choice for many scientific applications.
NetLogo is optimized for simulations of agents moving in a two-dimensional space. The moving agents are called “turtles” but you can think of them as objects endowed with a lot of built-in methods. It’s quite possible to use the turtles in the same way as objects in other object-based languages (although only a limited form of inheritance is available). For example, a turtle can contain other turtles as variables, and you can create new classes (called “breeds”) of turtles. The other basic objects, with many built-in methods, are the “patches” which tile the 2-d space, the “links” that you can set up between turtles, and the “observer.”
There are an impressive number of built-in primitive procedures, especially for anything that relates to simulations. You can also do all the basic things that you would expect a language to do: open and write to files, process strings, work with lists, etc.
The ability to quickly and easily build a GUI that will work on all platforms is very attractive. I have some experience building GUI’s for Mac OS X, using Cocoa and/or the Python bridge PyObjC (which is another worthwhile approach and something that I’ll post about at some point), and I can say that to build essentially the same simulation with the same GUI in NetLogo takes easily less than half as much work and code. It is also nice that it is so easy to construct applets and movies.
The syntax is similar to Lisp, but without parentheses, and with a great deal of syntactic sugar to make it look as close to English as possible. It is absolutely an optimal first language for the beginning programmer. My son was amazed that “everything worked, and when it didn’t I could understand the error messages.” He’s not really used to that from his experiences with other languages.
I looked for things that are missing. At first I thought hash tables weren’t there, but those are actually available through an extension. One thing that really is missing is the ability to treat a function as a value. You also can’t define your own special forms or macros, so I suppose that it’s not really Lisp. NetLogo also does not have, aside from in its core area of simulation, much in the way of libraries, but there is the ability to extend the language by writing functions using Java.
It’s easy to learn; but don’t neglect to look at the code examples section of the models library (you’ll need to download NetLogo first). You’ll see how easy it is to do things that take a lot more work in most languages.
Tags: GUI, Java, NetLogo, programming languages
September 23, 2007 at 4:41 pm |
[…] a future post (Edit: it’s here), I’ll step through this code and show you how it works (you do also need to click on a few […]
February 23, 2011 at 12:38 am |
Yes, Netlogo is great for a beginner like me.