Oskar Dudycz

Pragmatycznie o programowaniu

What does Mr Bean opening the car have to do with programming?

2021-10-20 oskar dudyczCoding Life

Before reading the article, please watch the video below:

Mr Bean

Mr Bean wants to add a new business feature to the project. First, the entity class, then the repository (and registers its generic version in Dependency Injection container), then the application service, request validator, mapping from request classes to entities. He is about to run it, but he reminds himself that it won’t work because he forgot to add a new controller. Time goes quickly, the controller is here, he’s firing it up and boom! It does not work because he forgot to register something else in the IoC container. Once that is done, only unit tests are left for each of the added classes, some integration tests and finally, endpoint adding a dictionary entity with two fields works.

Boy, that escalated quickly!

The more advanced code structures were used, the more Mr Bean can feel fulfilled. Generic factories, reflection-based aspect programming, fancy providers integrated with generators, that’s how serious enterprise architecture looks like.

I used to think so once. Once, during the team building, my colleague came to me and said, “Oskar, you know what, it took me about three months to understand our architecture. In the beginning I was totally lost, but now, once I understood it, I think it’s great!”. At first, I felt proud that I had designed such sophisticated architecture. I thought that has to be good if it requires a lot of time for understanding, but then it pays off. Then I realised that’s not complex. It’s just complicated. There was a lot of magical, generic code that could do anything, even brew coffee. Absolute champion was a class with 14 generic parameters to fill in. Well, we were making a serious business application after all!

Is complex or complicated really that cool? Is this whole ceremony really needed? I used to think that. Now I think the best code is the one that when we see, we’ll say, “Hell, how easy it is, why didn’t I come up with that”. Contrary to appearance, such code requires a lot of work. Designing upfront, a few iterations and cutting every redundant abstraction. Sometimes these are small things, such as adequately placed IFs. Sometimes these are slightly larger things, such as learning about new patterns, paradigms - e.g. functional programming, architectural patterns such as Event Sourcing, CQRS. Sometimes sideways, jumping on the neighbour’s lawn in a different language or technology gives us new insights and ideas.

I am not a dogmatist. I come from the .NET world - this is my lair, which I orbit, but I like to learn other technologies. There are times where I’m writing more in other than C# languages, e.g. in the last project, I coded much more in TypeScript and Node.JS. Working with different languages ​​and programming environments allows you to look at your code from a different angle. For example, I used to hate JS. I was calling it “shitty language”. Now, I think I just didn’t understand it and couldn’t write in it well at that time. When I changed my thinking, it made a lot of sense, and its dynamics, simplicity, and functional flair taught me a lot.

So, for example, when I come back to Visual Studio and .NET, I think, “why is it so heavy?!”. That’s why I’m happy about the improvements in C#9 (check also Notes about C# records and Nullable Reference Types), I’m glad that the main method is not required, or the ability to do endpoints without a controller. The fewer ceremonies, the better.

I also often come across the statement, “a programmer should know this and remember it”. The more a programmer has to know and remember, the more likely they will forget and make stupid mistakes. In my opinion, such necessary routine repetition causes the programmer to stop thinking and start copying and pasting, which is the best way to get stupid bugs that are hard to detect.

Therefore, homework for you:

  • think over how many classes and layers the request goes through until it is saved in the database,
  • how many generic classes do you have, especially with a few parameters, and what problems do you have with it,
  • do you know why composition is better than inheritance?

Consider whether it must be so and whether these structures do not resemble, by chance, Mr Bean’s car opening. Feel free to send your conclusions in the comments.

Cheers!

Oskar

p.s. if you like that article, check also Generic does not mean Simple!

👋 If you found this article helpful and want to get notification about the next one, subscribe to Architecture Weekly.

✉️ Join over 11500 subscribers, get the best resources to boost your skills, and stay updated with Software Architecture trends!

Loading...
Event-Driven by Oskar Dudycz

cover

Through my window, I see the result of good plans but poor execution. Opposite my flat, there is a partially completed construction place. Buildings were supposed to be eye-catching Mediterranean style apartments. Delivery date? Two years ago. Actual? More and more unknown.

Some time ago, I heard that using Event Sourcing makes creating Event-Driven Architecture easier. The arguments were correct, that if we’re already publishing events to trigger business workflows, then at some point, we may want to also store events to not lose information. Agreed. However, I also heard that keeping the state as events will simplify things. We’ll have a source of truth with a record of the system behaviour. This will allow, e.g. to confront the results of the operations with the recorded state. I’d agree with that, with one distinction. It’s easier as long as you already know Event Sourcing.

Many people in the DDD community claim that the essential is to properly break down the system into autonomous parts called bounded contexts. Once we have it, the rest is secondary and will sort itself out. For sure.

Many seasoned programmers speak similarly about new technologies. They claim that they can translate past experience into new technologies. That’s true that by analogy, they can catch the big picture quicker. But isn’t it a bold assumption to say that Win.Forms specialist will learn Angular quickly?

The end result may differ a lot from the initial ideas. I saw the plan of those buildings next to me. Now I can see the effects of the execution. Or actually, the lack.

I believe that we should carefully acknowledge not only the point of view of our authorities but also their seating point. If we want to find out how to form a wall, do we ask an architect or a foreman? An architect may know the theory, but the practice is what we’re looking for. On the other hand, if you want to know where to put the wall, you prefer the architect to do measurements. At least if you don’t want to have the roof falling to your head.

After I had torn a ligament in my knee, I went to two qualified orthopedists. One said I should have surgery and do a reconstruction. The second stated that there is no need for that; rehabilitation should be enough. Guess which one had a specialization in surgery and which in rehabilitation?

People usually give us advice from the point where they’re currently standing. They are entitled to a biased view. An architect who rarely does programming will tend to downplay the value of implementation and tactical patterns. Midlevel developers will focus on technicalities instead of the global system impact. The team manager or consultant will emphasize the importance of soft skills (or esoteric techniques known only to them).

The truth is that we need all of them. The excellent plan will fall on the bad execution. The best execution for the wrong case will be just a waste of time. We should carefully evaluate the advice considering what we need and what an expert can give us.

Therefore, when we’re reading an article, watching a talk, let’s also pay attention to the place where the person is standing. The perspective from there may be much different from where we are right now. That can be good, as it may push us in the right direction. But it may also be misleading, as we accidentally take biases of this person without understanding the tradeoffs. Personally, I prefer to follow not only people from pedestal but also those that are closer to my position. A bit further in the journey, but not too far. That helps me to calibrate my view as those people are more relative to my daily struggles.

Polish historical leader Józef Piłsudzki reportedly used to say: “Right is like an ass, everyone has its own”.

Cheers!

Oskar