A
A
Alexander Grishin2017-01-21 00:35:23
Programming
Alexander Grishin, 2017-01-21 00:35:23

Why are global variables not commonly used?

So why is it not recommended to use global variables in all languages?
The topic is no longer googling, but justification. Who has any thoughts?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
DevMan, 2017-01-21
@beerdy

because it becomes easy to shoot in the knee.
for example, when refactoring, renaming the variable not in all methods, and similar side effects.
or by installing a third party module/library/etc that uses a variable of the same name.
data control becomes more complicated and a whole lot more. there is little point in repeating what has already been written:
https://cbabhusal.wordpress.com/2015/09/27/ruby-wh...
softwareengineering.stackexchange.com/questions/14...

V
vsuhachev, 2017-01-23
@vsuhachev

Глобальная переменная это зависимость, что ведет к тому что код нельзя повторно использовать (перенести в другой проект, например).
Ситуация с глобальными переменными похожа на ситуацию с goto. Оба инструмента бывают очень полезны, но без знания всех особенностей ими легко злоупотребить во вред. Поэтому нубам их просто запрещают использовать без объяснений т.к. объяснять все тонкости будет дольше и все равно не поймут.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question