The walled city in your code
In this little post we will talk about when can our code feel a little bit safer.
An important lesson from Haskell
You can learn a lot from a pure functional programming language like Haskell, because it makes us view and solve problems in a different way. For example Haskell considers every IO action dangerous, because it causes side effects and side effects can cause unforeseen errors. It’s also one of the most important from Haskell is to be wary of any IO action.The outside world
The outside world is dangerous, because you can caught a cold or get hit by a bus. The “digital” outside world also has it’s own dangers like errors, exceptions and bad inputs, which are things that programmers hate the most. Unfortunately we can’t live without the outside world, because we need to get and share information, but we also want to get rid of the dangers, so what to do?The wall around the city
We build walls to control the madness of the outside world and also to feel a lot safer. In our case the goal of the wall is to protect us from the errors, exceptions and bad inputs. Basically it’s job is to handle any exception or error from the outside and also to validate any incoming value. This wall also needs to be robust so it won’t crash the system and it will recover from any unforeseen error.For the wall we need a programming language, which can handle a lot of IO action, but it’s also robust against any exception or error.
The best language for this role is Erlang or Elixir(which is basically Erlang with simpler syntax). Erlang is a good fit, because it’s scalable and robust thanks to it’s lightweight green threads and the use of supervisor trees.
The city inside the wall
We are inside of the walls in our little safe place, far from the dangers of the world. Inside the wall is the ideal place to be, but it needs to be very strict to avoid causing any inside danger. We want to avoid causing any error or exception here, because it would spread like a fire through out the city. That’s why I said we need to be strict and so we need to use a programming language with strong type system that emphasis on avoiding anything that can cause side effects, exceptions or errors.The best choices for this role is Haskell or OCaml, because both of them are strongly typed language. A strong type system is important, because it can guarantee that there won’t be any type mismatch or null exception(billion dollar mistake). They are also high level(functional) languages, which means it restricts the freedom of it’s users, which is a really good thing when you are going for correctness.
Another reason for using Haskell and Ocaml is that they both have a proof assistant based on them. Proof assistants are really important when you want to prove that your program works correctly. Proof assistants are basically really strict programming languages that can also be used for proving. These tools should be used, when you want really strong foundations for your city.
Final word
This idea describes a system where the core of the system is protected by the outer layer, so this way the system can isolate itself from the environment and the only thing that matters is the logical correctness of it’s code base. This is also why I really like this idea.I hope you liked my first post in english. :D
Best way to enjoy Autumn is to watch a Summer music clip. :D