Notifications
Clear all

Learning Python

Page 3 / 4

DaveE
(@davee)
Honorable Member
Joined: 1 year ago
Posts: 565
 

Hi @ronbentley1,

   re:

Anyone - am I right in my understanding that python us an interpreted language?

That is, the compiler creates pseudo code which is then interpreted.

If so then it comes with a significant overhead.

The sheer 'popularity' of Python, particularly in research and academic circles, suggests that it has some merits, and I offer the following, albeit without hard evidence, as a possible explanation to consider.

Others here are much better qualified to comment, but my impression is that the 'degree of overhead' depends upon what you are doing.

That is not to say, an optimally coded C/C++ program will not usually beat an optimally coded Python program, but rather a 'one-off' C/C++ program, which has not be honed to the bone, may have a larger overhead than a Python program consisting largely of well-tuned Python code.

Python has a huge number of libraries, etc., some of which have had a lot of work invested in them.  Plus a  significant amount of Python 'infrastructure' including libraries and so is reported to be written in C or C++, so there performance is close to  so some projects which heavily leverage these libraries. This is probably particularly significant in areas of 'research' interest, e.g. ML, AI, data science, etc.

Simplistically, I would guess, that relatively small, 'individual' programs, with little recourse to prewirtten code, would probably benefit from C/C+ coding. However, maybe programs using a lot of prewritten code libraries woud be a closer match, and if your project can benefit from the Python libraries, then perhaps the saving in effort is a good trade. Whilst, it is always good to feel you are getting the best from a computer with efficient software, in all but the smallest programs, there is always a point where efficiency of creating and testing the software is traded with the hardware needed to support it.

Just a thought ... personally, I am far from sold on the merits of Python over (say) C++... but I am looking to under issues, and suspect both candidates are 'superior' choices in different situations.

Best wishes, Dave


ReplyQuote
robotBuilder
(@robotbuilder)
Noble Member
Joined: 3 years ago
Posts: 1480
 

@inq 

I've noted from several of the forum members in Australia that electronics seem awfully expensive compared to what we get here in the US or even compared to direct from China prices. That part seems like a pretty inclusive part to do just about anything you could ever want.

Indeed it is really expensive from the two retail shops Altronics and Jaycar and they don't really have much stock or variety of products.  It might be a case of people buying online and essentially making it unprofitable to stock hobby electronic items. People for example go to the shops to try out clothes and if the product is to their liking they then buy it online where the sellers don't have to maintain stock or pay the lease on a physical shop.

A wireless connection between your pc and robot makes good sense.  Communicating via your phone also makes sense. Actually verbal communication is also an option for some human to robot interactions.

With the RPi hat I was thinking of you holding the pixel cloud maker in your hand while you walk around (see video showing moving the RPi and hat to control a 3d virtual object on the computer).

I never buy things online and with the few items I buy from a physical shop I just wear the high cost.

 

 


ReplyQuote
ron bentley
(@ronbentley1)
Estimable Member
Joined: 7 months ago
Posts: 249
 

@davee 

Thanks for your thoughts re python.

I agree with some of your thinking, and it depends on what you wish to achieve when thinking about the merits or otherwise of a programming language.

For me, interpreted languages will always perform code slower on the same platform as a fully C++ compiled machine equivalent.

It's really down to your needs. If you have mission critical needs then fully compiled code is the way to go. If your needs are otherwise then, yes, an interpreted language may be a better choice, especially when its constructs, data typing and syntax is less challenging and convoluted.

Regards

Ron B

Ron Bentley
Creativity is an input to innovation and change is the output from innovation. Braden Kelley
A computer is a machine for constructing mappings from input to output. Michael Kirby
Through great input you get great output. RZA
Gauss is great but Euler rocks!!


DaveE liked
ReplyQuote
Inq
 Inq
(@inq)
Prominent Member
Joined: 6 months ago
Posts: 891
Topic starter  
Posted by: @ronbentley1

For me, interpreted languages will always perform code slower on the same platform as a fully C++ compiled machine equivalent.

I completely agree with you.  In fact, if I had my druthers, I wouldn't even consider adding it to my bag of tricks.  In my 50 years of programming... languages have come and gone.  I can't count with both hands how many times I've heard some new language will replace C/C++.  Some I've used.  Some had a nitch in some area.  Some old established ones did die.  Python has survived longer than most of the young upstarts.

So far, I can think of several reasons why it is so prevalent and may be desirable...

  1. Debug AbilityOn microprocessors there is commonly no real debugging tools like are available with desktop C/C++/C# implementations or even JavaScript.  Really... Serial.printf() is the absolute drudgery of our experience.  Python provides some welcome middle ground between Serial and Interactive debugging.
  2. Malleable Field - It appears to me so far that much of the code for human simulations needs tons of tweaking.  Band-aide hear, fudge-factor there.  Python lets us do those adjustments faster.  
  3. Already established code base - It seems in this field of robotics, vision, machine learning, AI, etc... there is a huge code base already established using Python.  This forces us to at least be readers.
  4. Quick Prototyping - It's arguably faster/easier.
  5. Forgiving - Face it, it's easier for beginners and occasional users.  For a senior developer, the rigid C/C++ syntax is down in the muscle memory.  We often can write C/C++ better/faster than we can write our native speaking language.

The part I don't understand...

With microprocessors, RaspPi, etc the code is always CPU limited.  I don't understand why once the prototype phase is over, why things aren't ported back to C++.  The order of magnitude performance gain to re-porting back to C++ from Python seems to be necessity.  A one second pause in a robot's response is humanly acceptable.  A thirty second one is time to call for a reboot.  (Figuratively and literally) 

I've heard the excuse that much of the libraries Python uses are written in C/C++.  Hmmm... this reinforces the above statement and almost seems hypocritical that Python is better than C/C++.  

VBR,

Inq

3 lines of code = InqPortal = Complete IoT, App, Web Server w/ GUI Admin Client, Access Point Manager, Drag & Drop File Manager, OTA, Performance Metrics, Web Socket Comms, Easy App API, All running on ESP8266...
Even usable on ESP-01S - Quickest Start Guide


DaveE and ron bentley liked
ReplyQuote
ron bentley
(@ronbentley1)
Estimable Member
Joined: 7 months ago
Posts: 249
 

@inq 

We are of a like mind here.

I suspect every part of python i(the compiler  add-ons, libraries, etc) is written in C++ or equally powerful language. But it will still be interpreting pseudo code which is a middle layer of overhead.

No one can say that one is better than the other - it's back to what  I said - it depends what your purpose is for selecting a programming language, eg new to programming, esoteric purposes, teaching, mission criticality  etc.

I too have 50 years seeing them come and go, and some just endure.

Cheers

Ron B

 

 

 

 

Ron Bentley
Creativity is an input to innovation and change is the output from innovation. Braden Kelley
A computer is a machine for constructing mappings from input to output. Michael Kirby
Through great input you get great output. RZA
Gauss is great but Euler rocks!!


frogandtoad, DaveE and Inq liked
ReplyQuote
DaveE
(@davee)
Honorable Member
Joined: 1 year ago
Posts: 565
 

Hi @inq & @ronbentley1 ,

  Please understand, I was not even suggesting that Python (or any other language, excepting assembler for the underlying processor) was 'better' than C/C++, at any fundamental level.

Indeed, I am far from 'sold' on Python in many respects ...

Nor was I wishing for a flame war ... just politely playing the "friendly devil's advocate" in an attempt to better understand and discover ideas.

-----------

By definition, C was designed to be a 'human friendly' alternative to assembler, and hence C (in particular) can be compiled very efficiently into assembler (and hence converted to machine code).

Given unlimited programming skills and programmming time resources, C/C++ is going to win, on machine performance grounds, every time over a language/implementation like Python.

In the case of 'small' computers ... with limited memory, processing power, etc. a 'hand written program' in a language close to that of the processor itself, is often the only sensible course of action.

Having said that, those of us who remember the early microcomputers (PET, Apple II, TRS-80, Spectrum, etc.) might like to consider what people managed to achieve with an interpreter (BASIC) with typical processor of less than 1 MIPs and RAM memory 8k to 32k bytes and ROM memory 8k to 16k. So maybe considering interpreters is not completely reckless...?

----------------

I was suggesting:

  • In favourable circumstances, such as when most of the processor workload is engaged in processing a large amount of data with a 'standard' algorithm, then it is plausible that the interpreter overheads are minimal.
  • If a 'standard' (non trivial) algorithm has received a large amount of attention, its coding is likely to be more efficient than most programmers can produce on their own individual effort. Sadly, most of are not the most gifted at everything, programming included, so by using libraries, etc, we can benefit from reusing the efforts of those more gifted, whilst applying to the subject of our own interest or need. (Of course, this also risks adopting a sub-optimal implementation.) And you have 'best of both worlds' in that you still have the freedom to create a better solution.
  • Non trivial programs can usually be made 'more efficient' by applying more effort to the programme design and testing, albeit on a law of diminising returns. Thus, programs are usually accepted when they are 'good enough' ... that is they do the job with 'acceptable' limitations.
    • IF a Python implementation of task can be written in a fraction of the time it takes to implement in C/C+, and performs the task 'well enough', then it seems reasonable to suggest this is at the very least, a satisfactory approach.
    • Equally, IF the final performance is not satisfactory, then maybe C/C++ might be a way to 'optimise' the solution.

-----------

In 'partial answer to Inq's comment "the code is always CPU limited. I don't understand why once the prototype phase is over, why things aren't ported back to C++", then I guess there will be a number of plausible reasons, depending upon the specific case, e.g.:

  • The performance (of a specific program) is considered 'good enough' by those in a position to recode it. Of course 'good enough' can mean almost anything -- but recoding means more work and the incentive (be it personal, financial or whatever) must meet the 'cost'. The 'gain' must exceed the 'pain'. My guess is sometimes it happens, but in lots of cases the pain-gain balance stays in the 'not worth the bother' category. (And what makes your (Inq) projects look amazing!)
  •  
  • Achieving a 30 times speed up (30 secs --> 1 sec) implies the interpreter is dominating the processing time to a very large extent. It feels like an ambitious speed up, but I accept this may apply in some circumstances, especially when the task is virtually 100% running low level Python statements ... maybe not an area Python was well-suited in the first place. My suggestion is that Python has a better case when it is providing access to higher level constructs, not as simple 'bit basher'. 

As with many things in life, I do not believe there is a simple "A is better than B" answer ... rather both A and B should be considered in the context of the the project and the best solution chosen according to the circumstances. The aim of my discussion was to propose some of the considerations needed to achieve this. I realise you may already have done this, and I apologise for going over 'old ground'.

Best wishes my friends, stay safe and good luck with your projects, Dave

 

This post was modified 2 days ago 2 times by DaveE

ron bentley and Inq liked
ReplyQuote
ron bentley
(@ronbentley1)
Estimable Member
Joined: 7 months ago
Posts: 249
 

@davee 

Hey davee, no such view was taken or inferred, rather all views are equal on the forum.

Keep your views coming as I do find them helpful in providing me with differing directions to perturb my understanding! 👍

Regards 

Ron B

Ron Bentley
Creativity is an input to innovation and change is the output from innovation. Braden Kelley
A computer is a machine for constructing mappings from input to output. Michael Kirby
Through great input you get great output. RZA
Gauss is great but Euler rocks!!


Inq and DaveE liked
ReplyQuote
Inq
 Inq
(@inq)
Prominent Member
Joined: 6 months ago
Posts: 891
Topic starter  
Posted by: @ronbentley1

@davee 

Hey davee, no such view was taken or inferred, rather all views are equal on the forum.

Keep your views coming as I do find them helpful in providing me with differing directions to perturb my understanding! 👍

Regards 

Ron B

Yes!  But all professional programmers are prima-donna's... except me... I'm always right!  😆 🤣 

3 lines of code = InqPortal = Complete IoT, App, Web Server w/ GUI Admin Client, Access Point Manager, Drag & Drop File Manager, OTA, Performance Metrics, Web Socket Comms, Easy App API, All running on ESP8266...
Even usable on ESP-01S - Quickest Start Guide


ReplyQuote
robotBuilder
(@robotbuilder)
Noble Member
Joined: 3 years ago
Posts: 1480
 

My take is that you can learn Python if you just put your mind to it and practice, practice, practice the tutorial examples until you think in Python and get know how to convert an idea into Python code.

The hard part is actually the idea, the algorithm.

We all can speak some human language but that doesn't mean we can write a best selling novel in that language. Also it doesn't matter if you think one language is better than another, if you decide to live in France best to learn to speak French. If you want to understand and communicate with Python programmers best to learn Python. This is true even if you decide to write your own code in another language or your best selling novel in English instead of French.

 


DaveE and ron bentley liked
ReplyQuote
frogandtoad
(@frogandtoad)
Noble Member
Joined: 3 years ago
Posts: 1387
 

@ronbentley1, et, al...

Posted by: @ronbentley1

@inq 

We are of a like mind here.

I suspect every part of python i(the compiler  add-ons, libraries, etc) is written in C++ or equally powerful language. But it will still be interpreting pseudo code which is a middle layer of overhead.

No one can say that one is better than the other - it's back to what  I said - it depends what your purpose is for selecting a programming language, eg new to programming, esoteric purposes, teaching, mission criticality  etc.

I too have 50 years seeing them come and go, and some just endure.

Cheers

Ron B

It's no secret that C++ is my favourite language of all time, but that doesn't mean I hate python, or any other language for that matter!  In fact, I just love to program, and I embrace what each language has to offer, and I always maintain the adage to use the right tool for the job!

What frustrates me however, is that many people write legacy C code and call it C++, which it technically is, only because the ISO C++ standard, fully supports the ISO C standard (at least as far as I knew of late), but it is still C within C++, and not C++ as intended!

I have tried to promote the beauty of C++ here* in the past, but to no avail... no one here has ever even posted any modern C++, nor are they interested, or even know of it 🙁

In all my time here of trying to promote C++ modern features, no one has been interested, and I can count on 1 finger only one person* here who ever posted some modern C++ code for discussion and or debate.

Anyway, what I wanted to start out saying was that the latest ISO C++ Standard C++20, now includes the import of modules (like python, etc...), a spaceship 3 way comparison operator, etc... etc..., of which most of the later boards like ESP8266 and ESP32  etc... support the latest features in great detail.

I'd love to see people here post some real modern C++ here, specifically related to ESP8266 and ESP32 boards as they do support most of it's features, whereas UNO does not, and only supports a few basics of it, even though some of the features may surprise you!

Cheers


ReplyQuote
frogandtoad
(@frogandtoad)
Noble Member
Joined: 3 years ago
Posts: 1387
 

@robotbuilder, et, al...

Posted by: @robotbuilder

@inq 

I've noted from several of the forum members in Australia that electronics seem awfully expensive compared to what we get here in the US or even compared to direct from China prices. That part seems like a pretty inclusive part to do just about anything you could ever want.

Indeed it is really expensive from the two retail shops Altronics and Jaycar and they don't really have much stock or variety of products.  It might be a case of people buying online and essentially making it unprofitable to stock hobby electronic items. People for example go to the shops to try out clothes and if the product is to their liking they then buy it online where the sellers don't have to maintain stock or pay the lease on a physical shop.

A wireless connection between your pc and robot makes good sense.  Communicating via your phone also makes sense. Actually verbal communication is also an option for some human to robot interactions.

With the RPi hat I was thinking of you holding the pixel cloud maker in your hand while you walk around (see video showing moving the RPi and hat to control a 3d virtual object on the computer).

I never buy things online and with the few items I buy from a physical shop I just wear the high cost.

 

We are seriously RIPPED OFF here in AUS, taxed to the F&^%^EN eyeballs!

Even when you take the currency difference into account, it just doesn't add up!

eBay.com.au for example... a bare 4GB RPI4 can go from anywhere between $150AUD to $200AUD, and in kit form upto $450AUD!  F$%&^*BS!

Australia has fallen!

F7675k the WEF!!!


Inq and ron bentley liked
ReplyQuote
ron bentley
(@ronbentley1)
Estimable Member
Joined: 7 months ago
Posts: 249
 

@frogandtoad 

Go for it, post away, I am sure you will start a good series of debates and queries.

We are here to be enlightened!!

Only joking, but you clearly have a passion here and it would be great if you might share it to provide an opportunity for members to develop their understanding and skills.

If we are not prepared to learn, then what's the point!? We owe it to ourselves to explore and develop.

Looking for to new challenges

Regards

Ron B

Ron Bentley
Creativity is an input to innovation and change is the output from innovation. Braden Kelley
A computer is a machine for constructing mappings from input to output. Michael Kirby
Through great input you get great output. RZA
Gauss is great but Euler rocks!!


ReplyQuote
frogandtoad
(@frogandtoad)
Noble Member
Joined: 3 years ago
Posts: 1387
 

@ronbentley1

Posted by: @ronbentley1

@frogandtoad 

Go for it, post away, I am sure you will start a good series of debates and queries.

We are here to be enlightened!!

Only joking, but you clearly have a passion here and it would be great if you might share it to provide an opportunity for members to develop their understanding and skills.

If we are not prepared to learn, then what's the point!? We owe it to ourselves to explore and develop.

Looking for to new challenges

Regards

Ron B

Thanks Ron!

Indeed... I am passionate about programming, and I truly love to teach people, and not just about programming, that's why I am here!

I am no where near the best, but I do love to interact, debate and challenge the narrative to explore and arrive to the best outcomes for all in sundry... that's me in a nutshell 😉

I will think of something to post, that relates to such discussion and thoughts!

Cheers


ReplyQuote
frogandtoad
(@frogandtoad)
Noble Member
Joined: 3 years ago
Posts: 1387
 

@ronbentley1

Posted by: @ronbentley1

@robotbuilder 

thanks for the link which I have booked marked. This site looks quite interesting especially for C++ coders.

When the nights draw in and I have finished my to-do list I will explore the site for more fully.

Cheers

Ron B

PS

just a query ... why is it called PYTHON?

I'll give you a hint why:

The Meaning of Life 😉

This post was modified 1 day ago by frogandtoad

ReplyQuote
ron bentley
(@ronbentley1)
Estimable Member
Joined: 7 months ago
Posts: 249
 

@frogandtoad 

Monty?

42?

Struggling otherwise!

Ron B

PS

have you noticed that even the most innocuous of post spawn into long threads?

Ron Bentley
Creativity is an input to innovation and change is the output from innovation. Braden Kelley
A computer is a machine for constructing mappings from input to output. Michael Kirby
Through great input you get great output. RZA
Gauss is great but Euler rocks!!


ReplyQuote
Page 3 / 4