ComputerScientist
174 subscribers
14 photos
3 files
206 links
▜ The Inventor

Stuff that inspire you to create.

See also: ▙ @LitMind
Download Telegram
GoTo
- is a statement that performs a one-way transfer of control to another point of code; in contrast to a function call which returns control.

Its use has declined significantly since the advent of structured programming in the 1960s. Structured programming languages like #Pascal introduced control structures such as: subroutines, loops and multiway branch for clarity and efficiency. These replace equivalent flows written using gotos and ifs.

Language support:
#C
#CSharp: also makes case and default statements labels, whose scope is the enclosing switch statement; goto case or goto default is often used to replace explicit "fall-through", which C# disallows.
#Perl
#PHP there was no native support for goto until version 5.3
#Java: goto is a reserved word, but is unusable.
#Python: does not support it but there are several joke modules that provide it.

The structured program theorem proves that goto is not necessary to write programs.
The diamond problem
- is an ambiguity that arises when two classes B and C inherit from A, and class D inherits from both B and C. If there is a method in A that B and C have overridden, and D does not override it, then which version of the method does D inherit: that of B, or that of C?

For example, in the context of GUI software development, a class Button may inherit from both classes Rectangle (for appearance) and Clickable (for functionality/input handling), and classes Rectangle and Clickable both inherit from the Object class. Now if the equals method is called for a Button object and there is no such method in the Button class but there is an overridden equals method in Rectangle or Clickable (or both), which method should be eventually called?

How different languages deal with it:
• Common #Lisp: by order "...in the order in which parent classes are named in the subclass definition"
• Curl: "and the secondary constructor will be invoked for all other subclasses."
• Eiffel: "Eiffel will automatically join features together, if they have the same name and implementation."
• Go: compile-time error
#Java: compile-time error
#OCaml: by order "...are inherited in the same order, with each newly inherited method overriding any existing methods."
#Perl: by order "...from as an ordered list. The compiler uses the first method it finds..."
#Python: by order
#Ruby: by order "...as rightmost depth first resolution."
#Scala: by order "allows multiple instantiation of traits, which allows for multiple inheritance by adding a distinction between the class hierarchy and the trait hierarchy. A class can only inherit from a single class, but can mix-in as many traits as desired." This approach is the most similar to #Nile's; traits being qualifications.
• Tcl: by order "the order of specification in the class declaration affects the name resolution for members..."

Languages that allow only single inheritance, where a class can only derive from one base class, do not have the diamond problem.

Moreover, languages such as #Ada, Objective-C, #CSharp, #Delphi/Free #Pascal, Java, #Swift and PHP allow multiple-inheritance of interfaces (called protocols in Objective-C and Swift). Interfaces are like abstract base classes that specify method signatures without implementing any behavior.

When several interfaces declare the same method signature, as soon as that method is implemented (defined) anywhere in the inheritance chain, it overrides any implementation of that method in the chain above it (in its superclasses). Hence, at any given level in the inheritance chain, there can be at most one implementation of any method. Thus, single-inheritance method implementation does not exhibit the Diamond Problem even with multiple-inheritance of interfaces.
Blocks
- are lexical structures that allow many statements to be treated as one. A language that allows blocks and nested blocks, is called block-structured. Blocks are fundamental to #structured programming.

As scopes
Depending on the language, certain distinguished blocks may be treated as lexical scopes; otherwise, identifiers assigned in outer blocks are visible inside inner blocks, unless shadowed.

Syntax
• Free-form
Whitespace only delimits tokens and has no other significance
begin ... end: #ALGOL, #Pascal
{ ... }: #C, #Perl, #JS, #Nile
( keyword ... ): #Lisp

• Off-side rule
Indentation groups blocks of code
e.g. #Python, #Haskell, #Cobra, #CoffeeScript

Limitations
In some languages blocks do not fully support all declarations; for instance many C-derived languages do not permit nested functions.
Data layout
- is how multidimensional arrays are stored in a linear storage such as RAM. It is critical for:
• correctly passing arrays between programs written in different programming languages
• performance when traversing an array because modern CPUs, due to caching, process sequential data more efficiently than non-sequential data
• contiguous access makes it possible to use SIMD instructions that operate on vectors of data

Row-major versus column-major order
The difference between the orders lies in which elements of an array are contiguous in memory. In a row-major order, the consecutive elements of a row reside next to each other, whereas the same holds true for consecutive elements of a column in a column-major order. While the terms allude to the rows and columns of a two-dimensional array, the orders can be generalized to arrays of any dimension.

Transposition
As exchanging the indices of an array is the essence of array transposition, an array stored as row-major but read as column-major (or vice versa) will appear transposed. As actually performing this rearrangement in memory is typically an expensive operation, some systems provide options to specify individual matrices as being stored transposed.

Languages support
• Row-major: #C/C++/Objective-C (for C-style arrays), PL/I, #Pascal, Speakeasy, SAS, and Rasdaman
• Column-major: #Fortran, #MATLAB, GNU Octave, S-Plus, #R, #Julia, and Scilab.
• Neither (for less dense arrays):
• Iliffe vectors: #Java, #Scala, #Swift. #Ruby, #Perl, #PHP, #JavaScript, Visual Basic .NET
• Lists of lists: #Python, Wolfram Language of Wolfram Mathematica
• Tables of tables: #Lua
SISAL
"Streams and Iteration in a Single Assignment Language" is a general-purpose single assignment functional programming language with strict semantics, implicit parallelism, and efficient array handling. It was derived from VAL (Value-oriented Algorithmic Language by Jack Dennis), and adds recursion and finite streams.

By: James McGraw
First appeared: 1983
First compiled implementation: 1986
Paradigms: #functional, #dataflow
Syntax: #Pascal -like
Performance: superior to #C and rivals #Fortran

SISAL is more than just a dataflow and fine-grain language; it is a set of tools that convert a textual human readable dataflow language into a graph format (named IF1 - Intermediary Form 1). Part of the SISAL project also involved converting this graph format into runable C code.

In 2010 SISAL saw a brief resurgence when a group of undergraduates at Worcester Polytechnic Institute investigated implementing a fine-grain parallelism backend for the SISAL language.

In 2018 SISAL got modernized with ident-based syntax, first-class functions, lambdas, closures and lazy semantics within project SISAL-IS.

#SISAL