← Back to context

Comment by to11mtm

3 months ago

> Generics work as you would expect with very few weird corner cases. No boxed types because... everything is an object!

Took me a moment to realize you meant that 'Java has corner cases because everything is an object' but yes.

Will also add the 'advantage' that for value types (i.e. struct) the generics are 'specialized' for the type, in certain cases you can use that for performance optimizations. (although it can have downsides.)

> The last two facts mean that you also get generic arrays, which are fantastic (and, incidentally, are also _implemented_ in C#, which is super cool)

And, fun side note, the generic arrays actually existed before real generics (and we get fun hacks in the VM as a result!)

.NET does still have funkiness around Array Covariance tho, which sometimes can be a pain.

> By default, reference types are not nullable.

This is a newer feature and great, however it requires people to (1) use libraries that properly do it and (2) requires you to have the right tag in the csproj to flag the NRT warnings as errors. I've yet to see a shop that has adopted (2) as a default.

> In general, the standard library is also better organized. Interfaces start with "I". Collections libraries have been carefully designed and learned many lessons from Java. A good example of an improvement over Java is the IEnumerable<T>/IEnumerator<T> class, which is simpler than Java's Iterator<T>

Yes and also the sugar around yield syntax to do generators.

> Properties are really nice, and the shorthand syntax for property getters/setters saves a lot of time.

I still remember getting called into a Dev Manager's office, he's a JVM guy and he's goes into this overview of Lombok and how the JVM folks want to use it and he asks what I think and I'm like "Gee wow give me a moment I thought Java had AutoProps by now". (I think it was the first time he was impressed with C# as a language lmao, He and later I were disappointed in .NET's lack of a good set of thread pool abstractions...)

> .NET's runtime reflection capabilities are amazing. All of my autograders make extensive use of reflection instead of forcing students to compile with interfaces; this gives them a degree of freedom in implementing things.

That is so freaking cool and I love it. Profs like you made college fun back in the day.

> NuGet is a million times easier to use than Maven.

Truth; every time I have to do a thing in JVM dealing with maven feels like I need a goat or chicken to make anything work right.

> The downside is that C# is definitely not as fast as Java, in particular when the runtime is starting up. I remember how painful Java startup used to be, so I am optimistic that this will improve eventually.

We have AOT and R2R nowadays, I'm not sure if it's 'JVM Fast' for something like a webservice but unless you're pulling in something like an ORM it's typically fast enough I can't observe a difference as a user for utility apps/etc... Curious what examples you have in mind?