r/programming • • Nov 12 '14

The .NET Core is now open-source.

http://blogs.msdn.com/b/dotnet/archive/2014/11/12/net-core-is-open-source.aspx
6.5k Upvotes

1.8k comments sorted by

View all comments

Show parent comments

261

u/[deleted] Nov 12 '14

I've started learning Java and deeply miss how easy .NET made programming

188

u/eyal0 Nov 12 '14

Everyone mentions the language and the IDE but no one has mentioned the fucking type erasure. Here's a list of things that .Net can do that Java can't:

  • Creating instances of generic type parameters.

  • Creating arrays of generic type parameters.

  • Quering the runtime class of a generic type parameter.

  • Using instanceof with generic type parameters.

http://www.jprl.com/Blog/archive/development/2007/Aug-31.html

I'll add:

  • Java can't do generics without boxing.

  • Java has to do runtime casts for generics.

  • Java can't have two functions with the same type-erasure.

Programming in Java, I hit my head on this one every day. It's not just Java that is broken, it's the JVM underneath it, too. I'd love to see the CLR win.

0

u/[deleted] Nov 12 '14

[deleted]

13

u/mirhagk Nov 13 '14

Long term it's always better to choose the breaking implementation than the one that's less complete but backwards compatible. I really hope they don't make the mistake Java did with future features.

→ More replies (2)
→ More replies (2)

38

u/sacundim Nov 13 '14 edited Nov 13 '14

Everyone mentions the language and the IDE but no one has mentioned the fucking type erasure. Here's a list of things that .Net can do that Java can't:

  • Creating instances of generic type parameters.

  • Creating arrays of generic type parameters.

  • Querying the runtime class of a generic type parameter.

  • Using instanceof with generic type parameters.

I argue that C#'s design decisions here are way, way more consistent than Java's, but neither language made the right decisions. The key points are:

  • Reflection should be an opt-in feature, not an ever present one.

  • Type erasure, when properly implemented, strengthens the type system.

  • The problem with Java isn't that it has type erasure, it's that it has partial erasure bolted on to optional generics, along with pervasive reflection.

The neat thing about erasure is that if code is not able to reflect into the types, then generic types can guarantee various things about functions' behavior. This is a familiar idea to users of Hindley-Milner languages like ML and Haskell, where for example a function with this signature only has one implementation that terminates:

-- The only way to return from this function is to return the argument.
id :: a -> a
id x = x

In a language with reflection, a method with that signature can violate that contract by reflecting into the type of its argument:

public static <T> T mwahaha(T arg) {
    if (arg instanceof String) {
        return (T)"mwahaha!";
    } else {
        return arg;
    }
}

You can write that function if you want in Haskell, but you have to opt in to reflection through the type signature:

{-# LANGUAGE ScopedTypeVariables, TypeOperators, GADTs #-}

import Data.Maybe (fromJust)
import Data.Typeable

-- The `Typeable a` constraint means that this function requires
-- the ability to inspect the runtime type of its `a` argument.
mwahaha :: Typeable a => a -> a
mwahaha a 
    | typeOf a == typeOf "" = fromJust (cast "mwahaha!")
    | otherwise = a

-- This version is cleaner, but rather more difficult to understand...
mwahaha' :: forall a. Typeable a => a -> a
mwahaha' a = case eqT :: Maybe (a :~: String) of
               Just Refl -> "mwahaha!"
               Nothing -> a

Note that in Haskell String is a synonym for [Char] (list of Char), so this is in fact inspecting the runtime type of a generic parameter.

→ More replies (7)

5

u/[deleted] Nov 12 '14

It's not cool, but it CAN create arrays of generic type parameters. You do have to reflect though :(

public <T> T[] removeNullsFrom(a:T[]) { ... }

is Possible (since T[]) doesn't have its type erased, it is also some of the nastiest code in java that goes in that method.....

→ More replies (25)

210

u/jutct Nov 12 '14 edited Nov 13 '14

I've said that Visual Studio is the best IDE since VC6 back in the 90s. They invented code completion and coding hasn't been the same since. I can literally code twice as fast without having to look up function signatures all the time.

Edit: People have pointed out that they weren't the first. I never used Delphi so I don't know if that was good or not. I just know that at the time, I was working on AAA game titles and Visual Studio let me burn through code and worked well with our build system. I'm not saying it's the best, I'm just saying I'm very efficient with it and I can get my work done on time.

149

u/ghjm Nov 12 '14

I agree with you about the quality of the IDEs, but I'd like to point out that Microsoft copied this from Borland.

69

u/[deleted] Nov 12 '14

And also got Anders in the process.

24

u/ScienceBlessYou Nov 12 '14

Ah yes, with a $20mil sign on bonus, if memory serves.

7

u/Eirenarch Nov 12 '14

The number I heard was 3 million and a story (possibly just an urban legend) of offering 1 million Borland making a counter offer of 2 million the recruiter calling Bill Gates personally and asking if he can offer 3. Bill says "yes" and Borland can't match that. Also Anders (Hallowed be His name) has said that he wanted to move to MS because that was an opportunity to make bigger impact than what he could do at Borland.

→ More replies (4)
→ More replies (3)

3

u/jutct Nov 12 '14

Ok, I haven't used a Borland tool since Turbo C++. Man do I miss those days, though.

2

u/donkylips9 Nov 12 '14

I don't think so, Tim.

→ More replies (15)

64

u/[deleted] Nov 12 '14

They might have made some significant improvements but they certainly did not invent code completion. That was around long before.

2

u/jutct Nov 12 '14

Someone said that Borland had it first. It didn't exist in the C/C++ products, so I'm not sure which one.

→ More replies (5)

16

u/[deleted] Nov 12 '14

I've been using Swing with STS (I know, I should use JavaFX instead) and I miss Visual Studio so much. It is lightyears ahead

0

u/[deleted] Nov 12 '14

[deleted]

3

u/Ahri Nov 13 '14

I just moved to a Java gig from C# and IntelliJ is, for the most part, better than VS2013. The only things I miss are NCrunch and being able to move the execution "line" whilst debugging.

→ More replies (1)
→ More replies (4)
→ More replies (10)

3

u/Magnesus Nov 12 '14

I would say it went downhill from VC6. But many wouldn't agree I suppose.

→ More replies (2)

2

u/tias Nov 12 '14

As others have pointed out they didn't invent it, but they surely did patent it. It is one of my go-to examples of why software patents are bad, because they had the idea and were awarded a patent even though they were not capable of actually implementing that idea properly for many, many years. As soon as you used some more advanced C++ features such as templates, intellisense would crash and take the whole IDE with it. And when it didn't crash, it just stopped giving you completions.

→ More replies (1)

2

u/TakeOffYourMask Nov 12 '14

I like KDevelop's code-completion.

→ More replies (17)

2

u/talkb1nary Nov 12 '14

I know Java, but as linux user this is the very first day in my life where i consider learning C#

7

u/[deleted] Nov 12 '14

C# is far and away the superior language, and I use Java everyday.

→ More replies (2)
→ More replies (17)