Please join us at the new JavaWorld Q&A Forums. Your existing login will work there. The discussions here are now read-only.


JavaWorld Talkback >> 958924

Anonymous
Unregistered




Readability suffers
      04/27/04 11:15 PM

One of the reasons why I liked programming in Java was that Java always had to force me into making my code more readable. I wasn't free to whatever I liked; I had to follow Java's rules even if it meant more typing to get the job done.

1) Boxing, unboxing
I have mixed feelings about this. It'll definitely make my life as a code writer easier with the primitives, but what about my life as a code reader? Upon seeing other people's code, would I immediately think "this method always uses an int"?

2) Enhanced for loop
As said, the unenhanced for loop is "cumbersome", but for whom? The code writer, or programmer, of course! If I were a stupid code reader, I have to know explicitly that the collection is unmodifiable. It's a classic case of whether to trust the language or trust the API.

3) Variable method arguments and printf
Yes, there were many times back then when I asked "why oh why am I stuck using a fixed number of arguments?" I had to use workarounds to get around that "limitation". I usually ended up with more elegant solutions afterwards, solutions that were more robust because they were planned with the future in mind. That's one odd thing about good ideas: if necessity is the mother of invention, limitation is the mother of creativity.

4) Enumerations
Personally, I'm still confused about enumerations. Will they fit into the class heirarchy and get their own class files? I guess I better read up on Tiger then. (^_^) In the past, I used classes with private constructors; e.g.

Code:

public interface Switchable {

public class Mode {

private String mode_description;

private Mode(String mode_description) {
this.mode_description = mode_description;
}

public void append_to_string_buffer(StringBuffer buffer) {
buffer.append(this.mode_description);
}

}

public abstract final Switchable.Mode SWITCH_ON = new Switchable.Mode("this switch is on");

public abstract final Switchable.Mode SWITCH_OFF = new Switchable.Mode("this switch is off");

public abstract void switch_mode(Switchable.Mode mode);
public abstract Switchable.Mode get_mode();

}




It's nice for me because I can return to this code in six months even though I've forgotten all about it. A quick read is all it takes for me to know that my "enumeration" is intimately tied to the use of an interface.

5) Static imports
I'm not too hot on this, either. When I program, I don't leave off the fixtures in front of the variables; it helps the readers of my code determine from where the variable comes. For instance, if I use "this.variable", the code reader can automatically differentiate it from variables without the reference to "this".
In a way, it makes it easier for the reader to know whether the variable is local or not. Same goes for static. I love putting the classname in front (it was obligatory in the past) because it's an automatic flag for code scanners, people who didn't originally write the code but have to read code fast because they are either too busy to actually read the whole code throughout or have to fix a bug within five minutes.

It's all about readability. Shortcuts aren't really the solution; if they were, Java would have preprocessors by now! (^_^)

Post Extras Print Post   Remind Me!     Notify Moderator


Entire topic
Subject Posted by Posted on
* Taming Tiger, Part 1 JavaWorld 04/25/04 12:24 AM
. * * Goodbye Duke! Anonymous   04/27/04 02:33 PM
. * * Re: Goodbye Duke! Anonymous   06/07/06 04:46 PM
. * * Readability suffers Anonymous   04/27/04 11:15 PM
. * * Some good, some bad Daniel Barbalace   02/22/05 02:36 PM
. * * Re: Readability suffers Anonymous   07/20/04 03:35 PM
. * * Re: Readability suffers Anonymous   07/20/04 08:39 AM
. * * Re: Readability suffers Anonymous   06/09/04 04:50 AM
. * * bool ? GPX   04/27/04 04:41 AM
. * * Re: bool ? Anonymous   04/27/04 02:53 PM
. * * Re: Taming Tiger, Part 1 Anonymous   04/26/04 11:59 AM
. * * Re: Taming Tiger, Part 1 sud   09/22/05 06:06 AM
. * * Re: Taming Tiger, Part 1 Anonymous   04/27/04 02:51 PM

Extra information
0 registered and 1 anonymous users are browsing this forum.

Moderator:   



Forum Permissions
      You cannot start new topics
      You cannot reply to topics
      HTML is disabled
      UBBCode is enabled

Rating:
Thread views: 11061

Rate this thread

Jump to

Contact us JavaWorld

Powered by UBB.threads™ 6.5.5