News for hackers. Stuff that matters.
Re:Background: how we got the generics we have (2020) by dep_b on Thursday April 01, 2021 @07:47AM (#26659244)
I really don't enjoy anything about Java except for the JVM and if I press somebody that advocates for Java about what the reasons are that I should use Java it's always about either the JVM or the fact that there's so much of it around. But never really a solid argument why the language itself is nice to work with.

If I would want to use something like Java for a project, I would always pick C# which is a better Java in all aspects.

Re:Background: how we got the generics we have (2020) by skocznymroczny on Thursday April 01, 2021 @08:29AM (#26659591)
The relative simplicity of the language allows it to have excellent IDE support. I can select a class name, rename it, and have it renamed in all files that use this class. And the IDE knows that this actual class is being used, not another class from another module that has the same name, and that it's not a string with the same value as the class name. With languages like C++ all you can do is grep and cry.
Re:Background: how we got the generics we have (2020) by Semaphor on Thursday April 01, 2021 @09:21AM (#26660151)
OP mentioned C#. Exactly the same is possible there.
Re:Background: how we got the generics we have (2020) by gmueckl on Thursday April 01, 2021 @09:52AM (#26660514)
Yes and no. The C# language does have conditional compilation, which is modelled after the C preprocessor. That can interfere with refactoring and limit its accuracy. The good thing is that this mechanism is rarely used in practice.
Re:Background: how we got the generics we have (2020) by shellac on Thursday April 01, 2021 @11:29AM (#26661700)
Does the LINQ expression tree stuff complicate things? I don't know how that works with respect to parsing.
Re:Background: how we got the generics we have (2020) by northwindfoo on Thursday April 01, 2021 @09:09AM (#26660006)
Visual studio has c++ symbol rename, including class names. Has had it for a while as well. Fairly reliable, though occasionally it does fail, loudly.
Re:Background: how we got the generics we have (2020) by davnicwil on Thursday April 01, 2021 @08:36AM (#26659672)
> a solid argument why the language itself is nice to work with

Java with IntelliJ is awesomely productive. You barely have to type anything beyond new variable / field names, everything else is generated or tab completed. Refactoring is a breeze.

That, times 'worse is better' - it's the language and toolset I already know for the types of things it's good at. I have no doubt C# is comparable or better at most things, but probably not so much so that it is worth switching.

Re:Background: how we got the generics we have (2020) by Semaphor on Thursday April 01, 2021 @09:26AM (#26660221)
> Java with IntelliJ is awesomely productive.

They have a C# IDE (Rider) now, based on IntelliJ. While it was originally the only non-Windows C# IDE, I and others have switched to it from Visual Studio (which is almost as good) even on Windows.

> I have no doubt C# is comparable or better at most things, but probably not so much so that it is worth switching.

I’d say you are right. Now. 10 years or so ago (6/7/8 times) I’d have disagreed, C# avoided many of the mistakes* Java made and was able to become far more pleasurable to use, it took some time for Java to catch up again.

*: Mistakes only in hindsight

Re:Background: how we got the generics we have (2020) by ludovicianul on Thursday April 01, 2021 @09:21AM (#26660153)
Why does it always has to be language 1 vs language 2? "Better" is hardly something objective about languages. This is why people are still building new languages every year. To make things "better", although ultimately a bunch of others will find quite a big list of why they don't like it. Just pick whatever language you like. As long as you have good tooling and community around it, it won't be neither the best nor the worst choice... It's just "a choice"... Projects hardly fail because of the language itself (although there are some well known failures with dynamically typed languages). It's mostly bad architectural or business decisions...
Re:Background: how we got the generics we have (2020) by dep_b on Friday April 02, 2021 @09:35AM (#26671292)
> "Better" is hardly something objective about languages.

Rust is better than C

C# is better than Java

You can talk about tooling, environments, how many people use it, what you can use it for, but when it really boils down to the language there are languages that are better than others while trying to achieve the same.

I mean I use Elixir for other things than Swift or Rust or F#, Elixir is the best language for highly concurrent "message passing" systems. Some features of Elixir that I don't immediately like like it's type system unlock possibilities that no other languages have. But I don't see anything like that in Java, unless I really look around in 1993 and the only competitors are C++ and nobody-uses-it-yet Python.

Re:Background: how we got the generics we have (2020) by hackerbrother on Thursday April 01, 2021 @09:24AM (#26660190)
I think that in comparison, what happened with Javascript has been great honestly. People have been completely stuck with it, so we've built a great server side (Node.JS / npm / yarn) and client side (React, Vue, Typescript, Babel) ecosystem around it. I think great things can happen if you stick with a language and work with that limitation.
Re:Background: how we got the generics we have (2020) by thrower123 on Thursday April 01, 2021 @09:49AM (#26660483)
Things will be really exciting once WebAssembly finally breaks through (Next year in Jerusalem!...) and we're not forced to compile better programming languages to Javascript.
Re:Background: how we got the generics we have (2020) by thrower123 on Thursday April 01, 2021 @08:12AM (#26659458)
From what I have seen, I'd probably pick Kotlin if I had to be on the JVM. Seems to strike a nice balance between sanding off the rough edges of Java syntax, and still being conventional and blub enough that it won't put people off.
Re:Background: how we got the generics we have (2020) by dboreham on Thursday April 01, 2021 @09:22AM (#26660174)
Are you assigning any cost to : Kotlin is not Java and therefore new tools, developer training, etc are required? I'd want Kotlin to be significantly better than Java to justify the fact that it's not Java, if you see what I mean.
Re:Background: how we got the generics we have (2020) by dep_b on Thursday April 01, 2021 @01:58PM (#26663923)
You can write Java in Kotlin in less than a day.
Re:Background: how we got the generics we have (2020) by xwolfi on Thursday April 01, 2021 @10:26AM (#26660887)
Not sure everyone agrees but each time I've used type inference language (really just Groovy to be honest, but many many many different teams and companies), it ended up with an enormous mess of code that the brain of all of us devs had to parse themselves. We rolled back to Java many such critical paths just to be able to maintain them.

My little pitch when starting a migration project in a distressed no-type language team is to make them read the code and explain it, while asking about the type of objects they use and show them when they read it's their brain parsing it with high effort. If they de-optimize and just write the types more often, it becomes much clearer longer.

You can type usually in those language but often people want to use the "proper way" as shown in ultra simplistic examples in manuals for sales pitches and end up thinking the right way to code is to write as little as possible (combined with the no-comment belief they have but don't map to "no comment because clear enough code").

Re:Background: how we got the generics we have (2020) by thrower123 on Thursday April 01, 2021 @11:48AM (#26662017)
I mean, Groovy is terrible, and there is not very good tooling for it.

That's not the case for Kotlin, that has the full weight of JetBrains behind it.

Re:Background: how we got the generics we have (2020) by zmmmmm on Thursday April 01, 2021 @07:08PM (#26667419)
> We rolled back to Java many such critical paths just to be able to maintain them

I guess that's what I see as one of the advantages of Groovy. You can do ultra rapid implementation of something with minimal code and then as it becomes more critical you increase its type safety by adding first Groovy type hints, but further along that curve, convert it fully to Java or another statically typed language. So what you describe as a problem I see as sort of, optimal workflow, and the real problem is being forced to universally choose one or the other in other languages.

Re:Background: how we got the generics we have (2020) by pjmlp on Thursday April 01, 2021 @09:24AM (#26660194)
> But never really a solid argument why the language itself is nice to work with.

If you were trying to write portable C++ code in 1996 you would get it, specially when using each OS specific C++ compiler provided by the platform vendor.

Re:Background: how we got the generics we have (2020) by AnimalMuppet on Thursday April 01, 2021 @03:51PM (#26665208)
We cross-compiled to get gcc on every platform. Even then, it was still:

   #ifdef _AIX
   ...
   #else ifdef SGI
   ...
   #else ifdef WINDOWS
   ...
   #else // everything else
   ...
   #endif
Shudder.

But the other thing that Java had is the library. Compared to C++'s standard library in 1996, it was a revelation.

Re:Background: how we got the generics we have (2020) by dep_b on Friday April 02, 2021 @04:30AM (#26669916)
True, a decent standard library is really important. Every language I enjoy to work with has a good way to do all of the standard stuff
Re:Background: how we got the generics we have (2020) by codeulike on Thursday April 01, 2021 @09:27AM (#26660227)
Exactly, at the time it was invented, Java was a massive improvement on the incumbents in all sorts of ways
Re:Background: how we got the generics we have (2020) by shellac on Thursday April 01, 2021 @09:31AM (#26660277)
Your first paragraph is a fair encapsulation of what Java was intended to be from 1994: a mullet of a language that is deliberately unexciting at the language end, but brings in a number of (at the time exotic) features at the VM end.

Things like GC, reflection, runtime loading of code, that were very familiar from more academic languages at the time.

Re:Background: how we got the generics we have (2020) by xwolfi on Thursday April 01, 2021 @09:51AM (#26660506)
Well I may try ! I'm not very religious, I used Java for everything since I've started programming and I work in low latency in an investment bank now. I adore Java, it's my truly native programming language, I try to know all of its quirks, study each new version and know still not enough to satisfy my love of it.

I also did a lot of C# to help on a GUI optimization project (because doing low latency if the GUI freezes every 10 minutes isn't great), and I was really surprised by how good it was so I wouldn't disagree it works nice.

BUT I like that Java works simply in linux, I like that it didn't yet got contaminated by all the crazy constructs from elsewhere (Groovy grr), I love the tradition around the syntax (I can't stand C# quirks sometimes). I do HATE with passion the meaningless generics, and I wish we'd ditch backward compat to steal it all form C++ templates.

I enjoy more than the language syntax itself that is close to most languages I like (Javascript, C#, C++), the team spirit around it. Believe me, it's much easier to use and understand maven (or maybe gradle who starts to get dangerous in real world projects where you can't afford 2 weeks of reverse engineering a madman's build script) than it was nugget, it's easier to use IntelliJ than to receive yet another stupid email from compliance about a Visual Studio license missing, it's nicer to build a jar and run it than to go through all the kinks of exe files... I dunno I may have started from Java and got to C# and done the opposite of your journey, but while I agree C# has superior features in some aspects (but sometimes they chose mess vs safety) I just wasn't convinced it could work for something more critical where you must do things as simple as you can, as clear as you can.

And let's not even start on C++ who's superior in every conceivable way except that it encourage, or doesn't discourage, every team I ever meet to create unbearable messes they can't fix, so focused they are fixing problems we can't even imagine in Java for reasons we can't comprehend our company even accepts to finance :D

Re:Background: how we got the generics we have (2020) by mrkeen on Thursday April 01, 2021 @07:52AM (#26659284)
Does C# handle generics better than Java?
Re:Background: how we got the generics we have (2020) by paavohtl on Thursday April 01, 2021 @08:15AM (#26659487)
C# implements proper reified generics. Generic types parameterised with different types are actual types in C#, while in Java generics is basically just syntax sugar for avoiding type casts. Each element in a List<byte> in C# takes 8 bits, while in Java each element in a ArrayList<Byte> is actually just an Object and therefore is a pointer (64 bits) to a separate allocation.
Re:Background: how we got the generics we have (2020) by kaba0 on Thursday April 01, 2021 @11:41AM (#26661894)
But at the same time, reified types will create a separate object for each template type, making some optimizations happen only for a type that was used often. While in Java, ArrayList for example will benefit regardless of the concrete type.
Re:Background: how we got the generics we have (2020) by Felk on Thursday April 01, 2021 @08:13AM (#26659471)
As "better" isn't clearly defined, here are some things that some people might consider superior:

- primitives or any custom value types/structs can be used. No need for boxing or method duplication for primitives. - type information available at runtime, no need to pass 'Class<T>' parameters. - type constraint 'new' available, which means it must have a default constructor so you can do 'new T()'. No need to use reflection or pass a constructor parameter. - type constraint 'notnull' available - class-scoped compiler enforced covariance and contravariance, though I think you can get similar results with java's "? extends T" and "? super T" constraints

Re:Background: how we got the generics we have (2020) by accountLost on Thursday April 01, 2021 @08:04AM (#26659401)
You can't easily create a instance of the generic type in java. for example :

return new T();

is possible in C#, not in java.

Re:Background: how we got the generics we have (2020) by ohgodplsno on Thursday April 01, 2021 @08:28AM (#26659580)
There is a way-ish, which is passing a Class<T> as an additional parameter and doing clazz.newInstance().

Definitely not pleasant though.

Re:Background: how we got the generics we have (2020) by Felk on Thursday April 01, 2021 @08:30AM (#26659607)
For that particular use case it may be better to pass a constructor reference / new instance supplier to not rely on reflection.
Re:Background: how we got the generics we have (2020) by LandR on Thursday April 01, 2021 @08:01AM (#26659366)
C# generics are reified.
Re:Background: how we got the generics we have (2020) by overtomanu on Thursday April 01, 2021 @08:19AM (#26659513)
Backward compatibility is one of the biggest reasons
Re:Background: how we got the generics we have (2020) by HappySweeney on Thursday April 01, 2021 @09:14AM (#26660081)
Java has a much better AOP story, but that will likely change once source generators become more mature.
Re:Background: how we got the generics we have (2020) by xwolfi on Thursday April 01, 2021 @10:21AM (#26660815)
I find AOP dangerous. I love the abstract concept, but each time I used it myself I ended up creating a mess that I had to painfully rollback just to produce less insanity for my poor colleagues.

I'm sure it's me but do you use it yourself and why ? Don't you get lost in the indirections in big projects "oh shit where is that thing again that auto inject itself here" ?