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" expect(car_brands).to include "Porsche"
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.
Send and receive design + front end feedback visually about website issues – We’ll show you how
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 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.
The makers of DebugMe hope that you like this post and would love it if you follow us on Twitter. We are tweeting about web design, UI/UX and development related topics multiple times a day. DebugMe is an issue tracking, project management and screenshot tool for every website project. Get visual feedback right away and solve front-end problems faster. Try it now for free.