r/AskComputerScience • • Nov 24 '16

Is C# really that much better than Java?

Hi reddit,

I am a CS student and one of my fellow students always keeps saying how much better C# is than Java and what a bad language Java is overall.

Is he right? Are there any objective arguments/proofs that show that C# is superior to Java? What is your opinion?

31 Upvotes

29 comments sorted by

35

u/BonzoESC Nov 24 '16

Programming language slap fights aren't worth participating in. They're tools, and you don't see hammer people getting in fights with screwdriver or wrench people.

If something you need to do is particularly well supported in C#, like making a Windows app or something use it. If you need to work with Cassandra or Zookeeper or something, Java is probably a better choice.

Java and C# are basically the same anyways, going from those to something farther out like Rust, Elm, or Erlang is going to be more fun and educational in the long term.

9

u/glitchn Nov 25 '16

Obviously screwdrivers are superior to hammers. It can do the job of both, but let me see you try to screw in a flathead with a hammer!

3

u/BonzoESC Nov 25 '16

On the other hand, screwdrivers are of no particular importance in Norse or Motörhead mythology.

15

u/[deleted] Nov 24 '16

Environments aside, I prefer C#. I find that Java is too verbose and requires you to do a lot of unnecessary things. Obviously Java has the upside of running cross platform (readily).

0

u/[deleted] Nov 25 '16

[deleted]

2

u/exneo002 Nov 25 '16

I've heard this is coming with Java 9. A quick Google search doesn't show anything definite but there are tons of proposals.

The only thing I don't like about c# is windows haha.

1

u/AgentZeusChops Nov 25 '16

To Objective-C with that, then! lol

1

u/exneo002 Nov 26 '16

Jet brains could make it bearable

1

u/AgentZeusChops Nov 26 '16

I'm personally not a fan of IntelliJ. Who knew? Lol I program in Java, Objective-C, and Swift most of the time. IntelliJ also forces me to deal with different contexts and a slightly more-noticeable lag than with Eclipse, whenever I write Java code. As for Objective-C and Swift, I am currently using Xcode (macOS-only, unfortunately) for those.

24

u/PmMeYourSexyShoulder Nov 24 '16

Better is relative. Always the right tool for the right job.

7

u/theobromus Nov 25 '16

Agreed. Hijacking to mention the relative advantages:

  • C# came later and had the benefit of hindsight. It implemented many things in a cleaner way in my opinion (e.g. native types are boxed automatically so there's no int!=Integer). It's generics are arguably better as is Linq. The async/await features were integrated really well. Integrating with native (i.e. c++) code is so much easier with P/Invoke in C# compared to JNI in Java. If you're writing an app for Windows (or Azure, SqlServer, etc.), C# is usually the best way to go. For writing web apps Asp.net MVC is a solid choice, although there are so many competitors (python, ruby, node.js, and of course java jsp).

  • Java has a larger development community. There are probably more companies with business apps written in Java. It was the de facto language taught in many schools and so there's tons of people who can write and maintain java apps (businesses like this). Java 8 has added a number of features to give parity with c# like lambda expressions. Java is also the language of Android app development, so if you're writing for Android it's basically your option. Because of it's large cross-platform development community, there are a lot of libraries and open source projects that use Java.

Overall, both languages are excellent. If you are writing code that doesn't have to be in a native language (i.e. non-garbage collected), I'd say the choice comes down to your target platforms, the available open source libraries related to your problem, and which you prefer.

2

u/Xander260 Nov 25 '16

To add to the confusion, compiling a C# app to Android/iOS is pretty trivial now, thanks to Visual Studio taking on Xamarin, which in itself used C# as the language of choice. But again, native is always better (performance wise) and Java is the defacto standard at the moment for Android.

8

u/falafel_eater Nov 25 '16

Generally speaking, the majority of "Language X is better than Language Y" arguments you'll hear are pretty much rubbish. Especially coming from someone still in their undergrad studies who might not be basing their assertion based on a very fine-grained and complex understanding of the design choices made when developing the languages/compilers and the history and reasons for them.

Does Java allow you to perform the tasks you need performed? Can you develop painlessly? Do you have debuggers and other tools you need? Documentation is available? The application has sufficiently good performance for what it's intended to do?
If Java does all these things with respect to the task you assign to it, then Java is a fantastic tool for that task. If it only does some (or almost none) of the above, then it's probably poorly-suited.

The same goes for C#, Python, Ruby on Rails, or any other language.

Are there any objective arguments/proofs that show that C# is superior to Java?

No. There are probably dozens (if not hundreds) of different metrics you could compare the two by, and get different results for each one.
If you compare a hammer to a screwdriver, you get very different results if you compare their suitability for turning screws, driving in nails, making music, long-distance throwing or usability as a makeshift weapon.

6

u/tbrownaw Nov 24 '16

IIRC the CLR is better than the JVM, mostly due to being newer and having less historical baggage. But, this largely doesn't matter since most work is a couple levels of abstraction up from that.

Java as a language has had some pretty huge changes recently. Old versions kinda suck, new ones supposedly don't (but I don't get to work with them, so...).

C# has Visual Studio, which is frikken awesome. Java has Eclipse (which sucks), and IntelliJ (which doesn't).

Java has the problem that the language, standard library, and virtual machine are all the same thing. C# doesn't (the library/framework is .NET, the virtual machine is the CLR).

I hear a lot more about alternative languages running on the JVM than I do about them running on the CLR. This doesn't make sense to me, which makes me think I'm missing something.

C# works well with Powershell, since they're both CLR languages.

Java is a product of Oracle, ever since they bought out Sun. C# comes from Microsoft. As much as Microsoft has a known history of being evil, my understanding is that Oracle is generally considered worse (and Microsoft has realized lately that they need to do damage control on their reputation, and seems to have cleaned up their act a bit).

4

u/adimit Nov 25 '16

C# works well with Powershell, since they're both CLR languages.

That's really only relevant if you're running on Windows. Personally, I'd use both C# and Java mostly for web stuff, or enterprise-level stuff — so, on servers. Sure, you can have Windows servers. Though I like to keep my feet lead-free.

Java is a product of Oracle, ever since they bought out Sun. C# comes from Microsoft.

They're both heartless megacorps. Yeah, it really sucks that I have to look at Oracles logo when browsing Java-anything, but, truth be told, the Java version that came after the buyout was very good (8). And the next two ones are shaping up to be not-too-shabby either.

To me, the C#/Java divide is this:

C# runs well only in Microsoft-environments. Yes, there's Mono, and maybe one day that'll change, but I have little hope that developing C# and running C# is at any point going to be equally painless on Linux as it is on Windows. Windows is always going to be the first-class citizen. To me, this kills C#.

C# as a language has two main things going for it: LINQ, and un-fucked generics. Or rather, C# has LINQ and Sun seriously fucked up Java generics through type erasure. Also, generics are nowhere near powerful enough to be used properly with the new Stream API, which makes me a sad panda. I'd love something like LINQ in Java-land, but it won't be happening any time soon.

1

u/ISvengali Nov 25 '16

And now there is .Net Core. I havent done an analysis of it yet, but its an officially supported linux version of the CLR. I really want to port our server over to it and try it out.

Mono is unfortunately not good. Certainly nothing I would ever do production work with. If youre in a bind and people will kill you if you dont get their CLR program running on linux then yeah, use it otherwise, nope.

1

u/berlinbrown Nov 25 '16

But what cross platform systems does the CLR run on, effectively. Like JVM effective. For example, million dollar IBM JVMs. Or large scale clustered JVMs.

5

u/shadowdude777 Nov 25 '16

C# has better syntax. Java has a better ecosystem and better tooling. Both are fantastic languages.

2

u/andybmcc Nov 28 '16

As a general rule of thumb, a lot of your fellow students are full of shit and just want to get into a dick measuring contest over some completely asinine argument. Somewhere down the line, you'll both realize that neither of you knew your asshole from a hole in the ground, have a good chuckle about how silly you were back in the day, and move on. Languages are tools. You should use the most appropriate tool for the context of the problem.

1

u/wischichr Nov 24 '16

There is only a single pro for java and that is it's history of being platform independent (because C# and .NET started Windows only) and there are already many jvms for different machines.

So now the cons of java:

  • no unsigned byte (and byte should IMHO always be unsigned)

  • no unsigned types in general

  • no decimal datatype

  • override annotation is optional

  • No real enums in java

  • No delegates or function pointer, not sure if java has lambda expressions

  • Insane implemenation of modulus (in fact java implemented a remainder function with the % (which is modulus in most languages) and implemented modulus later in Math.floorMod (WTF)

  • No Generics with primitve datatypes - we have to use ugly wrapper classes.

  • No real setter and getter for properties - just (ugly) conventions

  • No structs or custom value types

  • No operator overloading.

  • And the .NET Framework does not install the freakin Ask Toolbar.

Java started as a great idea, but Microsoft open sourced a lot .NET and C# stuff lately and passed java years ago. But Oracle is very busy suing other companies 😁

-2

u/BlueFootedBoobyBob Nov 24 '16 edited Nov 24 '16

Not really. Of course on a Windows Maschine it is quite a bit faster and you have some nicer Features like the way that exeptions are handled and of course Linq.

But cross platform development is still a nightmare, which might be better with Java. And have a look at the serial com under C# its a fkn joke. Unsecure code parts.

In my opinion there is very little difference. Use what you know, if you need to, you can easily relearn. Learn the concepts: garbagecollector, Lambda functions, Linq.

Be careful with heredity. If you are used to C++ everything goes, the limits of Java are hard and C# only allows one parent.

IDE: first time i saw Visual Studio i was shocked of the lack of features and instablility. Eclipse is a gigantic plus for Java.

13

u/rikbrown Nov 24 '16

Eclipse is a gigantic plus for Java

Then IntelliJ is a gigantic multiplication sign.

5

u/urielsalis Nov 24 '16

Intellij idea is awesome and a real step up from eclipse

2

u/PM-ME-YO-TITTAYS Nov 25 '16

It took me ages to switch to Intellij because I was happy with Eclipse. But now, trying to do anything on my coworker's computer is impossible because there are so many things I'm used to in Intellij that Eclipse just doesn't do.

4

u/cdlight62 Nov 24 '16

Really? I learned development in Java on Eclipse but once I got used to VS there wasn't even a contest.

2

u/malsonjo Nov 24 '16

Add Resharper if you want to go nuclear.

0

u/[deleted] Nov 24 '16

[deleted]

6

u/adamkemp Nov 24 '16

Microsoft officially supports C# on Linux and Mac. They even just announced "Visual Studio for Mac" (basically rebranded Xamarin Studio). Since they open sourced their compiler/runtime and bought Xamarin they have been openly supporting cross-platform C# development.

0

u/[deleted] Nov 24 '16

[deleted]

3

u/adamkemp Nov 24 '16

With .Net Standard the same binary can be used on any platform. What is missing?

I'm not going to argue that it's perfect, but it sounds like your information is out of date. You might want to look at the current state of things.

1

u/wischichr Nov 24 '16

Am I getting this right? WPF Apps run on Linux and Mac? Edit: Googled it and nearly everbody suggest xamarin because WPF does heavily depend on windows.

1

u/adamkemp Nov 25 '16

WPF is a UI framework. C# is a language. .Net is basically the common language runtime and non-UI framework (things like file I/O and networking).

The question was about C#, not WPF. Today you can write and run an ASP.Net web application in C# on a Mac. You can't run a WPF app, but you can write and run C# code. Visual Studio for Mac is itself written in C# (using GTK# as its UI framework).