Monday, January 22, 2007

Ruby Screenshot of the Week #2

WARNING: This blog entry was imported from my old blog on blogs.sun.com (which used different blogging software), so formatting and links may not be correct.


Here:






Here are some things to notice:


  • NetBeans knows you're creating a method definition for a class, so it only
    shows method matches that are inherited from the superclass. In this case,
    we're inheriting from Integer and there are two method matches that start with "ab" - one from
    Numeric and one from Object.
  • It shows documentation for the method, based on the rdoc
  • It shows where each method is coming from
  • It's dealing with moderately broken source


Saturday, January 20, 2007

Live Centennial!

WARNING: This blog entry was imported from my old blog on blogs.sun.com (which used different blogging software), so formatting and links may not be correct.


On Monday night we're going to record our 100th episode of the Java Posse. To mark the occasion we're going to do it live at Google's headquarters in Mountain View. If you're a listener please join us - Monday night at 6:15pm. More details in the shownotes for episode 99½ - here.



Also, we have the upcoming unconference in Colorado - the Java Posse Roundup 2007, March 6-9, co-hosted by Bruce Eckel. Sign up now, it's going to be a blast!







Thursday, January 11, 2007

Ruby Screenshot of the Week

WARNING: This blog entry was imported from my old blog on blogs.sun.com (which used different blogging software), so formatting and links may not be correct.


If you've listened to the latest Java Posse episode (#99, around 56 minutes into the podcast) you heard me getting caught red handed, coding in the background while we were recording. Joe pressed me to state exactly what I was working on: Code completion within Ruby require and load statements in NetBeans. Here's a screenshot:






This will hopefully be available soon...


Saturday, January 6, 2007

Me-me

WARNING: This blog entry was imported from my old blog on blogs.sun.com (which used different blogging software), so formatting and links may not be correct.


The "5 Things Meme" is working its way around the internet, with people writing 5 things about themselves and then passing the baton to 5 others. Yep, exponential growth. I've been really busy with personal life recently but I'd better get this done before there's no-one left to tag! I've already been tagged by three different people (thanks
Alexis, David and
Todd)
so I guess the signs of congestion are already becoming apparent!



It's hard for me to write 5 things that you don't know about me, because I know many of my readers listen to the Java Posse, and we frequently talk about our personal lives and our past there. You already know about my Dragon 32, Commodore 128 and Amiga 500 days, as well as my kids and hobbies like paragliding.
Anyway, I think the following list should hopefully be new and entertaining:


  1. When I was 18, I came to the USA as an exchange student in high school in Kansas.
    I joined the cross country running team, and the first week of school they had
    a rally during a football game where the new team was introduced. The coach (who
    was also a wrestling coach) introduced me to the home crowd as an exchange student
    from Sweden! (If you're not a regular reader, I'm from Norway). Well, we have this
    little national tiff between Norway and Sweden, telling "Swedish jokes" the way Americans
    used to have Polack jokes. So, I promptly took one step forward, and proceeded to greet
    the coach with the middle finger!


    Yes, looking back at it, and having been immersed by American culture for the
    last sixteen (oh my, has it really been that long?) years, it sounds shocking to me
    that I'd do it, but hey, it was high school, it was impulsive, and meant as a joke.



    Suffice it to say, the coach did not find this funny. I don't think Kansas wrestling coaches
    are the most receptive audience for such a greeting anyway, especially on home turf with
    the yearbook photographers standing by!



    I convinced the coach that I was truly sorry and had not meant offense, and we patched up
    through the season. But at the end of the year, on the last running practice, the coaches
    had arranged a treasure hunt - we ran around the town, looking for clues and finding little
    gifts. My gift from the coach was a cutout of a hand, with the middle finger cut off at the
    middle, blood painted on, and the inscription "If you ever do that again..." !



  2. In high school they opened a local radio station in my home town. I immediately joined,
    and had a lot of fun as a D.J., playing my favorite records, having callers call in and
    asking them questions from quiz books, etc. I also occasionally ran the "reruns" of the
    news episodes. One Saturday I came in, turned on the antenna, and started the most recent
    rerun tape. I then pulled out my homework and started working on it. However, listening
    to news while doing calculus is not easy, so as I so frequently did, I turned on a record
    and turned down the volume of the live feed channel. It was actually Woodpeckers from Space
    if I recall correctly! However, this time I had apparently
    pulled the wrong control, because after 15 minutes, a friend of mine called the radio station
    and told me something was horribly wrong - there was disco music playing on top of the
    interview and nothing was legible! Ooops.



  3. I ran track as well. I was not good at it - though I did get a couple of regional titles.
    One time, when I had travelled 4 hours away to an indoor track meet, one of the local
    runners (who I knew was one of the best junior runners in Norway) came over and asked me
    out of the blue (and as if he knew me) if I had been training much this winter. I said
    something to the effect of "yeah, twice a week or so" to which he had a long good laugh. He
    then told me he was bitter I had beaten him by 2/100s of a second in Japan the previous
    fall! What was going on? It turns out I looked a LOT like another runner in Norway,
    Vebjørn Rodal, who later went on to win the 800 meter dash in the Olympics in Atlanta '96.
    At this time he was still a junior, but a top runner. Later that spring, I was running a race
    in Oppdal, near his hometown, and he was present. When I ran the 800m dash, my coach
    had been standing next to Vebjørn's coach, and his coach had said "I thought I had
    told Vebjørn not to run this one!". I wish I had pictures of him and myself at that
    age so you could be the judge yourself. Instead I'll give you a couple of pictures of him
    later; I think the similarity is still there but obviously not as much. Those of you who
    know me can be the judge:









  4. In 2000, I was in Norway for the summer when Bill Clinton was visiting the country.
    One night my ex wife and I went out on the town, and walked by a restaurant with a crowd
    outside of it. In the window we saw Bill Clinton and a group of people having dinner in an
    otherwise empty restaurant. The were a number of guards in black suits hanging out by the door.
    We asked if the restaurant was open for business - which it was, so we went in! We had drinks
    at the bar (hey, this was an expensive restaurant!), and we were the only other people there!
    When they were about to leave we decided we had to say something, so my ex wife went up
    and after the introductions joked something along the lines of "Well, we're thinking of moving
    to Norway now that Al didn't make it". (This was right after Al Gore had lost(?) the election.)
    Bill Clinton came right back and said (and you've gotta read this with an Arkansas accent, especially
    the "fight" word), "No, you've gotta stay and fight. Stay and fight!".



  5. I started graduate school at the Stanford University computer science department at the same time
    that Larry Page (one of the two co-founders of Google) did. We took a number of the same classes,
    and we both hung out in the HCI group on Fridays since they had a number of interesting
    guest lecturers, research topics and discussion groups. We've both done well for ourselves, huh? (wink wink)






And now it's time to pass the baton. Since my fellow NetBeans and Creator engineers are already tagging each other, I'm going to try to branch it out in new directions: My brother and Sun Norway engineer (and OpenGrok developer)
Trond Norbye,
my fellow Java Posse members
Joe and
Dick,
and JRuby developers
Charles and
Tom.


Tuesday, January 2, 2007

Code Tip: Statically Check Multiple Interfaces

WARNING: This blog entry was imported from my old blog on blogs.sun.com (which used different blogging software), so formatting and links may not be correct.


You may think generics is all about avoiding casts in collections. However, I found a really good use for them the other day that's pretty useful.



Let's say you have a method which takes a List and does something with it.


void doSomething(List list) {
...
}

(In my code, it's actually List<String>, but I'm trying to keep other generics out of this to motivate those of you still needing a good reason to learn them.)



In my case, I needed to iterate over the list in reverse order. Uh oh, that's going to be pretty expensive for some types of lists, and if I switch my implementation to for example a LinkedList in the future, I'd like to revisit this. Obviously, I could make my method the following:


void doSomething(ArrayList list) {
...
}



However, using specific implementation classes rather than interfaces is frowned upon, and besides, this needlessly prevents the method from being used with other random access list. On the other hand, I would like to state in some way that this method really wants to be able to access the list elements in random order.



java.util.RandomAccess to the rescue. Lists that provide random access implement this interface. But what do I put in my method signature? RandomAccess is not itself a List. I really want to specify multiple constraints on my parameter.



This is precisely what generic methods allow! The following method declaration will accomplish what I want:


<T extends List & RandomAccess> void doSomething(T list) {
...
}



Here we're saying that my parameter T is a generic type, which satisfies multiple constraints: it both extends List and it implements RandomAccess! You can pass an ArrayList to the above method, but not a LinkedList!



Think hard about the constraints you add. In some cases, adding a RandomAccess constraint on a method is leaking implementation through to the client - it reveals something about the implementation behind the method signature that may change later. I find this most appropriate within implementation code.


Monday, December 11, 2006

Another NetBeans+Ruby Preview

WARNING: This blog entry was imported from my old blog on blogs.sun.com (which used different blogging software), so formatting and links may not be correct.


There have been several great releases lately, and I'm remiss in covering them. However, they've been covered in great detail elsewhere. First, NetBeans Visual Web Pack shipped on schedule, bringing Creator functionality to NetBeans, along with new support for Java EE 5. Second, Mustan... ^H^H^H^H Java SE 6 shipped today. It's a great release. The number one reason I install it whenever I get to a new system is that I need the improved font aliasing built into Java2D - and of course, the gray-rect-fix. However, there's another reason I crave the release even when I'm on OSX: @Override. Yes, @Override has been there since Java SE 5, but in Mus... Java SE 6, you can use it to indicate that a method should implement an interface method, not only a method inherited from a super class. (Which arguably @Override should have meant all along.) Now if only Apple could ship an update to its dated September pre-release...



Anyway, I have an excuse for being late to blog. In addition to some work on JSR 273 which is coming along nicely, I've been coding away to get more Ruby tools support for NetBeans.
Charles and Tom will be demoing JRuby 0.9.2 (which just shipped, congratulations!) at JavaPolis this week, and showing the NetBeans tooling in the process.



I thought I would share another screenshot with you at this point. This shows the new language embedding. Notice how there's Ruby inside string literals, rdoc tags inside comments, string escape codes highlighted specially, and so on.






This is all made possible by the new Lexer API in NetBeans. It's really nice to build on top of it; writing incremental
lexers is a snap. This is part of NetBeans 6. If you've been using recent milestones, you might have noticed that all our javadoc is highlighted in your Java files. This is not done through hacks in the Java lexer - it's done through embedded sections where the Java comment tokens are then sub-tokenized by a Javadoc lexer. It's not just done for javadoc - if you look at your String literals you'll notice the same String-sequence highlighting that I'm showing for Ruby above. It only changes the font to bold, so it's a bit subtle. Perhaps something we should tweak before the release.



In Charles' pre-review of the Ruby support,
he wrote some very nice things about me ("Tor Norbye is a programming machine", etc.) Thanks Charles! While it's nice to get all the credit, I really want to point out that this is all made possible
because of the tremendous work on the editing infrastructure for NetBeans 6, by a number of
great NetBeans engineers. Not just the Lexer, which I've described above, but all the other things I've relied on, such as the
infrastructure for semantic highlighting, asynchronous parser task scheduling, and so on. I would love
to give individual credit here, but I'm not sure exactly who to attribute all the work to, so I'd rather credit
all of you rather than snub anybody. Not to mention the fact that I have an excellent Ruby AST to work with, thanks to JRuby!



Several of you asked after my last screenshot where or when you can download the code for this. It will show up in NetBeans soon, but since the work started in closed source, I have to follow the established open-sourcing process. It's in progress, but I can't make specific predictions about when it will be done.

Tuesday, December 5, 2006

Posse Night

WARNING: This blog entry was imported from my old blog on blogs.sun.com (which used different blogging software), so formatting and links may not be correct.


We had a fun in-person recording session for the Java Posse last night over at Joe's house. This was hopefully the first of many to come, since Dick started working at Google yesterday, and is in the process of moving from Georgia to California. Since we're all swamped with work and life it was definitely an unprepared podcast, but we eventually got into some technical discussions. And we accumulated more clips for the outtakes reel.



Here's the crew, from right to left: Dick, Carl, Joe, me.






(Other sizes at Joe's flickr page).