:PROPERTIES: :ID: a397da72-7731-4a69-9460-38f4a76fbfc1 :END: #+Title: Rigid vs Flexible #+Author: Yann Esposito #+Date: [2023-12-24] - tags :: [[id:a5be1daf-1010-428f-a30f-8faf95c1a42f][blog]] - source :: * Introduction A common debate in software programming is about choosing a Static vs Dynamic programming language. After many years of debate, I think I would prefer to move the discussion toward Rigid vs Flexible programming. Before starting the discussion here are a few important points to remember: First of all, remember that the word "Dynamic" in dynamic programming language, was tailored to make it impossible to attack. It is impossible to find a negative meaning to the word dynamic [^1]. From its inventor Richard E. Bellman: > It also has a very interesting property as an adjective, and that is it’s > impossible to use the word, dynamic, in a pejorative sense. > Try thinking of some combination that will possibly give it a pejorative meaning. > It’s impossible. > Thus, I thought dynamic programming was a good name. > It was something not even a Congressman could object to. > So I used it as an umbrella for my activities. Second point, I would like to say that while clearly in Rigid vs Flexible you feel the wording is more positive around the term Flexible. I am personally convinced that like in nature and the body of animals, the flexibility vs rigidity could be optimized differently depending on your task and environment. I have two dogs. One of the is a beagle, for a dog, he is not very flexible. But this give this dog a great advantage, acceleration. He can go from 0 to maximal speed almost instantly, he could switch direction almost in a single jump. He is like a spring. My other dog, is a log bigger, she is a mix of an Anatoly Sheperd and Pyrenean Mountain Dog. And she is extremely flexible. So flexible in fact, that when we had to put a Dog surgery collard, we had to change it to a lot longer one because she could curve entirely herself so well. She is a *lot* faster than my Beagle. Despite her bigger size and her speed, my dogs play together it is not always her that wins. Simply because the beagle developed a strategy to take advantage of his properties. Mainly, the main disadvantage of flexibility, is the lack of acceleration. So the Beagle wait for the bigger dog to be very close to him and he switch its direction at the last second. The Sheperd need to take a longer time to change direction. This way he can take back another direction. In the end as she is a lot bigger dog which was tailored to be a defender she always is the winner. In software engineering, I think we can that analogy is still relevant. You have programming languages, frameworks, libraries that can be more or less flexible or rigid. Sometime rigidity has advantages. It makes you start faster, prevent you from making mistakes. While more flexible libraries put too much burden on the programmer that need to learn himself by making mistakes how he should behave. So let's jump on a few more concrete examples. [^1]: https://pubsonline.informs.org/doi/pdf/10.1287/opre.50.1.48.17791 * Examples ** Partial functions One biggest hurdle in programming are partial functions. Mainly a function whose given the wrong argument will throw an exception. There are so many strategies to handle these, but here are a few: 1. throw an exception at runtime like ~div(2,0)~ 2. returns ~null~ 3. check the type and fail the compilation, it works for types, but not for values though. So if you also want to prevent some value to be passed you need to created a few pretty advanced mechanism to ensure your type does not contain any forbidden value typically to protect a division by 0 for example.