Questions tagged [scope]

77 questions
41
votes
9 answers

What did programmers do before variable scope, where everything is global?

So, I am having to deal with seemingly archiac language (called PowerOn) where I have a main method, a few datatypes to define variables with, and has the ability to have sub-procedures (essentially void methods) that does not return a type nor…
16
votes
2 answers

Why is it good programming practice to limit scope?

I'm relatively new to programming (July 2015), and I've always wondered why it's good programming practice to hide variables as much as possible. I've run into this question mainly recently when I looked into events and delegates in C#. I searched…
overki11
  • 187
  • 1
  • 5
8
votes
7 answers

Why is scope a good thing?

I'm a newbie coder. I find it troublesome to declare a variable in 1 function and not be able to access it in other functions. I have to make many of my variables global just to get my code to work. But a lot of people say that the global state is…
clickbait
  • 211
-1
votes
1 answer

if (a) {b();c();d();} else {c();} - prevent duplicate code c();

I've got the following scenario: bool bWantToWait = getRandomBool(); if (bWantToWait){ std::future bSuccesfullWait = this->doStartWait(); } //lots of lines of code //even more lines of code //doExecuteSomethingWithAsyncCallback if…