Global Variable and Constant
Why discuss about Coding here ?
Because I also include Haskell. And Haskell distinct clearly between global constant and mutable state.
Global variable is requirement in this project
Some say that global variable are bad. But there are quick and dirty condition, where global variable looks more suitable. The other way is change the entire logic design.
output module require a variable
that can be called from function,
without passing them as a parameter argument.
So we have to make scope of these variable global.
But since these variables live only in output module,
these are not so global after all.
Before getting deep, we need to distinct between global variable and global constant.
global variable: mutable state, must be initialized.
global constant: it is usually defined as a global variable, except that, the value won’t be altered during script execution. The value is defined at the beginning of program.
Accessing a global variable from within function need different trick for each language.
BASH: Variable is global by default.
Perl: Variable defined using
mycan be accessed within function in the same module.
Python: Access within function using
Ruby: In Module scope, variable defined using
@can be accesed within function.
PHP: Access within function using
Lua: Variable scope using table module such as
Haskell: Officialy there is a no way to define global variable Haskell. But Haskell provide a few workaround to simulate mutable state. The easiest one is using
Each language maintain global constant differently
BASH: There are ways to define constant in BASH. Constant in PHP may begin with the word
Perl: There are a several ways to define constant in Perl. Constant in Perl may begin with the word
Python: Officialy there is a no way to define constant in Python. Python does not differ between these two.
Ruby: Constant in Ruby start with capital case.
PHP: Constant in PHP begin with the word
Lua: Officialy there is a no way to define constant in Lua. Lua does not differ between these two.
Haskell: Every variables in Haskell are immutable.
There is no special need to worry about global variable, except with Haskell.
The rest is in their respective article.
Let's get it started.
Dotfiles (Dzen2 Source Code)
Dotfiles (Lemonbar Source Code)
Thank you for Reading.
- July 2017
- HerbstluftWM in Seven Languages Summary
- HerbstluftWM Idle Event in Haskell
- HerbstluftWM Idle Event in Lua
- HerbstluftWM Idle Event in PHP
- HerbstluftWM Idle Event in Ruby
- HerbstluftWM Idle Event in Python
- HerbstluftWM Idle Event in Perl
- HerbstluftWM Idle Event in BASH
- HerbstluftWM Idle Event Overview
- HerbstluftWM Tag Status in Haskell
- HerbstluftWM Tag Status in Lua
- HerbstluftWM Tag Status in PHP
- HerbstluftWM Tag Status in Ruby
- HerbstluftWM Tag Status in Python
- HerbstluftWM Tag Status in Perl
- HerbstluftWM Tag Status in BASH
- HerbstluftWM Tag Status Overview
- May 2017
- April 2017