“Hello world” is the start of the whole lot in relation to computing and programming. It’s the very first thing you be taught in a brand new programming language, and it is the way in which you take a look at one thing out or examine to see if one thing’s working as a result of it is often the only method of testing easy performance.
Warriors of programming language wars usually cite their very own language’s “hello world” in opposition to that of one other, saying theirs is shorter or extra concise or extra express or one thing. Having a pleasant easy readable “hello world” program makes for an excellent intro for novices studying your language, library, framework, or device.
I assumed it could be cool to create an inventory of as many alternative “hello world” applications as doable that may be run on the Raspberry Pi utilizing its Raspbian working system, however with out putting in any further software program than what comes bundled once you obtain it from the Raspberry Pi web site. I’ve created a GitHub repository of those applications, and I’ve defined 10 of them for you right here.
1. Scratch
Scratch is a graphical block-based programming atmosphere designed for teenagers to be taught programming abilities with out having to kind or be taught the synax of a programming language. The “hello world” for Scratch is straightforward—and really visible!
1. Open Scratch 2 from the principle menu.
2. Click Looks.
three. Drag a say Hello! block into the workspace on the proper.
four. Change the textual content to Hello world
.
5. Click on the block to run the code.
2. Python
Python is a robust and professional language that is additionally nice for novices— and it is a number of enjoyable to be taught. Because certainly one of Python’s principal aims was to be readable and persist with easy English, its “hello world” program is so simple as doable.
- Open Thonny Python IDE from the principle menu.
- Enter the next code:
print("Hello world")
- Save the file as
hello3.py
. - Click the Run button.
three. Ruby/Sonic Pi
Ruby is one other highly effective language that is pleasant for novices. Sonic Pi, the stay coding music synth, is constructed on high of Ruby, so what customers really kind is a type of Ruby.
- Open Sonic Pi from the principle menu.
- Enter the next code:
places "Hello world"
- Press Run.
Unfortunately, “hello world” doesn’t do Sonic Pi justice within the slightest, however after you have completed this text you need to take a look at its creator Sam Aaron live coding, and see the tutorials on the Sonic Pi website.
Alternatively, to utilizing the Sonic Pi software for this instance, you possibly can write Ruby code in a textual content editor and run it within the terminal:
- Open Text Editor from the principle menu.
- Enter the next code:
places "Hello world"
- Save the file as
hi there.rb
within the dwelling listing. - Open Terminal from the principle menu.
- Run the next command:
ruby hi there.rb
four. JavaScript
This is a little bit of a cheat as I simply make use of client-side JavaScript throughout the internet browser utilizing the Web Inspector console, however it nonetheless counts!
- Open Chromium Web Browser from the principle menu.
- Right-click the empty internet web page and choose Inspect from the context menu.
- Click the Console tab.
- Enter the next code:
console.log("Hello world")
- Press Enter to run.
You may also set up NodeJS on the Raspberry Pi, and write server-side JavaScript, however that is not out there in the usual Raspbian picture.
5. Bash
Bash (Bourne Again Shell) is the default Unix shell command language in most Linux distributions, together with Raspbian. You can enter Bash instructions straight right into a terminal window, or script them right into a file and execute the file like a programming script.
- Open Text Editor from the principle menu.
- Enter the next code:
echo "Hello world"
- Save the file as
hi there.sh
within the dwelling listing. - Open Terminal from the principle menu.
- Run the next command:
bash hi there.sh
Note you’d often see a “hashbang” on the high of the script (#!/bin/bash
), however as a result of I am calling this script straight utilizing the bash
command, it isn’t vital (and I am making an attempt to maintain all these examples as brief as doable).
You’d additionally often make the file executable with chmod +x
, however once more, this isn’t vital as I am executing with bash
.
6. Java
Java is a well-liked language in trade, and is usually taught to undergraduates finding out laptop science. I discovered it at college and have tried to keep away from touching it since then. Apparently, now I do (very small quantities of) it for enjoyable…
- Open Text Editor from the principle menu.
- Enter the next code:
- Save the file as
Hello.java
within the dwelling listing. - Open Terminal from the principle menu.
- Run the next instructions:
javac Hello.java
java Hello
I might virtually keep in mind the “hello world” for Java off the highest of my head, however not fairly. I at all times neglect the place the String[] args
bit goes, however it’s apparent when you consider it…
7. C
C is a basic low-level programming language. It’s what many programming languages are written in. It’s what working programs are written in. See for your self&mdash:check out the supply for Python and the Linux kernel. If that appears a bit hazy, get began with “hello world”:
- Open Text Editor from the principle menu.
- Enter the next code:
#embrace
int principal()
- Save the file as
hi there.c
within the dwelling listing. - Open Terminal from the principle menu.
- Run the next instructions:
gcc -o hi there hi there.c
./hi there
Note that within the earlier examples, just one command was required to run the code (e.g., python3 hi there.py
or ruby hi there.rb
) as a result of these languages are interpreted somewhat than compiled. (Actually Python is compiled at runtime however that is a minor element.) C code is compiled into byte code and the byte code is executed.
If you are occupied with studying C, the Raspberry Pi Foundation publishes a e-book Learning to code with C written by certainly one of its engineers. You should purchase it in print or obtain free of charge.
eight. C++
C’s youthful trouble, C++ (that is C incremented by one…) is one other basic low-level language, with extra superior language options included, equivalent to courses. It’s widespread in a spread of makes use of, together with sport improvement, and chunks of your working system might be written in C++ too.
- Open Text Editor from the principle menu.
- Enter the next code:
#embrace
utilizing namespace std;int principal()
- Save the file as
hi there.cpp
within the dwelling listing. - Open Terminal from the principle menu.
- Run the next instructions:
g++ -o hellopp hi there.cpp
./hellocpp
Readers acquainted with C/C++ will discover I’ve not included the principle operate return values in my examples. This is intentional as to take away boilerplate, which isn’t strictly vital.
9. Perl
Perl will get lots of stick for being laborious to learn, however nothing a lot will get in the way in which of understanding its “hello world” program. So far, so good!
- Open Text Editor from the principle menu.
- Enter the next code:
print "Hello worldn"
- Save the file as
hi there.pl
within the dwelling listing. - Open Terminal from the principle menu.
- Run the next command:
perl hi there.pl
Again, I discovered Perl at college, however in contrast to Java, I’ve managed to efficiently keep away from utilizing it.
10. Python extras: Minecraft and the Sense HAT emulator
So that is 9 completely different programming languages lined, however let’s end with a bit extra Python. The widespread laptop sport Minecraft is offered for Raspberry Pi, and comes bundled with Raspbian. A Python library permits you to talk along with your Minecraft world, so open Minecraft and a Python editor side-by-side for some enjoyable hacking your digital world with code.
- Open Minecraft Pi from the principle menu.
- Create and enter a Minecraft world.
- Press Tab to launch your focus from the Minecraft window.
- Open Thonny Python IDE from the principle menu.
- Enter the next code:
from mcpi.minecraft import Minecraft
mc = Minecraft.create()
mc.postToChat("Hello world")
- Save the file as
hellomc.py
. - Click the Run button.
Read extra about hacking Minecraft with Python in my article Getting started with Minecraft Pi.
Finally, let’s take a look at the Sense HAT Emulator. This device offers a graphical illustration of the Sense HAT, an add-on board for Raspberry Pi made particularly to go to house for causes defined in this article.
The sense_emu
Python library is similar to the sense_hat
library besides that its instructions get executed within the emulator somewhat than on a bodily piece of hardware. Because the Sense HAT contains an 8×8 LED show, we are able to use its show_message
operate to write down “hello world”.
- Open one other tab in Thonny and enter the next code:
from sense_emu import SenseHat
sense = SenseHat()
sense.show_message("Hello world")
- Save the file as
sense.py
. - Click the Run button.
More
That’s it! I hope you discovered one thing new, and have enjoyable making an attempt out new “hello world” applications in your Raspberry Pi!
You can discover extra on the GitHub repository —and be at liberty to recommend extra in a problem, or ship me a pull request along with your contribution. If you may have another fascinating “hello world” applications you need to share—associated to Raspberry Pi or not—please share them within the feedback beneath.