Various dialects of Pascal, such as UCSD Pascal, provide the separate compilation unit, called UNIT, as a half-way measure in the right direction. Unfortunately, the Pascal UNIT facility (interface portion) does not allow a physical separation between specification and implementation, which are tied together in the same compilation unit.

Because the interface section and the implementation section of a Pascal compilation unit are required to be in the same physical unit, the data structure for any Pascal data type must be completely specified in the interface portion except when only one variable of such data type is to be allowed. In such a case the data structure can be hidden in the implementation portion of the compilation unit. This restriction is rather severe. For example, only one complex number variable, only one stack variable, only one string variable, only one list variable, could exist in a program at a given time. This is unrealistic in most cases.

In the Modula-2 dynamic string abstraction presented in section 1.3, each procedure contains a parameter of type string. This permits many string variables to coexist in a program. Each individual string variable may be manipulated independent of the others. The data structure for the type string is not specified in the interface unit (definition module) because of Modula-2’s opaque type facility and the separation between specification and implementation.

To allow each Pascal procedure in the interface portion of a string compilation unit to contain a parameter of type string, the data structure for string must be completely specified before the first parameter reference to type string is given. Thus the essential feature of data hiding is lost in Pascal, even with the limited facility of separate compilation available in some dialects of Pascal.

#pascal #modula-2 #modula #encapsulation #interface

բնօրինակ սփիւռքում(եւ մեկնաբանութիւննե՞ր)

very interesting discussion for me https://github.com/modula3/cm3/issues/12

What do you think about implementing properties in Objects?

OBJECT
...
PROPERTIES
intValue : INTEGER READ GetIntValue() WRITE SetIntValue();

I wouldn’t mind adding some things like this as long as they are very obviously simple syntactic sugar for existing operations. This looks like something like that…

shouldn’t it be, though

PROPERTIES
intValue : INTEGER
READ := GetIntValue() : INTEGER
WRITE := SetIntValue(to : INTEGER);

to more closely match the syntax for methods.

Also it won’t work on RECORDs, which is a bit odd.

I suppose it follows the existing property (which I would not want to break) that you can almost always change a T = REF RECORD … to T = OBJECT … without breaking anything, but not the other way around.

#modula #programming #programming_languages #modula-3 #cm3 #modula3 #compiler

բնօրինակ սփիւռքում(եւ մեկնաբանութիւննե՞ր)

Now, modular programming is possible in C, but only if the programmer sticks to some fairly rigid rules:

  • Exactly one header file per module. The header should contain the function prototypes and typedef declarations to be exported, and nothing else (except comments).
  • The comments in a header file should be all that an external caller needs to know about the module. There should never be any need for writers to know anything about the module except what is contained in the header file.
  • Every module must import its own header file, as a consistency check.
  • Each module should contain #include lines for anything being imported from another module, together with comments showing what is being imported. The comments should be kept up-to-date. There should be no reliance on hidden imports which occur as a consequence of the nested #include lines which typically occur when a header file needs to import a type definition or a constant from elsewhere.
  • Function prototypes should not be used except in header files. (This rule is needed because C has no mechanism for checking that a function is implemented in the same module as its prototype; so that the use of a prototype can mask a “missing function” error.)
  • Every global variable in a module, and every function other than the functions exported via the header file, should be declared static.
  • The compiler warning “function call without prototype” should be enabled, and any warning should be treated as an error.
  • For each prototype given in a header file, the programmer should check that a non-private (i.e. non-static, in the usual C terminology) function with precisely the same name has its implementation in the same module. (Unfortunately, the nature of the C language makes an automatic check impossible.)
  • Any use of grep should be viewed with suspicion. If a prototype is not in the obvious place, that’s probably an error.
  • Ideally, programmers working in a team should not have access to one another’s source files. They should share only object modules and header files.

http://www.modulaware.com/mdlt35.htm

#programming #modularity #modular-programming #modules #C #modula #modula2 #oberon #consistency #safety

բնօրինակ սփիւռքում(եւ մեկնաբանութիւննե՞ր)