Women in Technology

Hear us Roar

  Technologies to Watch: A Look at Four That May Challenge Java’s Development Dominance
Subject:   Not the best Java code example
Date:   2005-10-29 08:37:52
From:   ttfkam
class Fib {

// It's "String[]" not "args[]"
public static void main (String[] args) {

// Variable declarations on a single line
int x1 = 0, x2 = 1;

// For-loop syntax is hard to grasp?
// I guess the hardest thing is to remember
// to count from zero.
for (int i=0; i<10; i++) {

// More on System.out later

// Temp variables should be local scope
int total = x1 + x2;

// Single line version
x1 = x2; x2 = total;

Now on to the critique of Ruby.

Ruby: x1, x2 = 0, 1
Java: int x1 = 0, x2 = 1;

Good for two variables. What happens when you have ten? How easy is it to keep straight? I think my Java example is easier to keep clear in this case.

puts x2

I've heard the argument that System.out.println is too long and verbose. I don't buy it. For simplicity, one could write:

PrintStream o = System out;

Once that is specified in your object, you can write:


Of course, writing a line of text might not be your aim, so with Java there are other options:

o.print(...) // no end-of-line character
o.append(...) // appending characters to stream
o.format(...) // formatted output
o.write(...) // writing raw bytes

There's also "System.err" for standard err, the PrintStream that you specify as a redirection to a file, or (my favorite) the OutputStream that is specified dynamically and independent of your section of code.

Ruby: x1, x2 = x2, x1+x2

Yes, I acknowledge you need to specify a temp variable here for Java. Point taken.

On a side note, if the primary goal of Ruby is to reduce the amount of code while improving readability, why include the extraneous do-end? Why didn't Ruby use Python's ommision of do-end in favor of indentation? I think Python's the winner here.

Which brings me to an important point. Let's take Plone in Python as an example of rapid development. Plone -- and Zope by inference -- is an amazing piece of code. It is incredible to me that so little code relatively speaking could do so much. On the other hand, Plone introduced me to what I consider the fundamental flaw in so-called dynamic languages: lack of clear interfaces.

Some have called it a strength that you do not have to be restricted by an interface set in stone. It is however what I consider to be the single greatest reason why Plone is excellent while almost every public extension to Plone is a steaming pile of ad-hoc crap. Dynamic languages as a foundation is like building on sand or mud.

Don't get me wrong. I like scripting languages. I use them extensively; However, I use them for small projects or "the last mile." Sand or mud makes the last step very quick, agile, and complete. But it's a horrible foundation for a large building. Sometimes you need things to be set in stone.

It's all about the right tool for the right job.

Full Threads Oldest First

Showing messages 1 through 3 of 3.

  • Not the best Java code example
    2005-11-21 07:06:57  JendaPerl [View]

    I think you are missing something. The multiple variable assignment is not that handy if you just need to assign two constants to two variables. You are right you could write it as two assignments and it would actually be more readable. The beauty of the multivar assignment comes when there are functions (or methods if you insist) involved. Suppose you need to return two integers from a function. Isn't it better to write

    min, max = find_supremes list

    than to either return an array:

    int []arr = find_supremes(list);
    int min = arr[0];
    int max = arr[1];

    or pass the variables by reference?

    Also suppose you need to switch the contents of two variables. Isn't

    x, y = y, x

    (or in the "oh-so-unreadable" Perl syntax ($x, $y) = ($y, $x);)

    easier to read than

    guessWhatType tmp = x;
    x = y;
    y = tmp;

    • Java as an "important standard"
      2006-01-17 11:39:19  AdrienLamothe [View]

      Mr. Tate states that "Java has been an outstanding development language for the industry because it's brought a remarkable unity and attention to important standards where practically none existed before."

      I'm not sure which standards he is referring to, but Java is nothing more than a de-facto standard, of sorts. When Sun approached ISO to approve Java as a certified international standard, they didn't get very far. The reason? ISO will not approve a programming language that is controlled by only one company. Sun can decide to change the Java specification anytime they want, for any reason. They can change the terms under which Java can be used. This is unacceptable for an international standard.

      C++ is much maligned, but virtually all major
      commercial software is developed in C++. Mr. Tate's
      emphasis seems to be web development, a domain
      where dynamic languages are more appropriate
      and where Java use is widespread.

      - Adrien Lamothe
    • Not the best Java code example
      2005-11-21 07:51:18  ikayak [View]

      Good point on || assignments. The most common improvement for me is saving the use of a temp variable, such as your x, y = y, x