Which language on the Raspberry Pi?

What language should you use on the Raspberry Pi? There is quite a choice, including Python, Scratch, Java, C, Julia, and that's not counting the web stuff like Javascript, Html and Php.
There is no definitive answer - it depends on what you want to do. If you are teaching a child the basics of programming then Scratch might be a good choice. If you are an older learner then you might go for Python or Java with Greenfoot.
If you are interested in programming the Raspberry Pi hardware then there are libraries for pretty much any language that will let you do that. 
If you want a graphical user interface then you may want to give C a miss. But not necessarily because you can tack on a GUI in almost any language these days.
So where does that leave us?
Here is a list of some of the programming languages available for the Raspberry Pi with my brief personal notes and an example program for each one (except Scratch).

Scratch This is a graphical language designed to teach kids about p…

A little bit of Julia

Julia is available for many platforms but was announced as a new programming language for the Raspberry Pi recently, so I just had to have a play with it.

Julia is designed for numerical computing but works as a general purpose programming language, too. The Raspberry Pi version also has libraries for interacting with the GPIO, SenseHAT and Minecraft.

The main Julia web page is here and the Julia web page for Raspberry Pi is here.

In this blog I'm just going to look at the basics of Julia by writing a simple guessing game program (similar to the one in my Just Enough Python blogs).


First, though you need to install it. This is simple just open a terminal window and type

sudo apt-get update 
sudo apt-get install julia
 Wait for a while and you are all set. You can run Julia from the command prompt. This will give you an interactive Julia session like this

To get out you have to type control-d.

This is great for experimenting with Julia but I'm not going to dwell on this.

Instead I'll present a simple program that shows how to use simple input and output, decisions, loops and functions.

Here's the program

# Simple guessing game
# the computer thinks of a number between 1 and 10
# you have 5 attempts to guess it

#define a function to get a guess
function guess()
    print("Enter a guess (1 to 10)")
    a = chomp(readline())
    return a

# Start here

#Get a random number
number = rand(1:10)   
# Convert it into a string   
answer = string(number)
# Get a guess from the user
attempt = guess()

# Let the user guess 5 times
for i in (1:5)
    if attempt == answer
        println("Correct - well done!")
        println("Wrong - try again")
        attempt = guess()

print("The answer was ")
You can run this from the command prompt using the command julia filename.jl (julia programs generally have the extension .jl).

As you can see it is quite straightforward. If you are familiar with Python, or any other language, really, you won't have too much problem in working out what is going on here.

One difference with Python is that blocks of code inside a function, if statement or loop end with the end keyword. Indentation is not strict, as in Python, but it is, of course, conventional to indent properly. It reminds me of Pascal in this respect.

This is the Julia version of the program in my tutorials Just Enough Python - if you need to find out how it works you can look there (see below).

Back to Which Language for the Raspberry Pi.


Just Enough Python
An brief introduction that will get you programming quickly


  1. This comment has been removed by the author.

  2. mmm, do we really need yet another language for the RPi,
    Python + numpy etc or Anaconda offers a lot of numerical support. However I will have a look at Julia later.
    The one thing I dislike about Python are the blanks as block structures - it looks as though Julia has that as well.

  3. I guess we don't actually need a new language and Python has the advantage of being more mature and well supported but Julia does look quite good and I think I agree about Python's strict indenting.


Post a Comment

Popular posts from this blog

Just Enough Python

Learn to code with C

Introduction to Python by Andrew Ng