
In engineering, every solution involves trade-offs—it's about weighing the pros and cons. The same applies to HN, which isn’t all evil. Back in the days, when we just gave up on GO TO instruction (hail to Edsger Dijkstra) and had only 72 characters for one line of code, marking variables as local/global was a way to manage situation, where we use 20 locals and 30 globals within one procedure and it's hard to guess what is what. Limited length of names didn't help either, so all those "ls_" had some significant advantages.
But times have changed. We now have modern IDEs like Eclipse and ABAP OO, allowing us to write smaller, more manageable routines. Most of the limitations that existed in the early days of ABAP are no longer an issue. As a result, the benefits of HN have disappeared, leaving only the drawbacks, which actively harm the quality of code.
Real life example (just one of many): gt_vbak, gt_vbak2, lt_vbak1, lt_vbak2. These names I had encountered in a > 10k long report. Trying to make sense of this was maddening. Eventually I decided to rename despite having no access to Eclipse on that system. The new names were:
The irony is that these tables weren't even based on the vbak type but were locally defined. So keeping 'vbak' in the name.
I know, nothing stops us from making meaningful names with HN, so gt_partners and ls_partner are possible. And yet almost no one writes gt_partners. What's worse, some create gt_partner and ls_partner. What is gt_partner in this case? It sounds like a table of data for one partner only, but I guess it's not.
To summarise: You could make good names with HN, but practice shows, that no one does. Whereas banning prefixes forces us to spend a minute on creating a proper name. It's not a technical issue. In fact it's a matter of human nature.
In the example above, no matter how familiar you are with prefixes (I had 10 years of prefixing ingrained in me), you’ll still mix up lt_vbak2 with gt_vbak2 every few minutes. It’s just impossible not to. These aren’t real words, so we don’t process them efficiently.
Our brains are wired to recognize words based on patterns. If the frist and last letters of a word are correct and the middle letters are slightly jumbled, we can still read it as if it were correct, sometimes without even notciing the errors 😉. This shows that our brains help us read familiar, pronounceable words , but offer no such support for prefixes like lt_, gs_, and so on.
A friend of mine once decided to try coding without prefixes. For the first two weeks, he cursed me and my descendants to the 20th generation, as breaking a habit of 10 years was tough. But after three weeks, he said it felt like seeing clearly for the first time. Code without lt_ reads like a novel - like human language - whereas prefixed code felt like hieroglyphics. Sure, if you’re used to hieroglyphics, you can read them quickly, but it’s still much slower than reading a regular novel.
As Uncle Bob once said, adding prefixes is like adding unnecessary code to the code itself. When reading, my brain first has to decode the prefixes, and only then can it process the ABAP. Writing in plain, human-readable language lets us focus entirely on the ABAP itself.
When using HN, it influences how we use code completion.: I write a code and now I need to get something from table of orders. So I don't bother thinking what was its name - it's enough to type "lt_" and hit ctrl+space.
When I gave up on HN, I had to start using meaningful names (because there was no option to add prefix to the terrible, 4-letter table name). Now, I "search" for variables by their name, not their type. I know I’m looking for a table of customers, so I type "cus" and hit ctrl+Space. After three months of working like this, I found myself improving the clarity of my variable names even further. I even started creating "families" of names, such as orders_rejected, orders_closed, and orders_in_processing, as it helps utilise code completion even further. At the same time code becomes even clearer.
Sticking with prefixes would have never allow me to improve this way.
Thousands of times have I seen:
This led to a habit where, if scope (l/g) really mattered, I would always check (by double click in SE80 or glimpse on the overview ruler in Eclipse). So I ignore letter l/g - it became a noise for me. The same goes for types - I never trust the letter and I check the type by myself (F2 in Eclipse). This double-check actually saves some time (and nerves).
Honestly, I’d rather have no information at all than false information (the same criticism applies to misleading comments, but that’s another story).
There is some general agreement in ABAP world, on which prefixes to use...
Oh is there?!? wa_, or ls_? What about mv_ for the "member" attribute in class? What if it's a static? By definition It's not a member, so should we still call it mv_ or maybe sv_?
How about field symbols? When I see <fs_some_data> it makes me fill like this:
Pulp Fiction - Any Of You Pricks Move
I mean come on, didn't you see the angle brackets <>? Are they not enough?
But what about <ls_some_data>? Is it a field symbol, or a structure? What if we agreed on prefixing field symbols, but this one is of any type?
And what about objects? After all, they are all references. So some will call them lr_sth, and some others lo_sth, whereas "lr_" will be reserved only for non-object references (but here you loose information if it's a reference to a variable, structure or a table!)
STOP! Go back to "wa_". Oh my, I don't know if it's local or global. The same with <fs_...>. I'm so confused 🤕!
Well, you end up with some naming rules and each new member of the team has to learn them and get used to them even though they bring no value. What's weird - prefixes are more required from the freshman than proper naming in general.
Because of the reasons above, one person in a program might use wa_ (making it unclear if the variable is local or global), while another uses ls_ or gs_. Some might use it_ (which I think stands for internal table), while others use lt_ or gt_. Then there’s the lr_ vs. lo_ debate. In the end, what we have is not a program, but a riddle.
Nothing forces us to make this mess... except human nature. I’ve seen plenty of programs suffering from MNA (Mixed Naming Arts. 😉 ).
Since I have mentioned mixed naming styles I'd like to point out, that it's absolutely essential to follow the existing style (or to rename the whole code). Having two naming styles is always worse than having one, no matter how bad the style is.
Basically, the only thing that holds us from dropping HN is habit. After using it for years, we think it’s easier because it’s all we know.
It takes about 3-4 weeks to retrain your brain, and I guarantee you won’t lose the ability to read old, prefixed code. You’ll still be able to read and write it.
However, giving up HN won’t noticably improve your code unless it’s part of a broader set of changes, including:
This short list is just the beginning, but following these three principles alone (along with giving up on prefixes) will significantly improve the quality and maintainability of your code.
If not HN, then which style should I follow? If you want some clues, please refer to CleanABAP. It's published as a book and also available on GitHub:
https://github.com/SAP/styleguides/blob/main/clean-abap/CleanABAP.md
Since I have started the topic, I guess I will continue and elaborate on this short list in next blog posts.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
11 | |
10 | |
9 | |
8 | |
6 | |
6 | |
6 | |
5 | |
5 | |
5 |