A Review of Static and Dynamic Scoping in Programming Languages

All programming languages allow names to be associated with values by means of definitions, and a name is said to be in the scope of its definition. When a name is mentioned in a program, its definition (if any) must be known, in order for its invocation to make sense. However, most languages allow names to be re-defined in a program – the rules for determining to which definition a name refers, are called the scoping rules.
There are two principal scoping methods: static and dynamic. This post will firstly explain these two concepts, comparing their similarities and differences. The uses of the two methods will be discussed, illustrating these with code from actual programming languages. Finally the essay will conclude with a critical summary of the pros and cons of static and dynamic scoping for present day programming problems.

Read More…

Call-by-reference vs. Call-by-value in programming

Generally speaking, in computer programming, a parameter is a special kind of variable, used in a function declaration to refer to one of the pieces of data provided as input to that function. These pieces of data, in turn, are called arguments. Therefore, in order to make a clear distinction between them, the argument is the actual value passed to a function, procedure, or method, whereas the parameter is a reference to that value inside the implementation of the function. The act of transmitting parameter values to and/or from a called function is known as “parameter passing”. The way that the arguments are evaluated and passed to the function depends on the programming language and the kind of parameter passing mechanisms it uses. Two very common mechanisms used in many programming languages are call-by-reference and call-by-value.

Read More…

The Dining Philosophers Problem in concurrent programming

Posed and solved by Edsger Dijkstra in 1965, the Dining Philosophers Problem is a classic problem in Concurrent Programming and is often used to illustrate synchronization issues and techniques for resolving them.

Five silent philosophers are sitting around a circular table. They never talk to each other, spending their time thinking. In the middle of the table is a bowl of rice. Between each pair of adjacent philosophers, there is a chopstick and they have agreed that each will only use the chopstick to his immediate right and left when eating from the bowl of rice. So unfortunately, as philosophy is not as well paid as computing, the philosophers can only afford five chopsticks laid out on the table such that the first philosopher’s right chopstick is the left chopstick of the second philosopher, whose right chopstick is the left chopstick of the third philosopher and so forth.

Read More…

 Scroll to top