Hi everyone,
I just made my first Hello World program in Eclipse (literally 10 minutes ago). I didn't know any code other than
So I wanted to know more code so I could have more ideas and do more things.Code:public class HelloWorld { public static void main(String[] args) { system.out.println("Hello World"); //TODO Auto generated method stub } }
Also, In the tutorial it said the names in Java are really long...do they really have to be? Coming from C++ my names are generally small.
then you should continue to follow the java tutorial ... good start ..~
Yes, In java names are long and they should be long as the name should describe what the Class/Method/Field does. For example it's okay to write a test for you program, that sounds like this:Also, In the tutorial it said the names in Java are really long...do they really have to be?
public void isDogBarkingWhenStrangerIsAtTheDoorAndImNotHome(){
}
this method name is very good, as it is self-documenting and describes everything it does.
That's why IDE's are very recommended when writing java, as they have the autocomplete and spellchecking functions. in Eclipse you can have autocomplete, when pressing ctrl+space.
Generally though I don't like having really long names because you will have to retype them later. That is a long name and is probably too descriptive. I'd rather go with a less descriptive name and add comments to be more descriptive as to what the function does.
I disagree, they do not have to be that long and I do not think they should.
Yes some names are long... especially function calls since they look like "System.out.println" but that is more than one name and might be difficult to remember. I would not recommend using long names as you will forget them easily.
Perhaps i explained myself a little bit wrong.
The above example was a test-method(JUnit) name, as i said earlier(And probably a bad example to bring here), it should never be called manually anyway, and needs no additional documentation. I would never name a normal method that long myself either.
When it's possible, it is always good idea to name the method as short as possible, but there is nothing wrong with long names if they justify themselves. Usually there's no need to have over two or three words to describe the method in a name. but there's no need to shorten the words if more words are used.
In one sense, I'm going ot have to side with Sinipull on this one. Longer names are generally better than shorter names, despite the need to perform more typing to write one out if you're not using an IDE. However, I think it's far more important that methods be simple rather than descriptive. They should perform one task, or get a single piece of information. This task can in itself be very complicated (for example, splitting a string), but regardless it should be simple for a user to understand what's going on with two or three words. As such, instead of this:
I'd prefer this:Code:public void isDogBarkingWhenStrangerIsAtTheDoorAndImNotHome(){ }
This is because the client can customize different conditions and utilize the code within the object better. I think it more important that objects be versatile than anything else, though.Code:public bool isDogBarking() { } public bool isStrangerAtDoor() { } public bool amIHome() { } //... if (status.isDogBarking && status.isStrangerAtDoor() && !status.amIHome()) { // Do something... }![]()
Wow I changed my sig!
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks