Monday, September 28, 2009

Integrated vs. open: what's more "free"?

OK, first of all, don't get me wrong.  I am totally an open-source advocate.  I worked in open source a lot at Sun, and I make use of a lot of open source in my day job.

But I also have a Mac and an iPhone.  As a matter of fact, many developers in the open source community have Macs and iPhones.  But Apple is the King of Proprietary.  So what's going on?

I recently got a comment on my Facebook page when I mentioned I was trying to unlock my wife's iPhone, basically warning me to stay away from proprietary systems that try to lock you in.  Now, I don't believe phones should be locked, or that you should have to revert to a downloaded software tool that hacks into the phone to unlock it.  But this comment did get me thinking: why do I use the iPhone even though it's proprietary and does try to lock me in, as does my Mac?

The problem with Apple's stuff is, it's just so gawdawfully easy to use.  My wife observed the same thing I did three years ago: "hey, this stuff just works!".

Apple can do this because they're proprietary and closed - they can build a completely integrated system and not worry about having to build something that works when it's pieced together by different vendors with different configurations.  The can focus on their configuration and just make it work.

So, when it comes down to it, I'll take proprietary over open when it offers such incredibly obvious advantages as the Mac and iPhone do.  Have I sold myself to the Devil in a Black Turtleneck?

In the midst of those ruminations, Tim Bray tweeted a link to this article in the Economist, that compares Mac vs. PC with our banking and health care systems.
Like Microsoft operating systems, America's health-insurance system is incoherent, hard to understand, often dysfunctional and bloated by obsolete legacy systems. (Though unlike Windows machines, it's not cheap.) Different parts fail to operate properly with each other, and the whole thing is incomprehensible to most users, patients and doctors alike. But try to set up a central authority like MedPAC to make decisions about how to fix Medicare, or to mandate that policies cover a set of basic conditions, or to make end-of-life counseling available to seniors so they don't go through their final weeks in a blizzard of legal confusion—try to fix any of this stuff, and you'll be accused of "taking the control of health care out of the hands of patients and their doctors." This rhetoric is often driven by vested commercial interests. Medical-industry groups don't want a panel of experts making decisions about Medicare because it reduces their ability to buy concessions through congressional lobbying.

The same goes for the banking and credit-card industries, where small-print legal confusion is used as a tool to extract money from customers, and efforts to ban such practices are attacked as restrictions on consumer freedom. In health insurance or credit cards, freedom's just another word for not understanding what's in your contract. A perfect illustration, from Republican congressman Jeb Hensarling: "The ironically named Consumer Financial Protection Agency (CFPA) would have the power to strip from consumers their freedom of choice and restrict their credit opportunities in the midst of a financial recession—all in the name of 'consumer protection'. Positively Orwellian."

What's Orwellian is describing your credit-card company's ability to arbitrarily raise the interest it charges you on past debt to 35% as "freedom". More broadly, we need to move away from the Orwell "1984" paradigm. It was a brilliant description of the most important threats to freedom in the middle of the 20th century, but it no longer describes the most important threats to freedom today*. It was already clear how creaky the paradigm was in 1984, when the Mac ad came out; it's only gotten creakier over the past 25 years. Orwell didn't pay much attention to the problem of an oppressive blizzard of "choices" designed to take advantage of the consumer or citizen by manipulating asymmetries of information. But that is the way the American commercial and political landscape feels much of the time

Definitely something to think about. What is the true freedom here? And, in terms of health care and other social services, who is benefiting from this 'freedom'?

Friday, September 25, 2009

Why I didn't want to do Test-Drive Development - and why I like it now

I've been thinking about why I didn't do Test-Driven Development for so many years (in particular, writing tests first), and why others don't.

You can be shown lots of books. You can be told it's important. But you still don't do it.

I think it's about discomfort. You're being asked to change. For years, the way I coded was: I did some analysis, thought about the design, and then started coding the design as I saw it, either from my head or from some basic UML.

TDD doesn't let you do that. You have to (ick) write a test first. Why on Earth would I ever want to do that? I'm trying to implement my design, not muck around with tests! So as much as I appreciated from afar the values of TDD, I just never get around to doing it, because it's just not how I did things. It's almost like you're coding naked or with a keyboard with a different layout - it's awkward, uncomfortable, and just feels wrong.

So I came up with all sorts of justifications for not doing it - I don't have time; I'm already writing tests, writing them first seems like overkill; I'm already overwhelmed with things I need to deal with; people who that are just anal design-freaks, and so on. But I think ultimately it came down to - that's just not how I do things.

But recently I finally forced myself to start doing it. I slowly started becoming more comfortable with this approach, and started to see the benefits.

To me the key thing is this concept of letting the design emerge rather than trying to impose a design. It's similar to starting with use cases first, and regularly validating your product with the customer, rather than building a technology and hoping they'll come.

Once I got used to letting the design emerge, I started really enjoying TDD. It was an act of discovery as much as an act of creation. And I truly believe the best creations are done that way - as an act of joyous discovery.

And yes, by the way, you get much better code coverage when you do TDD, because you ensure that each "piece" you build is tested, rather than writing a bunch of code and then trying to figure out how to test it.

And yes, by the way, you get designs that are much less coupled and more cohesive.

But to me my favorite part of it is that joyous process of discovery.

Why make methods small and do one thing?

I've been reading the ObjectMentor blog, and it's got some fun stuff in it. The one I particularly liked is how do you know when a function does "just one thing" - the answer - extract methods until you can't extract any more.

Now, I know there is the feeling of - why should I waste all this time writing lots of tiny little functions? But after trying it for a bit, I'm convinced, for two main reasons (although I am sure there are more):

Readability
When you write small functions, each one is eminently readable.  You look at it, and in an instant you understand what it does and its intent.  You don't have to "decode" the method to understand the intent - it just tells you.  I think this is essential - when you understand a code's intent, you can also understand if it is doing what you want it to.

Discovering New Classes
When you extract functions, sometimes you run into this situation where you are passing umpteen (meaning more than two) parameters into the function.  To me, particularly when the list of parameters is long, this indicates the need to extract a class which encapsulates all this data you're passing around.

And I often find once I've extracted the class, it clarifies the design for me.  You have an idea of a design, but you should really let the design reveal itself to you, and this is one of the great ways I have found that happening.

Also, often once a class is extracted, I can see how it can be used elsewhere - I have a new unit of reusability.

Anyway, I recommend keeping an eye on the ObjectMentor blog, there's good stuff there.

Thursday, September 24, 2009

You should like what you do

I was sitting down for dinner last night, after having grilled some chicken kabobs.  I mentioned that I thought I had cooked them long enough but they seemed undercooked.

My 9-year old daughter, Ariel, after a pause, said "You should like what you do."  I looked at her, confused.  "You're always saying something bad about what you do.  I get tired of it.  And it makes me not want to eat what you make."

She really stopped me in my tracks.  She was right!  And I told her so, "you're absolutely right, Ariel."   The words "never apologize!" from Julia Child's book "My Life in France" came back to me.  She tells a story of making a horrific dish, but she and her guests just shouldered through the dish as best as they could, and Julia never apologized and the guests never complained. 

I was so touched by Ariel's sentiment: "you should like what you do."  It was an admonishment, yes, but more than that, an encouragement - I believe in you, and you should too.

I spent some time looking at myself, and saw that indeed, yes, I have an underlying idea of myself as "not good enough."  We could go back into my history to understand how this happened, but I'd rather work with the present moment.  How can I work with this now?

"You should like what you do."  I see this in two ways.  First of all, whatever I do, take pride in it.  Yes, it may not be "perfect" but all the same take pride in it.  It is a creation from the heart.  Secondly, I should like what I do, rather than wish I were doing something else.  This is the key to a happy life.  "It is not doing the thing we like to do, but liking the thing we have to do, that makes life blessed," said Goethe.

So, I'm not rash enough to believe I can change my underlying perception of myself in a flash, but it's something to practice and be aware of.  When I find myself being overly critical or unhappy with something I'm going or have done, I can remember, "you should like what you do" and be happy about it.  Always room for improvement, but it's great the way it is.  My cooking is great.  My code is great.  My pictures are great.  My words are great.  My nose is great.  I am great.

Friday, September 18, 2009

A balance between flux and immutability

A fun blog post by John Rose about the delicate balance between the world of flux (e.g. volatile memory) and our attempts to enforce immutability through functional languages like Erlang.  Immutability is great, is helps rationalize and simplify your logic, but it just doesn't play well with the notion that "you don't step into the same river twice."  His overall conclusion - work with a language that encourages immutability but allows for in-place mutation where it is needed.  You know a craftsman at work when he sees the issues of software from the perspective of ancient philosophy :)
But we know from common sense (that trusty yet abused helper) that we live somewhere between the fluxy world of Heraclitus and the timeless world of Parmenides. In the days of Plato, it was his student Aristotle who balanced the claims of the two accounts, picking a middle way between the two. In short, the formal ideas we perceive and know inhere (in a way real though bound) in the mutable, moving reality around us. Object identities (what he called "substances") are real, though temporal. If Aristotle had marketers like we do, he might have called his account a hybrid paradigm (more Greek, actually, though to him "hybrid" would mean "having hubris") of flux and form. I think it's likely the story will end similarly for us, in our professional difficulties with software, with some sort of middle way.

Just to speculate wildly, maybe those hybrid functional-and-object-oriented languages (like Scala and F#) can provide a sort of dictionary and grammar of useful terms and constructs. These would somehow describe computations as immutable in most places, and manageably mutable in those few aspects needed to model real-world transitions. (Or to implement localized compute engines, like a quick-sorter.

Thursday, September 17, 2009

Racism in America? Shocking!

What?!  Racism still exists in America?!  I am shocked!  And some of the media and politicians are trying to use this to get attention and money?!  Doubly shocking!

I like Obama's approach: we all know racism exists, let's move on and focus on doing our job: fixing health care, fixing the economy, dealing with global warming, and so on.  I suspect he's done that all his life.  Why waste your time putting energy and attention into something that is divisive and ultimately gets you nowhere.  I've never met someone who stopped being racist because someone said "you're a racist!" to them.

I suspect that underlying all of this is not racism per se but a fear of the unknown.  If we work together create a country where each individual feels safer - in terms of their job, their health, and their overall prospects in life - then there will be less hate-filled speech and actions.

Tuesday, September 15, 2009

Time out on timeouts

A very interesting (and somewhat tragic) article about the long-term damage caused by withholding attention and affection as a way to discipline children. 

The most common tool in this toolbox is "time-outs".  My wife and I just didn't feel comfortable with this - it felt humiliating and mean - and the research seems to be confirming it's not the best approach
The studies found that both positive and negative conditional parenting were harmful, but in slightly different ways. The positive kind sometimes succeeded in getting children to work harder on academic tasks, but at the cost of unhealthy feelings of “internal compulsion.” Negative conditional parenting didn’t even work in the short run; it just increased the teenagers’ negative feelings about their parents.

What these and other studies tell us, if we’re able to hear the news, is that praising children for doing something right isn’t a meaningful alternative to pulling back or punishing when they do something wrong. Both are examples of conditional parenting, and both are counterproductive.

...

In practice, according to an impressive collection of data by Dr. Deci and others, unconditional acceptance by parents as well as teachers should be accompanied by “autonomy support”: explaining reasons for requests, maximizing opportunities for the child to participate in making decisions, being encouraging without manipulating, and actively imagining how things look from the child’s point of view.

The last of these features is important with respect to unconditional parenting itself. Most of us would protest that of course we love our children without any strings attached. But what counts is how things look from the perspective of the children — whether they feel just as loved when they mess up or fall short

Monday, September 14, 2009

Monday, September 07, 2009

Color photographs of Russia from 100 years ago

Go look at these amazing photos on Newsweek.
Between 1907 and 1915, Prodkun-Gorskii rode through even restricted parts of revolutionary Russia in his specially fitted darkroom rail-car, shooting color photos ... by a method of his own invention
Really quite stunning. So used to seeing black-and-white photos of these times, and here it is, the turn of the century in living color.

Color photographs of Russia from 100 years ago

Go look at these amazing photos on Newsweek.
Between 1907 and 1915, Prodkun-Gorskii rode through even restricted parts of revolutionary Russia in his specially fitted darkroom rail-car, shooting color photos ... by a method of his own invention
Really quite stunning. So used to seeing black-and-white photos of these times, and here it is, the turn of the century in living color.