Do you mean .NET or C#? There are several functional languages that
run on .NET, such as F#.
- James
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
1) STM, for many applications, STM is a major plus (F# doesn't have
STM currently)
2) The LISP syntax can be quite freeing once you learn it
3) Clojure is a dynamic language, unlike F# and C#
Now here's the kicker. Depending who you talk to, all of these can be
"cons" as well as "pros". Dr. Cliff Click and Rich Hickey have had
some rather friendly arguments over STM and its usefulness in large
applications.
The LISP syntax can be viewed as a bad thing. I for one struggle with
it from time to time. I personally haven't decided if I think the LISP
syntax is a pro or a con.
And the dynamicness of Clojure can be considered a bad thing
performance-wise. Many benchmarks will show Clojure trailing a bit
behind C# in pure number crunching performance.
So it goes down to using the tool that fits.
My parents built a house years ago that uses steel for all the
internal structure. The thing is rock solid, and if it got hit with a
tornado it would probably still be there. But you know what? Hanging a
mirror on the wall ends up being an hour long process because you have
to drill into a metal beam before hanging the picture. Is steel better
than wood? Ask 10 people and you'll get 12 answers. It's all in the
style of the project, and your goals.
Timothy
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clo...@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+u...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
--
“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)