[Rd] Conventions: Use of globals and main functions

Cyclic Group Z_1 cyc||cgroup-z1 @end|ng |rom y@hoo@com
Wed Aug 28 05:16:13 CEST 2019


Definitely, I agree that global variables have a place in programming. They play an especially important role in low-level software, such as embedded programming, as you mentioned, and systems programming. I generally would disagree with anyone that says global variables should never be used, and they may be the best implementation option when something is "truly global."

However, in R scripting conventions, they are the default. I don't think it is controversial to say that in software engineering culture, there is a generally held principle that global variables should be minimized because they can be dangerous (granted, the original "Globals considered harmful" article is quite old, and many of the criticisms not applicable to modern languages). I do think it is equally important, though, to understand when to break this rule.

I like your suggestion of documenting this as an alternative option, though it seems the general sentiment is against this, which I respect.

Best,
CG



More information about the R-devel mailing list