Proficiency in code

There is an interesting story in German road traffic regulations. If the road narrows, then the rules prescribe to get to the end, and only then rebuild one by one, and the neighboring car must let through. All are rearranged strictly one after another – this sign speaks about it.

This is a living example of possible serialization, when the public was taught for a very long time to follow the rules. I think that everyone who travels by car in Moscow understands how utopian this picture is.

Basically, we need to do the same with the data that we write to disk.

How can the situation be improved?

● Operations must be independent of each other – isolation.

In a purely theoretically controlled manner, the operation must know what is happening outside. It cannot be that as soon as one operation changed something, the result immediately became visible to another. There must be some rules.

This is called transaction isolation. In the simplest case, transactions do not know at all what is happening with their neighbors. These are actions in themselves, within the limits of one function there is no outward interaction until it is over.

● The operation takes place according to the principle “all or nothing” – atomicity.

That is, either the whole operation took place, and then its result was recorded, or if something went wrong, we must be able to return the status quo. Such an operation must be recoverable, and if it is recoverable and isolated, then it is atomic. This is an elementary operation that, like the result, is not divisible. It cannot pass halfway, but only passes entirely or does not pass entirely.

● We need a mechanism to check that everything happened correctly – consistency.

I asked how much money turned out on the balance sheet in our example, and for some reason you said that 700. We all know that there is arithmetic, common sense and the Criminal Code, which monitors banks and accountants so that they do not do something illegal. The Criminal Code is one of the private versions of consistency. If we are talking about databases, there are many more of them: foreign keys, constraints, everything.

Related Post

One thought on “Proficiency in code

  1. Author is wrong. It is not about proficiency, it’s about correct logic of thinking.

Leave a Reply

Your email address will not be published. Required fields are marked *