musings on java and object oriented software development

Tuesday, August 28, 2007

Implicit declaration / short instance creation in Java 7

So today I'm reading Alex Miller's blog about proposed features of Java 7. I noticed something he refers to as "Short instance creation" and has a few links to other bloggers. I then notice some of the dates on the linked blogs, some in 2006, some in 2007.

I'm thinking "hang on, didn't I post something, somewhere, about this ages ago?".

So I googled for "implicit declaration java distiller" and, sure enough, I'd posted to a Sun forum about new language features in October 2004. 2004 !

I'm not suggesting that I was the first to ever write this, but way back on October 7 2004 I posted to that forum about the ":=" syntax and got shot down from folks who thought the world would end if such evilness was ever brought into the language. I honestly hadn't seen that syntax or read about the concept anywhere before that, but I'd implemented it in the now defunct project UCL (Universal Class Language) about 5 or 6 years ago.

Even James Gosling is suggesting it !

I still think it is good idea.


PowerBook narcolepsy - Part II

My sincere apologies to those who have posted comments on this issue and I've not published them. I hadn't received any comments because I think when blogger changed their account management to be part of the Google framework, they forced people to re associate their accounts with the blogs. In the mean time, no comments go through to my gmail account. I hadn't logged in for a while and only noticed this today.

Anyway, I've been away from this blog for a while and have been running my PBook for almost 10 months now and it is has not spontaneously caught on fire !

The rough guide ( this was back in October 2006 so my memory is a little hazy):

The crucial bit is in the xnu source, in
iokit/Kernel/IOPMrootDomain.cpp look for the "emergency overtemp signal" line.

I just commented out the sleepSystem() call, though in theory you could write something better to deal with it.

You'll need to get : [ this list is probably a little out of date, I'm currently running 10.4.10 but still with the patched kernel ]


from the apple opensource site and build the kernel corresponding to
Apples instructions (which may not fully work for you).

You'll need to tell the boot loader to use the new kernel, so you'll have to do something like this (this differs per system)

nvram boot-file="pci2/ata-6@D/@0:3,mach_kernel_10_4_8"

You can get this figure by typing

nvram boot-device

and using the bit before the comma, e.g. mine says pci2/ata-6@D/@0:3,\\:tbxi


Thursday, October 19, 2006

PowerBook narcolepsy issue hack

A few months ago, when doing some photo editing, I noticed that my 1-year-old PowerBook G4 1.67 was a bit sluggish. So I had a look at the available RAM on the machine and sure enough the maximum RAM reported was 512MB, rather than the 1GB that I had installed. I had a look at the memory slots in the System Profiler and one of the memory banks indicated that it was empty.

After a bit of research I found that this was a fairly common problem and Apple were repairing the problem free of charge. So I sent it to a local shop and got it fixed. ( The fix, it turns out, is to replace the Logic Board).

About a week later, my laptop suddenly went to sleep with out warning. It would wake, when you hit the keys, then go back to sleep soon after. Eventually the only way to get it awake was to pull out the battery and power cord. After this cold reboot (which was irritating because you had to reset the clock all the time), it would work fine for an hour or so then the pattern would repeat it self.

I searched about the issue and found that it is a problem with the Trackpad temperature sensor on the PowerBook. The sensor would sporadically display 100+ degrees C, causing the system to think it will melt if it doesn't shut down. The system.log will show a message "Power Management received emergency overtemp signal." prior to it going to sleep.

Very frusted, I searched on the net and tried various remedies which involved removing Kernel Extensions that monitor the temperature of the trackpad. I don't think these extensions actually stop anything, just allow third-party apps to read the temperature sensors, because the fixes didn't make any difference.

After trying all of the fixes, I thought I'd take matters into my own hands (a hardware repair was out of the question because the laptop is out of warranty), so I downloaded the mach kernel source, found the block of code that sleeps after displaying the "emergency overtemp signal" message and commented it out. After rebuilding the kernel, I pointed Open Firmware to the new kernel and rebooted.

I wouldn't recommend anybody doing this because it is potentially very dangerous!. You might ignore real overtemp signals, your PowerBook could catch on fire!

Several minutes after the restart I got the dreaded "emergency overtemp signal" message twice within seconds of each other, while watching the temperature of the trackpad with the very handy app "Temperature Monitor". Because I had commented out the sleep code, the system did not sleep. The temperature of the trackpad temporarily went to 102.5 C, then back to a cool 37 C.

Problem solved ! In future I will change the code so that it is safer, i.e. keep a history of the fluctuation so that random 100+ degress C temperatures can be put in some perspective and only ignoring overtemp signals coming from the Trackpad.

Thursday, September 14, 2006

Taxophobia: the fear of class-ification

My workplace is being overrun by taxophobics or classphobics - those who believe it to be expensive to create new classes, they fear refactoring and would rather stick all their methods in one, gigantic, manager class.

A taxophobic would rather have a single class with 5 similar sounding methods than 5 classes sharing a common interface with one method in it.

A taxophobic believes that there is some inherit cost in creating new files; they're self appointed byte-conservationists.

Taxophobics will try to convince you of their infantile designs based on an argument of "pragmatism". "Refactoring" is a dirty word. They love static methods and they hate unit-testing.

I've been facing an uphill battle trying to convince these people that that doing something like this :


would be much better replaced with something more generic :

for(Validator v : validators){

But you know what ? I realised that you can't argue with these people because they have no sense of style. They've got no hope either because you can't be taught style.

My belief is that you can't have style forced on you, you've got to come to your own enlightenment, your own epiphany, though I hope I'm wrong.

Wednesday, September 13, 2006

Apple pricing anomaly

I'm living in London at the moment and I'm considering a trip to New York for some christmas shopping. I want to buy a SLR lens for my Nikon plus some Christmas presents for myself/wife and others.

I've got 3 Apple things on my shopping list. A 80gb iPod and iMac 24" for myself and a 15" MacBook Pro for my mother who lives in Australia.

So I did some pricing comparisons between the 3, taking into account current exchange rates, £/$US of 1.87 plus NYC sales tax of 8.375% and £/$AU of 2.49.

Below is a table, all prices are converted to £ sterling :

80gb ipod202259200
mbp 2.16 1gb144816991606
mbp 2.0 0.5 gb115813991284
24" iMac 2.16 1gb 250gb15813491204
pimped 24" iMac 2.33 *163318991718

(* 2.33Ghz, 2GB RAM, 500GB HDD, 256MB graphics, Wireless keyboard / mouse )

Two things stood out above. Firstly the UK iPod is almost 30% more expensive than US or AU cost. Secondly, yes it is cheaper to buy in the US compared to Australia, but it isn't as much as I had thought ( around 10% ). (Why it would be 10% is another matter since Australia is a very close to Thailand or Shanghai where some products Apple are assembled).


Friday, June 30, 2006

How is your Google-print ?

When I meet somebody new at work, I often google them to get a feel for their "google-print" (I think I just made this term up!), their online presence.

How well they "score" depends on a lot of things. Having a common name obviously doesn't help. Posting on mailing lists makes a big difference. Sharing a name with somebody famous is not going help your cause. People involved in IT have a bit of advantage because they will often post to mailing-lists/news groups.

Being a bit vain, I occasionally google my self to see how I'm scoring. I used to be about more than 70% of the first 3 pages, but this has gone down recently. I suspect Google has tweaked their algorithms for removing duplicate identities from these sorts of searches.

So, I'm possibly doing some contract work with somebody who, according to the company website, seems to have a really impressive CV. So I google him and don't come up with much at all. Is it because he has a common name (not really) or is it because he doesn't "get out" on the 'net much ?

Proceed with caution I suspect !

Friday, May 26, 2006

Choice is not the problem with Java

Much has been said recently in the Java world about the problems with Java, particularly the problem with choice.

In Java Succumbing to .NET in my Organization
Neil Chaudhuri says that there are two many frameworks, too many IDEs, too many app servers etc. and that is why his organization is moving to .NET. According to Neil choice is a bad thing.

His answer, at least to the IDE "problem", is more standardization, but I believe the source of the standard must come from something that already works, a de-facto standard not a committee standard.

The problem with Java is not choice, but rather that the early standards were created by committee and Sun's "Not invented here" mentality.

Take, for example, EJB.

EJB 1.0/.1 was a fairly pitiful effort. Just horrid, like they gave the job of designing it to an intern. All sorts of (anti-)patterns were born out of 1.1.

EJB 2.0 is a classic example of something born from committee. It mostly did what you wanted to do, but the extra 10% was hard and messy. It promised so much, yet did not deliver and people turned to alternate persistence mechanisms such as Hibernate.

Now with EJB 3.0, Sun has done the right thing; taken something (Hibernate) that works, that people like and makes them productive and turned it into a standard. Yet, they still try to re-invent the wheel with respect to Dependency Injection.

Another example of this is JSF. They formed a committee to define a new web framework, cocked it up and now are already up to 1.2 of the specification. (It probably didn't help that they had the creator of the worst web framework of all, Struts, on the committee).
Why couldn't they have taken something like Tapestry and made it a standard ?

The underlying problem is that Sun have had a real "Not invented here" mentality. They realised a while ago that they couldn't implement anything that was usable (e.g. AWT, then early Swing) so that they started going specification mad. Yet they failed to realise that writing specifications is really hard, harder in fact than writing an implementation.

What should they have been doing all along ? Adopting open-source projects that are de-facto standards and making them into official standards.


Thursday, May 25, 2006

Google Web Toolkit Angst

I've been using Google Web Toolkit for the last week or so. I'm really liking it, it is really productive and once you getting it working everything is sweet.

The problem is, getting it working is kinda hard, particularly if you want to use Eclipse. I struggled for a day or so to create my own project from scratch but gave up and just copied the DynaTable example and changed a few things. All this is because GWT has these unwritten conventions for stuff that is almost impossible to figure out without days of trial and error.

GWT tries to be all Rails like with "Convention over configuration", which is fine, if you can find out what the convention is.

Another thing that is annoying is the self-righteousness of the tools :

c:\dev\gwt-windows-1.0.20>junitCreator -junit c:\dev\eclipse\plugins\org.junit_3.8.1\junit.jar -eclipse project -out c:\dev\workspace\project com.xyz.project.DataImportViewTest 'com.xyz.project.DataImportViewTest': Please use 'test' as the final package, as in 'com.example.foo.test.MyTest'. It isn't technically necessary, but this tool enforces the best practice.
Google Web Toolkit 1.0.20

Whose best practice are they referring to? I hate the term "Best Practice" - it implies that the currently accepted best way of doing something is the final say on the topic, so don't even bother trying to think of something better. It is arrogant and is like saying "trust us, we are bigger and better than you, go away and leave the real thinking to us".

Anyway, I had thought that this ".test" package style had gone out of favour a long time ago, but it doesn't matter really whether it is best practice or not, what is with the arbitrary conventions ?

I'm sure (and hope) , over time Google will listen to the criticism and make GWT better. It is very good at the moment, but I think it is probably only about 95% there. Another 5% with Maven, Eclipse integration and more configuration options (with sensible defaults ) will truly make it rock !