Κnow thy domain!

I don’t throw darts at a board. I bet on sure things. Read Sun Tzu, ‘The Art of War.’ Every war is won before it is ever fought

Gordon Gekko – Wallstreet (1987)
Image from Letterboxd

Introduction

Let’s assume you are hired to develop a software system for a pharmaceutical company. Till that time, you knew nothing about that specific domain, no more than everybody knows about the pharmaceutical sector and medicines.And the knowledge you carry is from the side of the patient-client.

You start gathering information to build the requirements, but you come to point that you feel ready to start writing code. Well, don’t hurry that much. Are you sure the information you have in your hands is right, and at the same time is the one you actually need?

Lack of domain expertise

Programmers, unfortunately, sometimes change domains a lot. Take for example! I was working for a company that develops HR and payroll software, and now I work for European funded R&D projects related to Industry 4.0. Far from similar. But no matter what I have to adapt, to learn and be productive as fast as possible.

In the agile world, the product owner represents a range of stakeholders, not just end users, and in practice it isn’t reasonable to expect them to be experts at everything in the domain. As a result the product owner will bring in domain experts to work with the team. The programmers responsibility is to be open minded and learn from every word information that comes from the expert. Also don’t be a “know all” person. Trust the domain expert and work with them.

Understanding the domain helps you design a better software. A software with the expected, by the stakeholders, behavior as the stakeholders and not assumptions.

The pharmaceutical example

The moment comes that you have to create a class for medicines. What you will take under consideration for the fields (state) and the methods (behavior) of the class? Most medicines come in a variety of types or formats. The types of medicines are the following:

  • Liquid
  • Tablet
  • Capsules
  • Topical medicines
  • Suppositories
  • Drops
  • Inhalers
  • Injections
  • Implants or patches
  • Buccal or sublingual tablets or liquids

Have you been aware of that? Probably you knew some of them… but we need all of them, cause this is what the pharmaceutical company asked for! Are we done? Far from there! We still have to decide about the the methods of the class. Methods denote actions. A medicine what kind of actions does it carry? The “every X hours” frequency action is part of the Medicine class or the Prescription class? Of course is part of the Prescription class! But I believe that all of us agree, that some programmer would do that mistake. I could carry with many more examples, but I am confident that you got the point.

What if… there is no domain expert?

Well, if I were you, I wouldn’t accept the role, of let them hire me. In the past two years, I wouldn’t be able to develop software that matters with the support of the domain experts (electrical, mechanical and chemical engineers). It’s not easy to model a problem without the concrete knowledge of the domain.

Additionally, the domain expert has to have a basic IT knowledge. It is, at least unacceptable, to work with people who do not understand the basics of how a computer or a software system works. And believe me, there are a lot of them!

Conclusions

A piece of advice. All domains, no matter how easy or boring might seem in the beginning, they all carry knowledge and history. Understanding the domain, doesn’t just make you a better programmer, but it helps you understand how things work in a more insightful way. You become a better citizen in the end.

Why static code hurts project’s architecture?


This is our world now. The world of the electron and the switch; the beauty of the baud. We exist without nationality, skin color, or religious bias. You wage wars, murder, cheat, lie to us and try to make us believe it’s for our own good, yet we’re the criminals. Yes, I am a criminal. My crime is that of curiosity. I am a hacker, and this is my manifesto.” Huh? Right? Manifesto? “You may stop me, but you can’t stop us all.

Agent Bob – Hackers (1995)
Image from Dentalfloss

Introduction

Static method and classes are one of the OOP world’s drawbacks. I am not implying that you shouldn’t use it at all, but in long term I believe a source code full of static methods and classes add more burden into the maintenance process.

How does static code look like?

  • Worker methods. Good for Simple calculations / processing, i.e
    b MyUtilityClass.ConvertAtoB(a)
  • Factory methods. Used to return preconfigured instances of a class, i.e.
    MyClass MyClass.GetInstanceOfClass()**
  • Singleton methods. Used to enforce a single global instance of a class, i.e.
    MyClass MyClass.SharedInstance()
  • Global variables. Used to store configuration values, i.e.
    int MyClass.TimeoutDuration

** Do not confuse it with Factory design pattern!

Why do we prefer the easy way out?

Suppose we have two classes A and B, and have a method M() that both must use, then the most naive approach is to repeat the method in both classes. However, this violates the “Don’t repeat yourself” (DRY) approach. It’s not just about reducing work: if both classes truly need the same method, then it should be the same method.

The most natural solution is inheritance, but it’s not always beneficial for A and B to be sub classes of some parent class. The bad and easy alternative is to define a “Utility” class: a public static class that sits in the global namespace, awaiting anyone to “borrow” them.

Static classes and methods imply relationships between data that are not explicitly defined. Also, if the static classes have any static variables, then A and B have no idea which object called them.

Where do static methods belong?

A class in OOP has state. When we look at our classes from the Single Responsibility Principle (SRP) viewpoint, a static method is usually a violation because it tends to have a responsibility that is not the same of the class it is attached on. So it ends up sitting out there trying to belong to the class it is on, but it doesn’t really belong, because it doesn’t use the internal state of the class.

Furthermore, based again on SRP, a class should have one and only one reason to change. But if we end up designing huge utility classes that contain any method the developer could think of, (e.g. a class containing a helper method for URL encoding, a method for looking up a password, and a method for writing an update to the config file) this is crystal clear violation of the Single Responsibility Principle.

Static methods and the rest of S.O.L.I.D.

Liskov Substitution PrincipleDerived classes must be substitut-able for their base classes — If a class has only static methods , can not have a derived class. Maybe it’s not a direct violation, but every time we loose, we loose more and more destroying the project’s architecture.

Interface Segregation PrincipleClass interfaces should be fine-grained and client specific. Since static classes do not derive from an interface, it is difficult to apply this principle with any degree of separation from the Single Responsibility Principle.

The Open Closed PrincipleClasses should be open for extension and closed for modification. We cannot extend a helper class. Since all methods are static, we cannot derive anything that extends from it. In addition, the code that uses it doesn’t create an object, so there is no way to create a child object that modifies any of the algorithms in a helper class.

They are all “unchangable”. As such, a helper class simply fails to provide one of the key aspects of object oriented design: the ability for the original developer to create a general answer, and for another developer to extend it, change it, make it more applicable. If we assume that we do not know everything, and that we may not be creating the “perfect” class for every person, then helper classes will be an anathema to we .

The Dependency Inversion PrincipleDepend on abstractions, not concrete implementations. This is a simple and powerful principle that produces more testable code and better systems. If we minimize the coupling between a class and the classes that it depends upon, we produce code that can be used more flexibly, and reused more easily.

With static classes/methods we have a clear violation of DIP. A class like that, cannot participate in the Dependency Inversion Principle. It cannot derive from an interface, nor implement a base class. No one creates an object that can be extended with a static class.

Static code and architecture

What is inside static methods? Well no one knows, and that is the problem. Static code must not keep inside it any meaningful state to the project . It should only carry out calculations statements like Math.Abs(), or String.ToUppercase(). We give an input, it works on that, generates the output. That’s it!

But unfortunately, reality is different. People always want more, and end up hurting their projects. Static methods might end up being huge, with complex code in them, with state, and sometimes create and manipulate objects, thus the complexity of the application is increased. The more static methods there are, the more a programmer working in the application has to know where is what and what’s in there. And this is only part of the problem.

Another part is naming static classes and methods. A static method with the name CalculateHolidays which calendar satisfies? Gregorian you will say!And you are right… most of the times! But there are seven calendars in regular current use around the world.

They are the following:

  1. The Gregorian (Is used worldwide for business and legal reasons)
  2. The Chinese (The Chinese calendar is not used in China but is used in various countries of south east Asia, usually with local variations. For example the calendar used in Japan is a variation of the Chinese one. It is also used socially by ethnic Chinese around the world.)
  3. The Hebrew (The Hebrew calendar is used, of course, in Israel, as well as by Jews around the world for their religious observances)
  4. The Islamic (is used by Muslims around the world for setting the dates of religious celebrations)
  5. The Persian (Iran and Afghanistan)
  6. The Ethiopian (Ethiopia)
  7. The Balinese Pawukon (Bali).

So 7 static methods with the appropriate names might one say ! Wrong! We have enums, factory design pattern, we can’t just drop all of them away and being lazy. Plus, renaming or replacing the class containing static methods necessarily requires refactoring all references to it.

Another issue we must address is memory management. Referring to a static class, the class itself is guaranteed to be loaded and have all of the necessary fields inside instantiated before it is ever referenced with the code. Its constructor will only be called a single time. So, this class and methods will remain in memory for the lifetime of the application’s domain.

Static code and unit testing

Unit testing assumes that we can instantiate a piece of the application in isolation. During the instantiation we replace any dependencies with mocks/fakes/stubs. We prevent the execution of the normal code path and is how we achieve isolation of the class under test. With static code we can’t away from the normal path, we can’t replace the static code, because there are no objects to replace.

Also, sometimes static methods is a factory for creating other objects. In tests we rely on the fact replacing important dependencies with mocks. A caller of such a static factory is permanently bound to the concrete classes which the static factory method produced.

In unit testing, we intent to test the monkey and how it eats the banana. With the static code, we are forced to add in the act, the tree the monkey sits on, the plantains the banana grew, and even worse the jungle itself. In the end, this is not unit testing…

The solution?

Maybe the solution is interfaces! Composition or aggregation of objects over inheritance! Both of them are fairly easy to understand, we can see composition in everyday life: a chair has legs, a wall is composed of bricks and mortar, and so on.

Inheritance is more of an abstraction. Though it is possible to mimic inheritance using composition in many situations, it is often unwieldy to do so. The purpose of composition is obvious: make wholes out of parts. The purpose of inheritance is a bit more complex because inheritance serves two purposes, semantics and mechanics.

Inheritance captures semantics (meaning) in a classification hierarchy (a taxonomy), arranging concepts from generalized to specialized, grouping related concepts in sub trees, and so on. The semantics of a class are mostly captured in its interface, the set of messages to which it responds, but a portion of the semantics also resides in the set of messages that the class sends.

When inheriting from a class, we are accepting responsibility for all of the messages that the super class sends on our behalf, not just the messages that it can receive. This makes the subclass more tightly coupled to its super class than it would be if it merely used an instance of the super class as a component instead of inheriting from it. Note that even in classes that don’t “do” much, the name of the class imparts significant semantic information about the domain to the developer.

Inheritance captures mechanics by encoding the representation of the data/state (fields) and behavior (methods) of a class and making it available for reuse and augmentation in sub classes. Mechanically, the subclass will inherit the implementation of the super class and thus also its interface.

The dual purpose of inheritance can cause more confusion. Many people think that “code reuse” is the primary purpose of inheritance, but that is not its only purpose. An overemphasis on reuse can lead to tragically flawed designs.

References

[1]. https://blogs.msdn.microsoft.com/nickmalik/2005/09/06/are-helper-classes-evil/

[2]. https://simpleprogrammer.com/2010/01/29/static-methods-will-shock-you/

[3]. https://objcsharp.wordpress.com/2013/07/08/why-static-code-is-bad/

[4]. https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/static-classes-and-static-class-members

[5]. https://github.com/marshallward/marshallward.org/blob/master/content/avoid_util_classes.rst

[6]. https://www.thoughtworks.com/insights/blog/composition-vs-inheritance-how-choose

[7]. http://misko.hevery.com/2008/12/15/static-methods-are-death-to-testability/

Explaining software to business people, and business to programmers

Dilbert saves the Agile day

Agitma

Introduction

Business people are completely different than us. Their point of view is sometimes so far away from ours, that in the end, there might be no overlap at all. Every domain has its own principles, its own constants, and that’s why we must setup a common ground, in order to achieve productive communication and it the end quality software.

My truth, your truth

Before setting up any principles with people different than you, the first step to identify their truth, their principles that lead them to design/build/work. For business people those pillars are for sure two: time and money. Yes, those two! Of course there are more, but but the last square will always be those two. Do you know what programmers hate? Deadlines (time)! Although this sound totally against the every day’s life of a programmer, it is true. And the reason is simple. We are craftsmen, not a factory’s production line. And as craftsmen we have one principal, a principal to rule all the others in software development, and this one is software quality. If your house constructor needs more time to finish building you will him all the time he asked, even under pressure. I am sure, no one of us would live to an half built home.

Communication breakdown!*

So what is wrong? What happens and we deliver bad software? We can’t blame the tech stacks any more. We have powerful languages, libraries, cloud, tasks automation, experience and knowledge to solve almost any known problem in the business world (AI is still on the go). So what is left to check? What is always has been the problem! People!

Businesses do not always define IT services. It’s more a perception question than a size one. And after one is defined, someone has to explain to the IT guys what to do. In all of cases, the IT department has not a clear view of what the business does, and is unaware of the business priorities. A lot of business people, consider the IT department as a black box. They don’t care how they work, they just expect the final result (software) and clients happy! Well, software development is not a vending machine!

On the other hand, the IT department needs to know what the company does. Let’s take under consideration the following example: A company named iBuildBuildings is mixing cement. The cement takes less than an hour to harden once it’s mixed, and it has to get where it’s going before that. A client called in because he was having trouble dispatching the truck and the IT guy says, “I’m going to lunch. I’ll deal with it when I get back.” That’s showing he didn’t understand that it hardens.

No matter how good your software is, or if the server was 100% up all year long, the cement guy doesn’t care about that. Well he should, but in that specific moment, the problem, was not the bug in the software, bug the IT guy who didn’t care about the business needs.

I am IT, can I contribute to business?

A lot of business decisions are made upon IT feedback. Is this good or bad? It depends. If everybody knows their places, their responsibilities, their goals, their limits, the business needs, then probably is good. If not, then we have communication breakdown.

When an IT guy talks to a business one, he has to speak in terms of money and time, not in technical terms.

For example:

A small deliver company that is called iDeliverEverythingAndEverywher wanted to update their smartphones. If the IT department is trying to contribute by talking on smartphone CPU speed, version, OS it will achieve nothing. It has to speak in business terms. To explain that the new smartphones can handle GPS better, and will speed up deliveries.

A lot of times, the IT guys make things more complex and tend to cause more problems in the business, than they solve.

Time is killing software quality, for the sake of money

Everyday thousands, maybe millions, decisions are made in the is fashion. But let’s set the record straight here. Any software that is developed with the wrong people, with less people, with ambiguous or half described requirements, underfunded and with time pressure is gonna suck big time. An application of that kind doesn’t create problems only at the moment, but for the future times to come, by generating a technical debt.

For a company that doesn’t have a lot of time, money or people, any decisions on software implementation must be extremely lean. No one can afford to waste a huge amount of time and money, thinking about processes that give no value to the business or to the clients.

If it is not clear, what the process does and what will offer to the business value, there is no time wasting on thinking about that. Also half solutions must be avoided. They are worst than taking no decisions at all.

Only the processes that are going to have a measurable impact matter. Once the strategy is laid out, you can understand the process, you can see what needs to be worked on.

That is way software development must NOT be a black box for business people. Time and money are wasted on wrong decisions that were meant to be right.

*https://en.wikipedia.org/wiki/Communication_Breakdown

Conclusions

In the end what really matters is to initially understand what is the problem that needs be solved? But processes have not value if the principles are not defined. All parts must contribute, but on the same principles. The goal view must be same and must not deviates influenced by the department you come from.

English language and programmers

The more you know who you are and what you want, the less you let things upset you.

Bob Harris – Lost in translation (2003)
Image from FocusFeatures

Introduction

For the past, almost, two years, I have been working in H2020 EU projects. In simple terms this means that I participate in consortiums with partners from all around the European Union, so I have to use my English language skills almost every day.

My mother tongue is Greek, so my English is not perfect. But I try, and I try a lot my speaking and my writing to be as correct as possible. I try to improve daily as much as possible, and the reason is simple: I am a professional, and there is no room for excuses!

Usual excuses

  • Lack of opportunities to practice English.You can watch a movie, read a book, or find people online to practice it!
  • Lack of time. This is the biggest excuse ever! Instead of using the Spanish or Italian or whatever translations of a technical manual, use the English version. Grammar, vocabulary, terminology are all in there.
  • Not understanding everything. Well, you understand some or a lot!, So engage into the conversation, make mistakes and improve your English language skills!
  • No one corrects me. Besides the fact that you can find a tutor to support you, practicing and checking now and then a grammar and a vocabulary book will actually help you a lot you to make less mistakes.

The impact

Not improving your English language lead to bad professional impact. It’s not that it makes it more difficult to communicate with your current partners, but keeps you away from the labor market, at least the part of it you are interested in.

I could write down at least three to four examples, of failed communications cause the other party didn’t speak English. And those incidents didn’t occur to a small local city but in the center of Brussels!

And to be totally honest, English is not enough anymore. Speaking languages like German, Chinese, Russian, Spanish is a huge advantage. And the reason for learning those languages is simple: Those languages are spoken to many countries that are markets to services and products provided by the companies you probably want to work for.

Conclusions

Don’t keep yourself out the IT industry, or any industry. English is nowadays part of the basic skills, not the extras. Even I, at the age of the 36 I am planning to take German language courses.

Do programmers suck?

I  can’t rely on my memories

Rachael – Blade Runner movie (1982)
Image frame from the “Blade Runner” movie (1982)

Introduction

Programmers are people, not aliens. Well maybe not the most social ones, but still people. They carry their own personalities, emotions, culture, and set priorities based on their interests, as everybody else! Why programmers should be the exception? The reason is simple: Programmers work in teams by default, even if it seems otherwise!

They are always part of a team, even if that team is consisted by the sole programmer and the client. Programmers, at least, always need a domain expert who might be a colleague, a supervisor, the client, the product owner of someone else. Of course, those kind of teams are not (always) efficient but sometimes this is all we might get.

The key issue is that programmers are trained to be programmers, but they are not culturally educated to work as team members, nor in universities, nor when in business line. We prefer to work alone, with minimum distractions, we avoid meetings like vampires the garlic, and assembling a team of programmers for a project is not an easy task, at all.

Not everybody want to participate to a team, at least quite actively, and sometimes they might not like their teammates for numerous reasons. So in the end, what we have are programmers as units addressed as a team, and those units only care to make their boss happy, or themselves. Additionally, what happens when we set a team of junior and senior programmers? Without the right principles and processes, that team is going to collapse in no time!

The bad programmer

All the bad programmer types below, that you have read about them again and again, are based on bad attitude, not lack of skills.

  • Don’t just copy paste code. Copy pasting itself is not bad. Not knowing what this code does, and why is bad! If you are not aware of the consequences don’t paste till you are sure.
  • Dirty code. Don’t just write code that works. Write code that is understandable by others, and by yourself after some time. Follow a variables naming guideline, indentation, coding style, avoid fat objects etc (clean code is going to be an article in the future).
  • Don’t avoid testing. Avoid testing is not bad for the project itself, it is mainly bad for your and your colleagues. Testing help us reduce technical debt, fix unpredictable code, remove useless or/and old code if it exists, help us keep things under control.
  • Learn the domain.: Focus and learn the domain you are working on, don’t just develop a feature or fix a bug. Knowing the domain help us write better code, develop the expected, by the clients, behaviour of the system, and utilise this knowledge in the future. Programming without understanding the domain is like shooting in the dark.
  • The rigid programmer. Always learn new languages, new frameworks if needed. Don’t feel side if you have to program using another language. Try leaving your comfort zone, and embrace something new!
  • The super wow solution. Complicates problems ask for simple solutions. Over-engineered and complex code works for a short time and crashes after a while. This adds to the technical debt, and the later the debt it handled, the worse!
  • The not case! How many times we have heard by our colleagues, or even by ourselves the following phrases: “I did’t write this”, “It is not my problem”, “It is not my fault, it is X’s fault ” “I can’t (don’t want to) fix it”. Negative attitude leads to negative responses, so be careful.
  • The wanna be hero. Huge ego is bad for the team. If you are the best and most experienced programmer in the team, do not enforce your personality or ideas to others. On the contrary, teach them, guide them, give them a change to listen and understand you. It’s not your project, it’s the team’s, and the company’s, project. Huge ego is equal to low productivity.
  • Avoiding documentation. Clean code is a must. But sometimes extra comments or documentation are needed. Especially, besides the technical details you have to describe the domain details to add value to the provided solution. Do not forget that one day you might leave the company. What you will leave be behind must be clean, transparent, well described and detailed.

Programmers soft skills

Again, programmers are people as everybody else. And every professional who respect themselves, their colleagues, their bosses, the companies they work for, they must be honest, open minded and modest, they must listen but not speak, share and not keeping to themselves, understanding, supporting and not judging are skills that are needed. Programmers, unfortunately tend to fight like artists. Who is the best artist, whose methodology overrule the others, whose work is most important? No matter if a programmer works as a freelancer, or for a company the concept is the same. You have to play nice, by the rules and with others. Unfortunately, reality is different. Not all programmers have a business culture, nor companies either.

So how do you build a culture? First of all this is perpetual process, and doesn’t complete after a specific period of time. Be honest to yourself and to others and open minded. Read books, watch talks on YouTube. No programmer is perfect, nor in skills, nor in personality.

Always try to work for companies with transparent, crystal clear culture. It’s the best feeling to know since day one what is your role, your responsibilities, your limits, the etiquette, with whom you will work with and why. If things are always blur, or change all the time then quit and find a new job! A long as you allow yourself into a rotten environment, in the end you will rot also.

Conclusions

Unfortunately, a lot of programmers and companies are ignorant and selfish. They think they know something when they don’t, or they have no idea that there is something more to know. This mentality leads to poor project results and in toxic relationships. Many software companies, don’t attempt to improve their employees, their principles, their processes and lot of programmers aren’t willing to improve themselves.

Feeling flexible and taking liberties at work is good, but if the company doesn’t align back you back to the company’s philosophy and principles if you diverge, that both you and the company are not disciplined.

References

[1].  https://www.codesimplicity.com/post/why-programmers-suck/