Wednesday, October 1, 2008

Two Days In A Life

The ban that Israel's government has put on The Beatles performance in the 60s disappointed not only Israelis, but many Jewish people who were part of The Beatles phenomena, like their legendary manager Brian Epstein. Over four decades later, Paul McCartney represented the Fab Four on stage in Park HaYarkon, Tel Aviv, and rocked the audience with a great show.


Negotiations for the concert have been tough, but after a series of rumors and denials the deal was finally set. Ticket offices were stormed on opening, 50,000 tickets were sold eventually, filling the park with fans and music lovers.

Read more in this illustrated account of Paul McCartney's visit to the Holy Land...


Tuesday, September 30, 2008

Beware of the subs

No, I don't mean these cute yellow things beneath the waves. I am going to talk about List#subList and String#substring methods in Java.

Apparently many people are unaware of what exactly these methods do. Unfortunately their ignorance may lead to unpleasant consequences. So getting straight to the point: both methods do not copy a portion of the original data, instead they create a view, or, in other words, a proxy to it. The important thing is that the new wrapper object holds a strong reference to the original object.

The Javadoc of subList at least admits that it's a view, as for substring, the only way to find out is by looking at the source - the method redirects to this constructor:

//Package private constructor which shares value array for speed.
String(int offset, int count, char value[]) {
this.value = value;
this.offset = offset;
this.count = count;
}
So what's the problem? Let's look at the following snippet from a real code-base:
List leaky = ...; //long list of big & hairy objects
leaky = leaky.subList(from, to);
Assuming that leaky wasn't referenced anywhere else in the code, there is no way for the programmer to access the elements that lie beyond the (from,to) range. But these bytes aint going to rehab, no, no, no - as far as JVM is concerned they are still strongly referenced. So if you really mean to extract a portion of a list (or string), and throw the rest away - copy it manually to a new list (or string). For example:
List sneaky = ...;
sneaky = new ArrayList(sneaky.subList(from, to));
Is there any better way a "sub" could be implemented? Well, maybe the reference to the original data could be kept weak, and only when (if) the original object is enqueued for garbage collection then the data could be copied into the "view". This would require backwards references from "original" object to "views", which would also need to be weak, so... overall this doesn't seem worth the effort, and hence avoiding leaky lists and strings shall remain the responsibility of the programmer.

Speaking of subList, another nasty thing about it is that sub-list is not Serializable, nor Cloneable or anything like that, even if the original list was. And speaking of leaky things that are caused by undercover strong references - never forget non-static inner classes that refer to their enclosing instance.

Take care, and keep your head above the water :-)

Friday, July 4, 2008

Software: Live and Let Die

This week I was lucky to attend Gilad Bracha's guest lecture on Networked Serviced Programming at the Hebrew University. He has been talking about Service Objects for some time now, but nothing compares to hearing it live - Gilad's presentation was witty and fun!

So here is my interpretation and some take-aways.

What's the problem with software? It is too damn complex. Projects crumble under their own weight. It happens to successful projects - our dearly loved Java, for example. Also look at Vista, if you dare. And it's certainly true for the monster-size projects I used to work on. Once upon a time our team took the corporate "quality improvement" policy seriously and decided to investigate what causes bugs in our multi-million lines of code project. We collected all sorts of statistics and ran all possible metrics (which was tricky 'cause some of the tools would choke on such a huge code-base) but long story short our finding was this: the only metric that correlated clearly with defectiveness was LoC. It is hardly news, but a cure to the disease has yet to be found.

There are certainly several things to be done, but what this talk focused on is getting rid of code which shouldn't be there, or in other words - dumping unused code and backwards compatibility. The way we work today - we are bound to not just specs and APIs, but to all the accidental behaviors and bugs in the previous version of our code. It seems that Gilad views code as if it was a live organism. Staying alive means being connected (and network plays a central role in his vision), but we should make way for evolution and some code should die - Gilad calls it "bit rot".

So how do we turn software into a healthy living organism? According to Gilad, there are several things to be done on the technical front first.

  • Take advantage of the network: maintain a bi-directional connection with the control center - let programs pull upgrades from the net, but also send back operation statistics. This means that programming platform has to be aware of the network, and aware of the fallacies of distributed computing. This is cloud computing utopia: Internet as a platform, browser as an OS, and Javascript as the low-level programming language into which other languages can compile (in a GWT kind a way).
  • Modularity: it should be possible to extend and replace individual objects without interference to the whole organism. Gilad has a well developed theory about how modularity should be done in a programming language, based on principles of object-orientation using mix-ins, nested classes and inheritance hierarchies; his new language, Newspeak, is going to implement it.
  • Explicit Dependencies between modules - no static, no imports, modules are truely independent and dependency management (wiring) is performed by passing other module instances as parameters to module constructors. This allows to maintain clear boundaries between modules and flexibility in module composition.
  • Frequent Updates: to allow the "clients" of the object APIs to deal with changes, in addition to maintaining modularity, the changes should be made small and frequent. Call it agility, if you like. That means that we can't afford reboots, and we need to find out when the system is quiescent so that upgrade can be performed, which brings us to the next point...
  • Reflection and Hot-swapping: objects should allow other objects to find out both static and run-time information about them without breaking the encapsulation. Objects should also allow other objects to modify them "live". Gilad and his team at Cadence are building the support for these features in Newspeak using Mirrors, a concept that originates in Self programming language. It's worth noting that there exist dynamically typed languages that implement hot-swapping today - Erlang being one of them.
  • Security is important in any distributed system, and even more so if we allow remote objects to mess with the program. So in addition to dynamic typing and pointer safety, Gilad proposes mirrors to be guarded by capability-based security, similar to the one in E programming language.
  • Synchronization: many programs need to work with persistent data and it is important to keep the program and the data in-sync. Gilad proposes orthogonal synchronization, based on Smalltalk orthogonal persistence idea, where objects are split into transient and persistent ones by marking object tree roots accordingly. Persistent objects are upgraded whenever the corresponding part of the program is upgraded, and transient objects are lazily recomputed. If the data is ever to outlive the service, it would be exported into some generic format, such as XML.
  • The most extreme and bold part of this vision is probably No Versions and No Releases - there would be only one version for every program out there. Gilad sees software becoming more of a service than a product, but in order for this to realize we'll have to overcome not just technological, but also psychological and economical barriers - we will have to change the way we develop software and the way we make money of it.
Bottom line, all this may sound too futuristic, but "software as a service" and "platform as a service" are making their way in the industry and this wave, if strong and successful enough, may bring the significant change Gilad is predicting.

P.S. As for the rest of us, living in the JVM world, some of the ideas ring a bell. We hope that modularity JSRs and OSGi will improve Java. Those of us who survived Ant and Maven, and felt the weight of a DI framework, will probably appreciate the amount attention Gilad is putting into software composition. It's worth noting the attempts to address hot-swapping on JVM, such as JavaRebel and Jonas Boner's experiments with Scala Actors and Terracotta. Terracotta server also utilizes some ideas which (in my mind at least) look quite similar to the orthogonal synchronization scheme.

Wednesday, June 25, 2008

JunkedIn

Indeed LinkedIn runs on Java, no doubt about it:

Tuesday, June 17, 2008

Noble cause

Duchess is an on-line community of female Java developers with members from all over the world, but currently active mainly in the Netherlands. I figured they could use some promotion, besides it's a perfect excuse to put this cute mascot on my blog:

Thursday, June 5, 2008

Typesy Turvy

Lambda The Ultimate feed just notified me that types are considered harmful. Ah yes, I heard this before, so what's the news? The news is that it's not Stevey vs. Cedric or anything like that, this is Benjamin C. Pierce in his own write. Benjamin C. Pierce, from "Types and Programming Languages" and "Advanced Types and Programming Languages", King of ML, Lord of the Functional Programming Commonwealth, Defender of Type Systems Faith!

Nice presentation, BTW. I think it's one of these situations when a big shot computer scientist is confronted with a real life problem. So you say the language is perfect for writing a compiler - good for you. How about a database application with a web front-end?


(click to see full-size)

Mr. Language Designer, where are you in this picture? Yes you, who designed the mousetrap which "the bug" has safely escaped from. Now it is here, so are you at least by the developer side, handing him something heavy to throw at "the bug", or are you on the bed with the rest of the crowd going "ah ah ah, what do they teach computer science graduates these days..."?

One thing that impressed me during otherwise boring (let me just read you aloud the tutorial) JRuby on Rails preso I recently attended - here is a system that tries to serve the needs of the developer. Not server vendor, not language designer, not JSR politician, not some brandthirsty marketing person or buzz-oriented architect, THE DEVELOPER. I am not used to that. So all I have to say - programmers of the world, unite! Stand for your rights! We deserve better tools, because we are the ones getting the job done.

Thank you for reading.

Thursday, May 15, 2008

In whining there is truth?

What do Java developers want? Hard to say. But here is what Java bloggers don't want Sun to do:
No evolving Java syntax - no properties, no closures, etc. - fix what is already there first.
No extending Java capabilities via annotations.
No investing in a new JVM language (JavaFX, or JRuby in the past)
Ok, maybe add Groovy, but don't change JVM spec.
Hey, wait, why are key people leaving Sun? We didn't want that either!

Tuesday, May 13, 2008

Girl Power

I have been reading recently that women are abandoning computer science, and that percentage of women in our profession is not just low, but getting lower. I'm not sure actually that the situation here is as bad as in North America, but it's certainly true that software engineering and computer science are not very popular among women. Why? To be honest, I don't have the answer.

Here is what comes to mind:

  • Geek-ness is viewed in the society as the opposite of being attractive; this is much more important for young women, than for men. For a guy - a nice high-tech salary will provide the attraction instead.
  • Sitting in a cube by the computer all day and doing one thing, coding, is probably not very attractive for most people, but for women especially, since most of us are better at performing a variety of tasks and interacting with people - I mean there has to be an explanation why "secretary" or "teacher" are such typical women professions.
  • Hi-tech jobs are very demanding, too demanding. For most women family life is at least as important as professional life, and usually family comes first. But there just aren't many positions you can find after getting computer science degree that allow you easily balance work and family life.
  • Hi-tech is for young people - look around, how many programmers you know are over 45? Why? For the same reason you don't see many women - it's hard to compete with the smart kids when you are pregnant, or haven't slept for a week, or worried about some family matter.
  • But can't we just switch roles with the husband? well, go back to first bullet, double standards of the society certainly don't make it easier on us or our partners.
  • People we are surrounded with (nerdy young men mostly) are pretty anti-social creatures in the first place, even more so with species of the other sex, even more so with the ones that don't fit social stereotype.
  • Now suppose you survived all the obstacles, because you passionately love science and engineering. Did you watch the knack? There's a grain of truth there... society became less tolerant of weirdness, and people who 100 years ago may have been referred to as crazy geniuses nowadays live "normal life" on prescribed medications. And for a girl it's even stranger to be a crazy genius then for a boy.
  • Male domination in the field - yes, it's chicken and egg problem. The field will change only if there will be enough women in it to drive the change from within and help other women. So I will devote the rest of the post to the ones who made it.
Lady Ada (Byron) Lovelace


She was more of a technical writer really, but she was a visionary.

Admiral Grace Hopper


The inventor of COBOL and debugging.

Professor Barbara Liskov


The one from the substitution principle. I chose her among several prominent computer scientist women because she was the first female computer science Ph.D in the US.

SVP Jayshree Ullal


I originally thought to put the Google princess here, but having personally met Jayshree (she was my manager's manager's manager at one point) and impressed by her personality and professionalism (she is so clever, and yet such nice and humble person), I decided she's a better candidate to represent successful women in computer industry.

Alice, Dilbert's workaholic colleague

What did she achieve exactly? Surviving in the office should not be underestimated! So I am going to honor another ex-colleague, although we never met, for providing inspiration for a character I can identify with :-)

Keep coding girls!

Net, Goddess of Wisdom

No, it's not a joke or some kind of wordplay.


Net (also Neith) was an ancient Egyptian goddess, not very well known perhaps, unlike her Hellenistic reincarnation - Athena. Net was a warrior goddess, just like Athena, and the goddess of weaving - "weaver" is actually the translation of her name.

Athena was a weaver too, according to the Arachne myth, and of course the goddess of wisdom.

So why weaving, or net, and wisdom? Well, for several reasons. What our ancient ancestors have probably recognized is that wisdom is acquired via communication. Today we know in addition that human thinking is powered by neural net in our brains. Net, yes net. We even use the same word. Internet, collective intelligence... "there's nothing new under the sun" said another wise ancient man.

Wednesday, April 30, 2008

Synthetic bridge method annotations

Update regarding "walls and bridges": Sun has kindly opened an enhancement request on my behalf for the issue. Please vote if you are affected by it too.

Monday, April 28, 2008

Java properties links

Since I am trying to keep up to date with what's going on in "Java Properties" land, I started with Alex Miller's collection and have been adding things that I find either relevant or influential. Another idea I nicked from Alex was to put them on Tumblog.

A disclaimer: this is a personal collection, so if something looks irrelevant, it means that I think it is influential :-)

I'll be more than glad to hear suggestions for more links or feeds.

Sunday, April 27, 2008

My OO My

No, I don't mean the song, but it's to do with Scandinavia. Mads Torgersen mentioned this during interview with Joe Armstrong (highly recommended, there is also a part II), and later I saw another reference in a paper: apparently there is "Scandinavian school of object orientation", sometimes compared to "American school".

Here are some insights on the difference between the two. The point is that the former is about concepts and philosophy, and the latter is about pragmatic aspects like software reuse and organization. I am not gonna pretend that I'm smart - all I know about it comes from searching Google, so you can go there and find out for yourself.

* On a side note, since I am linking to MSDN here, I want to say that even though my last post wasn't very favorable to Microsoft, to be fair - the company plays an important role in renaissance and democratization of functional programming (LINQ, F#, etc.), with guys like Mads Torgersen and Erik Meijer largely responsible.