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:
# "How long ago?" 10.years.ago # "I expect my list of car brands to include the best one" .to include "Porsche"expect(car_brands)
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.
export const ADD_TODO = 'ADD_TODO' export const DELETE_TODO = 'DELETE_TODO' export const EDIT_TODO = 'EDIT_TODO' export const COMPLETE_TODO = 'COMPLETE_TODO' export const COMPLETE_ALL = 'COMPLETE_ALL' export const CLEAR_COMPLETED = 'CLEAR_COMPLETED'
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:
data Action = AddTodo | DeleteTodo | EditTodo | CompleteTodo | CompleteAll | ClearCompleted
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 is to convey intent, couldn’t that intent also be
communicated with documentation? Or tests? If the argument against documentation
and/or tests is that eventually they will become untrue, then perhaps it’s time
correctness guarantees you seemingly crave?
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.
allows you to achieve so much with so few keywords. For example, the
keyword is a function, as well as a method, a class, and a lambda. But
developers shoe-horning features onto a language that doesn’t really support
them. In the same way that you could build an e-commerce site with WordPress:
it’s possible, but there are less painful ways you could live your life.