Notifications
Clear all

using c++

30 Posts
5 Users
15 Likes
256 Views
robotBuilder
(@robotbuilder)
Noble Member
Joined: 3 years ago
Posts: 1554
Topic starter  

@frogandtoad

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 used to program in TurboC++ on the old dos machines. Later I used the Bloodshed Dev C++ and bought some books on writing computer games for Windows. It wasn't that I was interested in writing games merely these books (including one for dos) provided the tutorials using graphics and working with the Windows environment.  A games writing book provided all I needed to know to use C++ on the old DOS machines. On the old DOS machines graphics was simple if limited in some ways but for an old Assembler programmer the old chips were easy to use.

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!

Well I am interested. I am not sure what you mean by real modern C++.  As an occasional hobby programmer I found some of the new stuff (iterators and so on) not that easy to visualize and really didn't have the time to study and practice using them.  If my old coding did the job why make it less readable (to me) then needed even if my version was a bit long winded at least I understood it. I was using Bloodshed Dev C++ at the time. I bought books on writing OOP code as well although I found it an overkill for my simple programs even if I used the c++ library classes all the time.

I would probably still be using C++ but the coding environment was so complicated requiring more than an understanding of the language itself. I wanted to play with graphics and i/o programs. The Centronics port was gone and I couldn't find a simple way to use the USB port and I couldn't get a graphics library installed on the CODE::BLOCKS ide I was using. Also the old code I wrote with DevC++ would not run with the latest C++ compiler!!

I probably would have persevered with C++ had I not discovered FreeBASIC.  Super fast compiled code with inbuilt easy to use graphics. It also has C++ features enabling parts of code to be made faster also you can write inline assembler although I found I didn't need it for speed.  The forum also had an expert who made it possible to use a Windows .dll to access webcams something I needed for my interest. The same expert also made it possible to use OpenCV.

It is also runs on Linux not just Windows.

So to cut a long story short I am interested in using C++ on the pc and the RPi but I am not a professional and without those easy to read and informative "program games with C++ for dummies" books I am stuck.

The Arduino IDE c++ is easy to use so no problem there.

And maybe I will buy an ESP32 although I haven't had much interest in using the internet connections.

My early self taught programming was BASIC and Assembler on the TRS80, C64 and Amiga. Actually my first programming experience was machine code entered as binary code using toggle switches with a binary LED display 🙂

 

 


   
frogandtoad reacted
Quote
Will
 Will
(@will)
Noble Member
Joined: 1 year ago
Posts: 2112
 

I don't think that true (whatever that means) C++ really has much of a place here. This is a haven for tinkerers and explorers. You can see the types of questions being asked, people don't even know the significance or requirement of data typing.

They're not stupid, they're just inexperienced and learning to use C to get something done. So it seems to me that introducing concepts like multiple inheritance and namespaces are just going to confuse them farther, possibly to the point of throwing up their hands and saying forget it ! Before you can use C++ effectively you need to know how to work in C. Many of the people here are still in that category.

I am not biased against C++. In the seven plus years I've been using the Arduino, I've written a few classes to make my life easier. Not a single one of them embodied a concept or operation that couldn't have been handled just as gracefully in C (albeit with more typing).

We're talking about programming Arduino's here, The power of C++ is not required for a system that has to fit inside 32K. By all means talk about it and absolutely use it to make wrappers for instruments and other components, but don't make its use seem obligatory.

You don't take a Ferrari to the grocery store.

I was kidnapped by mimes.
They did unspeakable things to me.


   
Ron, Inq and Lee G reacted
ReplyQuote
Ron
 Ron
(@zander)
Famed Member
Joined: 2 years ago
Posts: 3403
 

@will Well put.

"Don't tell people how to do things. Tell them what to do and let them surprise you with their results.” - G.S. Patton, Gen. USA
"Never wrestle with a pig....the pig loves it and you end up covered in mud..." anon


   
ReplyQuote
robotBuilder
(@robotbuilder)
Noble Member
Joined: 3 years ago
Posts: 1554
Topic starter  

@frogandtoad

From thread

https://forum.dronebotworkshop.com/python/learning-python/paged/3/

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.

Just bought an ESP32 and an ESP32 cam and a Raspberry Pico hopefully I will find time to play with them.

 

This post was modified 2 months ago by robotBuilder

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

@robotbuilder

Posted by: @robotbuilder

I used to program in TurboC++ on the old dos machines. Later I used the Bloodshed Dev C++ and bought some books on writing computer games for Windows.

I have a very old version of Object Oriented programming using C++ by Robert Lafore (imo, a great technical writer), and I still enjoy looking through it occasionally to this day.

Posted by: @robotbuilder

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!

Well I am interested. I am not sure what you mean by real modern C++.  As an occasional hobby programmer I found some of the new stuff (iterators and so on) not that easy to visualize and really didn't have the time to study and practice using them. 

Glad to hear.

Ok, let me expand on what I'm calling modern stuff, which is in fact over a decade old!
I am talking about learning and using the very basic C++ standard classes and container types ('string', 'vector', 'map', etc...), and iterators are used to manipulate these objects (they are nothing more than pointers wrapped in a class to make them easy to use).

Writing your own very basic classes too.

Posted by: @robotbuilder

I would probably still be using C++ but the coding environment was so complicated requiring more than an understanding of the language itself.

That's true, a poor environment can turn you off something quite easily, but these days there are many good free IDE's around, and the new Arduino IDE is quite good for microcontroller programming, so I don't see that as being a problem anymore.

Posted by: @robotbuilder

So to cut a long story short I am interested in using C++ on the pc and the RPi but I am not a professional and without those easy to read and informative "program games with C++ for dummies" books I am stuck.

The Arduino IDE c++ is easy to use so no problem there.

And maybe I will buy an ESP32 although I haven't had much interest in using the internet connections.

My early self taught programming was BASIC and Assembler on the TRS80, C64 and Amiga. Actually my first programming experience was machine code entered as binary code using toggle switches with a binary LED display 🙂

No worries, feel free to ask for any help if you get stuck, and I'll do my best to help you understand it.

Cheers


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

@will

Posted by: @will

I don't think that true (whatever that means) C++ really has much of a place here.

On what basis do you then justify such a concrete opinion?

Posted by: @will

This is a haven for tinkerers and explorers.

Indeed, and there are many who have a taste for creating more and more complex projects as their knowledge grows, in both hardware; and the programming of that hardware.

Posted by: @will

You can see the types of questions being asked, people don't even know the significance or requirement of data typing.

This is a moot point in the context of my previous posts else thread.  Learning to program in any language can be broken down into three basic levels (basic, intermediate & advanced). If we can agree on that?, then understand that I am talking about those who are transitioning into the intermediate level, and there are many in that boat who are missing out on using features that can not only help them a great deal, but are easier to use and understand.

Posted by: @will

They're not stupid, they're just inexperienced and learning to use C to get something done.

Of course they're not, but you seem to only focus on the absolute beginner, rather than those who have moved on from Arduino... isn't it possible that they could benefit from using more modern features?

Posted by: @will

So it seems to me that introducing concepts like multiple inheritance and namespaces are just going to confuse them farther, possibly to the point of throwing up their hands and saying forget it !

Oh come on now, I think you're being disingenuous about my intentions... do you really believe that I'm pushing for basic to intermediate programmers to start using 'multiple inheritance'? I know professional programmers who don't even know anything about it after years of programming! And as for 'namespaces', they are one of the most basic and first things you learn in C++, and have been around for more than a decade already.

Posted by: @will

Before you can use C++ effectively you need to know how to work in C.

That is simply not true, and in any case a different topic for discussion.

Posted by: @will

Many of the people here are still in that category.

Does that mean that we should overlook those that aren't?

Posted by: @will

I am not biased against C++. In the seven plus years I've been using the Arduino, I've written a few classes to make my life easier. Not a single one of them embodied a concept or operation that couldn't have been handled just as gracefully in C (albeit with more typing).

Excellent... so you wrote a few classes to make your life easier!  Making ones life easier is one of the key aspects, that using more modern C++ techniques actually addresses, and that is a good thing.

Posted by: @will

We're talking about programming Arduino's here,

Actually, I made it clear that I was referring to the ESP8266 & ESP32 devices.

I mentioned else thread that Arduino did not support any modern C++ features, albeit a handful that are not even documented in the Arduino reference pages, and I specifically mentioned targeting the ESP8266 and ESP32 devices. However, even an Arduino for example, does benefit from the modern C++ features it does support, even for total beginners to programming... 'String' vs 'character array' for example is indisputably easier to use, and far superior in functionality - If you don't agree with that, please provide some degree of evidence that really does debunk that claim.

Posted by: @will

The power of C++ is not required for a system that has to fit inside 32K. By all means talk about it and absolutely use it to make wrappers for instruments and other components, but don't make its use seem obligatory.

You don't take a Ferrari to the grocery store

I am always willing to, and often do provide examples of code to endorse (and demonstrate) such a position as best I can, therefore I don't think that trying to promote something I believe in makes it sound obligatory at all - Thus far, your position doesn't really offer a convincing counter argument, and if anything just adds fear and doubt into the readers mind.

Cheers


   
ReplyQuote
Inq
 Inq
(@inq)
Noble Member
Joined: 8 months ago
Posts: 959
 
I am unconditionally pro C/C++/C#.
 
... Although because of the lack of any real debugging ability on most MPU's, I'm really getting enamored with doing more and more client side coding.  My servers-side coding on the MPU is getting  more and more basic - Get/set the raw data to/from the sensor/actuators using the MPU, but pump it in/out to the client WHERE THE REAL HORSE POWER IS and simply use JavaScript with its excellent multi-threading and powerful debugger to display and accept very cosmetic I/O.  But... I diverge.
 
Posted by: @frogandtoad

Ok, let me expand on what I'm calling modern stuff, which is in fact over a decade old!

Oh good!  I was getting nervous to think the whole world had gone and left me behind since I left the corporate world... 5 years ago.  I was waiting for the modern stuff to be taught. 😣 

Posted by: @robotbuilder

Well I am interested. I am not sure what you mean by real modern C++.  As an occasional hobby programmer I found some of the new stuff (iterators and so on) not that easy to visualize and really didn't have the time to study and practice using them.  If my old coding did the job why make it less readable (to me) then needed even if my version was a bit long winded at least I understood it.

This is the corporate stance also.  Readability trumps, coding line count, binary size and/or binary speed EVERY day.  This is necessary for code that has a life measured in decades versus game software that is measured in minutes.  I'm sure game, CAD software (high performance programs)  on minimal hardware do need optimizations, but that tends to go the other way from C++ and heads toward Assembler.  Although these days, it would be hard for an Assembler programmer to consistently out-do a modern, optimizing C/C++ compiler.  But... I diverge again.

Two case come to mind.  

  1. I tended to be one of the more progressive programmers keeping abreast of new stuff.   I started using (1) LINQ Query Operations and having 1 liners that did the work of other developers 200+ line routines.  My bosses did NOT like it.  They didn't trust it.  (2) In-line anonymous delegates.  Same thing.  In-line multi-threaded routines.  Again... they didn't like that "magic" happened with a small fraction of the line count of others.
  2. In my own code base - Some of my earlier libraries were all full of abstract and virtualization some with 5 levels of inheritance and even including multiple-inheritance.  I had a couple year hiatus from it and came back to it.  It was complex impossible trying to determine which virtual override was being called in what condition.  This is easy with a good debugger to just "tag along" for the ride and watch what function is called.  It is impossible keeping everything Grok'd in you mind at one time and near guessing which is being called.  I loathe Serial.printf() debugging!  I started over and re-wrote the whole library into one class. 

Point being... readability should be YOUR subjective level of feature usage of any language.  I would always suggest OVER comment AND use very descriptive variable names to make it more readable AND neatness counts.  What is totally, trivially obvious to you right now, will blow you mind when you come back to it six-months down the road and say to yourself, "What drugs was I on that day?"

With modern editors and Code Complete this should not be a burden.  But... I was the only male to ever take typing class at my rural high-school... because I new touch typing would save me man-years of time in the future... now being the past... I was right! 😉  

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


   
Dazza, frogandtoad and Ron reacted
ReplyQuote
frogandtoad
(@frogandtoad)
Noble Member
Joined: 3 years ago
Posts: 1476
 

@robotbuilder,

Here is a simple program example for you using a standard vector<string> type on an ESP32 - This is how arrays in real C++ have been used for over a decade:

# include <iostream>
# include <string>
# include <vector>

  using namespace std;

vector<string> myArray {"one", "two", "three", "four", "five"};

void setup() {
  myArray.push_back("six");
  myArray.erase(myArray.begin() + 2);
 }

void loop() {  

  for(string element : myArray) {
    cout << "Element: " << element << '\n';
   }
    
  cout << "\nmyArray contains: " << myArray.size() << " elements\n\n";

  delay(1000);
 }

Note:
1) No Serial object, no print statement (can mix and match different data types to stdout)
2) A dynamic array, with an element later added to the end, and then one element removed, and uses an internal member function to print its size
3) Range based for loop

Now, I know what it takes to reproduce this in C, and handle all the memory issues on your own, and the amount of code you need to write over and above what's shown, not to mention, this is very self documenting - I'm sure the C version is quite an ugly duckling in comparison.

The vector resizes and reallocates all the memory for you - This is the tip of the iceberg, but as you can already hopefully see, just how superior it is!

Please feel free (anyone), to criticise any pro's or con's you may see.

Cheers


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

@inq

Posted by: @inq
I am unconditionally pro C/C++/C#.
 
... Although because of the lack of any real debugging ability on most MPU's, I'm really getting enamored with doing more and more client side coding.  My servers-side coding on the MPU is getting  more and more basic - Get/set the raw data to/from the sensor/actuators using the MPU, but pump it in/out to the client WHERE THE REAL HORSE POWER IS and simply use JavaScript with its excellent multi-threading and powerful debugger to display and accept very cosmetic I/O.  But... I diverge.

I have no problems with that, because you're using the right tool for your job.  I like javascript too (though haven't used it in a while) - You might like to check out p5.js with WebGL and all the fantastic libraries that support it here

I totally agree with the rest of your reply, as I am a big nit-picker when it comes to naming of variables and code readability, and I really think C++ helps to achieve that readability, especially when using classes, which allow you to focus on your program logic and workflow, rather than scrolling through hundreds and even thousands of lines of repeated procedural code just to find a bug etc...

As for that serial object, check out my very basic example to @robotbuilder - The baud rate defaults to 115200 - If you want a different rate, just declare Serial.begin(baud); with your desired rate.

Cheers


   
Inq reacted
ReplyQuote
Will
 Will
(@will)
Noble Member
Joined: 1 year ago
Posts: 2112
 

@frogandtoad 

Yes, I have an opinion and no, it doesn't seem to match yours.

I'm not preventing anybody from learning C++, just saying that I don't think it's a required asset for working on micro controllers.

I was kidnapped by mimes.
They did unspeakable things to me.


   
Ron reacted
ReplyQuote
Inq
 Inq
(@inq)
Noble Member
Joined: 8 months ago
Posts: 959
 

I see the battlements going up again.  Chill people!  The thread was opened up by someone that genuinely wanted to learn more about C++.  Opinions either way really have no purpose in here... except to piss someone else off.  If you don't value C++... don't read it.  Anyone else can join in... asking or helping. 

Posted by: @frogandtoad

1) No Serial object, no print statement (can mix and match different data types to stdout)

??? I'm not sure if I'm misunderstanding some nuance you're making OR you not aware of:

const char* name = "Gonzo";
u8 day = 23
s32 year = -1492;
float pi = PI;
Serial.printf("%s was here on %u/%d and got some %f\n", 
  name, day, year, pi);

I think some of this screws up the Arduino compiler, but works fine ESP8266 compiler.  I must admit I don't use cout but that is because I have a wrapper in my library so I selectively output it to the Serial monitor AND/OR to the log window on the browser Admin client, so I only call Serial.print in one location in my whole code base.

Posted by: @frogandtoad

The vector resizes and reallocates all the memory for you - This is the tip of the iceberg, but as you can already hopefully see, just how superior it is!

Please feel free (anyone), to criticise any pro's or con's you may see.

I extensively used the dynamic stuff on Windows, but tend to avoid them on an MPU.  I've seen way too many times where under long term, extensive abusive testing that lots of things can easily fragment an MPU till it pukes.  I tend to use the recommendations on MPU's to do all the allocation at the beginning and handle the memory management throughout the life of the program.  Maybe with more modern MPU's with lots more memory (ESP's) this isn't as big a concern anymore.  Have you seen any issues under long term usage?  I usually consider a test valid after millis() wraps and it still works... yes - 49.7 days worth.

Posted by: @frogandtoad

You might like to check out p5.js with WebGL and all the fantastic libraries that support it here

I'll take a look at it, but I tend not to use JavaScript libraries as much as possible.  The 3MB maximum "disk space" on a typical ESP8266 tends to force that issue.  I err on the side that a user might not have access to the Internet.  (My SOP with my crappy Internet)  Like when I use a phone connected to the ESP8266 in SoftAP mode and use the phone as a remote control... no Internet.  I went to great lengths to avoid using jQuery and/or libraries that require it.  All my  written libraries are pure JavaScript.  I also found a satisfactory graphing library that uses raw JavaScript.  It's one of the few.  

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
Inq
 Inq
(@inq)
Noble Member
Joined: 8 months ago
Posts: 959
 
Posted by: @frogandtoad

You might like to check out p5.js with WebGL and all the fantastic libraries that support it here

On further thought... My current project will be to take raw coordinate mapping data.  Have you any experience with just plain HTML5 type cavas verus this WebGL library?  Can I do all the 3D output (Point Cloud) to the browser page and simply use mouse type navigation to rotate inside and around the cloud so I can look at it from any angle?

I know how to write this from the ground-up and have in C++, but really don't want to do it for JavaScript if there is an easier solution.

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


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

@will

Posted by: @will

@frogandtoad 

Yes, I have an opinion and no, it doesn't seem to match yours.

I'm not preventing anybody from learning C++, just saying that I don't think it's a required asset for working on micro controllers.

Wow, you refuse to even answer one of my questions, that's OK!

I was really looking forward to a civil debate, to challenge your opinion with valid coding examples, and even more than happy for you to elaborate with counter examples to prove my view wrong - I guess we'll just have to leave the reader make up their own minds!

Cheers


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

@inq 

Posted by: @inq

I see the battlements going up again.  Chill people!  The thread was opened up by someone that genuinely wanted to learn more about C++.  Opinions either way really have no purpose in here... except to piss someone else off.  If you don't value C++... don't read it.  Anyone else can join in... asking or helping. 

I agree... I just want to help people learn!
Likewise, I want to have a civil debate, but this is what always happens when a challenge occurs to an opinion!

Posted by: @inq

??? I'm not sure if I'm misunderstanding some nuance you're making OR you not aware of:

const char* name = "Gonzo";
u8 day = 23
s32 year = -1492;
float pi = PI;
Serial.printf("%s was here on %u/%d and got some %f\n", 
  name, day, year, pi);

I think some of this screws up the Arduino compiler, but works fine ESP8266 compiler.  I must admit I don't use cout but that is because I have a wrapper in my library so I selectively output it to the Serial monitor AND/OR to the log window on the browser Admin client, so I only call Serial.print in one location in my whole code base.

Actually, I am aware of printf, but that wasn't the main objective of my example and comment - The main takeaway was the dynamic array, the range based for loop, and that doing that in C was much more difficult, and harder to learn - Do you disagree?

Posted by: @frogandtoad
Posted by: @frogandtoad

The vector resizes and reallocates all the memory for you - This is the tip of the iceberg, but as you can already hopefully see, just how superior it is!

Please feel free (anyone), to criticise any pro's or con's you may see.

I extensively used the dynamic stuff on Windows, but tend to avoid them on an MPU.  I've seen way too many times where under long term, extensive abusive testing that lots of things can easily fragment an MPU till it pukes.  I tend to use the recommendations on MPU's to do all the allocation at the beginning and handle the memory management throughout the life of the program.  Maybe with more modern MPU's with lots more memory (ESP's) this isn't as big a concern anymore.  Have you seen any issues under long term usage?  I usually consider a test valid after millis() wraps and it still works... yes - 49.7 days worth.

No, I have never tried it for such duration, so I can't say that there are any issues in doing that. ISO C++ improves in every iterations, so it might be worth a new test 😉

Posted by: @frogandtoad
Posted by: @frogandtoad

You might like to check out p5.js with WebGL and all the fantastic libraries that support it here

I'll take a look at it, but I tend not to use JavaScript libraries as much as possible.  The 3MB maximum "disk space" on a typical ESP8266 tends to force that issue.  I err on the side that a user might not have access to the Internet.  (My SOP with my crappy Internet)  Like when I use a phone connected to the ESP8266 in SoftAP mode and use the phone as a remote control... no Internet.  I went to great lengths to avoid using jQuery and/or libraries that require it.  All my  written libraries are pure JavaScript.  I also found a satisfactory graphing library that uses raw JavaScript.  It's one of the few.  

I don't like jQuery much either, however, node.js and other libraries of late are offering greater possibilities.  p5.js is the equivalent of the processing environment in web form.  It allows you to write both 2D and 3D directly into the HTML5 canvas, which in fact is OpenGL in a browser!

Cheers


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

@inq

Posted by: @inq
Posted by: @frogandtoad

You might like to check out p5.js with WebGL and all the fantastic libraries that support it here

On further thought... My current project will be to take raw coordinate mapping data.  Have you any experience with just plain HTML5 type cavas verus this WebGL library?  Can I do all the 3D output (Point Cloud) to the browser page and simply use mouse type navigation to rotate inside and around the cloud so I can look at it from any angle?

I know how to write this from the ground-up and have in C++, but really don't want to do it for JavaScript if there is an easier solution.

VBR,

Inq

Yes, you can do everything you desire, and use the mouse to navigate through the 3D environment to your imagination - p5.js offers WebGL (OpenGL), directly in the browser, camera, lighting, textures, etc...

Cheers


   
ReplyQuote
Page 1 / 2