Is it good practice to pull global variables into a local, private variable before manipulating them?
>>54536526
>not making all your variables global
scrub.
>>54536526
use gotos
>>54536570
seems more orthogonal to me to pull a global inside, then give it a local variable name, manipulate the data using the local variable, then returning a new global, than it is to just do all the work on the original globals. what if another function is using that global?
>>54536526
Is the goal to change the values globally?
I'll let you figure this out.
>>54536633
my original question left of a key piece of information: i then return a new global like
func takes(input_dirty) {
wash(input_dirty)
return global input_clean
}
>>54536570
>polluting the global namespace for no reason
scrub.
send help
wtf language is that
anyway
global input_dirty = "I AM A FILTHY BOY"
function clean(dirty) {
return wash(dirty)
}
input_dirty = clean(input_dirty)
>>54537826
whats going on here?global input_dirty = "a dirty string"
function clean(dirty){
//define wash() here?
return wash(dirty)
}
//always run the function clean on input_dirty?
input_dirty = clean(input_dirty)
>>54537826
is this functional programming?
>>54537877
I was just recommending against having functions modify their parameters directly. Better to return a separate new value, and use that value as a global if necessary, imo.
Or were you asking a different question? Your worded it rather strangely.
>>54536661
>global not const
>>54537944
>const
>ever
>>54537928
yep that was what i was asking, thanks, anon
but is this style "functional"? if so, then i think i understand it now
nigger
>>54536615
This
>>54538041
According to Wikipedia: "In functional code, the output value of a function depends only on the arguments that are input to the function, so calling a function f twice with the same value for an argument x will produce the same result f(x) each time."
So, yes? I've never heard it called that, it just seems like common sense for the most part. I break it occasionally, e.g. when passing a pointer to a queue in the constructor method of a class when doing threading.