How do you deal with excess verbosity in C#? I know this is a separate argument from the monkey patching issue but for me the conciseness and elegance of the Ruby syntax versus C# is the primary reason to choose Ruby.
Hopefully a user of C# will chime in -- I've spent very little time with it, and only recently evaluated C#'s extension mechanism for the purpose of comparing it against other language's implementations.
That said, elegant and concise syntax does not require eschewing an internally consistent, fully specified type system -- the two are not incompatible, as demonstrated (subjectively) -- by many existing FP languages. I argue that elegance/conciseness requires either FP language features and advanced type system, or abandonment of rigorous typing.
In C# 3, the verbosity level is much less than in C# 2, where it's slightly less than C# 1.
I don't see where Ruby syntax is particularly more concise than C# 3's.
Well, let me clarify "particularly". I don't find myself feeling like I'm suffering under C#'s syntax, relative to Haskell's. It has about the same amount of syntactic overhead: writing types for method parameters, and when defining data structures. Occasionally I have to explicitly write a type parameter to a function.
Of course, "UpTo" requires first extending int, which is trivial:
public static class IntExtensions {
public static List<int> UpTo(this int start, int end) {
var range = new List<int>();
for(int i = start; i < end; i++) {
range.Add(i);
}
return range;
}
}
This is a fairly uninteresting example, however. Something more interesting would be, for instance, the use of structural types to implement type-checked duck typing.
Scala example:
// Declare a structural type for any class implementing close()
type Closable = {def close(): Any}
// Executes the provided function with the given
// closable generator, creating a new instance which
// will then be closed on completion. The provided
// function's value will be returned.
def withClosable[T, C <: Closable] (c: => C) (f: (C) => T) = {
val closable = c
try {
f(closable)
} finally {
closable.close
}
}
// Example usage
def usage = {
val updated = withClosable(db.openConnection) { conn =>
conn.update("INSERT INTO example VALUES (...")
}
System.out.println("Rows updated: " + updated)
}
This could be compared with Python's new 'with' syntax.
That said, elegant and concise syntax does not require eschewing an internally consistent, fully specified type system -- the two are not incompatible, as demonstrated (subjectively) -- by many existing FP languages. I argue that elegance/conciseness requires either FP language features and advanced type system, or abandonment of rigorous typing.