Timeline for Global or local
Current License: CC BY-SA 4.0
7 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Dec 20, 2018 at 15:36 | comment | added | Edgar Bonet | @minisaurus: I don't know on these environments. My answer is specifically for the kind of programs you write on smallish embedded devices. | |
Dec 20, 2018 at 14:04 | vote | accept | minisaurus | ||
Dec 20, 2018 at 13:50 | comment | added | minisaurus | I'm out of touch, but is the ban really lifted in professional environments with several developers, APIs, libraries and who knows how many files of source code? But I can see how globals maybe aren't a big problem in these single file small Arduino projects. | |
Dec 20, 2018 at 10:32 | comment | added | Edgar Bonet | @minisaurus: Yes, that's right. However, now that he ban is lifted, I suggest you try to avoid thinking of globals as evil. If you find yourself passing a variable around through many functions, consider making it global: does that hurt the program's readability? If the answer is "no", then a global is probably a good choice. | |
Dec 20, 2018 at 10:21 | comment | added | minisaurus | Thanks for all your answers, I've changed the code, and it's good to know I don't need to change my practices too much :) (Global variables were banned in all the development environments I worked in in the 1990s) So am I right to conclude that I only NEED to use a global if I refer to it in setup() and loop()? Everything else can be local and passed around? | |
Dec 20, 2018 at 10:11 | vote | accept | minisaurus | ||
Dec 20, 2018 at 14:03 | |||||
Dec 20, 2018 at 9:56 | history | answered | Edgar Bonet | CC BY-SA 4.0 |