6 ms·
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
by dep_b 6y ago
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.
- mrkeen 6y agoDoes C# handle generics better than Java?
- LandR 6y agoC# generics are reified.
- accountLost 6y agoYou can't easily create a instance of the generic type in java. for example : return new T(); is possible in C#, not in java.
- ohgodplsno 6y agoThere is a way-ish, which is passing a Class<T> as an additional parameter and doing clazz.newInstance(). Definitely not pleasant though.
- Felk 6y agoFor that particular use case it may be better to pass a constructor reference / new instance supplier to not rely on reflection.
- Felk 6y agoAs "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
- paavohtl 6y agoC# 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.
- kaba0 6y agoBut 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.
- thrower123 6y agoFrom 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.
- dboreham 6y agoAre 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.
- dep_b 6y agoYou can write Java in Kotlin in less than a day.
- xwolfi 6y agoNot 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").
- thrower123 6y agoI 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.
- overtomanu 6y agoBackward compatibility is one of the biggest reasons
- skocznymroczny 6y agoThe 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.
- northwindfoo 6y agoVisual studio has c++ symbol rename, including class names. Has had it for a while as well. Fairly reliable, though occasionally it does fail, loudly.
- Semaphor 6y agoOP mentioned C#. Exactly the same is possible there.
- gmueckl 6y agoYes 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.
- shellac 6y agoDoes the LINQ expression tree stuff complicate things? I don't know how that works with respect to parsing.
- davnicwil 6y ago> 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.
- Semaphor 6y ago> 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
- HappySweeney 6y agoJava has a much better AOP story, but that will likely change once source generators become more mature.
- xwolfi 6y agoI 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" ?
- ludovicianul 6y agoWhy 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...
- hackerbrother 6y agoI 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.
- thrower123 6y agoThings 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.
- dep_b 6y ago> "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.
- pjmlp 6y ago> 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.
- codeulike 6y agoExactly, at the time it was invented, Java was a massive improvement on the incumbents in all sorts of ways
- AnimalMuppet 6y agoWe 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.
- dep_b 6y agoTrue, 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
- shellac 6y agoYour 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.
- xwolfi 6y agoWell 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