Notifications
Clear all

C Vs Python

17 Posts
7 Users
5 Likes
664 Views
(@lhedrick9701)
Member
Joined: 8 months ago
Posts: 11
Topic starter  

I have no real desire to learn every language available and for some reason new languages take me a long time to learn.  Since I have been writing C code for almost 40 years, I just stick with what I know.   I have used various assembly code system in the early years and in modern times PHP and some HTML (which I find boring) and I have no desire to look into CSS.

 

Seems Python is becoming pervasive.   Since I know how to develop in C, is there any real benefit too putting time into learning Python?  Is there something which can only be done with Python?


   
Quote
robotBuilder
(@robotbuilder)
Member
Joined: 5 years ago
Posts: 2042
 

@lhedrick9701

It depends what it is you want to do that involves writing code?

 


   
ReplyQuote
Inq
 Inq
(@inq)
Member
Joined: 2 years ago
Posts: 1900
 

Posted by: @lhedrick9701

Since I know how to develop in C, is there any real benefit too putting time into learning Python?  Is there something which can only be done with Python?

Poke that bear!  

This is IMO... and not to just your circumstances...

If you are just starting out in programming and it's your first language... sure, Python will get you productive far faster than C.  Arguably, Python is faster to iteratively make it, but that's its only real claim to fame.  It is reliant on C for its heavy lifting libraries.

If your desire/need to program is for employment purposes, companies are more interested in speed to market, not speed and efficiency of the program.  Pumping out 10x production code with Python as compared to C, will easily justify its relevance.

If on the other hand, you are needing speed and efficiency to say... work on a Microcontroller and needing critical micro-second timing like driving multiple steppers while reading sensors or number crunching like AI and Artificial Neural Networks (ANN), Python will plateau at a far slower level than C.  If you're just wanting to read a temperature sensor out in the garden and MQTT it to a server once a minute... Python is your go to.

If you're proficient at C, then you can do anything that can be done on a cpu/mpu... ANYTHING.  If you can puke out C code without too many bugs, then those iterative advantages of Python become almost meaningless.  You have to gauge how much time you spend compiling C versus instantly re-running a one-line code fix.  Me... I just plan my next additions (or get a cup of coffee). 

Like you... I keep bouncing off the same question.  Will I gain enough advantage in the time learning Python and all its idiosyncrasies and accessing new/different libraries to offset what I can do with C/C++/JavaScript.  So far the answer has always been a resounding, No.  My new interest in ANN says that a whole lot of work in ANN is with Python at the prototyping level.  But I still fall back that for anything to really be efficient to run on an MPU or even a stout GPU leveraged PC, will always get converted over to C/C++ after the prototyping phase.

So in your case... I'd say no. 

Poking the bear.

Inq

 

 

3 lines of code = InqPortal = Complete IoT, App, Web Server w/ GUI Admin Client, WiFi 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


   
Ron reacted
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2507
 

Posted by: @lhedrick9701

Since I know how to develop in C, is there any real benefit too putting time into learning Python?  Is there something which can only be done with Python?

I think that the question whether one should learn Python only applies to somebody starting and doesn't know any programming language to start. Then it makes sense to try to evaluate learning C/C++ OR Python.

If you already know how to program in C/C++, then learning Python is up to your discretion only. It's not so much that you can do something with it that you can't do with C/C++ (or vice versa); it seems to be more a question of what is available for the hardware on which you want to develop. Some boards only support C/C++; some only support Python; and some support both.

Even now it seems that the gap is narrowing, with more support growing on both sides. But I believe that Python requires the interpreter to be on the same device as the program, so there must be some minimum flash size for any board to support Python. So a technical answer to your question would be that you can only use smaller capacity boards with C/C++.

The generally used argument is that C/C++ is faster to run since it's compiled and Python is faster to develop/prototype because you can execute directly from the REPL. Many use cases won't require lightning speed and often one can use Python to quickly mock up some project subsection and then translate it into C/C++ for later integration into a project requiring speed.

 

Anything seems possible when you don't know what you're talking about.


   
Ron reacted
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6865
 

@lhedrick9701 I generally agree with @inq and @will. If you already know C, then learning Python is no big benefit. I am in a similar situation, I am good with C, struggle with C++ and am ignorant of Python. I may someday 'play' with Python just because it is another tool that may come in handy.

 

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
(@cristishor201)
Member
Joined: 3 years ago
Posts: 23
 

I find C language more versatile than Python.

Sure, micropython it's faster and easier to learn, but with C you can programming a wider range of microcontrollers than with python.

Furthermore the binary size when you flash it to a microcontroller should be far less with C language, than micropython. So you don't have to worry about many lines of code. Also I readed than with C you can substract even more flash size, with the help of pointers.

On one of my workplace I had to study espresif toolchain for the ESP8266 microcontroller, which is writen in C. Because is more secure than Arduino style.

I am better in python rather than in C, so I wish I was in your place.

So my poor advice: stick to C if you know it well.


   
Inst-Tech reacted
ReplyQuote
(@lhedrick9701)
Member
Joined: 8 months ago
Posts: 11
Topic starter  

Posted by: @zander

@lhedrick9701 I generally agree with @inq and @will. If you already know C, then learning Python is no big benefit. I am in a similar situation, I am good with C, struggle with C++ and am ignorant of Python. I may someday 'play' with Python just because it is another tool that may come in handy.

 

I have never really liked C++ and don't really see any big advantage and there are down sides.   It can be a big problem for support groups who need to support code which was written my maniacs who go off the deep end with crazy polymorphism and multiple class inheritance.  C++ code can get out of hand fast. 

 


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6865
 

@lhedrick9701 I have the same issues with C++ BUT if you ever want to write library code, even if only for yourself, it is almost guaranteed it will need at least basic class and member elements. Even I, who never wrote a line of C++ before that and only briefly looked at Stroustrup's book decades ago have managed to create one library so far.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2507
 

Posted by: @lhedrick9701

I have never really liked C++ and don't really see any big advantage and there are down sides.

 

That's very strange since it seemed to me that C++ tried to improve on the safety of C. Classes wrapping pointers and handles as well as arrays are good examples. These allowed safer creation and allocation while at the same time permitting more rigorous control over memory and array limits by way of deallocation of assets in the destructors without need to specifically do so in the program.

Posted by: @lhedrick9701

It can be a big problem for support groups who need to support code which was written my maniacs who go off the deep end with crazy polymorphism and multiple class inheritance. 

 

Any language is subject to abuse by the untalented and/or underqualified programmer though; this isn't an exclusively C++ problem. It exists for most (if not all) object oriented programming languages.

In my experience this is especially true of designers and programmers who have had to migrate from procedural to OOP environments, some of them never really get comfortable with conceptualizing objects. I know I had a lot of trouble making the switch.

 

Anything seems possible when you don't know what you're talking about.


   
ReplyQuote
robotBuilder
(@robotbuilder)
Member
Joined: 5 years ago
Posts: 2042
 

@lhedrick9701 

Like I wrote before and you haven't replied. It depends what it is you want to do that involves writing code?

The kind of code I liked to mess with (not professional) involved speed and thus Assembler and/or Turbo C++ was my choice in the old MSDOS days. If you dabble in OOP then C++ can be a bit top heavy and wordy but you don't have to use all the C++ features when using a C++ compiler. I use it because there are lots of libraries and functions to use. Also I like cout and cin instead of printf(). However I don't bother with writing classes, although I know how, because my code is simple. But if whatever you want to do can be done with C and you are happy with that I see no reason to change.

 


   
ReplyQuote
Inq
 Inq
(@inq)
Member
Joined: 2 years ago
Posts: 1900
 

Posted by: @lhedrick9701

It can be a big problem for support groups who need to support code which was written my maniacs who go off the deep end with crazy polymorphism and multiple class inheritance.

Posted by: @zander

I have the same issues with C++

I'm old enough where I was formally trained on the procedural programming style with Basic, then Fortran and then C.  I also had some problems making the transition to the OOP style of programming.  I had to force myself to drink the Kool-aid!  I can also agree that it can be overly abused to the point of making it confusing to the uninitiated.  

But, there is no way in the world, I'd go back to the simplistic model of procedural programming.  The fact that your support groups were either too entrenched in the past or that the company failed to hire and train support staff that could handle OOP only says the company is going to fail.  Again, some constructs of C++ can be abused, but just the one basic concept of Encapsulation is critical to a long duration product.  EVEN for secondary, support groups.  A class defined object that ONLY exposes what can be changed is a safe interface.  C having no such capability... having global variables, routines amuck only invites sloppy upgrades and quick-fixes that are not fully and rigorously tested.  These ALWAYS lead to more failures and bugs.

Posted by: @will

That's very strange since it seemed to me that C++ tried to improve on the safety of C. Classes wrapping pointers and handles as well as arrays are good examples.

I completely agree with this.  I know some developers get cold-chills when even seeing pointers.  However, there are constructs that simply can't be done without them... or would use hundreds of lines to attempt  to mimic the same behavior.  Case in point... my C++/OOP library supports changing Sketch variables on the fly from the browser without the developer doing a single thing.  This would be IMPOSSIBLE without pointers!  However, a properly designed C++/Class object can encapsulate and shelter the weak of heart from the evils of pointers.

A proficient, C++/OOP developer creating code locks out any possible tampering by future develops who fail to fully Grock the class object.  They simply can't break it.  If the changes they need to make are so drastic, they can simply inherit the object and extend the capabilities leaving the base (original) class as-is.  I worked on a decades long-term product for a large corporation (SAP, AG) that hired top-notch C++/OOP programmers for original design and development as well as support.  The product was exceptionally stable being in the millions of lines of supported code... by about twenty developers.  There was no "second string" support developers.  All developers supported their own code base.  This company strategy alone reinforced the concept... you don't get to enjoy writing new code into the product if your old code is keeping you busy fixing it.

As far as working with the Arduino world... if a library was only based on C, I'd keep on looking for a C++ version... or write my own.

Like I said originally.  This topic will only poke the Bear.  I just thought it'd be between Python and C/C++.  Not procedural C against OOP C++.  But to each... their own!

 

3 lines of code = InqPortal = Complete IoT, App, Web Server w/ GUI Admin Client, WiFi 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)
Member
Joined: 5 years ago
Posts: 2042
 

@inq wrote:

"I know some developers get cold-chills when even seeing pointers. However, there are constructs that simply can't be done without them... or would use hundreds of lines to attempt to mimic the same behavior."

Pointers variables are fine it is the nomenclature that catches me out and I have to look it up. I just haven't used C++ seriously for over 12 years and only use Arduino C++ for the hardware projects.  I used to write a lot of Assembler code so I understand pointers all the way down to that level.

"Like I said originally. This topic will only poke the Bear."

I don't see why it should. It depends on what you want to do that involves writing code. It is not about which language is best,  it is about which language is best for you and what you want to do with it.


   
Inq reacted
ReplyQuote
Inq
 Inq
(@inq)
Member
Joined: 2 years ago
Posts: 1900
 

Posted by: @robotbuilder

I don't see why it should. It depends on what you want to do that involves writing code. It is not about which language is best,  it is about which language is best for you and what you want to do with it.

Agreed, it shouldn't and to each their own.  But a former member seemed to take personal affront to programming languages, and even people's styles.  I guess I was kind of expecting there being more friction than actually occurred.  Gun-shy I guess. 😉 

Some things are objective.  Some are subjective.  I can write procedurally... I just go out of my way to make it OOP.  Heck!  I even force JavaScript into OOP constructs and it's not really geared to it.  

VBR,

Inq

3 lines of code = InqPortal = Complete IoT, App, Web Server w/ GUI Admin Client, WiFi 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
(@hilldweller)
Member
Joined: 1 year ago
Posts: 111
 

Posted by: @lhedrick9701
Is there something which can only be done with Python?

The other way round, because Python is interpreted and object based you run the risk of it being too slow for some things.

But if you wanted a slick PC interface to your C Arduino machine Python plus Qt5 would be a good choice.

 


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6865
 

@inq In my case, there are features of C++ I do not like for very specific reasons, and there are features I do like. I liked them enough to change the style guide and standards for how to write subset G C code. It only worked for subset G, though. Also, I have NEVER worked professionally on a platform that had a C++ compiler. I did look into it as a home hobbyist when it first came out. There is no such thing as a perfect language. In my case, I am quite happy using Macro Assembler but even happier (mostly) using K&R C or Arduino C++.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
Page 1 / 2