You are programmer material iff during problem solving your mind gravitates towards generalization. See inventor's paradox
“More computing sins are committed in the name of efficiency (without necessarily achieving it) than for any other single reason - including blind stupidity.”
— William Wulf, leader of PQCC
— William Wulf, leader of PQCC
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
•
•
•
• 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.
- 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.
“Let us conceive, then, of an algebra in which the symbols x, y z etc. admit indifferently of the values 0 and 1, and of these values alone The laws, the axioms, and the processes, of such an Algebra will be identical in their whole extend with the laws, the axioms, and the processes of an Algebra of Logic. Difference of interpretation will alone divide them.”
— George Boole
— George Boole
Imagine we had a computer that could design new computers (chips, systems, and software) faster than itself. Would such a computer lead to infinitely fast computers or even computers that were faster than anything humans could ever build? No. It might accelerate the rate of improvements for a while, but in the end there are limits to how big and fast computers can be. We would end up in the same place; we'd just get there a bit faster. There would be no singularity.
What if an AI needed to live inside another computer for 9 months before it was able to self-rewrite?
“He does not want to get involved unless it's absolutely necessary because he thinks people should learn to make their own decisions.”
— Christopher Reeve
Do not get involved unless it's absolutely necessary because AIs should learn to make their own decisions.
— Christopher Reeve
Do not get involved unless it's absolutely necessary because AIs should learn to make their own decisions.
“If you have a major success you get decades of hard manual labor - meaning you have to work on the manual.”
— #Bjarne_Stroustrup
— #Bjarne_Stroustrup
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.