Dear community, what are the "ingredients" of this blog? We have a
blog about software metric by
christian.drumm, a blog about
working with strings by
frehu, my
blog with some thoughts on finding class and method names and Uncle Bob's recommendation "
You should name a variable using the same care with which you name a first-born child." (thanks to
enno.wulff for the quote) ... a few more considerations from me ... mix everything ... wait 5 minutes ... et voila, we have a "method name scanner" and are able to generate basic statistics about method names
🙂
What's the story? I've noticed that it takes a lot of my time to find good methods names during my work. In the sense of "
Clean ABAP" I want to do it as neatly as possible because the method names should already document my source code.
However, 30 characters are sometimes not enough. This can be an indication that I want to achieve too much with a method or 30 characters are really not enough due to the
terms I choose. In any case, it takes me time to find the right method name.
After thinking about it for some time, I didn't find a "simple" solution to my problem. Experience probably speeds up the process of finding the right method name
🙂 Therefore I had the idea of learning from the work of other ABAP developers. But how?
Idea
A SAP ERP system has a large repository of development objects. This also includes the classes with their methods. The method names can be found in the SEOCOMPO database table.
Since spaces in methods are usually marked with an underscore, the idea was to analyze the method names for their words and the position of the words. So you can generate simple statistics which words have been used in which places and how often.
Use
Here are a few ideas for meaningful use:
- In connection with a code review, the methods of the classes which have been created in a project can be checked for noticeable words in advance.
- Based on the choice of words, you can conclude whether words from the solution or problem domain were used.
- Abbreviations used in method names can be checked for clarity.
- You can improve your own vocabulary for the design of method names.
Implementation
I wrote a "Proof of Concept" report to check my idea. The report can be imported from this GitHub
repository via
abapGit. At the moment my report doesn't have an ALV output.
For analysis, you therefore have to set a breakpoint at the end of the "ANALYZE_METHOD_NAMES" method and look at the STATISTICS table while debugging. The table can be downloaded via debugger as a file for further processing in Excel or use the ALV output via debugger.
The structure of STATISTICS is as follows:
Column |
Description |
WORD |
A word used in a method name. |
COUNT_USED_OVERALL |
The number of times a word was used in method names. |
COUNT_USED_AT_THE_BEGINNING |
The number of times a word was used at the beginning of a method name. |
COUNT_USED_IN_THE_MIDDLE |
The number of times a word was used in the middle of a method name. |
COUNT_USED_AT_THE_END |
The number of times a word was used at the end of a method name. |
REFERENCES |
This is a link to a table where you can check in which method names the word was used. |
Example
I used my demo report to create statistics of classes with prefix "CL_GUI_" on my SAP Netweaver 7.52 stack. Because there are many classes with even more methods, the view is a bit like "looking at the stars". Everything at once doesn't work because of the long run time.
It's therefore best to narrow your view to certain areas (selecting the classes by application component would certainly be a useful improvement ;-)).
Here is an overview of the results:
- 1,408 different words or numbers were used to build method names.
- The different words were used 10,729 times.
- Space was found due to method names like "_DELETE_ALL" or "__CALC_RGB".
- 876 words were used more than once.
- 678 words were used only once.
- The majority of the terms are from the technical area (like "UI" or "GRID"). That fits the expectation based on the class selection.
Here are some details:
Word |
Count overall |
Comment |
SET |
837 |
Ok, no surprise. |
GET |
673 |
I wouldn't name my first-born child SET or GET 😉 |
DATA |
118 |
Hopefully it's clear what data is meant. |
MATRIX |
6 |
No methods like "TAKE_RED_PILL" or "TAKE_BLUE_PILL" but "SET_MATRIX_VALUES". |
HAIRS |
4 |
Used in method name in combination "GET_CROSS_HAIRS". |
CHECKMAN |
2 |
Used in method name "UC_CHECK_CHECKMAN". |
4 |
2 |
Used in method names like "TREE_BREAK_4_ANALYSE". This saves space. |
2 |
2 |
Used in method names like "SUBSCRIBE_2_DISPLAY_MESS". This saves space. |
Further ideas
- The scan could be extended to class and attribute names.
- Unfortunately I didn't find any AI in SAP Leonardo to check if a word is noun or verb. But that seems to work with Google Spreadsheet.
- Improvement of the select options.
- <your ideas, please comment>
Best regards, thanks for reading and have fun
Michael