What are conditions, really?

What is Blogvent? (tl;dr I am going to write one post a day for all of December as a way to practice writing.)

We use them every day. They make our code interactive. They force us to question.

Why?

Let’s have some fun and ask this question in what Wikipedia calls “an iterative interrogative technique” or as kids would say “why? why? why?”

First on the chopping block…

Why do we have if?

Without conditions, code would execute one statement after another, in order, and then the program would quit. Which isn’t technically wrong. There are plenty of examples of this being fine.

But you don’t need to go far until you need to ask a question of some sorts.

if1

In some “programming language” we open a file, store the result of that in a variable called file and then we ask the question, if file not open.

Here we are creating a requirement. For the code to continue, we need the file to be open. Everything else is unacceptable.

Why is it required to have the file open?

The program needs data, this file seems to contain some sort of data. We could open the file and continue on, assuming that the file is there and cause some sort of stronger failure than exiting the application. This is a strategy used by some, where a requirement of the application is that certain files exist, and without their existence, we will crash.

We also might want to change the data without changing the application.

Why don’t you want to change the application?

Change is hard, even for developers. A system might be complex enough that constant changes can take more time than changing a file, and here we are only thinking of development or compilation time.

If a change of the application is required every time a file needs to be updated, then having a file by itself isn’t strictly needed. Then there is a strong connection between the application itself and the data that is within the file.

Also even if a change is quick, not everyone has access to the code to change it and not everyone is a developer.

Why isn’t everyone a developer?

Good question… time for bed.

Comments

If you want to chat about this, Twitter or Mastodon