Global variables (again)

前端 未结 11 1081
感情败类
感情败类 2021-01-21 16:31

I keep hearing that global variables should never be used, but I have a tendency to dismiss \"never\" rules as hot-headed. Ar

11条回答
  •  死守一世寂寞
    2021-01-21 16:59

    "Why not": global variables give you spaghetti information flow.

    That's the same as goto gives you spaghetti control flow.

    You don't know where anything comes from, or what can be assumed at any point. The INTERCAL solution of introducing a come from statement, while offering some initial hope of finally being sure of where control comes from, turned out to not really solve that problem for goto. Similarly, more modern language features for tracking updates to global variables, like onchangeby, have not turned out to solve that problem for global variables.

    Cheers & hth.,

提交回复
热议问题