I know talked a bit about this when you e-mailed me personally on the
subject, but perhaps I'll take another stab at it.

But back to the subject at hand of C# vs Clojure. For me the biggest
thing comes down to immutability and functions with zero side effects.
I tend to code very functionally when I write code in C#. Infact,
since learing F#, my code C# looks more and more like F# code.

In OOP and C# you'll see something like this allot (sadly):

public void WriteData()
{
     _fileWriter.Write("foo");
}

Now, just looking at this function, what is _fileWriter? Where is it
assigned? If it's null in this function where the heck do I go to
figure out what's gone wrong? We haven't a clue. So now we have to
either put a null check in this routine, or specify somewhere in the
documentation "Call open file before you call WriteData() or this
program will bomb".

Instead, let's write this like a functional program should be written:

public static void WriteData(StreamWriter fileWriter)
{
     fileWriter.Write("foo");
}

Ah! Now we know exactly what _fileWriter is, and if it's null, well
then we know exactly where to go. And it's very clear that we don't
need a null check, since why on earth would you pass a null in to
WriteData(StreamWriter) and expect it to do something?

Now let's throw multicore into the mix. On the second example we can
do whatever we want to fileWatcher (such as seeking) and not be
worried about messing up the data for other threads using this same
class.

All this to say. Functional languages such as F# and Clojure make this
sort of programming easier. And as time goes on C# is slowly shifting
more and more to functional programming Eric Lippert (one of the main
devs working on C#) has said that immutability is future of C#.

I hope this helps some.

Timothy

-- 
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