Language in Programming

Bernardo de Araujo
2 min readJan 5, 2019

--

How many times has it happened that after learning about a new concept you become suddenly very aware of its existence around you to the point where you tend to overemphasize this new knowledge? It happens to me all the time, I learn about markets and everything around me behaves like one, I start a new sport and out of nowhere I start noticing that this or that movement would be a good fit for the sport while doing something completely unrelated. I suddenly became aware of something that I didn't even know was a thing a few moments ago.

Image from BrainFacts.org

Has the world changed? Probably not. What really changed is that we acquired a new vocabulary and this vocabulary allows us to talk about and see the world in ways that we couldn't before. It shapes how the information flows to and from us since it is composed mostly of written words and verbal communication. But what does this have to do with programming?

Programming is all about keeping the information flow as clear and expressive as possible. Programmers have been striving to express the proper domain knowledge since day one. This knowledge is composed of words like "customers", "transactions", "discounts" and so on and shapes the day-to-day communication within your team and user base.

When we are programming it is really easy to write what it is happening, but not what it really means, we pollute our language and wonder why the next programmer to change that code got it wrong. As an example:

if (condition_a && condition_b) || (condition_a && !condition_c)
# ...
end

versus

if subscribed_through_marketing_channel?
# ...
end
def subscribed_through_marketing_channel?
subscribed_through_google? || subscribed_through_facebook?
end
def subscribed_through_google?
condition_a && condition_b
end
def subscribed_through_facebook?
condition_a && !condition_c
end

Which one is easier to get right? A meaningful code trumps a clever code any time of the day.

But is that the only thing that we have to be aware of? Not quite, language also shapes behaviour. A team that only talks about productivity but does not understand or know at all the concept of resiliency might skip tests or code reviews. It's really important to define the proper vocabulary in order to achieve the desired behaviour.

As our spoken languages, our domain knowledge is ever changing, ever evolving towards our business needs. Trying to keep it clean and expressive is a constant battle, but a very rewarding one if the team does not want to end up with a legacy code littered with old definitions that no one can really explain as time goes on.

Use language with care, enrich your code and behaviours with the proper concepts.

Thanks for reading. I'm always up for a good conversation about this topic, you can find me on Twitter as bernardo_amc.

--

--