Jump to content

Java Ideas

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
6 replies to this topic

#1
hetra

hetra

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 298 posts
Hi everyone,

I just made my first Hello World program in Eclipse (literally 10 minutes ago). I didn't know any code other than

public class HelloWorld {
 public static void main(String[] args) {
 system.out.println("Hello World"); 
  //TODO Auto generated method stub
 }
}

So I wanted to know more code so I could have more ideas and do more things.

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.

#2
Guest_R3.RyozKidz_*

Guest_R3.RyozKidz_*
  • Guests
then you should continue to follow the java tutorial ... good start ..~

#3
Sinipull

Sinipull

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 386 posts

Quote

Also, In the tutorial it said the names in Java are really long...do they really have to be?

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:

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.

#4
chili5

chili5

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 7,247 posts
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.

#5
BlaineSch

BlaineSch

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,448 posts

Sinipull said:

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:

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.
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.

#6
Sinipull

Sinipull

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 386 posts
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.

#7
ZekeDragon

ZekeDragon

    Writes binary right handed and hex left handed

  • Moderators
  • 2,103 posts
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:
public void isDogBarkingWhenStrangerIsAtTheDoorAndImNotHome(){
}
I'd prefer this:
public bool isDogBarking() {
}
public bool isStrangerAtDoor() {
}
public bool amIHome() {
}
//...
if (status.isDogBarking && status.isStrangerAtDoor() && !status.amIHome()) {
    // Do something...
}
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. :)
Wow I changed my sig!