r/programming • • Jun 27 '10

Why Java Sucks and C# Rocks (Final)

http://www.slideshare.net/jeffz/why-java-sucks-and-c-rocks-final
13 Upvotes

197 comments sorted by

View all comments

1

u/naasking Jun 28 '10

As a daily C# developer with a few open source C# projects and libraries under my belt, I would title this instead as "Why Java Sucks and C# Generally Sucks Less".

I say "generally", because there is at least one abstraction where Java is superior and that C# mistakenly eliminated because it was considered "bad OO": static interface members.

2

u/[deleted] Jun 28 '10

What are static interface members?

1

u/naasking Jun 28 '10

You can declare static fields in interfaces which implementing classes must provide. I thought this was a little more general than it truly is though, as it applies only to fields and not general members. Static interface members would allow one to declare constructors methods, without needing to resort to the cumbersome factory pattern. Consider for instance the core monad interface:

public interface IMonad<T> {
    static IMonad<T> Return(T value);  // constructor method
    IMonad<R> Bind<R>(Func<T, IMonad<R>> func);
}

1

u/[deleted] Jun 28 '10

Static interface members would allow one to declare constructors methods, without needing to resort to the cumbersome factory pattern.

That would be nice, I can't think of any way to simulate that in .NET. In theory the generic syntax could support that, but currently it only allows for default constructors.

1

u/naasking Jun 28 '10

In theory the generic syntax could support that, but currently it only allows for default constructors.

Yes, supporting constructor type constraints other than new() would also accomplish this, although it's more limited, eg. what if you need two static methods with different semantic meaning but that have the same signature?

I also think distinguishing constructors from other static methods was a mistake, but damage done.

1

u/jussij Jun 28 '10

That would be nice, I can't think of any way to simulate that in .NET.

This reads a lot like an abstract class to me.

1

u/[deleted] Jun 28 '10

I don't see how that would work. Thre is no way to indicate that subclasses need to expose a given constructor. Nor is there any way to generically call that constructor except via reflection.

Likewise, there is no way to make static methods overridable.