JakHmakc
Posts: 1
Joined: Fri May 11, 2018 1:55 am

Where to start? Do I use python for creating things or would I be better using JS or C or C++?

Fri May 11, 2018 2:00 am

I want to get into creating things with the raspberry pi (make a camera, drone, etc.) But my question is what coding language do I use? the pi has python set. Do I use python for creating things or would I be better using JS or C or C++?

markkuk
Posts: 137
Joined: Thu Mar 22, 2018 1:02 pm
Location: Finland

Re: Where to start?

Fri May 11, 2018 10:05 am

Do you have any previous programming experience? If you know a language already you can most likey continue to use it on RPi. If you are starting from beginning then Python is a good choice.

hippy
Posts: 6230
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: Where to start?

Fri May 11, 2018 10:28 am

With limited experience it would, in my opinion, be best to start with Python as there are a lot of resources and tutorials for learning and using Python with a Pi.

As you gain experience you will be in a better position to learn other languages and determine which would be best to use, which would be best for particular projects.

Learn to swim and then it's your choice where you choose to swim to.

User avatar
B.Goode
Posts: 8987
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: Where to start?

Fri May 11, 2018 11:22 am

my question is what coding language do I use? the pi has python set.


What does "the pi has python set" mean in your mind?

There is no direct built-in support for Python in the Raspberry Pi hardware.

It is true that python (both Python2 and Python3) are installed and available by default with the Raspberry Pi Foundation recommended and supported Raspbian Operating System. But there is nothing 'set' about it: C, C++, Ruby and other languages are also installed and available by default. And pretty much every other programming language you have ever heard of can be installed as an optional extra: Basic, Pascal, Fortran, Java, php, JavaScript (and NodeJS), Go...



So you can in principle use whatever language you are comfortable using. But in practice you should probably also consider the availablity of existing libraries to interface with the additional hardware you will be using, and the strength of support you can get from the Raspberry Pi community if you need help. In both cases Python is the obvious choice.


So start by learning some basics by visiting https://projects.raspberrypi.org/en/pro ... ng-started

Look at some of the Projects published by the Raspberry Pi Foundation
https://projects.raspberrypi.org/en/

And look at the free online back issues of The MagPi magazine
https://www.raspberrypi.org/magpi/issues/

Heater
Posts: 13877
Joined: Tue Jul 17, 2012 3:02 pm

Re: Where to start? Do I use python for creating things or would I be better using JS or C or C++?

Fri May 11, 2018 12:12 pm

JakHmakc,

Do you know how to program in any language? If so what is it? What did you do?

As pointed out above pretty much all languages are available for the Pi with a simple "apt-get install ... " command.

Ones choice of language for a project is strongly influenced by what the project has to do. For example:

If you need maximum performance, or fast, real-time, deterministic performance or minimal size of code then C/C++ are an excellent choice.

If you are handling lot's of communications between multiple sensors, serial links, network connections etc then Javascript is an excellent choice thanks to it's event driven programming model and no need to mess around with threads. Speed is not up there with C/C++ but pretty damn good.

For general not so fussy programming Python is popular. Put there are many others, Java, C#, Scala, etc, etc..

My usual choices are C/C++ when I feel the need for speed. Javascript under node.js for pretty much anything else as it so quick and easy to develop, there are node.js modules to handle almost anything you need to do on a Pi, and performance is far better than other so called scripting languages.

Python is no use to me. It's slow and there is no standard for it.

If you want to build that drone, especially if you are creating your own control software you will need to be working in C/C++ to get the real-time behavior.
Memory in C++ is a leaky abstraction .

User avatar
jadro
Posts: 429
Joined: Sun Oct 02, 2016 1:20 pm
Location: Croatia

Re: Where to start? Do I use python for creating things or would I be better using JS or C or C++?

Fri May 11, 2018 9:10 pm

Python is best choice for beginers in programming world..
Jadro
Oracle backend database developer
SmartHome IoT & Microprocessor enthusiast and hobbyist

User avatar
Pan Szymanowski
Posts: 15
Joined: Wed May 09, 2018 10:48 pm
Contact: Website

Re: Where to start? Do I use python for creating things or would I be better using JS or C or C++?

Sat May 12, 2018 3:13 am

There is a simple rule. The best language is the language that was used for the OS development. If you work with Raspberry, the best language is C. All unixes were written in C.

Heater
Posts: 13877
Joined: Tue Jul 17, 2012 3:02 pm

Re: Where to start? Do I use python for creating things or would I be better using JS or C or C++?

Sat May 12, 2018 7:30 am

Pan Szymanowski,
There is a simple rule. The best language is the language that was used for the OS development.
That is a very bad rule.

What if you want your code to be maximally portable and hence maximally available to others, and the OS they are using is not written in C? They do exist and perhaps more will in the future. Then you have selected the worst language.

What if the target does not have an operating system? Like many micro-controller applications or even the Pi without Raspbian? Then the rule makes no sense at all. You may as well write you code in something some would say is better. Like Ada, Pascal and the like.

What if you value ease of use and rapid development over raw performance? Say for a throw away program or something that does not demand speed. Then you have possibly selected the worst language.

What if you want to leverage the huge libraries of modules and such that are available for languages like Java, Python, Node.js. Then you have selected the worst language possible.

What if you value correctness and "error proofness". Then you might select Ada or Pascal and C would be the worst choice.

On the other hand I love C/C++ and don't imagine ever abandoning it. Despite the fact that most of what I do today is Javascript, which is a lot easier to work with, has a huge number of useful modules available, handles multiple things at the same time easily with it's event driven programming model and has a performance closing in on that of C/C++ itself.

Many of the languages we have today depend on compilers/run times written in C/C++. So we can follow your rule, by using C/C++ under the hood, without even thinking about it :)
Memory in C++ is a leaky abstraction .

User avatar
DougieLawson
Posts: 36540
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Where to start? Do I use python for creating things or would I be better using JS or C or C++?

Sat May 12, 2018 8:24 am

Pan Szymanowski wrote:
Sat May 12, 2018 3:13 am
There is a simple rule. The best language is the language that was used for the OS development. If you work with Raspberry, the best language is C. All unixes were written in C.
In some people's view the best language is forty year old COBOL. That one has so much value because nobody knows it any longer. The folks who can cope with its excessive wordiness and the paragraph [un]structure of ancient COBOL and can write & maintain ancient old COBOL programs can command a premium. The same argument holds true for FORTRAN and ALGOL. I'll count "God's own programming language" S/360 assembler in the same group.

The reality is that most third generations programming languages are a largely a semantic variation on IF...THEN...ELSE, DO...WHILE, Do...UNTIL, FOR...NEXT, FOREACH...NEXT and SELECT...CASE...OTHERWISE

It gets more interesting with object orientation and polymorphism but again OO-COBOL, C++ and Java are closely matched in terms of the basics (methods available to work with an encapsualted data object). Again there are clearly semantic differences.

The operating systems I've used are written in Assembler, ALGOL, C/C++, PL/AS, PL/X so you're saying application programmers should ignore python, php, lua, ruby, java, javascript, ruby, go, REXX and all of the other rich variety of languages from the last forty years that make the programmer's task easier.

You're spouting nonsense.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

Heater
Posts: 13877
Joined: Tue Jul 17, 2012 3:02 pm

Re: Where to start? Do I use python for creating things or would I be better using JS or C or C++?

Sat May 12, 2018 9:26 am

Pretty much all modern languages can trace their roots to ALGOL and ALGOL 68. In terms of the concepts they support and even down to specific reserved words.

In fact it has taken a long time for many language to catch up to where ALGOL 68 was in the 1970. C++ for example only got nested, first class functions with C++11 in, well 2011. See C++11 lambda and std::function.

Sadly IBM swept over all that with FORTRAN and COBOL abominations. Then came the runaway chaos of C++. Itself based on Simula which in turn derives from ALGOL 68.
Memory in C++ is a leaky abstraction .

jahboater
Posts: 4831
Joined: Wed Feb 04, 2015 6:38 pm

Re: Where to start? Do I use python for creating things or would I be better using JS or C or C++?

Sat May 12, 2018 9:50 am

Pan Szymanowski wrote:
Sat May 12, 2018 3:13 am
There is a simple rule. The best language is the language that was used for the OS development. If you work with Raspberry, the best language is C. All unixes were written in C.
Here C is just an example. If your OS was written in Java then the suggestion is the best language might be Java.

The point is that for the system language, you get the best support, the best libraries, usually the best compilers. Thats always been true.

For example, on Raspbian, the standard manual pages all include C library and other C related stuff.
So "man stdio" and "man puts" give you C stuff. Do you get that with Python, Algol, Cobol - no.

On Raspbian the main library glibc is obviously intended for use by C programs, anything else (Python say) has to use wrappers round it.

The compiler will likely be pre-installed and ready to go (its very unusual to find Linux without a C compiler).
Furthermore, it becomes reasonable and common to distribute your program as source because you can expect a decent compiler to be present on the end-user's machine.

And so on.

So regardless of any technical merit other languages might have, the "system" language has certain "practical" benefits. In the case of Linux, C may not be best language around, but when you just want to "get the job done" without any unrelated hassle it is the language people turn to. The fact that C is also the most efficient language is a bonus (but likely the reason why the system was written in it).

I speak as a big fan and user of REXX, Algol68 and other languages in the past, but when I want to write a program on UNIX/Linux the "path of least resistance" is C.

Heater
Posts: 13877
Joined: Tue Jul 17, 2012 3:02 pm

Re: Where to start? Do I use python for creating things or would I be better using JS or C or C++?

Sat May 12, 2018 11:09 am

jahboater,
If your OS was written in Java...
God forbid, if there were such an atrocity it's boot time would measured in days :)

Besides, I'm pretty sure Java run-times are written in C/C++ so you will have that on your system anyway.
...the suggestion is the best language might be Java
I think Java is a bad example but, yes, I do get your point.
So regardless of any technical merit other languages might have, the "system" language has certain "practical" benefits. It is often the best language when you just want to "get the job done".
Certainly the "system" language has many practical benefits. However when I want to get the job done the choice of language rather depends on the job at hand. For example, if I want to parse/generate multiple streams of XML or JSON, C would be the last language I would consider. It would be much harder to do in C, using whatever libraries are available to help, and the performance would not be much ahead of doing it a more suitable language like Javascript.

For many applications C offers a lot of resistance.

Better to use C/C++ to create a more helpful language and then write your application in that. That is why we have Python, Perl, PHP, Javascript, etc, etc. Even Java and C#.

The man pages on a typical Linux system are great. On the other hand all the documentation about pretty much any library or module you want to use in Python, Javascript, Java, etc, etc is only a google away.
Memory in C++ is a leaky abstraction .

jahboater
Posts: 4831
Joined: Wed Feb 04, 2015 6:38 pm

Re: Where to start? Do I use python for creating things or would I be better using JS or C or C++?

Sat May 12, 2018 11:20 am

Heater wrote:
Sat May 12, 2018 11:09 am
jahboater,
If your OS was written in Java...
God forbid, if there were such an atrocity it's boot time would measured in days :)

Besides, I'm pretty sure Java run-times are written in C/C++ so you will have that on your system anyway.
...the suggestion is the best language might be Java
I think Java is a bad example but, yes, I do get your point.
I quite deliberately chose Java as a particularly bad example :)

I didn't want to discuss the features and advantages of different languages (that could go on forever), I was just agreeing with Mr Szymanowski that the "system" language, whatever it is, usually has certain practical benefits.
Last edited by jahboater on Sat May 12, 2018 11:45 am, edited 1 time in total.

ghellquist
Posts: 68
Joined: Thu Aug 02, 2012 8:47 am
Location: Stockholm Sweden

Re: Where to start? Do I use python for creating things or would I be better using JS or C or C++?

Sat May 12, 2018 11:43 am

The most important factors in selecting a language, in my mind, are:

1- The support libraries that you easily use to tackle parts of your application. As example, if you need to manipulate pictures there are libraries that help with that. No need to write the code yourself.

2- The support you can get from fellow users. When you get stuck, which you will, a friendly forum will help.

So why not start by checking how well the answers on the different sub forums here align with what you expect to do. I would expect that you will find very little on, say, Erlang or Haskell. Probably a lot on Python.

/Gunnar

Heater
Posts: 13877
Joined: Tue Jul 17, 2012 3:02 pm

Re: Where to start? Do I use python for creating things or would I be better using JS or C or C++?

Sat May 12, 2018 11:44 am

jahboater,

Ah yes. Sorry. My sarcasm detector is on the blink.
Memory in C++ is a leaky abstraction .

ybirch
Posts: 5
Joined: Sun May 13, 2018 1:04 am

Re: Where to start? Do I use python for creating things or would I be better using JS or C or C++?

Mon May 14, 2018 1:49 am

Python may not be the best for near the real time hardware programming, e.g. drone balancing. At the minimum it will significantly reduce your time in the air.

Return to “General discussion”