May 28, 2016
Rant Mode: Engaged.
The word “expressive” is often bandied about when describing the features of a language. In the same way that every new CSS framework that hits the front page of Hacker News is “light-weight”, “modular”, and “modern”, everyone’s favourite language will be at some point described by them as expressive.
Whether or not a language is expressive is a relative measure. To be expressive is to effectively convey thought or feeling. There are some languages that are so expressive that you immediately understand the author’s intent without needing to know the syntax. Take the following lines of Ruby, for example:
I feel confident offering up those lines of Ruby for debate because they are indeed idiomatic. I want to also argue that Haskell is an expressive language (and it most certainly is), but I concede I would be cherry-picking from the nice parts and there is indeed some syntax to learn first.
What thought, feeling, or idea is the preceding snippet of code trying to convey? We can clearly see that we have six different things here, that in a better language might be expressed as a list of six things.
All of the noise is a result of having to work around failings of the language. We’re telling the language how to do its job, whereas we should only be telling the language what we want. How might that work in a more expressive language? Well, take Haskell, for example:
Here we can see that the language allows us to boil down our code to just the ideas we’re trying to convey. It also doesn’t hurt that GHC will check that all our action names match up, but that’s a different topic.
Why does Redux have the crazy
export const… convention anyway? Am I the only one who is uncomfortable with this? Turns out, I am not. The justifications offered up essentially come down to “all action names in one place”, and “please protect me from typos”. If the problem really is one of organisation and you want all your action names in one place, then why not an array of strings?
If the use of
const because although the intent its supposed to convey is “this value shall not change”, it actually has nothing to do with immutability. Although
const will prevent a developer from assigning some other value, the original value can still be mutated.