Stop asking your students to write command line UIs

How often have you used a UI like this?


/==========================\
| 1. List files            |
| 2. Show the current time |
| 3. Show Top              |
| 4. Quit                  |
\==========================/

Enter your selection: 

Even if you are a banker, travel agent or a medical doctor I would argue never. These groups are unfortunate enough to still have to use arcane command line interfaces to do unspeakably complex things like recording last week’s hours or reserve a ticket to your home town. But none of these systems are razor thin wrappers for simple shell tools – they are that way because they are really hard to replace. And more importantly, no employer is ever going to ask anyone to make a menu based command line UI for their shell script. It just doesn’t happen anymore. It is not a valuable skill. ASCII art is recreation, not work. So the time spent fiddling with echo and read is wasted, and could be put to better use.

There are many generally applicable skills you can teach shell newbies:

  • The Unix philosophy: writing programs that do one thing, that work with other programs, and that handle text streams. An hour of cobbling together a pipeline of grep, cut and a light sprinkling of sed can save days or weeks of data processing which might take a week to write in Python or six months in a spreadsheet.
  • On the flip side, they should know the limitations of the shell. Why while read is several orders of magnitude slower than other language equivalents. Why writing secure shell scripts is basically impossible. Or why big shell scripts are a maintenance nightmare compared to other languages.
  • Which tools are available to do what. There are so many useful tools you could probably spend a week full time just touching briefly on each of them. Check out for example BusyBox for a set of generally available tools.
  • Where to look for answers and how to ask good questions.
Advertisements

Minecraft mine analysis – mian

The mian wiki is now up! Updates will be put there for your convenience.

Pepijn de Vos has made a tool to graph materials in Minecraft save games across heights, to see how deep one should mine to find for example diamond. As a propaganda minister Minecraft player with too much time on his hands, this was too cool. I just tweaked it a bit, we both contributed speed improvements, and now it looks like this:

Graph of block count for several materials across the height of the world

On Ubuntu, you can install it with the following command:
sudo apt-get install python-matplotlib && sudo easy_install mian
… and run it like this:
mian ~/.minecraft/saves/World1

Options include:
-b, --blocks – Specify block types to include as a comma-separated list, using either the block types or hex values from the list.
-l, --list – List available block types.
-n, --nether – Show Nether data instead of the normal world.

For example, run mian -b 01,dirt,09,sand ~/.minecraft/saves/World1 to get a map of the more common elements in the map, with the abrupt cutoff of stationary water showing the sea height:

Common materials in Minecraft

More information is available in the form of a Git repository (of course it’s open source) and Ohloh project.

Update: Now works with The Nether, included in today’s Halloween Update. To graph The Nether, make sure you visit it first, update mian with sudo easy_install -U mian, then add the parameter -n to your command. For example mian -b 56,57,58,59,5a,5b -n ~/.minecraft/saves/World1 to show all the new materials:

Graph of the new materials in an existing world

Beta update: mian 0.6 works fine with Minecraft Beta. If you have an older version, simply run sudo easy_install -U mian