Search code examples
oopprogramming-languagesnaming-conventions

topic-comment naming of functions/methods


I was looking at American Sign Language the other day... and I noticed that the construction of the language was topic-comment. As in "Weather is good". That got me to thinking about why we name methods/functions in the manner of:

function getName() { ... }
function setName(v) { ... }

If we think about naming in a topic-comment function, the function names would be

function nameGet() { ... }
function nameSet() { ... }

This might be better for a class had multiple purposes. IE:

class events {
    function ListAdd();
    function ListDelete();
    function ListGet();

    function EventAdd();
    function EventDelete();
    function EventGet();
}

This way the functions are grouped by "topic". Where as the former naming, functions are grouped Action-Noun, but are sorted by Noun.

I thought this was an interesting POV, what do other people think about naming functions/methods Topic-Comment?

Obviously, mixing naming conventions up in the same project would be weird, but overall?


Solution

  • Modern OOP techniques should enable us to not have to specify the subject of our function, but only the action, so for Ex.

    Your events class should only have add/delete/get, and you should have a separate, Event_List class that would also have add/delete/get.

    so, depending on the language it would be called event_obj.get(), or event_obj.delete()... etc..

    like event_list_obj.add() etc...

    This actually lines up with what you said about sign language, which is a very good point.