DEV Community

Joe Eames for Thinkster

Posted on

Constraints — Why Less is More in Programming Languages

Constraints are an interesting concept. Much has been written and spoken about them.

On their surface, constraints are misleading. Saying that more freedom is bad is not very common. Normally we want more features, more flexibility, and more freedom. But constraints, if used wisely, can actually increase productivity and efficiency and reduce cost.

Constraints are used in many capacities, such as reducing analysis paralysis, improving efficiency, and inciting innovation. As a productivity technique, people often use artificial constraints like timeboxing and artificial deadlines.

In art, we use constraints to inspire creativity. Think of the intense constraints of Haiku.

In Star Wars (it always pleases me when I can throw a Star Wars reference into my articles), Luke didn’t begin to feel the force until Obi-Wan made him fight blind.

!image

In programming, constraints seem to be all the rage. Functional Programming, immutability, TDD, these are all examples of artificial constraints.

In programming languages, constraints are an interesting concept.

Years ago, the language BASIC was somewhat popular. At that time Edgar Dijkstra, one of the pioneers of our industry, wrote the seminal paper “Go To Statement Considered Harmful.” Sadly, the most likely reason you know about this paper is the many times this phrase has been copied for less accurate purposes. It’s a short paper and worth a read through.

Another interesting example is Rust. Rust doesn’t have exceptions. Error handling is done very differently in Rust from other languages. Again the use of a constraint has given Rust what most people consider to be a significant advantage.

Recently Microsoft announced Bosque. Bosque has no looping mechanism. You can use functions like map to operate on all elements in a collection, but you can’t loop over them the way other languages do. Again, the intention is to improve by taking away.

JavaScript is an incredibly flexible language. Many things can be done in so many ways. But taking advantage of all that freedom often leads to disaster. Just look at smooshgate, which is why we have Array.flat() instead of Array.flatten().

So as you design your applications, and create conventions for yourself and other members of your team to follow, be sure to consider the value of constraints on all aspects of how you build your code.

Happy Coding!

Enjoy this discussion? Sign up for our newsletter here.

Visit Us: thinkster.io | Facebook: @gothinkster | Twitter: @gothinkster

Top comments (0)