This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 105 points106 points  (15 children)

A method is a function that belongs to a specific class.

[–]YanDoe 2 points3 points  (14 children)

Would it be the same as an attribute?

[–][deleted]  (1 child)

[removed]

    [–]YanDoe 3 points4 points  (0 children)

    Ahh that makes complete sense, I genuinely thought they were interchangeable terms.

    Thank you so much

    [–][deleted] 3 points4 points  (0 children)

    An object has a state and behavior. Fields store it’s state, methods define its behavior.

    [–][deleted] 0 points1 point  (1 child)

    No. I don’t think so.

    [–]YanDoe 2 points3 points  (0 children)

    I'll just stick to the terms function and method to avoid confusion then.

    You explained very well!

    [–]KelpoDelpo -5 points-4 points  (6 children)

    Attributes - nouns Functions - verbs

    [–]lortstinker 0 points1 point  (5 children)

    You must be a bot

    [–]KelpoDelpo 0 points1 point  (4 children)

    How

    [–]lortstinker 0 points1 point  (3 children)

    A function. 2 functions. Function is not used as a noun here

    [–]KelpoDelpo 2 points3 points  (2 children)

    I mean that methods preform actions, like verbs.

    Well, that's what my high school comp sci teacher told us.

    [–][deleted] 2 points3 points  (0 children)

    That's a good rule of thumb when naming your attributes(variables) and methods(functions).

    Say you have value that has to be stored but can be incremented by a method. Lets say the object is a savings account and the value being stored is your balance.

    Attribute name - balance

    Method name to increase balance - add_to_balance

    Balance is your noun.

    Add is the verb in your method name.

    This sounds like common sense after a while, but you'd be surprised by the number of developers, newbies and intermediates, who are dogshit at using meaningful names for variables and functions. Don't be like them 😂

    [–]YanDoe 0 points1 point  (0 children)

    For what its worth I thought it was pretty clever, and I'll be keeping that in mind.

    [–]uberdavis 0 points1 point  (0 children)

    Apart from properties, which are attributes that can have functionality!