'method' vs. 'message' vs. 'function' vs. '???'

后端 未结 11 842
北荒
北荒 2020-12-24 12:59

I recently asked a question about what I called \"method calls\". The answer referred to \"messages\". As a self-taught hobby programmer trying to phrase questions that don\

相关标签:
11条回答
  • 2020-12-24 13:36

    I've found this to be a language and programming-paradigm thing. One paradigm — OOP — refers to objects with member methods, which conceptually are how you send messages to those objects (this view is reflected in UML, for example).

    Another paradigm — functional — may or may not involve classes of objects, but functions are the atomic unit of work.

    In structured programming, you had sub-routines (notice that the prefix "sub" implies structure).

    In imperative programming (which overlaps with structured quite a lot, but a slightly different way of looking at things), you have a more formulaic view of the world, and so 'functions' represent some operation (often mathematical).

    All you have to do to not sound like a rube is to use the terminology used by the language reference for the language you're using.

    0 讨论(0)
  • 2020-12-24 13:39

    I am pretty sure (but a quick Wikipedia check seems to confirm this) that the `message passing' terminology comes from the Smalltalk community. I think it is more or less equivalent to a method call.

    0 讨论(0)
  • 2020-12-24 13:42

    I believe message is used in smalltalk.

    Java, C# etc. tend to use method or instance method.

    0 讨论(0)
  • 2020-12-24 13:43

    Here's some simplified definitions:

    methods/subroutines/voids: perform an action

    functions: perform an action and return a value

    events: are called when an object is acted upon

    handlers: are the functions/methods that handle the events


    PS: this is a perfect example of why SO should support DL/DT/DD tags.

    0 讨论(0)
  • 2020-12-24 13:44

    I believe that it is a matter of preference at this point. The words that you mention are basically synonyms in today's languages and for the most part people will understand what you mean if you say either "method" or "function". If you use "message", which is only used really in OOP, then you may confuse what you are attempting to convey.For example: "I need to create a message to send an email message." Other terms that could be synonymous, and this isn't a complete list, are subroutine, action, procedure, operation (although usually mathematical in nature), subprogram, command...

    0 讨论(0)
  • 2020-12-24 13:47

    Usually, "Method" seems to be the proper name for Functions. However, each language has it's own keywords. Delphi for example even makes a difference between Methods that return something ("Functions") and Methods that return Nothing ("Procedures") whereas in C-Type languages, there is no difference.

    0 讨论(0)
提交回复
热议问题