Continuously about programming

Yerassyl
3 min readAug 29, 2020

Procedures, functions and methods

Subprograms that are called are referred as “procedures”. In general, function returns value of a certain type, whereas procedure doesn’t return anything. But C-like languages which have only functions, see procedures as functions returning Void. Void means returns nothing. And methods in OO languages behave as functions and procedures but connected with a class. (Dragon Book).

Static scope

Inner blocks(scope) can see parameters from outer blocks(scope). But if a variable is defined in an inner block with similar name, the inner redefined variable is used when called.

Dynamic scope

#define a (x + 1)

void b() { int x = 1; printf(“%d\n”, a); }

void c() {printf(“%d\n”, a); }

void main() { b(); c(); }

When we define macros a with body { x + 1 }, x is undeclared yet, so it will search for definition of x variable when executed. For example, in main method b is called, which calls macros a in its turn in its definition. b defines int x = 1; when macros a is executed its x will refer to local x inside function b. Similar with function c. (Dragon Book)

Parameters

Procedures have parameters. Parameters are usually actual(фактические) and formal(формальные).

Formal parameters are those used in procedure definition. func add(a: Int, b: Int) -> Int

Actual parameters are those values/variables passed to procedure when it’s called. add(2, 5), add(x, y); (Dragon Book)

Pass by value

All changes are made to local copy of an actual parameter. But it’s possible to pass a pointer to a variable, so that function can change its value. Similar when a is the name of an array and passed to a formal parameter x, then x[i] = 10 will be equivalent to a[i] = 10. Although Java uses only passing by value, actually arrays, strings, class examples are passed by reference. (Dragon Book)

Pass by reference

It is the memory address which is passed when a parameter is passed by reference. So changing formal parameter will result in changing the actual parameter. Is used in C++ and other popular languages for passing large objects, arrays etc. Because passing those elements by value is very costly because of copying and locating.(Dragon Book)

Pseudonyms

When the same parameter is passed to procedure, whose parameters are passed by reference then they are pseudonyms. It’s crucial for compiler to optimize program to know that a variable has no pseudonyms and defined only in one place. (Dragon Book)

Workspace, productivity

An ideal workspace for a programmer is where less people, less disturbing factors like phone ringing, coworker talking etc. Per day one should work at least 2–3 productive hours. Productive means in the flow. The flow is a state when you don’t realize how time passes by. (Peopleware)

The Parkinson’s law is not somehow valid for developers, and the more you put pressure on them doesn’t guarantee you succeeding project on time. But it gives only pressure and kills passion in developers. As a manager your responsibility isn’t to control developers and make them work, but to provide conditions for work. (Peopleware)

10x rule

The best performers are in 1:10 ratio with the worst in terms of productivity. Usually, best performers, developers work mostly in specific companies. It might mean that specific conditions that those companies provide helps to raise productivity and improve as a developer, and also that best performers choose the one with specific workspace, conditions etc. My recap may somehow differ from what’s written in the book. But overall meaning is correct. (Peopleware)

Simple Design

Three rules are:

  • Consider the simplest working thing. If flat files are ok, there’s no need to use database i.e.
  • YAGNI(You Ain’t Gonna Need It). But one day we’ll need that database, one day something else etc. When considering new things XP teams are initially against such changes, and need solid evidences of the opposite point of view to consider it.
  • Once and Only once. Extract duplicated code fragments to methods or to some patterns, like template method etc. (Agile Software Development)

--

--