Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy does java/javascript/python force the use of () after a method name, even if it takes no arguments?
    text
    copied!<p>One of my most common bugs is that I can never remember whether something is a method or a property, so I'm constantly adding or removing parentheses.</p> <p>So I was wondering if there was good logic behind making the difference between calling on an object's properties and methods explicit.</p> <p>Obviously, it allows you to have properties and methods that share the same name, but I don't think that comes up much.</p> <p>The only big benefit I can come up with is readability. Sometimes you might want to know whether something is a method or a property while you're looking at code, but I'm having trouble coming up with specific examples when that would be really helpful. But I am a n00b, so I probably just haven't encountered such a situation yet. I'd appreciate examples of such a situation.</p> <p>Also, are there other languages where the difference isn't explicit? </p> <p>Anyways, if you could answer, it will help me be less annoyed every time I make this mistake ^-^.</p> <p>UPDATE: Thanks everyone for the awesome answers so far! I only have about a week's worth of js, and 1 day of python, so I had no idea you could reference functions without calling them. That's awesome. I have a little more experience with java, so that's where I was mostly coming from... can anyone come up with an equally compelling argument for that to be the case in java, where you can't reference functions? Aside from it being a very explicit language, with all the benefits that entails :). </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload