Re: Hijacked: C vs C++

Jack, W8TEE

Who is making these "Arduino design recommendations"? I don't see why a "user" would ever need to know if I was using char * versus char x[]. The difference is syntactic sugar. As to fragmentation, if the programmer knows this is going to happen and is willing to run that risk, that says something. Memory fragmentation never "settles out" and I doubt that you should rely on "if the percentage of holes stabilize". Simply knowing that it does, in fact, create holes is good enough reason not to use the String class.

To say that makes your programming effort go faster seems a bit odd to me, as the time savings between:

   newString += oldString;

seems little different to me than:

   strcat(newString, oldString);

It may take a little more effort up front to learn all of the string functions (see, especially if you're coming from a Basic background, but it quickly become second nature to use them.

I, too, would regret using the String class...always, if for no other reason than fragmentation. The fact that you're willing to fritter away unused memory resources simply because they exist seems like burning all the firewood around your Alaskan cabin in the middle of summer...not a good reason to be wasteful. It also teaches bad/lazy programming habits.

Just my $0.02 worth...

Jack, W8TEE

On Tuesday, July 3, 2018, 10:59:42 PM EDT, Tom, wb6b <wb6b@...> wrote:

The Arduino design recommendations are to hide as much of the nitty gritty details from the users as possible. They even recommend not exposing the user to the horror of "char *" and use "char whatever[]" instead. 

I use the string class when it makes it easier for a user to understand what is going on or simply makes my programming effort go faster. The Arduino is not like a Unix machine at a company. it is usually running the same small set of tasks over and over again, so many of the memory allocations that would lead to memory fragmentation will settle out as the routines will find a home for their memory allotments in the memory blocks they the previously abandoned. So if the percentage of holes stabilize and is not a fantastically large percentage it seems a fair tradeoff. 

If I was short on memory and had to shoehorn yet another feature into the fixed resources of one processor, I'd regret using the String class. And I'd probably move to the chip manufacture's leaner tool chain. But, in a $3.50 Nano with only half the resources being used, the convenience of the String class is worth it. String provides a nice encapsulation of the things people do with strings. So, depending on the situation I'll use convenience classes at one moment and do direct point manipulation in another. 

Tom, wb6b

Join to automatically receive all group messages.