9

Why is python perceived as the preferred language to control and manipulate Raspberry Pi?

Why is Python language chosen over other other programming languages like PERL, etc. (which are included with distributions like Raspbian) ?

Question is not inclined towards any one of them but just trying to find merits over one another in relation to raspberry pi.

Chetan Bhargava
  • 1,252
  • 3
  • 15
  • 29

4 Answers4

10

Python was designed as a teaching language.

It's very easy to get started, and the Python ecosystem is very friendly to beginners[2]. Just go check out archives for the Python Tutor list.

Replies like this one are extremely common - especially for non-help-vampires.

I have yet to find a community anywhere nearly as welcoming and friendly to newcomers. Plus a few years ago at PyCon they gave out Raspberry Pi's to all the attendees, so many Pythonistas will at least have a Pi kicking around even if it's just running XMBC ;)

And from a Pi-specific point of view, it's very very easy to start controlling the GPIO ports

# blink.py
import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BOARD)
GPIO.setup(7, GPIO.OUT)

while True:
    GPIO.output(7,True)
    time.sleep(0.2)
    GPIO.output(7,False)
    time.sleep(0.2)

9 lines and you're done. All it takes to run this is sudo python blink.py - there's very little that you have to understand about compiling or linking or anything else. You barely need to understand anything about programming.

Plus if you think about the fact that they have two options - recommend nothing, or recommend something - a minimal one-line recommendation for Python is probably the best one they could make. Anyone with a preference will probably gloss over it and go to their language of choice, and anyone with no experience will (hopefully) have the least frustrating experience possible[3].


[2]: Though, I think Ruby is also pretty friendly to newcomers

[3]: Even the difference between Python 2 and 3 isn't as painful as what I've heard some of the problems are between Ruby versions.

Wayne Werner
  • 461
  • 2
  • 14
4

As Ghanima mentioned in the comments:

Right from raspberrypi.org: "The Raspberry Pi Foundation recommends Python as a language for learners. Any language which will compile for ARMv6 can be used with the Raspberry Pi, though; so you are not limited to using Python. C, C++, Java, Scratch, and Ruby all come installed by default on the Raspberry Pi." So they just recommend it for virtually no reason at all. They kindof seem to have missed PERL on that list though but then again it is probably true that Python is easier to pickup on than PERL

The answer seems to be that they arbitrary selected Python, being newer and popular over other similar languages.

Chetan Bhargava
  • 1,252
  • 3
  • 15
  • 29
2

Well there are other OS's available to the raspberry pi on the ROM site which require or can allow better use for other languages, but the main reason why python is preferred for use on the raspberry pi is because it is a lab-on-a-chip where its more for educational use than anything where we all know python is a fairly easy language to pickup. But in saying that you can find libraries which enable functionality and books on how to use other languages on the raspberry pi like c/c++ for example.

Pariah
  • 382
  • 1
  • 5
  • 14
1

I suppose they wanted a mainstream language which might figure highly in a software engineers career, languages like Java, C, Ada, Python etc. etc.

Languages like Algol, Pascal, Perl, PHP, JavaScript, FORTRAN, BASIC, Ruby, Smalltalk etc. etc. are more niche.

Whether Python is a sensible choice or not is moot. It has been chosen.

My concern is with learning Python in an unstructured way, which is how most Pi users will learn. I think it really needs to be introduced to programming learners as part of a structured course so that bad habits can be discouraged and good practice can be explained.

joan
  • 71,852
  • 5
  • 76
  • 108