Why the JAVA tutorial....

Why the JAVA turorial says you have to use verbs as method names?it's ain't too important... so why should I call it in a verb name?
[155 byte] By [z999a] at [2007-10-3 2:47:19]
# 1

> Why the JAVA turorial says you have to use

> verbs as method names?

> it's ain't too important... so why should I call it

> in a verb name?

You don't have to. The compiler won't care. But the people who read your code later will. It's not just a Java thing. It's common practice in OO that classes and objects are named with nouns (because they represent things and ideas) and methods are named with verbs (because they represent actions).

And yes, it is important. Clear communication leads to better, more maintainable code.

jverda at 2007-7-14 20:36:05 > top of Java-index,Java Essentials,New To Java...
# 2

clarity, consistency, conforming to standards - which would you like ?The purpose of a method is to do something a verb describes doing something. The definition of a verb is:

content word that denotes an action or a state

A method would be an action would it not ?

*Edit* As jverd said you don't have to but don't be surprised when your fellow programmers come after you with threats after having to maintain your unique code.

Aknibbsa at 2007-7-14 20:36:05 > top of Java-index,Java Essentials,New To Java...
# 3

It's actually good OO practice to name your methods as a verb. One of the many reasons to do so is that it solidifies the behaviour of the method in your mind. If you can't think of a way of stating it as a verb, then perhaps you're not creating an appropriate method.

Mind you, this is all just stylistic. If you don't like the style suggestions or the OO design that you find in the textbooks and tutorials, you're certainly free to use your own. However, if you ever want anybody to read your code or contribute to your projects, you'll make more friends if your style is legible and familiar.

Brian

brian@cubik.caa at 2007-7-14 20:36:05 > top of Java-index,Java Essentials,New To Java...
# 4

The whole point of OO Design is style.

To build a car that runs forward somehow, isn't the big difficulty. But nobody will buy it or even like it, if it's ugly and will break as soon as you leave the motorway.

Robustness, maintainability, extendabiltity, reusability... those are all "weak" requirements, but they are very important. You will learn this the hard way, as soon as you program your first bigger application.

Mongera at 2007-7-14 20:36:05 > top of Java-index,Java Essentials,New To Java...