Go Down

Topic: String concatenation and printing (Read 32620 times) previous topic - next topic

GoForSmoke

Thanks for all suggestions.
Eventually I found out there was no problem with the printing code, but rather with the data in the structure.
The suggested format using String concatenation is just fine, and has nothing to do with laziness.
It is a useful tool that was added to Arduino, and is the best choice.
(Such tool is available in all higher languages I know)

I use it for the simple reason that I re-use the same text in several locations, thus building a single string and re-using it is the correct approach.

In my code I use it: (and it is just fine)
String message = (String)"Rev " + configData.configVersion + "," + configData.versionDate;
Serial.println(message);
lcd.print(message);

samtal
The reason you were steered away from using String is because the ARV chips have very little RAM and the way that String works is a very bad fit that causes lots of problems that the ones of us that steer you away from the practice have helped many others fix their code.

Perhaps you did not know but that does not help YOU one bit with your code. Your ego, maybe, but that just holds YOU back.

"The suggested format using String concatenation is just fine, and has nothing to do with laziness.
It is a useful tool that was added to Arduino, and is the best choice.
(Such tool is available in all higher languages I know)"

Funny how you dismissed the reasons you were given to not use String but instead go straight to "laziness". The one thing you can object to is the thing you base your choice on.

I've typed out full explanations for why not to use String many times but I do that for people who ask in words that say they are ready to learn something. Of course it helps after they've painted themselves in a corner and are ready to learn.

A little bit of "know" lets you compare how to code modern PC's to AVR microcontrollers because languages.

I've been helping members here for over 6 years. When I tell you something is going lead you to trouble, that's because it will.
1) http://gammon.com.au/blink  <-- tasking Arduino 1-2-3
2) http://gammon.com.au/serial <-- techniques howto
3) http://gammon.com.au/interrupts
Your sketch can sense ongoing process events in time.
Your sketch can make events to control it over time.

nitePhyyre

Sad that a post like this is one of the first google results for "arduino string concat". Even though the community isn't generally like this, it looks bad. Any noobs readingthis, please don't be scared away.

"The suggested format using String concatenation is just fine, and has nothing to do with laziness.
It is a useful tool that was added to Arduino, and is the best choice.
(Such tool is available in all higher languages I know)"

Funny how you dismissed the reasons you were given to not use String but instead go straight to "laziness". The one thing you can object to is the thing you base your choice on.
This was the very first reply:
Code: [Select]
Serial.println((String)"Rev " + configData.configVersion + " " + configData.versionDate);
Quit being lazy. Use as many Serial.print() statements as needed to output each piece of data. Quit pissing away resources (ab)using the String class that way.
Emphasis mine.

The next response was:
There is also the function sprintf(). You should think about looking into it.
Then there was the response from the OP about not being lazy that you've quoted.

Funny how you think that this is jumping to laziness. Funny how you think this is "dismissing the reasons" not to use String. What "reasons"?  Laziness and (ab)use?

Quote from: Donald Knuth's 1974 paper
There is no doubt that the grail of efficiency leads to abuse. Programmers waste enormous amounts of time thinking about, or worrying about, the speed of noncritical parts of their programs, and these attempts at efficiency actually have a strong negative impact when debugging and maintenance are considered. We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil. Yet we should not pass up our opportunities in that critical 3%."
Written about computers with much less power and resources than an arduino.

I've been helping members here for over 6 years. When I tell you something is going lead you to trouble, that's because it will.
Instead of bragging about how "helpful" you are and warning people they will have problems if they don't heed your holy decrees from on high, maybe, you could try actually being helpful?

Like actually saying what problems they will encounter by using String? Benchmarks or links showing how much of a difference there is between the 2 options. Other problems people will encounter from low resources scenarios.

GoForSmoke

Like actually saying what problems they will encounter by using String? Benchmarks or links showing how much of a difference there is between the 2 options. Other problems people will encounter from low resources scenarios.
Too bad you didn't dig up all the posts and threads that do that but then I doubt that those fulfill your narrative.

You came to TROLL. You feel a need and this is how you indulge it.
1) http://gammon.com.au/blink  <-- tasking Arduino 1-2-3
2) http://gammon.com.au/serial <-- techniques howto
3) http://gammon.com.au/interrupts
Your sketch can sense ongoing process events in time.
Your sketch can make events to control it over time.

Go Up