I recently upgraded the MediaWiki software that powers Spivey's Corner. If you notice any glitches in the new setup,
please let me know and I will see what can be done. – Mike

Setting up a programming environment/Notes

From Spivey's Corner
Jump to navigation Jump to search

Other pages to be merged into this one:

Notes

  • Bullseye with RPi desktop needs more than 8GB disk for a full installation with a swap partition: try 20GB.
  • For first boot, there's a file /etc/xdg/autorun/piwiz.desktop and also a directory /home/rpi-first-boot-wizard with subdirectories Desktop, Documents, Downloads, Music, Pictures, Public, Templates, Videos, all owned by rpi-first-boot-wizard:nogroup. That directory and the user ID are deleted after running the wizard.

Contents of /etc/xdg/autorun/piwiz.desktop:

[Desktop Entry]
Type=Application
Name=Raspberry Pi First-Run Wizard
Exec=sh -c 'gsettings set org.gnome.mutter center-new-windows true; sudo -AE piwiz'
StartupNotify=true


To write:

  • A note about establishing ssh connection to account on ecslab machines, and using that for backup.


All of the software recommended in these notes is free, and easy to find and download.

Linux (with the Raspberry Pi desktop)

If you want to have your own Linux-based programming setup, there are basically two options: get a computer that you can install with Linux, or use a computer you already have – a Mac or a Windows machine – and install a version of Linux inside the virtual environment called VirtualBox.

Get a Linux laptop

Though it seems extravagant, buying a laptop specially to run Linux need not be expensive. If you choose a lightweight Linux distribution such as the Raspberry Pi desktop, then a suitable second-hand laptop can be bought for £150–200. Look for a machine with at least 2GB of RAM and a 60GB hard disk or SSD, if you can still find one that small. It may be that you can find a cast-off machine from a friend that is no longer powerful enough to run recent versions of Windows, but is perfectly fine as a lightweight Linux machine. If you want to buy a second-hand laptop, I won't put any supplier recommendations here, but would be glad to be asked in person.

The Raspberry Pi people produce their own Linux distribution, Raspberry Pi OS (formerly known as Raspbian). It's based on the popular Debian distribution, but compiled to run on the ARM processor of the Raspberry Pi. It comes equipped with a graphical environment (the Raspberry Pi desktop) that's based on LXDE, a lightweight alternative to Gnome, but with a much more polished appearance than LXDE.

The "Raspberry Pi desktop for PC and Mac" is a kind of side project, consisting of Debian for the i386 or x86_64 equipped with the same desktop environment as Raspberry Pi OS. It is a simple and easy-to-use Linux distribution that is well suited to less powerful, older machines. An installation image can be downloaded from

https://www.raspberrypi.com/software/raspberry-pi-desktop

The 32-bit i386 version is perfectly adequate for our purposes, but if a 64-bit edition becomes available (and you have a laptop with a 64-bit processor) then that will work too, and might be slightly faster.

I don't recommend trying to run Linux from a memory stick, except as a demonstration that it is possible.

Use VirtualBox

VirtualBox uses hardware features of recent processors to provide an emulated environment where a 'guest' operating system can run as a single process within a 'host' operating system. Some of the RAM of the host machine becomes dedicated to the guest operating system, and a single large-ish file in the host operating system provides a simulated hard disk drive for the guest. For our purposes, the host might be a PC running Windows or a Mac running Mac OS, and the guest will be a version of Linux. The lightweight nature of the "Raspberry Pi desktop for PC and Mac" makes it ideal as the guest in such a setup, able to run in the modest share of the memory of the host machine that can be lent to the guest.


Geany

There is a huge variety of editing and program development environments on offer – and tastes differ, sometimes in a way that is expressed all too passionately. More experienced participants in our courses will already have their own ideas about what tools they like, but for beginners it's good to have an environment that provides simple editing commands, a small selection of clear program building actions, and a clear interface, without complex tools or too great a focus on one programming language. I think that the open source development environment Geany fulfils these requirements very well.

Geany can be installed on Windows and Mac OS as well as Linux, but on Linux it shines particularly well. It does not attempt to integrate too tightly with compilers for various programming languages, but is capable of running any compiler in a sub-process, and usually able to parse the compilers error messages in order to highlight the source lines that contain the errors.


Tools for various courses

Functional programming

The Glasgow Haskell compiler GHC is easily installed on Debian as the package ghc.

Imperative programming

Programs in all three parts of the Imperative Programming course are written in the Scala language. The compiler is available on Debian as the package scala.

Digital systems

For Digital Systems, we will use a cross-compiler that runs on a PC but generates code for the Cortex-M ARM chip in the BBC micro:bit. The compiler is provided in Debian as the package gcc-arm-none-eabi; instructions for installing it and supporting software are given on a page on the course website.

Compilers

The second year Compilers course features a programming assignment that is carried out over the Christmas vacation, making it especially convenient to have your own machine set up for development. The compilers studied in the course are written in the (non-pure) functional language OCaml, provided under Debian by the package ocaml-nox, which contains the OCaml compiler but not the extra libraries needed to write GUI programs for X windows. Further instructions are given on a page on the course website. Towards the end of the course, we will generate native code for the ARM, and there is an emulator packages as qemu-arm that allows the object code to be executed on a PC. The ARM cross-compiler package gcc-arm-linux-gnueabihf that is needed to support this differs from the bare-metal package used in Digital Systems, but it's OK to install both at once.

Mike's choices

My own programming setup is a bit different from what I've recommended here. I have Debian with Gnome 3 on most of the PCs I use, but I also use Raspberry Pis for some purposes, and I find the Pi desktop quite comfortable, and much tidier than basic LXDE.

I am a long-term user of Emacs, principally because at the time I adopted it, the choice was more or less Emacs or Vi, and Emacs had the feature of allowing a project to be built within the editor, with any error messages parsed afterwards. I had used Vi quite a lot, and never liked the style of interaction that separated command mode from insert mode.

For almost all projects, I stick with Make as a build tool, because it is universal, and adapts well to projects that are written in more than a single language. I use it to manage the processing of collections of TeX documents too.

For version control, I always use Mercurial, just because its set of commands seem to be better designed for human use than the (entirely equivalent) commands offered by Git. When I work with public Git repositories like GitHub, I just use Hggit, which enables Mercurial to be used as a client for Git.