Go Down

Topic: What do you look for when examining posted code? (Read 1 time) previous topic - next topic

wildbill

I was wondering whether there would be some value to having a thread in the Introductory Tutorials section that details what errors people are looking for when trying to help someone posting for help.

Although the view counts in that area are quite high, the number of new posters that don't use code tags shows all too well just how little the stickies and tutorial threads are used. So perhaps this is a Bar Sport topic instead.

If someone is reporting mysterious crashing behaviour after some time, I'll run my eye down their code looking for String, malloc or recursive calls. If I find any of those, I'll say so but I'm unlikely to dig further.

After that I'll look for exceeding array bounds.

If the issue is that things go haywire after thirty or sixty seconds, I'll look for an int used with millis().

If things are slow, check for 9600 used as a serial baud rate.

Always check for the ever popular test Serial.Available()>0 and then read multiple characters.

= != ==

I'm sure that there are other things I do too, depending on the request but I'm drawing a blank on any more right now. What do other folks start with?

AWOL


groundFungus

Probably less common:

Global and local variable with the same name.
Local variables accessed in a different function (scope error).
Missing curly brackets to enclose a code block.

Qdeathstar

A creaking creeping shadow
stiff against the freezing fog
glares at a tickless watch.

Time has failed him -- all things shall pass.

ChrisTenone

What, I need to say something else too?

sterretje

Proper indents. I often copy to PC and <ctrl>T for starters.

A lot of obvious mistakes show that way.
If you understand an example, use it.
If you don't understand an example, don't use it.

Electronics engineer by trade, software engineer by profession. Trying to get back into electronics after 15 years absence.

TomGeorge

Proper indents. I often copy to PC and <ctrl>T for starters.

A lot of obvious mistakes show that way.
Yes, same here, I copy via Notepad++.
Then using programming pins, then pullups/downs.
Tom... :)
Everything runs on smoke, let the smoke out, it stops running....

wildbill

And then compile it with max warning level. That's found the problem on any number of occasions.

TomGeorge

Sorry, the first thing I do is "Take a deep breath".... :) :) :)
Everything runs on smoke, let the smoke out, it stops running....


Robin2

If the OP is just asking for someone to review a program I generally give it a miss. I am not good at spotting mistakes without trying to run a program.

If the OP has given a sensible title to his Thread then that often gives a clue to the solution before I ever look at the program. Then I look at the program to see if my guess was correct.

Where there are lame titles like "I need help" I do often look at them and my first approach is to try to identify the question, or to ask the OP for clarification. Several times I have not been able to help beyond suggesting a better title.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

GoForSmoke

#11
Dec 17, 2018, 08:05 am Last Edit: Dec 17, 2018, 08:07 am by GoForSmoke
I've read so much code that I'm looking first at

how long it is --- do I have time to spend on this?

does it make sense? --- or is it like a Trump/Palin transcript, meaningless drivel.

mostly or all lifted code --- let's see what the OP thinks it does

is specialized and outside of my experience --- good luck!

is written with no arrays but certainly needs them --- try to get the user to learn all the ABC's and more than 2 words before writing that novel.
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.

dougp

It's not a strength of mine but if it looks simple enough I'll examine it.  However, if a poster won't even make an effort to write up a semi-coherent description or puts down two paragraph's worth of stream-of-consciousness run-on sentence, I just pass.
Everything we call real is made of things that cannot be regarded as real.  If quantum mechanics hasn't profoundly shocked you, you haven't understood it yet. - Niels Bohr

No private consultations undertaken!

sterretje

And then compile it with max warning level. That's found the problem on any number of occasions.
Problem often is that one doesn't have the relevant libraries. So compile will already fail on some of the includes :) Or different libraries (with not quite the same functions) with the same names :(
If you understand an example, use it.
If you don't understand an example, don't use it.

Electronics engineer by trade, software engineer by profession. Trying to get back into electronics after 15 years absence.

Go Up