Jack Purdum
Jerry: Someone once said C is powerful enough to let you shoot yourself in the foot, but C++ has the power to blow your entire leg off. I think that's true. There are features in C++ that I rarely ever use (e.g., multiple inheritance) but there are concepts in OOP/C++ that can also be used in "straight" C, too. Perhaps the best pillar of the OOP Trilogy is Encapsulation. Simply stated, encapsulation means you hide the data. In C++, that means you hide the data in a class. In straight C, it means you avoid global variables. For those who may not know, global data is everywhere visible throughout the program and, hence, it can be changed by any statement in the program. If you define a variable within a function, you hide it from every statement outside that function. In C, a global variable is like placing a hooker at the top of your code and then giving a $100 bill to every statement in your program. If the program spawns a bug, you have very little idea which statement is the father of the bug. If you practice Encapsulation in your C programs, at least you know in which function the father is hiding. About all the C++ I do in the book is explain what a class is and how its syntax manifests itself in an Arduino library. I don't really touch the complexities of C++ beyond that. Al (AC8GY) and I are writing a new book similar to my Arduino Projects for Amateur Radio, but we are also adding the Teensy and Blue Pill families of microcontrollers. Because of the expanded resources of those processors (e.g., the Teensy has 256K of SRAM and 1Mb of flash, all clocked at 180MHz), that book spends a little more time discussing C++, but does not dig that much deeper into it. You can do some serious programming with these additional processors. (Our JackAl project has over 11,000 lines of source code spread over 19 project files!)? I felt the expansion was necessary because I wrote some of my own class libraries for the projects. Anyway, perhaps our viewpoints differ on the word "understand". I don't expect someone who is just starting out with an Arduino project to jump in and start writing class libraries. However, I do feel they need to understand what the Serial object brings to the table for them, especially for debugging purposes. In the Beginning C book, the title for Chapter 14 was selected with considerable care: A Gentle Introduction to Object Oriented Programming and C++, and I sincerely believe that's what it is...useful, but gentle. Jack, W8TEE
On Tuesday, March 12, 2019, 3:21:06 PM EDT, Jerry Gaffke via Groups.Io <jgaffke@...> wrote:
I stand by my advice. Yes, you do need to figure out a bit of C++ if you want to understand ArduinoLand libraries. But you don't need to understand those libraries when starting out with programming under Arduino. I have absolutely no use for the complications of C++ on a machine with 2k of RAM,? it just gets in the way of figuring out how all the time/RAM/Flash has gotten eaten up. That said, your book comes highly recommended. And likely gives a good introduction to C++ for those so inclined. Sounds like just about the right level of exposure. Jerry On Tue, Mar 12, 2019 at 10:34 AM, Jack Purdum wrote:
|