# Today I Learned

Some of the things I've learned every day since Oct 10, 2016

## 132: PHP is Ugly

So I learned the basics of PHP today. My main takeaway was that it is a very, very ugly language.

I don’t really know what else there is to say about it. But I will try to illustrate.

$\texttt{for (item in iterable)}$

it’s

$\texttt{foreach (iterable as item)}$. A deliberate effort to make human readability less intuitive, I guess?

You have to start variable names with $\$??? Why.

$\texttt{strlen()}$$\texttt{strpos()}$$\texttt{strtolower()}$$\texttt{strtoupper()}$? Really?

Also, using $\texttt{.}$ for concatenation just so you can’t use standard dot notation.

How was all this syntax actually intentionally designed this way?

I just

## 131: Pierce’s Law

In classical logic, Pierce’s Law is the property that

$((P \rightarrow Q) \rightarrow P) \rightarrow P$.

Proof:

$(P \rightarrow Q) \rightarrow P$

$\Downarrow$

$\overline{P \rightarrow Q} \vee P$

$\Downarrow$

$\overline{\overline{P} \vee Q} \vee P$

$\Downarrow$

$(P \wedge \overline{Q}) \vee P$

$\Downarrow$

$(P \wedge \overline{Q}) \vee (P \wedge 1)$

$\Downarrow$

$P$

## 130: Consequentia Mirabilis

Consequentia Mirabilis, also known as Clavius’ Law (after the German mathematician) is the principal in classical logic

$(\neg X \rightarrow X) \rightarrow X$.

That is, it’s the principle that if a proposition’s negation implies the proposition, then the proposition must be true.

Its use is similar in form to that reductio ad absurdum. To use reductio ad absurdum, one assumes that a proposition is false, sees that a contradiction follows, and from this concludes that the proposition must be true. To use consequentia mirabilis, by contrast, one assumes that a proposition is false, sees that the proposition itself follows, and from this concludes that the proposition must be true.

## 129: UUIDs

Universally Unique Identifier (UUID) is a 128-bit number used to uniquely identify things, whatever those things might be, in computer systems. The way they are represented in text varies, but they typically look something like

123e4567-e89b-12d3-a456-426655440000

or

00112233-4455-6677-8899-aabbccddeeff,

with 32 hexadecimal digits being broken into 5 groups by hyphens. The usefulness of UUIDs comes from the sheer improbability of the same UUID being generated 2 different times.

To give an idea of the improbability: the number of Version 4 UUIDs you would have to generate to have at least a 50% probability of a collision would be around 2.7 quintillion. If a computer generated 1 billion UUIDs every second, it would take 85 years just to compute that many, and even then the amount of physical storage required would be around 45 exabytes, much larger than the largest databases currently in existence.

This is to say that for now, UUIDs are a very good way of uniquely identifying things with almost impossible collisions.

## 128: Git Commit Message Subject Conventions

Some conventions that should be followed when writing the subject of a commit message in Git:

• Separate the subject from the body (if it exists) with a blank line
• Keep the length at no more than 50 characters
• Capitalize the first letter, don’t end it with a period
• Use the imperative mood. For instance, “Update getting started information” instead of “Updated getting started information”, “Refactor X for readability” instead of “Making X more readable”.

Additionally, a commit message subject should convey information about not only what was done but also why.

## 127: Linters

Linters in the modern sense generally refer to programs which check code for potential errors (or even just style errors) in a static context (without running the code). Potential such errors might include syntactic errors, “variables being used before being set, division by zero, conditions that are constant, and calculations whose result is likely to be outside the range of values representable in the type used.” [Wikipedia]

The name comes from a program called Lint that performed this function for C code, but has since become a more general term.

Linting can be helpful for debugging interpreted languages like Python, since they don’t have a compilation phase where things like syntactic errors would be caught.

## 126: Principle of Explosion

In logic systems such as classical logic, the principle of explosion is the principle that from a contradiction any proposition can be inferred to be true.

To show this, suppose we’ve arrived at a contradictory statement, $P \wedge \neg P$. Let $Q$ be any proposition we want to prove. By conjunction elimination, we have $P$, and then by disjunction introduction we have

$P \vee Q$.

However, since we also have $\neg P$, it follows that $Q$ is true.

This principle suggests an interesting alternative attitude towards contradiction in systems that exhibit this behavior: contradiction is not undesirable because of any ‘intuitive’ nonsensicalness, but simply because a set of assumptions leading to contradiction gives us no information.

## 125: Duck Typing

Duck typing is a term used to describe programming languages in which, when a method is called on an object, it’s never formally confirmed that the object is of a specific type acceptable as input to the method, just that the object has whatever properties are required to perform the needed operations. In other words, it isn’t formally checked what an object is but rather what it can do.

The name is a reference to the saying, “If it walks like a duck and quacks like a duck, then it’s a duck”, which echoes this same principle.

## 124: Skip List Search Algorithm

The following is an informal description of the algorithm for searching for an element in a skip list:

If you look the shape of the nodes that the algorithm visits on a given example, the general case of the search time being $O(\log{} n)$ makes intuitive sense.

## 123: Skip Lists (Intro)

skip list is a data structure similar to a linked list which stores an ordered sequence of elements and is built specifically for fast search within the sequence. The way it’s commonly implemented is as a hierarchy of linked lists, with the first list containing all the elements of the skip list, and each successive linked list containing a sparser subset of the elements in the previous one.

To search for an element within the skip list one then starts with the sparsest linked list, getting as ‘close’ to the desired element as possible, then moves directly down to that same position in the next linked list and continues searching until the item is found (or not).

This animation depicts the insertion of the element 80 into a skip list of positive integers (insertion being equivalent to searching):

Credit: Artyom Kalinin

In the average case, the skip list uses $O(n)$ space and takes just $O(\log{} n)$ time for searching operations.