To achieve homoiconicity, i.e. "code is data", statements must become expressions.
Treat operators as methods and thereby allow operator overriding and overloading.
Dispose pattern versus Scope-based resource management
Abstractly, they offer the same interface; their implementation however, is quite different.
Dispose pattern
An external system provides the resources and the handles for them. Handles are abstract references which concretely are usually integers. Handles can be used directly by storing the value in a variable and passing it as an argument to functions that use the resource. However, it is be useful to abstract the handle itself by storing it as a field in a record, along with other data.
This pattern is primarily used in languages with garbage collectors to allow manual resource management for uncommon situations.
Scope-based
a.k.a. RAII (Resource acquisition is initialization)
Holding a resource is a class invariant and is tied to object lifetime: resource acquisition and its release occur during initialization and finalization, respectively.
• prevents resource leaks
• encapsulation
• exception safety
• allows acquisition and release logic to be written next to each other
“In realistic systems, there are far more resource acquisitions than kinds of resources, so the "resource acquisition is initialization" technique leads to less code than use of a "finally" construct.”
— #Bjarne_Stroustrup
Abstractly, they offer the same interface; their implementation however, is quite different.
Dispose pattern
An external system provides the resources and the handles for them. Handles are abstract references which concretely are usually integers. Handles can be used directly by storing the value in a variable and passing it as an argument to functions that use the resource. However, it is be useful to abstract the handle itself by storing it as a field in a record, along with other data.
This pattern is primarily used in languages with garbage collectors to allow manual resource management for uncommon situations.
Scope-based
a.k.a. RAII (Resource acquisition is initialization)
Holding a resource is a class invariant and is tied to object lifetime: resource acquisition and its release occur during initialization and finalization, respectively.
• prevents resource leaks
• encapsulation
• exception safety
• allows acquisition and release logic to be written next to each other
“In realistic systems, there are far more resource acquisitions than kinds of resources, so the "resource acquisition is initialization" technique leads to less code than use of a "finally" construct.”
— #Bjarne_Stroustrup
#C is not machine independent; but the thing is that everyone has to compile it for their own system, so no one notices it.
“The idea is that the configure script performs approximately 200 automated tests, so that the user is not burdened with configuring libtool manually. This is a horribly bad idea, already much criticized back in the 1980s when it appeared, as it allows source code to pretend to be portable behind the veneer of the configure script, rather than actually having the quality of portability to begin with. It is a travesty that the configure idea survived.”
— Poul-Henning Kamp, criticizing the GNU Build System
“The idea is that the configure script performs approximately 200 automated tests, so that the user is not burdened with configuring libtool manually. This is a horribly bad idea, already much criticized back in the 1980s when it appeared, as it allows source code to pretend to be portable behind the veneer of the configure script, rather than actually having the quality of portability to begin with. It is a travesty that the configure idea survived.”
— Poul-Henning Kamp, criticizing the GNU Build System
The names of #Java constants are in capital letters; and are never one character long.
#Naming_convention
#Naming_convention
String
- is a composite, usually built-in, data type implemented as an array, or some other sequential data structure, of bytes.
Fixed-length versus variable-length strings
Although formal strings can have an arbitrary but finite length, the length of strings in real languages is often constrained to an artificial maximum. In general, there are two types of string datatypes: fixed-length strings, which have a fixed maximum length to be determined at compile time and which use the same amount of memory whether this maximum is needed or not, and variable-length strings, whose length is not arbitrarily fixed and which can use varying amounts of memory depending on the actual requirements at run time. Most strings in modern programming languages are variable-length strings.
Terminated versus length-field strings
The string length is either explicitly stored as a separate integer or implicitly through a termination character, usually the null character (NUL), which has all bits zero, a convention used and perpetuated by #C. In terminated strings, the terminating code is not an allowable character in any string; whereas strings with a length field do not have this limitation.
Length versus size
Representations of strings depend on character encoding. Older implementations use #ASCII, and modern implementations use Unicode. With certain encodings, a single logical character may take up more than one entry in the array. In these cases, the logical length of the string (number of characters) differs from the physical length of the array (number of bytes in use).
- is a composite, usually built-in, data type implemented as an array, or some other sequential data structure, of bytes.
Fixed-length versus variable-length strings
Although formal strings can have an arbitrary but finite length, the length of strings in real languages is often constrained to an artificial maximum. In general, there are two types of string datatypes: fixed-length strings, which have a fixed maximum length to be determined at compile time and which use the same amount of memory whether this maximum is needed or not, and variable-length strings, whose length is not arbitrarily fixed and which can use varying amounts of memory depending on the actual requirements at run time. Most strings in modern programming languages are variable-length strings.
Terminated versus length-field strings
The string length is either explicitly stored as a separate integer or implicitly through a termination character, usually the null character (NUL), which has all bits zero, a convention used and perpetuated by #C. In terminated strings, the terminating code is not an allowable character in any string; whereas strings with a length field do not have this limitation.
Length versus size
Representations of strings depend on character encoding. Older implementations use #ASCII, and modern implementations use Unicode. With certain encodings, a single logical character may take up more than one entry in the array. In these cases, the logical length of the string (number of characters) differs from the physical length of the array (number of bytes in use).
note to self: disallow varargs, especially of different types
annoying example: printf
annoying example: printf
Unicode
- is a computing industry standard for the consistent encoding, representation, and handling of text expressed in most of the world's writing systems. Its success at unifying character sets has led to its widespread and predominant use in the internationalization and localization of computer software. The standard has been implemented in many technologies, including operating systems, programming languages, and markup languages.
Unicode can be implemented by different character encodings; such as: UTF-8, UTF-16, and UTF-32, and UCS-2.
UTF-8
- is a variable-length character encoding capable of encoding all valid code points in Unicode. It was designed for backward compatibility with ASCII i.e. any ASCII text is also a UTF-8 text. It has been the dominant character encoding for the World Wide Web since 2009, and as of September 2018 accounts for 92.2% of all web pages.
- is a computing industry standard for the consistent encoding, representation, and handling of text expressed in most of the world's writing systems. Its success at unifying character sets has led to its widespread and predominant use in the internationalization and localization of computer software. The standard has been implemented in many technologies, including operating systems, programming languages, and markup languages.
Unicode can be implemented by different character encodings; such as: UTF-8, UTF-16, and UTF-32, and UCS-2.
UTF-8
- is a variable-length character encoding capable of encoding all valid code points in Unicode. It was designed for backward compatibility with ASCII i.e. any ASCII text is also a UTF-8 text. It has been the dominant character encoding for the World Wide Web since 2009, and as of September 2018 accounts for 92.2% of all web pages.
“Great genius takes shape by contact with another great genius, but less by assimilation than by friction.”
― #Heinrich_Heine
― #Heinrich_Heine
#language #D
D
- is a system programming language first appeared in 2001. Though it originated as a re-engineering of C++, D is a distinct language, having redesigned some core C++ features while also taking inspiration from other languages, notably Java, Python, Ruby, C#, and Eiffel.
D attempts to combine the performance and safety of compiled languages with the expressive power of modern dynamic languages. Idiomatic D code is commonly as fast as equivalent C++ code, while being shorter and memory-safe. Type inference, automatic memory management and syntactic sugar for common types allow faster development, while bounds checking, design by contract features and a concurrency-aware type system help reduce the occurrence of bugs.
Paradigms: #imperative, #object_oriented, #metaprogramming, #functional and #concurrent (actor model)
Comparison with C
Despite their difference, D has been constrained in its design by the rule that any code that is legal in both C and D should behave in the same way.
Comparison with C++
Things D gained before C++:
• closures
• anonymous functions
• compile time function execution
Things D adds:
• design by contract
• unit testing
• true modules
• garbage collection
• first class arrays
• associative arrays
• dynamic arrays
• array slicing
• nested functions
• lazy evaluation
• built-in support for documentation comments, allowing automatic documentation generation
Things D replaces:
• multiple inheritance is replaced by Java-style single inheritance with interfaces and mixins.
• template syntax is re-engineered
Things they have in common:
• D's declaration, statement and expression syntax closely matches that of C++.
• D retains C++'s ability to perform low-level coding and to add inline assembler. The inline assembler typifies the differences between D and application languages like Java and C#. An inline assembler lets programmers enter machine-specific assembly code within standard D code, a method often used by system programmers to access the low-level features of the processor needed to run programs that interface directly with the underlying hardware, such as operating systems and device drivers.
Docs: https://dlang.org/spec/spec.html
D
- is a system programming language first appeared in 2001. Though it originated as a re-engineering of C++, D is a distinct language, having redesigned some core C++ features while also taking inspiration from other languages, notably Java, Python, Ruby, C#, and Eiffel.
D attempts to combine the performance and safety of compiled languages with the expressive power of modern dynamic languages. Idiomatic D code is commonly as fast as equivalent C++ code, while being shorter and memory-safe. Type inference, automatic memory management and syntactic sugar for common types allow faster development, while bounds checking, design by contract features and a concurrency-aware type system help reduce the occurrence of bugs.
Paradigms: #imperative, #object_oriented, #metaprogramming, #functional and #concurrent (actor model)
Comparison with C
Despite their difference, D has been constrained in its design by the rule that any code that is legal in both C and D should behave in the same way.
Comparison with C++
Things D gained before C++:
• closures
• anonymous functions
• compile time function execution
Things D adds:
• design by contract
• unit testing
• true modules
• garbage collection
• first class arrays
• associative arrays
• dynamic arrays
• array slicing
• nested functions
• lazy evaluation
• built-in support for documentation comments, allowing automatic documentation generation
Things D replaces:
• multiple inheritance is replaced by Java-style single inheritance with interfaces and mixins.
• template syntax is re-engineered
Things they have in common:
• D's declaration, statement and expression syntax closely matches that of C++.
• D retains C++'s ability to perform low-level coding and to add inline assembler. The inline assembler typifies the differences between D and application languages like Java and C#. An inline assembler lets programmers enter machine-specific assembly code within standard D code, a method often used by system programmers to access the low-level features of the processor needed to run programs that interface directly with the underlying hardware, such as operating systems and device drivers.
Docs: https://dlang.org/spec/spec.html
System software versus application software
System software is designed to operate and control the hardware, and to provide a platform for running application software; e.g. operating systems, utility software, device drivers, compilers, and linkers.
System programming languages, in contrast with application languages, typically offer more direct access to the physical hardware of the machine: an archetypical system programming language in this sense was BCPL.
System programming languages often lack built-in input/output (I/O) facilities because a system-software project usually develops its own I/O mechanisms or builds on top of basic monitor I/O or screen management facilities.
e.g. PL/I, #C, C++, #Ada, #D, Nim, #Rust, #Swift
System software is designed to operate and control the hardware, and to provide a platform for running application software; e.g. operating systems, utility software, device drivers, compilers, and linkers.
System programming languages, in contrast with application languages, typically offer more direct access to the physical hardware of the machine: an archetypical system programming language in this sense was BCPL.
System programming languages often lack built-in input/output (I/O) facilities because a system-software project usually develops its own I/O mechanisms or builds on top of basic monitor I/O or screen management facilities.
e.g. PL/I, #C, C++, #Ada, #D, Nim, #Rust, #Swift
Documentation generators
Here are some documentation generators, their language support, and output formats:
ROBODoc
By: Frans Slothouber, 1995
Supports: C, C++, Java, VB, VBScript, Delphi, Pascal, Ada, D, IDL, Fortran, PHP, Perl, Ruby, JavaScript, ActionScript, PL/SQL, Tcl
Outputs: HTML, RTF, LaTeX, man pages, DocBook
Doxygen
By: Dimitri van Heesch, 1997
Supports: C, C++, Java, C#, VB, VBScript, Delphi, Pascal, D, IDL, Fortran
Outputs: HTML, CHM, RTF, LaTeX, man pages, DocBook, XML
HeaderDoc
By: Apple Inc., 2000
Supports: C, C++, Java, Delphi, Pascal, IDL, PHP, Perl, Python, Ruby, JavaScript, Tcl, AppleScript, MIG, Bourne shell, C shell
Outputs: HTML, man pages, XML
Natural Docs
By: Greg Valure, 2003
Supports: C, C++, Java, C#, VB, VBScript, Delphi, Pascal, Ada, Fortran, PHP, Perl, Python, Ruby, JavaScript, ActionScript, PL/SQL, Tcl
Outputs: HTML
Sphinx
By: Georg Brandl, 2008
Supports: C, C++, Java, Ada, Fortran, PHP, Python, Ruby, JavaScript
Outputs: HTML, CHM, LaTeX, man pages, XML
Other
• D: Ddoc
• Python: Epydoc, pydoc
• Haskell: Haddock
• Java: Javadoc
• JavaScript: JSDoc, JsDoc Toolkit
• Perl: perldoc (pod)
• PHP: phpDocumentor
• Ruby: RDoc
Here are some documentation generators, their language support, and output formats:
ROBODoc
By: Frans Slothouber, 1995
Supports: C, C++, Java, VB, VBScript, Delphi, Pascal, Ada, D, IDL, Fortran, PHP, Perl, Ruby, JavaScript, ActionScript, PL/SQL, Tcl
Outputs: HTML, RTF, LaTeX, man pages, DocBook
Doxygen
By: Dimitri van Heesch, 1997
Supports: C, C++, Java, C#, VB, VBScript, Delphi, Pascal, D, IDL, Fortran
Outputs: HTML, CHM, RTF, LaTeX, man pages, DocBook, XML
HeaderDoc
By: Apple Inc., 2000
Supports: C, C++, Java, Delphi, Pascal, IDL, PHP, Perl, Python, Ruby, JavaScript, Tcl, AppleScript, MIG, Bourne shell, C shell
Outputs: HTML, man pages, XML
Natural Docs
By: Greg Valure, 2003
Supports: C, C++, Java, C#, VB, VBScript, Delphi, Pascal, Ada, Fortran, PHP, Perl, Python, Ruby, JavaScript, ActionScript, PL/SQL, Tcl
Outputs: HTML
Sphinx
By: Georg Brandl, 2008
Supports: C, C++, Java, Ada, Fortran, PHP, Python, Ruby, JavaScript
Outputs: HTML, CHM, LaTeX, man pages, XML
Other
• D: Ddoc
• Python: Epydoc, pydoc
• Haskell: Haddock
• Java: Javadoc
• JavaScript: JSDoc, JsDoc Toolkit
• Perl: perldoc (pod)
• PHP: phpDocumentor
• Ruby: RDoc
#mathematics
Type theory
A type theory is a system in which every "term" has a "type", and operations are restricted to terms of a certain type. A well-known type theory that can serve as a mathematical foundation is Alonzo Church's typed lambda calculus.
Typed lambda calculi
- use the lambda-symbol to denote anonymous function abstraction. They are the base of typed functional programming languages such as ML and #Haskell. Routines of strongly typed languages closely correspond to typed lambda expressions.
kinds:
• Simply typed
• System T
• System F
• System F<:
• System F-omega
• System U and U-minus
“The fundamental problem addressed by a type theory is to ensure that programs have meaning. The fundamental problem caused by a type theory is that meaningful programs may not have meanings ascribed to them. The quest for richer type systems results from this tension.”
― Mark Manasse
Type theory is closely related to, and may overlap with, type systems, which are a feature of programming languages.
Type theory
A type theory is a system in which every "term" has a "type", and operations are restricted to terms of a certain type. A well-known type theory that can serve as a mathematical foundation is Alonzo Church's typed lambda calculus.
Typed lambda calculi
- use the lambda-symbol to denote anonymous function abstraction. They are the base of typed functional programming languages such as ML and #Haskell. Routines of strongly typed languages closely correspond to typed lambda expressions.
kinds:
• Simply typed
• System T
• System F
• System F<:
• System F-omega
• System U and U-minus
“The fundamental problem addressed by a type theory is to ensure that programs have meaning. The fundamental problem caused by a type theory is that meaningful programs may not have meanings ascribed to them. The quest for richer type systems results from this tension.”
― Mark Manasse
Type theory is closely related to, and may overlap with, type systems, which are a feature of programming languages.
Flynn's taxonomy
- is a classification of computer architectures, proposed by Michael J. Flynn in 1966. The classification system has stuck, and has been used as a tool in design of modern processors and their functionalities.
Classifications are based upon the number of concurrent instruction (or control) streams and data streams available in the architecture.
• SISD: one operation at a time, e.g. very old PCs
• SIMD: can be achieved by pipelining, multiple functional units, or vertor processors
• MISD: uncommon, e.g. Space Shuttle flight control computer
• MIMD: e.g. most of the TOP500 supercomputers
The names are each short for a variation of "single/multiple instruction streams single/multiple data streams".
- is a classification of computer architectures, proposed by Michael J. Flynn in 1966. The classification system has stuck, and has been used as a tool in design of modern processors and their functionalities.
Classifications are based upon the number of concurrent instruction (or control) streams and data streams available in the architecture.
• SISD: one operation at a time, e.g. very old PCs
• SIMD: can be achieved by pipelining, multiple functional units, or vertor processors
• MISD: uncommon, e.g. Space Shuttle flight control computer
• MIMD: e.g. most of the TOP500 supercomputers
The names are each short for a variation of "single/multiple instruction streams single/multiple data streams".
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
- 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