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-11-21 07:06:57
From:   JendaPerl
Response to: Not the best Java code example

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;


Full Threads Oldest First

Showing messages 1 through 2 of 2.

  • 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