Deprecated: Function set_magic_quotes_runtime() is deprecated in /home/mwexler/public_html/tp/textpattern/lib/txplib_db.php on line 14
The Net Takeaway: Things I don't get about Java, Pt. I


Danny Flamberg's Blog
Danny has been marketing for a while, and his articles and work reflect great understanding of data driven marketing.

Eric Peterson the Demystifier
Eric gets metrics, analytics, interactive, and the real world. His advice is worth taking...

Geeking with Greg
Greg Linden created Amazon's recommendation system, so imagine what can write about...

Ned Batchelder's Blog
Ned just finds and writes interesting things. I don't know how he does it.

R at LoyaltyMatrix
Jim Porzak tells of his real-life use of R for marketing analysis.







Things I don't get about Java, Pt. I · 03/28/2004 05:04 PM, Tech

For example, the classic is the car.

auto mycar = new auto;

We expect this to change the state of the car. But now…
is a method nominally acting on the car but in reality leaves the car alone and changes everything else around it.

Ok, don’t like that? Try this one from the Java NIO library:
(Using examples from Java Developers Journal, Feb 2004, Page 43-48,
It makes sense that buffer.put(data) copies data into the buffer. We are acting on the buffer, and putting into it. “data” is not touched, its just a parameter.

Oh, wait, that’s wrong. buffer.get(data); goes the other way. Now, buffer is untouched, and data is overwritten. Now, silly me, wouldn’t it make sense for use to see data=buffer.get? Sure, not consistent for put vs. get, but clear how they act.

So, basically, you have an object, you call a method on it, that method may or may not change the object, may or may not change the parameter, and may or may not return anything of value for use in assignment. Flexible, or just inconsistent… you make the call.

You know, back in the bad old days of basic, things changed when you assigned new values to them. It was clear what was changing, who was changing it, and what was driving it. In this new version, you have to be a mind reader to understand what is being changed by a statement.

* * *


  1. In your NIO example, buffer.get(data) modifies the buffer by advancing its current position. The data specified is a pre-allocated byte array, which makes sense and gives the program control over how much data should be dealt with at any one time. You don’t have to be a mind-reader to figure that one out, just read the JavaDoc.

    Your beef is not with Java. Most programming libraries provide these same constructs.
    ian    Mar 29, 12:31 AM    #

  2. Hmm… So you are saying that buffer does change (well, not really, the pointer “curpos” changes, but semantics), which is ok, but not really the point.

    My concern is simple: Methods should act upon the objects they are attached to. They should not rampantly change other things as well.

    Simply stating it in the javadoc doesn’t make it right, imho.
    Michael Wexler    Mar 29, 09:56 AM    #

  Textile Help
Please note that your email will be obfuscated via entities, so its ok to put a real one if you feel like it...

powered by Textpattern 4.0.4 (r1956)