After watching Rich's talk the other day about "Making Simple Easy", I
started thinking about how to incorporate parts of this talk into the
software we're writing at work. During this thought process, I have
begun to wonder, are simple and statically typed languages mutually
exclusive?

Let me explain by a simple example. In the following text, I will be
using C# as my example "static" language, and Clojure as my example
dynamic language.

For instance, let's say we have two structures, Contact and Staff. The
two are completely unrelated, except for the fact that they both have
a first name, and they both are required fields:

Clojure:

{:first-name "Billy" :age 42 :record-type "Contact"}
{:first-name "Joe" :position "manager"  :record-type "Staff"}

Now in Clojure, writing a validation check for this is as simple as:

(not (nil? (:first-name record)))

But how would we do this in C#?

new Person() {firstName="Billy", age=42 };
new Contact() {firstName "Joe", Position="manager"};

Person and Contact are unrelated, so I'm left with duplicating my
validation routines (once for each object), or going and making both
implement IFirstName. This gets even more fun when you start taking
into account generics: In C# a List<IFirstName> cannot be casted to a
List<Person> because they are considered two completely different
objects.

In the Clojure source code, Rich gets around most of the above issues
by simply referring to everything as a object and then casting to get
the type at runtime. This works fine for code that will be run in a
dynamic language anyways, but makes for some ugly code when you're
actually writing the static language parts:

if (lst[0] is IFirstName) runFirstNameChecks(lst[0]);
if (lst[0] is Person) runPersonChecks(lst[0]);

However, this then requires tons of type checks and casting throughout
the entire system.

So yes, I understand that this is all a bit off-topic for a Clojure
mailing list, but I thought it was applicable to Rich's talk. Are we
getting half way to simple, simply by using Clojure in the first
place? Is it possible to write simple code in a language that shuns
the use of simple containers (List, Dictionary, etc.) as the primary
transport system for data?

If anyone has some thoughts, they are more than welcome to ponder them
"out-loud" with me on this thread....

Timothy

-- 
“One of the main causes of the fall of the Roman Empire was
that–lacking zero–they had no way to indicate successful termination
of their C programs.”
(Robert Firth)

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to