The book Clean Code: A Handbook of Agile Software Craftsmanship by Robert C. Martin was published in 2008 with the tagline: “Even bad code can function. But if the code isn’t clean, it can bring a development organization to its knees.”
What is this elusive “clean” code? Clean code can be easily understood not only by the original creator but by anyone reading it (possibly a non-developer) and it is easy to adjust and maintain.
The SAP ecosystem has been a bit slow to jump on the clean code bandwagon, and Clean ABAP, the style guide specifically for SAP ABAP language, publicly surfaced on GitHub only in 2019. In this post, I will address some of the questions typically raised by the organizations looking to improve their SAP development by following Clean ABAP principles.
Will Clean ABAP make our code bug-free?
Once I read a review of a Dyson vacuum that said: “this vacuum picks up dirt I didn’t know I had”. Clean ABAP is something like that.
My first foray into “cleanish” ABAP years ago was prompted by the SAP Community discussions regarding the disadvantages of Hungarian Notation. Hungarian Notation is a set of naming conventions which dictates, for example, that a variable name should have a prefix signifying its scope and type. In ABAP, this led to the variable names like gt_vbak or ls_ekko. This notation has been followed by ABAP developers for decades for the main reason that someone told us so.
As a solo developer at the time, I had only myself to convince, so I decided to start using more human-readable variable names. After bravely renaming itab_vbak as sales_orders, I realized that this name might in fact be inaccurate. The data source in the program was the well-known SAP table VBAK that stores not just sales orders but other sales documents, such as quotations or contracts. But the program did not consider that variety. So, was it a wrong name choice or was the code itself wrong? A quick check with the users uncovered that the report indeed was including the irrelevant document types and the users were hiding unnecessary data using their personal filters. A minor change allowed to read thousands of records less from the database thus improving the report’s performance. Not to mention, new names made the code much better readable, with clearly stated intentions.
Code is the means of communication for developers. I’m sure everyone already understands the importance of clear communication in business. Imagine if a shipping label sent your customer’s order to a wrong address or if a wrong order quantity was given to a supplier? Clean ABAP prompts the developers to communicate more clearly via code, thus reducing the number of errors and misunderstandings.
Does following Clean ABAP mean that we will need to update all our legacy code?
No. This is a very common misconception. Clean ABAP is not an “all or nothing” concept and “don’t fix what ain’t broken” very much remains one of the main programming principles (although I always warn the readers to mind for the definition of “broken”).
Cleaning your house or apartment does not necessarily mean stripping the wallpaper and moving the plumbing pipes. One day you might just clean your desk, another day the kitchen, and so on. Similarly, we can keep building “clean islands” within the legacy code, as we work on it.
What benefits exactly can we gain by following Clean ABAP principles?
The most obvious and immediate benefit: Clean ABAP guide can replace thousands of outdated, confusing, oppressive corporate ABAP guidelines. As a consulting company, at Mindset we always follow our clients’ guidelines first and foremost. But in their absence or in case of “grey areas”, we follow Clean ABAP principles to create best value for our clients. And we advocate for Clean ABAP to anyone who would want to listen.
Clean ABAP prompts the developers to use modern language and better coding techniques. For decades, ABAP developers have been indulged by backwards compatibility taking care of running our code like it’s 1999. Well, guess what, the world is changing now. If your organization has plans to migrate to S/4HANA, to the Cloud and beyond, the time to modernize your ABAP development practices was yesterday.
Most importantly, adoption of Clean ABAP fosters collective code ownership and the feedback culture. “Oh, Bob wrote this report, you better check with Bob before making any changes!” Even though this situation is unhealthy for both the organization (because we need to wait for a week till Bob is back from a trip) and the individual (Bob gets stuck working on the same code for ages), it somehow continues to exist. Or worse, some companies waste time and money engaging in “whodunit” games to find a developer responsible for a production issue. Whatever for?
We cannot innovate when we are afraid to touch “Bob’s code” or do not have our colleagues’ support for better or for worse. When the whole team is invested in the outcome, they more freely engage in the ideation and knowledge exchange. The dreaded code reviews become less dreaded because the code has already been discussed naturally, as part of the work process. And the feedback from other developers is no longer criticism but an opportunity to learn and improve.
What are the first steps to start following Clean ABAP principles?
Good news, everyone! Clean ABAP does not require any investments or waiting for an upgrade to a specific ABAP version. Anyone can start at any time. All you need is to review the guide on GitHub and commit to using the principles in any new development.
The Clean ABAP book highlights these rules that help developers to achieve a foundation in clean ABAP:
- use descriptive names
- do one thing
- keep methods small
- express yourself in code.
If you are an IT manager, your role would be to support the developers in this endeavor. Any change can lead to confusion and even slow down the development process at first. But progress is only possible through change. In the case of Clean ABAP, your reward will be better code quality, healthier team relationships, and innovation-driven environment. If it’s not worth the effort, then I don’t know what is.
* * *
Is your organization interested in Clean ABAP and other best development practices? Mindset Center of Competence would love to talk your ears off! Please reach out to us via contact form below.