3

I wrote a function in which I use several superassignments. This enables me, when I source this function, to automatically create new global variables ready for later use.

I got a comment on my code that briefly stated that using superassignments was a terrible idea and that this person would not consider the code trustworthy as long as I did not change that.

I am not trained in programming and I naively did not consider bad side effects of using superassignments.

When am I putting my code at risk by using them?

Julian Wittische
  • 1,219
  • 14
  • 22
  • 4
    You can put all your result in a named list that is returned by your function . It will be as convenient for end user – HubertL May 19 '17 at 22:03
  • 5
    Proper functions in a functional language should not have side-effects. You pass in parameters, they return values of interest. If they do things that you can't know about without reading the source code, then that's not very friendly. Creating variables outside their own scope is a potential problem. What if you write to a variable name that already exists and has a value the user would like to continue to use after calling your function? Superassignments can destroy existing variables values. – MrFlick May 19 '17 at 22:07
  • 3
    You are asking the wrong question. It is always ill-advised unless you are using it correctly. Assigning into the global environment is usually not something you should do from within a function. See answers to [this question](http://stackoverflow.com/q/2628621/1412059) for some legitimate uses. – Roland May 20 '17 at 06:45

0 Answers0