About Me!

This blog is about my musings and thoughts. I hope you find it useful, at most, and entertaining, at least.

Résumé [PDF]

Other Pages

Quotes

Links

Oak Island

Items for Sale

Presence Elsewhere

jim@jimkeener.com

del.icio.us

Twitter

Facebook

LinkedIn

GitHub

BitBucket

Keybase.io

AMP and Instant Articles are Good Ideas, but hurt the web

Date: 2016-01-01
Tags: programming c++ types

I've always struggled to come up with a good explanation for types for new programmers. (It is just such an ingrained and intuitive concept for me at this point that it's hard to describe.) Having been playing with both Rust and C++ over the past few weeks, which have extremely expressive type systems, the idiom I'm settling on is that when you're writing a program, you're actually writing two: the "type-program" and the "data-program." The "type-program" is evaluated at compile-time for statically typed languages and concurrently dynamically typed languages. (Note that I left out a distinction between compiled and not-compiled languages. Python, Ruby, and JavaScript, as three examples, all compile to bytecode before execution, but all three are dynamically typed.

What is a "type-program"? It's the validation that the type-systems rules are followed at each expression in the program. For instance, when a+b is encountered, the there must exist a + operator that can accept a left-hand side of the type of a and a right-hand side of the type of b. The evaluation of the + operator doesn't happen, only the validation of the type rules. This happens recursively, so now

Some languages, like Rust and C++ also allow for certain types of (arbitrarily complex) data expressions to be evaluated concurrently with the type-program.