Search This Blog

Saturday, September 18, 2010

Why does java/javascript/python force the use of () after a method name, even if it takes no arguments?

Programmer Question

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.



So I was wondering if there was good logic behind making the difference between calling on an object's properties and methods explicit.



Obviously, it allows you to have properties and methods that share the same name, but I don't think that comes up much.



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.



Also, are there other languages where the difference isn't explicit?



Anyways, if you could answer, it will help me be less annoyed every time I make this mistake ^-^.



Find the answer here

No comments:

Post a Comment

Related Posts with Thumbnails