Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Michael_Keller
Active Contributor
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:

  1. 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.

  2. Based on the choice of words, you can conclude whether words from the solution or problem domain were used.

  3. Abbreviations used in method names can be checked for clarity.

  4. 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. 1,408 different words or numbers were used to build method names.

  2. The different words were used 10,729 times.

  3. Space was found due to method names like "_DELETE_ALL" or "__CALC_RGB".

  4. 876 words were used more than once.

  5. 678 words were used only once.

  6. 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



  1. The scan could be extended to class and attribute names.

  2. 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.

  3. Improvement of the select options.

  4. <your ideas, please comment>


 

Best regards, thanks for reading and have fun

Michael
3 Comments
Labels in this area