Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

So, how would you go if you were to eliminate the hungarian notation?

felipe_dimmu23
Participant

Going away from the discussion of best practices, and why people think naving convention belongs to best practice documents, I would like to know what would be your approach as a developer to something that still feels weird to me on the way I have practiced not using the hungarian in a personal project.

Recap from wikipedia

Hungarian notation is an identifier naming convention in computer programming, in which the name of a variable or function indicates its intention or kind, and in some dialects its type.

So iv, it, rt, gc,lv...those things.

Continuing

Perhaps because I can't visualize both method definition and implementation at the same instant (Eclipse, at least), I have to navigate sometimes to understand what is what, justifying the hungarian again. My issue example:

methods:
  do_something
    importing
       item_list type <something>.

data:
   items type <something>
endclass.
...
method do_something.
   items = item_list.
endmethod.

Sure, we have cleancode to keeps things small and improve my reading of it. But still, once I felt in my own trap of assuming item was a member attribute and item_list was an importing paremeter, while both were member attributes and the importing parameter was something else. I will accept you saying that then it "is a code smell, refactor", and it is what I did but I still lost time to figure "Who's who". And I'm used to write parameters with importing and returning only, so I'm don't even consider "is this a changing, exporting"?

What I have tried and see as option:

1) Really old stuff, and seems like a negation operator like in javascript:

methods:
  do_something
    !item_list type <something>.

method do_something.
   item_list = !item_list. 
endmethod.

2) Using me, allowing even exact same name...but people don't invite me to dinners anymore when I use me:

methods:
  do_something
    importing
       item_list type <something>.

data:
   item_list type <something>
endclass.
...
method do_something.
   me->item_list = item_list.
endmethod.

3) ...yes, the Hungarian for import, (I always just give result as a name to returning).

method do_something.
   item_list = i_item_list.
endmethod.

Should I keep without any prefix? Will this feeling go away if I keep practicing? I've practiced for 3 days and feeling is still there.

Thanks for chipping in!

1 ACCEPTED SOLUTION

matt
Active Contributor

Read the ABAP style guide in help.sap.com. Search the various discussion concerning the use of HN.

1)

methods:
  do_something
    !item_list type <something>.

Discussed here: https://answers.sap.com/questions/1734571/what%27s--in-method-declaration-in-class.html
I see it when I edit a class in Eclipse that was created with SE24.

2)

I used to use me->, but stopped. (I do use this. in Java) The idea is that the code in a method should be small enough that it's obvious what's local and what's a class attribute, especially when the local variable is declared very close to use or via DATA(var) = 'Fish'. Parameters aren't an issue, because...

3)

HN is used with L_ to indicate scope, and T_, R_ or S_ to indicate kind - i.e. Table, Structure, Reference... That is considered in modern programming to be bad and, with more complex types, in many cases utterly useless.

But it's fine to use it to indicate use. That's why I use G_ for global variables (when I absolutely must use them), and I_ E_ and X_ for importing, exporting and changing parameters. Although, to be honest, when programming in Java, I don't... Hey, I'm nothing if not irrational and inconsistent! ��

Finally, some True Believers of the HN Holy War will be along soon. Don't listen to them.

7 REPLIES 7

matt
Active Contributor

Read the ABAP style guide in help.sap.com. Search the various discussion concerning the use of HN.

1)

methods:
  do_something
    !item_list type <something>.

Discussed here: https://answers.sap.com/questions/1734571/what%27s--in-method-declaration-in-class.html
I see it when I edit a class in Eclipse that was created with SE24.

2)

I used to use me->, but stopped. (I do use this. in Java) The idea is that the code in a method should be small enough that it's obvious what's local and what's a class attribute, especially when the local variable is declared very close to use or via DATA(var) = 'Fish'. Parameters aren't an issue, because...

3)

HN is used with L_ to indicate scope, and T_, R_ or S_ to indicate kind - i.e. Table, Structure, Reference... That is considered in modern programming to be bad and, with more complex types, in many cases utterly useless.

But it's fine to use it to indicate use. That's why I use G_ for global variables (when I absolutely must use them), and I_ E_ and X_ for importing, exporting and changing parameters. Although, to be honest, when programming in Java, I don't... Hey, I'm nothing if not irrational and inconsistent! ��

Finally, some True Believers of the HN Holy War will be along soon. Don't listen to them.

Hehehe yes! It is weird like something feels natural in a language and weird on others!

I guess those true believers need them...If my code is always an FM with 2k lines in a function group with shared variables all over, I would defend it to the death too!

Amem to clean code! All hail uncle bob for saving us \o/

Hi.

I do it the same way. G_ for global and the prefix Eclipse sets for the parameters of a method. So there ist no need of ME and it's a bit better for those who still use HN.

The problem with the HN ist that you must know if it is local or global. When i see codings form others at work it is often mixed or they use I instead of l. And then they scream when they see coding without HN. :')

Sandra_Rossi
Active Contributor

! is explained in the ABAP documentation Escape character for names, but I'm surprised that it's used by the compiler to distinguish the attribute from the parameter. I wouldn't trust this solution, as it could be incorrect in the future.

The two other solutions would be fine for me, but I prefer the 2nd one.

matt
Active Contributor

It must be obsolete. When I use eclipse to edit class created in SE24, I see the !. When I remove them, it all works fine.

matt
Active Contributor
0 Kudos

Ah - now read the link. I've not tried with a parameter called WRITE for example. I use prefixes here anyway.

felipe_dimmu23
Participant
0 Kudos

I'm very much inclined to go for option 2 too...