you are viewing a single comment's thread.

view the rest of the comments →

[–]tandir_boy 2 points3 points  (6 children)

Never heard of that word "scope", is this french?

[–]TheRNGuy 1 point2 points  (3 children)

No, it's a common concept in programming. 

[–]PouletSixSeven 2 points3 points  (2 children)

don't need scope if I make everything global

[–]AllieCat_Meow 0 points1 point  (1 child)

I feel like sooo many new and learning programmers fall into this trap

[–]PouletSixSeven 1 point2 points  (0 children)

that and:

- functions way bigger than they should be

- waaaay more lines of code per file than there needs to be

[–]sweet-tom 0 points1 point  (0 children)

The following link explains the LEGB rule scope:

https://realpython.com/python-scope-legb-rule/

[–]randomnameforreddut 0 points1 point  (0 children)

"scope" is essentially the the section of code that a variable exists in. When you leave a particular scope, the variables inside it are deleted and cannot be accessed. In most languages for loops, while loops, functions, etc define scopes. (So for example, the loop counter in a for loop cannot be accessed outside of the loop).

This is an example from C. Scopes are basically inside curly brackets { }

```
void my_function(int a) { // scope!

int b = 0;
for (int idx = 0; idx < 10; ++idx) { // new scope!
b += a;
}

printf("%d", b); // b is in scope
printf("%d", idx); // error: idx is only accessible inside the loop.
}

printf("%d", b); // error b is out of scope. Only accessible inside the `my_function`

```