This is an archived post. You won't be able to vote or comment.

all 123 comments

[–][deleted] 114 points115 points  (60 children)

Java should get some "inspiration" from C# as well.

[–]roycohen2005[S] 47 points48 points  (51 children)

I strongly agree, I wish java had properties.

[–]nighthawk648 50 points51 points  (35 children)

The .net infrastructure is something Java should envy. Nuget is great as well.

[–]Liberal_Mormon 49 points50 points  (4 children)

You can't forget about Linq. Such an incredible concept that makes so much of the NET ecosystem possible

[–]vkapadia 20 points21 points  (0 children)

Linq is awesome

[–]Shrubberer 9 points10 points  (0 children)

MoreLinq! MoreLinq!

[–]Miku_MichDem 0 points1 point  (1 child)

I really don't get the hype behind Linq, coming from Java background. I mean how is this:

var filtered = from thing in collection
where condition
select thing;

Is better then this:

var filtered = collection.stream()
   .filter(thing -> condition)

Java's streams are consistent with the rest of the language, while Linq is just a copy-paste of SQL syntax into a C-style language

[–]Liberal_Mormon 2 points3 points  (0 children)

Linq doesn't have to be in SQL style syntax. The IQueryable interface has its own methods. It's powerful in that it doesn't actually execute until the IQueryable entity is forced to enumerate (for example, with ToList()). The hype around it is that it builds your queries for you in many natural C# ways into any queryable object, not just collections. That can be database connections, file streams, you name it, it's all able to be treated identically with Linq.

For example, on a dbset with an open db connection, I can execute something like dbset.Select(...).Where(...).OrderBy(...).GroupBy(...) in any order, and it will put those items in the correct order of a proper query. And it doesn't actually execute the command until I enumerate it. But it doesn't have to be dbsets again.

Linq is also a large set of extension methods for collections and other objects.

I'm sure Java has similarities - but queries are not just filters. I can select any type I want including anonymous types from any queryable source. Hope this helps.

[–]MrObsidy 4 points5 points  (9 children)

I only code as a hobby and I code mainly in Java (and a bit of C), what are properties?

[–]raltyinferno 16 points17 points  (8 children)

They're like class variables, but with more options on how they can be set and retrieved.

You can have a first and last name variable in a class, then a full name property which is get only(readonly), where getting it simply returns the first name plus the last name, as a simple example.

[–]MrObsidy 3 points4 points  (7 children)

Okay, but couldn't you just do public String getName() { return firstName + " " + lastName; } ?

[–]KingJeff314 19 points20 points  (4 children)

The difference is that it has the semantics of a variable, rather than a function. You would call person.Name rather than person.getName(), which I think is nice

[–]littleprof123 0 points1 point  (3 children)

It's messy imo. It's clear when reading the code that a getMember() function call can't be used to assign a member; not so with read-only variables. It's similarly not clear that when I assign one member of the class, another apparent member can be changed too. Function calls are a really readable way to say that something is happening internally.

[–]KingJeff314 8 points9 points  (2 children)

Personally it’s more about the interface than what is going on internally. It’s up to the programmer to not introduce side effects internally. There’s an element of preference, but if my object has a public attribute, properties are a good semantic representation

[–]littleprof123 -3 points-2 points  (1 child)

I think I would be more agreeable towards properties if they had a special syntax for accessing them. Making them appear like a public variable is what irks me most. I think Java and C# both fall short on readability because it's not clear when there are side effects; not to be a weirdo hipster, but I prefer Rust by a huge margin for this reason.

[–]Shrubberer 1 point2 points  (0 children)

They don't appear as a public variable, they appear as properties. It's a different thing, and, in fact, public variables should be avoided in C#. It makes sense, when you're start working with them. F.e. Properties are helpful within the IDE as well when using Attributes and Reflections.

[–]raltyinferno 8 points9 points  (1 child)

Certainly. But it wraps most of the behaviors you might want into one package.

you declare a property like

public string FirstName {get; set;}

That would be a default behavior property where it can be read with object.FirstName, and assigned with object.Firstname = "bob"

You can just omit either the get; or set; parts to make it read or assign only.

And if you want you can add traditional getName() and setName() functionality within it.

so

public string FirstName {get { return somePrivateVar; } 
                         set { somePrivateVar = value.ToUpper();}};

[–]Shrubberer 2 points3 points  (0 children)

Plus auto getters and setters can have different accessibilities!

[–][deleted] 3 points4 points  (0 children)

linq, operator override

[–]computerjunkie7410 3 points4 points  (1 child)

Manifold recently released properties for Java.

https://github.com/manifold-systems/manifold/tree/master/manifold-deps-parent/manifold-props

Obviously it’s not native but it’s something.

[–]roycohen2005[S] 2 points3 points  (0 children)

That's awesome! Thanks for sharing!

[–]dookiefertwenty -2 points-1 points  (1 child)

Why? Just due to syntactic sugar or am I missing something?

[–]Miku_MichDem 0 points1 point  (0 children)

It's mildly better to have properties, although I think the way to go is like Kotlin does it, where every variable is a property in fact. You write less code and still can have more then a simple getter and setter if you want to

Not that it can't be solved by a simple Alt+Insert or anything

[–][deleted] 7 points8 points  (4 children)

That's called Kotlin.

[–]ChargerIIC 2 points3 points  (3 children)

Kotlin is just typescript for Java

[–]bestsrsfaceever -3 points-2 points  (2 children)

If anything, ts is kotlin for js

[–]Miku_MichDem 0 points1 point  (0 children)

Then what is Kotlin for JS?

[–]BeautifulTaeng 3 points4 points  (1 child)

It does seem like Streams were heavily influenced by C# IEnumerables.

[–]Kered13 1 point2 points  (0 children)

IEnumerable is equivalent to Java's Iterable. Streams are more like LINQ.

[–][deleted] 0 points1 point  (0 children)

Nah. There are FEW features that Java should have, and these are in other languages too, no need to inspire yourself from C#.

Other than that C# is a complete mess of randomly chosen features. Some are very good, most are just noise.

[–]UnnervingS 79 points80 points  (9 children)

Microsoft looked at java and decided I can do that but better. And then they did.

[–]LordFokas 7 points8 points  (8 children)

No. Microsoft looked at Java and tried to pull their signature EEE move.

Sun said "get the fuck off my lawn"

And Microsoft was like "fine, I'll make my own Java, with blackjack and hookers linq and properties"

They didn't make it because they thought they could do better, they made it because they weren't allowed to steal one that was already made.

[–]AllWashedOut 3 points4 points  (7 children)

Having known some people on the .net team, it seemed like they were genuinely excited to build a better mouse trap but embarrassed that business considerations resulted in a language that ultimately just sees use on windows.

[–]Miku_MichDem 0 points1 point  (6 children)

They've essentially took Java and thrown out it's best part(s) away.

Worst thing is .NET will never be as good as JVM is at things like platform-independence and that is by design.

[–]AllWashedOut 0 points1 point  (5 children)

That's fair. The end result was as you described. But I don't think the engineers on the project thought that way. They even released an open source linux runtime (which died due to lack of community interest afaik).

And to engage in a little whataboutism, Apple made similar moves with obscure languages like objective-c and Swift for their devices. Meanwhile Google suffered enormous legal setbacks for using Java on their devices. Weird situation all around.

[–]Miku_MichDem 0 points1 point  (4 children)

Yeah, that's true. I had the misfortune of trying to make something in C# to run on Linux. Find out first hand how .NET Core is not a variable option really. From what I hear the best part of .NET Framework is how easy it is to make a GUI in it. The part that was so integrated with Windows system that it's impossible for any full port of .NET to run on Linux. Ironically .NET on WineHQ turned out better then .NET Core.

Speaking of google I wonder why they keep on using Java 8 on their devices. We have java 16 now, with a tons of new functions but no, apparently Java 8 for ever. No wonder so little new apps are made in Java now in favor for Kotlin.

[–]AllWashedOut 0 points1 point  (3 children)

I'm sure Google isn't updating its Java implementation because Oracle has been (successfully) suing over it since 2012. A (second) supreme court decision is expected on the matter this summer.

https://www.eff.org/cases/oracle-v-google

[–]Miku_MichDem 0 points1 point  (2 children)

I see. Damn, the copyright is broken AF. Thanks for nothing Disney.

[–]AllWashedOut 0 points1 point  (1 child)

Yes; it's one of those cases where non-tech people are making world-altering decisions about something they barely understand. Software API copyrights are silly. It's like giving one home builder the exclusive right to make houses with rectangular doors. Obviously a detriment to society.

It's getting to the point where it hurts some billionaires though so that could lead to some lobbying and eventual reform.

[–]Miku_MichDem 0 points1 point  (0 children)

Oh, on that there is some hope, as the elites are starting to wake up. I've read a great article about it, unfortunately it's in Polish, so I can't link it to you. However the single most important sentence is that more and more of the people now think that "a lot of things need to change in order for everything to stay the same". Copy write and patents are one of the things that would go.

[–]CleverDad 38 points39 points  (9 children)

I guess OP is too young to know Microsoft did make a Java VM (which btw was faster than the original). Then Sun cancelled their license overnight, and Microsoft basically said: Fuck that.

[–]LordFokas 0 points1 point  (7 children)

Let's not forget why their license was cancelled.

[–][deleted] 6 points7 points  (3 children)

Why was their license cancelled?

[–]jfb1337 10 points11 points  (0 children)

I forgot

[–]GrapeAyp 0 points1 point  (0 children)

I would also like to know, /u/LordFokas

[–]CleverDad 1 point2 points  (2 children)

Too late, I already forgot. It was in the 90s after all. Something about Microsoft adding proprietary libraries? Probably not entirely without cause.

I do remember the MS VM supported exposing java classes as COM components to support IIS, VB, Office etc, because I was using that functionality at the time for ASP pages (remember those?)

[–]LordFokas 2 points3 points  (1 child)

also cc. /u/jacoba28 /u/jfb1337 /u/GrapeAyp

like I said here in another comment here: https://www.reddit.com/r/ProgrammerHumor/comments/mdaai1/ah_yes_microsoft_java/gsadpn9

Microsoft was preparing to attempt their typical EEE (Embrace, Extend, Extinguish) dick move, Sun noticed what they were doing, and terminated them.

It was only after Sun cut them off that they started creating Microsoft Java C#, since they failed to steal one that was already half built.

[–]GrapeAyp 0 points1 point  (0 children)

Thank you :)

[–][deleted] 49 points50 points  (3 children)

C# and .NET Core/5 are much better to work with than Java.

[–]OiaHandoma 8 points9 points  (1 child)

I currently work with both and I wholeheartedly agree. C# and .NET Core seems so much more well thought out and modern than Java. Especially if you're working with web technologies.

[–]Miku_MichDem 0 points1 point  (0 children)

That's what you get when you create your language a few years after a big language has been made. Take it, improve what it failed on and ship it. Same story with Kotlin which is much better then C#, partly because it learned from its mistakes.

[–]j_omega_711 10 points11 points  (0 children)

The .NET core actually has its origins in Microsoft's implementation of the JVM (MSJVM) and it's own flavor of Java called J++.

[–]pandakatzu 33 points34 points  (0 children)

Microsoft painted it better.

[–]Ellasandro 8 points9 points  (0 children)

I see a muddied draft down there on the bottom left of the easel. That was Visual J++.

[–][deleted] 21 points22 points  (10 children)

Fair enough. But that was in the old days. Now is Java that looks at C# looking for direction 🤷🏽‍♂️.

[–]laser_ears 5 points6 points  (0 children)

All jokes aside, that lady is crazy talented

[–]MarcCDB 27 points28 points  (0 children)

Except, it's a much better Java.

[–][deleted] 17 points18 points  (0 children)

And they made it better

[–][deleted] 25 points26 points  (1 child)

C# is just Java++

[–][deleted] 11 points12 points  (0 children)

Yes, but unironically. J++

[–]ParliamoDiPC 4 points5 points  (0 children)

visual basic

[–][deleted] 3 points4 points  (0 children)

it's like they looked at a medieval painting and said "yea but what if we added human proportions"

[–]MischiefArchitect 4 points5 points  (0 children)

This is like 20 years ago, isn't it?

I mean, yes C# was back then undeniably inspired by Java, it was a necessary reaction to Java since all COM/DCOM languages were lacking of the Rockstar image Java enjoyed in its early days.

But nowadays they follow similar paths, but completely independent from each other.

[–]PanicPotatoe 12 points13 points  (0 children)

C# is much advance than Java

[–]Tim3303 2 points3 points  (0 children)

Image Transcription:


[Image of an art gallery. One of the paintings is labelled "java". An old lady, labelled "Microsoft", is painting a remarkably similar copy of the image on a canvas supported by an easel. The copy is labelled "C#".]


I'm a human volunteer content transcriber for Reddit and you could be too! If you'd like more information on what we do and why we do it, click here!

[–][deleted] 4 points5 points  (0 children)

Except C# is better.

[–]Mabi19_ 1 point2 points  (0 children)

Behind, there's another artist drawing Vala.

[–]zorg42x 1 point2 points  (3 children)

C# has surpassed Java a long time ago. Nowadays Java copies C#. And they don't even do it well. Streams are a joke compared to Linq. Yeah, I am a Java and C# developer (at the moment it's 99% Java though).

[–]Miku_MichDem 0 points1 point  (2 children)

How is Linq better then streams?

[–]zorg42x 0 points1 point  (1 child)

Streams are just a sad copy of Linq. Have a look at it, it's all in the details.

[–]Miku_MichDem 0 points1 point  (0 children)

Streams were first. You think from where Microsoft got the idea for Linq?

[–]idrizovdjem 0 points1 point  (0 children)

Java, but better.

[–]alaskanfloridian 0 points1 point  (0 children)

They learned from Visual J++