Thursday, July 09, 2009

James Strachan: Scala is the new Java

I've been hearing about Scala for a while now, and have been contemplating digging into it a bit, trying to write some code and get an idea of its strengths and weaknesses.

I think James Strachan's blog post just put me over the edge.  I'm not sure when I'll find the time, but learning Scala has just moved high up on my "things to do to expand my knowledge" list.

What particularly kicked me into high gear was that James is the author of Groovy, from all I've heard an excellent language in its own right.  In his post he says I can honestly say if someone had shown me the Programming in Scala book by by Martin Odersky, Lex Spoon & Bill Venners back in 2003 I'd probably have never created Groovy.

Wow.  That's some statement.

James' salient points:

  • Scala has type inference - and that's a good thing: "it makes code comprehension, navigation & documentation much simpler"
  • Scala has high order functions and closures "so you can write beautifully concise code"
  • Scala has mixins (called "traits") "so you don't have to muck about with AOP wackiness to get nice modular code"
James summarizes "the beauty of Scala soon becomes apparent; its simplified so many of the gremlins in the Java language, allows you to write very concise code describing the intent behind the code rather than the implementation cruft - together with providing a nice migration path to elegant functional programming which is awesome for building concurrent or distributed software"

Time to get Odersky's book and give it a spin. 


Monday, June 29, 2009

Shut up and write those tests

One of the things I love about my new job is that this team is committed to the craft of software development, and is introducing me to Deep Testing.  I was pointed to this excellent book, Working Effectively with Legacy Code by Michael Feathers, and to this amazing little toolkit called Mockito.


Working Effectively with Legacy Code assumes a Test-Driven Development attitude and philosophy, and then tells you how to go into a hairball of existing code and get it to be testable.  Chapter titles include "I Can't Get This Class into a Test Harness" and "I Don't  Understand the Code Well Enough to Change It," and includes techniques for breaking that bugaboo of unit testing, hard-coded dependencies, like "Extract and Override Method Call," "Introduce Instance Delegator" and "Subclass and Override Method."  Excellent stuff.

Mockito is a mocking framework that is just insanely easy to use.  Here is a piece of code I wrote where the class to test had a large number of dependencies, and I just mocked out all but the relevant ones.  This took me about ten minutes to write, and it was an excellent way to test impact of the changes I was making:

Checkpointable mockCheckpointable = mock(Checkpointable.class);
CrawlerContent mockCrawlerContent = mock(CrawlerContent.class);
List crawlerItems = new ArrayList();
crawlerItems.add(mockCrawlerContent);

ContentStream mockContentStream = mock(ContentStream.class);

when(mockCheckpointable.getItems()).thenReturn(crawlerItems);
when(_mockCrawlerContent.getContentStream()).thenReturn(mockContentStream);

_messageManager.sendCheckpoint(mockCheckpointable);

verify(_mockContentBuffer).handleContentFromCrawler(mockContentStream, mockCrawler);
verify(_mockWalkUpdater).handleCheckpoint(mockCheckpointable);

With tools like this in hand, plus an attitude of commitment to excellence, I now firmly believe you can wrestle your code to the ground and get it into a unit test framework and start improving not only the testability and quality but overall architecture of your code.  I don't care if your code is full of massive, crufty code you can't understand, with lots of accesses to the network and the database, you can write unit tests that test modules independently. 

So shut up and write those tests.  You have no excuses.

Friday, June 26, 2009

Ayatollah you so - Daily Show

Very funny clip, and sweet too, of the Daily Show in Iran

Tuesday, June 23, 2009

NYT: Saudi royal family lavishes $$$ on terrorist groups

Looks like the lawyers for the families of Sept 11 got tired of trying to get the justice system to hear them, so they took it to the press. They gave the New York Times a stack of damning evidence linking the House of Saud to Al Qaeda, Taliban, and others.  From the article:

A self-described Qaeda operative in Bosnia said in an interview with lawyers in the lawsuit that another charity largely controlled by members of the royal family, the Saudi High Commission for Aid to Bosnia, provided money and supplies to the terrorist group in the 1990s and hired militant operatives like himself.

Another witness in Afghanistan said in a sworn statement that in 1998 he had witnessed an emissary for a leading Saudi prince, Turki al-Faisal, hand a check for one billion Saudi riyals (now worth about $267 million) to a top Taliban leader.

And a confidential German intelligence report gave a line-by-line description of tens of millions of dollars in bank transfers, with dates and dollar amounts, made in the early 1990s by Prince Salman bin Abdul Aziz and other members of the Saudi royal family to another charity that was suspected of financing militants’ activities in Pakistan and Bosnia.
If this is true, this is a Big Deal.  I don't fully understand why the Saudis would want to support these organizations.  Maybe somebody more versed in the ways of the Middle East can explain it to me.

Medical records = transparency = trouble for medical industry

Via @timoreilly, an article in Technology Review gives its take on why the medical industry has been so resistant to going electronic. Surprise - it's all about the money...

Dangling $19 billion in front of a $2.4 trillion industry is not nearly enough to get it to reveal the financial secrets that electronic health records are likely to uncover--and upon which its huge profits depend. In those medical records lie the ugly truth about the business of medicine: sickness is profitable. The greater the number of treatments, procedures, and hospital stays, the larger the profit. There is little incentive for doctors and hospitals to identify or reduce wasteful spending in medicine.

Monday, June 22, 2009

Health care: you get what you pay for

Great article by Atul Gawande in the New Yorker where he does some serious snooping around as to why health care costs are skyrocketing.  His conclusion: it's how we pay the doctors.

Somewhere in the United States at this moment, a patient with chest pain, or a tumor, or a cough is seeing a doctor. And the damning question we have to ask is whether the doctor is set up to meet the needs of the patient, first and foremost, or to maximize revenue.

Friday, June 19, 2009

Iran: it wasn't supposed to happen this way

A great guest editorial in the New York Times  from a student in Iran. It starts slow, but has a wonderful finish, really gives you the sense that everybody is surprised by the sweep of events, even those participating directly in them...

Everyone watched everyone else and we wondered how all of this could be happening. Who were all of these people? Where did they come from? These were the same people we pass by unknowingly every day. We saw one another, it feels, for the first time. Now in the second week, we continue to look at one another as we walk together, in marches and in silent gatherings, toward our common goal of having our vote respected.

...

It wasn’t supposed to happen this way. Until last week, Mr. Moussavi was a nondescript, if competent, politician — as one of his campaign advisers put it to me, he was meant only to be an instrument for making Iran a tiny bit better, nothing more. Iranians knew that’s what they were getting when they cast their votes for him. Now, like us, Mr. Moussavi finds himself caught up in events that were unimaginable, each day’s march and protest more unthinkable than the one that came before.

Wednesday, June 17, 2009

The Guardian seems to have it right

While other news media seem to be flailing in their attempts to keep up with the speed and detail of information coming from social media, the Guardian in the UK has a live page (updated every minute) that seems to get the balance right: keep an eye on the stream of information, and use journalistic discipline to avoid rumors, innuendo and falsehoods.  As an example, Twitter is posting this picture, and The Guardian says

A picture claimed to be of today's opposition rally has been posted to Twitpic. It shows thousands of people marching on a flyover labelled the "Krimkhan bridge". The date of the picture is impossible to confirm, please let us know if you have more information.
 I think this is great, as it gives me a source of information I feel I can trust that is also up-to-date and using new media sources and not just the traditional reporting resources.

New York Times on social media as the only way to get the word out

A good article that seems to capture the power of Twitter and other social media tools to break down the walls put up by repressive regimes.

I've been reading the Twitter #iranelection stream, and a lot of it is chaotic, doubtful, over-enthusiastic, or silly.  But there are also gems in there, with links to articles and lots of pictures showing the emotion of the demonstrators and the violent repression that is going on.

It definitely gives a different more real and emotionally engaging view of what is unfolding from traditional media, with an article here or there, mostly talking about what they've heard is going on through Twitter, and only showing "sanctioned" pictures of pro-government rallies.

But to me what is most important is not what I can learn about what is going on, but what Iranians can communicate with each other even as the government tries to shut down communications.  I read in a NYT article that demonstrations are being organized through Twitter.  That was great news to hear.  And I pray for them, because the risk of serious injury or death is very real, and they are still moving forward.  Incredibly bravery and determination.

 
Clicky Web Analytics