Another Take on Design Patterns

Posted by Rick DeNatale Tue, 19 Jun 2007 20:48:00 GMT

Most programmers these days are familiar with, or at least aware of the now classic “Gang of Four” book Design Patterns: Elements of Reusable Object-Oriented Software.

One of the recurring arguments about design patterns is how they relate to individual programming languages. The “Gang of Four,” Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides, were by majority, proponents of strongly typed languages. Ralph was the sole representative of Smalltalk and the rest of the dynamic object oriented languages. As a result, The GOF book had and has more resonance with the C++ community and it’s successors. Although there are some Smalltalk examples in the book, many of the patterns express things which are easier, and in some cases unnecessary to express in a dynamically typed language. I find this a bit ironic, since the whole patterns movement seems to have started when Ward Cunningham and Kent Beck, two of the best known Smalltalkers, discovered the work of architect Christopher Alexander and thought that his approach to building and municipal design could be translated to the design of software.

As I was browsing today, I was reminded that there is another “Design Patterns” book, “The Design Patterns Smalltalk Companion” by Sherman Alpert, Bobby Woolf, and Kyle Brown. Which might be of interest to not just Smalltalkers but also Rubyists, since it approaches the subject from they dynamic language point of view. It’s not easy to find, but Amazon has a few copies in stock.

Sherm was one of the researchers in the IBM User Interface Institute which was housed in the same building where John Vlissides and Richard Helm of the “GOF” worked, the IBM Watson Research center in Yorktown Heights, NY. I spent quite a bit of time with Sherman and the rest of the UI institute team under John T. Richards back in the late-1980s to early 1990s. Bobby and Kyle were OO consultants, who I also knew through Knowledge Systems Corp.

You never know what you might learn from the old Smalltalkers.

Posted in , ,  | Tags , , ,  | no comments | no trackbacks

Die Hard?

Posted by Rick DeNatale Tue, 12 Jun 2007 15:24:00 GMT

At the last meeting of the Agile RTP group, I won Michael T. Nygard’s book Release It! which I’m reading as a background task. This morning I ran across this:

Interpreted languages such as Java and Ruby almost never crash. Sure they get application errors, but it’s relatively rare to see the interpreter or virtual machine crash. I still remember when a rogue pointer in C could reduce the whole machine to a navel-gazing heap.

I remember “back in the day” when there were endless arguments between the C++ and Smalltalk advocates. The C++ folks would often quote Bjarne Strroustrup’s fear of flying in an airplane whose flight control system was written in Smalltalk, and threw a “message not understood” exception.

Those of us in the Smalltalk camp found this amusing, since the alternative was a system crash caused by an invalidpointer.

Now maybe Nygard framing rogue pointers in C as a memory means that the problem has been solved, but I seem to recall having seen it recently.

It’s Not Just The Language Stupid

One point here is that pet-features such as strong vs. dynamic typing or garbage collection vs. allegedly more performant[1] manual memory management aren’t panaceas. They can have a major effect on aspects such as easo of development, or tweaking out the last bit of performance, sometimes in non-intuitive ways.

Making robust software requires more than just choosing a language, it requires craftmanship, adherence to best practices for the chosen language(s) and technologies, and a realistic understanding of the challenges at hand.

Release It!

And that’s where we come back Nygard’s book. Although I assume that most of my readers are Rubyists, and Nygard is a Java guru, there is much of value here for anyone concerned with producing robust software that can stand up to the real world.

Based on what I’ve read sofar, and skimming the rest, I can recommend it. If you’re interested you can buy it directly from the Pragmatic Programmers, or via the amazon.com link. The later would help feed the duckdogs who run this site, and lower my distraction from their gowling stomachs.

[1] The “allegedly” will no doubt be explained in further posts here.

Posted in , ,  | Tags , ,  | no comments

Ruby Extensions vs. Smalltalk Primitives

Posted by Rick DeNatale Mon, 04 Jun 2007 14:16:00 GMT

One of the ways in which Ruby differs from Smalltalk is in how much of the implementation is buried in C, which forms a barrier for deep understanding.

For the purposes of this article, I’m going to use the term extension a little loosely to refer to both core library and extension code written in C.

For example, in Ruby, much of the code which implements core classes like Array, is implemented by C code. This is good for performance, but for those with a need or desire to grok the code, not so much. In contrast, Smalltalk has a large brigade of Collection classes which are written in Smalltalk.

This is not to say that Smalltalk doesn’t use the equivalent of extensions. Smalltalk calls them primitives.

There are some interesting differences which might be interesting for the Ruby Core team to ponder, if they haven’t already.

Read more...

Posted in ,  | Tags , , ,  | 3 comments

Power, Responsibility and Tricksy VM Implementers

Posted by Rick DeNatale Thu, 15 Mar 2007 12:05:00 GMT

In a ruby-talk discussion of the pleasures and perils of adding to or changing core ruby classes. A practice denigrated as “monkey patching” by some, but embraced as a powerful technique, when practiced with care, by others. Someone just reported an experiment involving changing a basic core method:
 Fixnum.class_eval do
   def +(number)
     self - number
   end
 end

The result: It blew up his irb.

Ruby certainly gives a lot of power. A little, and in some cases a lot, more than most popular OO languages. Read on..

Read more...

Posted in ,  | Tags , ,  | 1 comment

Boolean Implementations, Ruby, Smalltalk and self

Posted by Rick DeNatale Tue, 10 Oct 2006 16:43:00 GMT

The topic of defining a new ruby class which could have instances that, like false and nil were seen as a boolean which was not true, just came up on ruby-talk.

This has come up before, and it turns out that in Ruby being untrue is reserved to these two specific instances.

The boolean test is pretty deeply engrained into the implementation of ruby. The actual test seems to be defined in the RTEST macro in ruby.h
#define Qnil   ((VALUE)4)
#define RTEST(v) (((VALUE)(v) & ~Qnil) != 0)

Which means that any object whose reference VALUE has any bit set other than the 3rd LSB is true.

In ruby, the control flow statements like ‘if’ aren’t messages, but are ‘compiled’ into a direct test and conditional branch.

Even Smalltalk, which defined even if/then/else as a message, e.g.
    booleanValue ifTrue:[Transcript show:'true'] ifFalse: [Transcript show:'false']
Tended to cheat in the implementation… Read more...

Posted in ,  | Tags , ,  | 2 comments | no trackbacks

Simulee, Simula, Simulee, Simu-la-ah-ah-ah

Posted by Rick DeNatale Thu, 05 Oct 2006 15:48:00 GMT

Recently, a certain “gentle-reader” questioned my statement in my “mini-memoir” that Simula lacked classes and inheritance.

I stand by my guns. Simula (now known as Simula I) had neither. These were introduced by Simula-67 about five years later. It was Simula rather than Simula-67 which was one of the influences on Alan Kay’s early conception of Smalltalk.

For more details, see my reply to “gentle reader” in the comments to my mini-bio article.

Posted in  | Tags , , ,  | no comments | no trackbacks

Performance Anxiety

Posted by Rick DeNatale Tue, 26 Sep 2006 19:17:00 GMT

I've been meaning to write about Ruby performance for a while, and a recent blog post by an old friend and colleague, got me off my proverbial.

The old friend is John Duimovich, who wrote about the relative performance of C++ and Smalltalk and what that could mean for ruby.

John's message is important for those who bemoan the performance of Ruby, and I plan to expand on that message in this and later posts to this blog, but first a few words about Mr. Duimovich.

Read more...

Posted in ,  | Tags , , , ,  | 10 comments | no trackbacks

On Variables, Values, and Objects

Posted by Rick DeNatale Wed, 13 Sep 2006 19:47:00 GMT

I’ve recently observed some posts to ruby-talk which evidence some confusion on the part of the posters about the relationship between variables and objects in Ruby. One currently active thread concerns several participants who are upset that instances of the Matrix class in the Ruby standard library can’t be changed once created.

In Ruby, like in other uniformly object-oriented languages, the relationship between variables and their values is subtly different than in other languages, and this is a crucial paradigm shift, which must be crossed in order to understand Ruby.

In many languages a variable names an area in memory which holds a “bag-of-bits” representing the value of the variable. The size of that area depends on the type of the variable. A variable holding an integer might be 4-bytes long, while one holding a particular structure might be 325 (or whatever) bytes.

In a uniformly object-oriented language, all variables reference objects, and any variable can reference any object, or different objects over time. My good friend at IBM, the late David N. Smith, used to say that in such a language, “all variables are the same size,” when he wrote about or taught Smalltalk.

This distinction can trip up the unwary. Let’s try to clear some of the stumbling blocks out of the way.

Read more...

Posted in ,  | Tags , , , , ,  | no comments | no trackbacks

About me

Posted by Rick DeNatale Sat, 29 Jul 2006 13:34:00 GMT

For those who don’t want to read a lot, or dont care too much, here’s the executive summary:

  • I’m a long time object programmer.
  • I worked for IBM for 31 years.
  • I was one of the early adopters/advocates of Smalltalk in IBM.
  • I’ve done a lot of Smalltalk.
  • I’ve done a lot of standards work.
  • I’ve done a lot of Java.
  • I’m now free of IBM and Java, and I’m learning to love Ruby.

As a result of all of the above I’ve developed lots of strong opinions, weakly held, which I’d like to share.

Now for those with the stamina, some more details on my personal journey…

Read more...

Posted in , ,  | Tags , , ,  | 7 comments | no trackbacks

On Hunting Ducks

Posted by Rick DeNatale Wed, 26 Jul 2006 19:39:00 GMT

Five doctors go duck hunting, they draw lots to determine the order in which they will shoot from the blind.

The Psychiatrist gets the first chance.

A flock of birds fly over. He looks down at his shotgun and says

They look like ducks! They sound like ducks! I wonder how they feel about being ducks?

Meanwhile the birds fly by.

Next up is the internist:

They look like ducks! They sound like ducks! But we can’t rule out the possibility that they might be geese.

Then the general practitioner:

They look like ducks! They sound like ducks! What do you guys think?.

The surgeon takes his place next. He confidently feels the trigger of his shotgun with his highly skilled right forefinger. The next flock flys over.

Bang! Bang!

And the surgeon turns to the pathologist and says:

Check them out and see if they are ducks.

I’ve known this joke for quite a few years, but I’ve never thought about it in relationship to software, until I started playing around with Ruby, and discovered an old friend under a new name, “Duck Typing.”

Read more...

Posted in , ,  | Tags ,  | 6 comments | no trackbacks

Older posts: 1 2