[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
Is it good practice to pull global variables into a local, private
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 18
Thread images: 1
File: 1462408861719.jpg (438 KB, 900x2134) Image search: [Google]
1462408861719.jpg
438 KB, 900x2134
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.
Thread replies: 18
Thread images: 1

banner
banner
[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y] [Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.