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,262
  • 3
  • 15
  • 29
  • 5
    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. – Ghanima Nov 26 '14 at 08:39
  • 3
    It's totally meaningless. I believe all this has to do with is one casual sentence on the web site (quoted above). Because python is easy and popular on linux generally is all, but in that sense they could have have said perl or ruby. It would not make any difference to anything in any case. – goldilocks Nov 26 '14 at 15:14
  • 3
    Never used Python, but I know its old school Linux programmers goto language. Maybe that's why they recommend that. I cannot see any other reason. Good question though. Hopefully this will demystify everything. Besides, everything extra that I need to compile is in C. – Piotr Kula Nov 26 '14 at 18:43
  • 2
    Because Python is awesome? (https://xkcd.com/353/) – User Dec 26 '15 at 11:09
  • 1
    @user our comment is irrelevant unless accompanied by specific reasons. Why don't you answer my question. – Chetan Bhargava Dec 28 '15 at 04:21
  • 2
    I program in Python at work, but (mostly try to) use Perl everywhere else. For instance, I wrote WiringPi::API and RPi::WiringPi specifically so I could use Perl on my Pis. – stevieb Dec 22 '16 at 15:21

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
  • 13
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,262
  • 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,024
  • 5
  • 73
  • 106
  • The Pi is just a tool and therefore not responsible whether somebody is learning to code in an unstructured way or not. There are lots of books and content in this "internet" to aid anybody willing to be helped. – Ghanima Nov 26 '14 at 12:12
  • 2
    "I suppose they wanted a mainstream language which might figure highly in a software engineers career" is certainly incorrect. There are probably more lines of FORTRAN still in use than have ever been written in python, there are probably 10 times as many people making a living with PHP than python, etc. etc. Stack Exchange itself is principally ruby and I believe C#. They might as well have picked anything off either list above if the reason was "something a software engineer might highly use". – goldilocks Nov 26 '14 at 17:00
  • Totally agree with goldilocks. C# is my main stream language on the Pi :) I dont use Perl or Python at all. PHP just because there is no IIS on Linux, yet. – Piotr Kula Nov 26 '14 at 18:41
  • SE is principally .NET (C#) and runs mostly IIS. They did this for pragmatic reasons - all the original dev team were much more proficient in .NET and the IIS environment. At least that's what they say on some blog posts I've read. – Wayne Werner Nov 29 '14 at 14:29
  • Here in the future, javascript is not a niche language. It's in all the webpages, from all the other webpages. – YetAnotherRandomUser Nov 08 '17 at 00:51