Performance: Should I use global variables instead of local?

econjack:
Would you really want to hire a programmer who doesn't understand or use scoped variables?

This is a completely irrelevant question.

The whole point of this Forum is that I am not trying to create a hirable programmer. I am just trying to help someone get her/his project to work reliably and in a way that s/he can understand and maintain.

I get the impression many people use an Arduino for a on-off project (such as controlling a fish tank or a chicken coop) and have no particular interest in programming per se. They just want to learn enough to make their project work.

Other people, starting with the same objective may discover that they like programming and may progress to become avid hobby programmers or even professional programmers. But they well never discover they like programming unless they get their first project to work.

The Forum also has many members who have come to the Arduino late in life and have no intention of becoming professionals. Of course some of them were professional programmers in an ealier life and may bemoan the lack of discipline that I display.

...R

This is a completely irrelevant question.

I disagree. I'm simply trying to point out that someone who does understand scope will write better and more maintainable code than someone who doesn't. I've taught this stuff for over 30 years at the university level and I would much rather start teaching someone who knows absolutely nothing about programming than someone who has bad habits and slogs through a mountain of their sloppy code. It seems everyone wants to take shortcuts rather than invest a little time in learning how to do it right. My guess is that the "shortcutters" will find someone else's code and try to modify it to their own needs. How many times have we all read: "I got this code from www.xyz and it doesn't work"? If they don't understand some of the basics, it's going to be a pretty rough road until they do grasp those basics. Simply telling them they don't need to know about scope and let them hack around until something magically happens to work seems like a bad way to introduce someone to programming.

You have to know about scope, or else you will someday try to access something out of scope. You will be baffled by it. Since you have to know about it, you might as well learn to use it.

econjack:

This is a completely irrelevant question.

I disagree.

I was only referring to the bit about hiring people !

aarg:
You have to know about scope, or else you will someday try to access something out of scope. You will be baffled by it. Since you have to know about it, you might as well learn to use it.

I feel I am being taken out of context.
All I am trying to get across is the difference between a reasonable way for a newcomer to get something done without spending 2 years in college and the "perfect" way to write code.

You would not wait until you could cook a perfect 6-course dinner before you had your first meal.

By the way, there is one type of application where global variables don't work - web programming where the code must be able to respond to hundreds or thousands of different requests and the scope only exists for a fraction of a second.

...R

Robin2:
By the way, there is one type of application where global variables don't work - web programming

As someone who works in this area - trust me there are plenty of ways to spoil one's life with globals even here.

scope only exists for a fraction of a second.

Depends on the environment.

@Yem, you were trying to say something? I only see a quotation.

aarg:
@Yem, you were trying to say something? I only see a quotation.

Oops, my bad, thanks for letting me know.
Fixed.

Think global, act locally. :slight_smile:

YemSalat:
As someone who works in this area - trust me there are plenty of ways to spoil one's life with globals even here.

That is what I was trying to say.

...R