Skip to main content
25 events
when toggle format what by license comment
Apr 17, 2018 at 12:48 comment added ATE-ENGE Hey All: This got a lot more popular than expected. I've learned a lot in the last 9 months and would like to make this as useful to "other me's" as possible. Would people appreciate it if I appended this post with links to tutorials/ideas that helped me as a beginner improve my code? I'm still not 100% confident on stack exchange's edicate, so I thought I'd ask 1st.
S Jul 14, 2017 at 8:47 history suggested Mast CC BY-SA 3.0
Improved indentation and use of capitals.
Jul 14, 2017 at 6:53 review Suggested edits
S Jul 14, 2017 at 8:47
Jul 13, 2017 at 17:26 comment added Zeta.Investigator related: electronics.stackexchange.com/questions/97241/…
Jul 13, 2017 at 9:57 answer added dannyf timeline score: 0
Jul 13, 2017 at 7:25 answer added hobbs timeline score: 4
Jul 12, 2017 at 15:38 comment added Restioson @Muzer huh, always thought it was Processing. TIL
Jul 12, 2017 at 15:11 comment added Code Gorilla @LookAlterno - The biggest issue with global variables is poor programmers. You should pass every value as an argument (try to keep it less than 5), because that compartmentalises your code and allows for reuse. Copy and pasting functions together into programs is really easy, but only if you avoid globals as much as possible. It also prevents monolithic functions, if you are passing in 20 args into a 2000 line function then you should be refactoring it.
Jul 12, 2017 at 15:07 comment added Code Gorilla Global variables on an Arduino are less evil that on a PC. I have seen people declaring a loop variable, i, as a global variable. TBH I try and avoid them, but they do have their place in memory management.
Jul 12, 2017 at 14:24 comment added antipattern Static and global variables offer the advantage of knowing memory consumption at compile time. With an arduino having very limited memory available, this can be an advantage. It quite easy for a novice to exhaust the available memory and experience untraceable failures.
Jul 12, 2017 at 13:42 review Close votes
Jul 12, 2017 at 15:48
Jul 12, 2017 at 13:14 answer added Arjen timeline score: 5
Jul 12, 2017 at 1:53 comment added Rob Actually, some embedded programmers ban local variables and require global variables (or function scoped static variables) instead. When the programs are small, it can make it easier to analyze it as a simple state machine; because variables never overwrite each other (ie: as they do stack and heap allocated variables).
Jul 11, 2017 at 22:46 comment added underscore_d @LookAlterno That's a mundane truism of C/C++ (namespaces notwithstanding), which is not specific to Arduino at all, and as you then yourself indicated, does not by any means lead to the conclusion that global variables cannot be avoided; they can, and often should. Where the answer to this question might differ when the platform is an Arduino is not on the level of the language, but rather in the design patterns that make sense on the platform and whether they make globals desirable.
Jul 11, 2017 at 20:58 comment added Lightness Races in Orbit @LookAlterno: "I avoid" and "you can't" are very different things.
Jul 11, 2017 at 17:07 history tweeted twitter.com/StackArduino/status/884821499441332225
Jul 11, 2017 at 16:16 comment added user31481 @Muzer. I use C++ classes only for library development, and, well, larger programs. I avoid C++ for reasons.
Jul 11, 2017 at 15:56 comment added Muzer @LookAlterno Err, can you not write classes in Ardunio, since it's just C++ with weird macros and libraries? If so, not every variable is global. And even in C, it's usually considered best practice to prefer passing variables (perhaps inside structs) into functions rather than having global variables. Might be less convenient for a small program but it usually pays off as the program gets larger and more complex.
Jul 11, 2017 at 15:17 answer added BOC timeline score: 6
Jul 11, 2017 at 14:19 answer added Michel Keijzers timeline score: 5
Jul 11, 2017 at 13:49 answer added Andrew timeline score: 5
Jul 11, 2017 at 13:35 comment added user31481 In Arduino you can't avoid global variables. Every variable declaration outside the scope of a function/method is global. So, if you need to share values between functions, they have to be globals, unless you want to pass every value as an argument.
Jul 11, 2017 at 13:29 answer added Edgar Bonet timeline score: 24
Jul 11, 2017 at 13:19 answer added Majenko timeline score: 41
Jul 11, 2017 at 13:07 history asked ATE-ENGE CC BY-SA 3.0