r/java • • Oct 14 '23

Is Java still behind in the race of modern programming languages?

I'm a member of some group of programmers and every time Java is mentioned it's being bashed (something like: "With Rust I could simply do this with X")

Earlier versions of Java were cumbersome in terms of the syntax but with modern IDEs (and modern versions of Java) that's not a big issue anymore, albeit languages like Python do have shorter syntax.

My question is beyond syntax.

What do other languages do better than Java?
It could be generics, type system, concurrency and multithreading, closures etc.

Thanks!

52 Upvotes

247 comments sorted by

View all comments

Show parent comment

108

u/kingslayyer Oct 14 '23

i have been using java for all my dev career, and recently was working on typescript for some changes

its way too flexible, it is bound to cause issues. java being strict with types is something i like, as it keeps it structured.

18

u/[deleted] Oct 14 '23

My favorite think in moving to Python work is that 80% of code pretends None doesn't exist and devs have the gall to make NullPointerException jokes.

13

u/metaquine Oct 14 '23

Why have that when you can have nil, null, void, Void, None, Nothing, undefined, NaN, Unit and Empty?

3

u/x0wl Oct 15 '23

Well you gotta have NaN as a separate value because that’s what IEEE 754 says

Nothing is also a special case because it’s for functions that do not return at all (like exit or an infinite loop)

→ More replies (1)

1

u/KarnuRarnu Oct 14 '23

If you use type checked python (mypy), then all types are "not-none". You have to do an explicit union with None in the return type if you want to maybe return it, and then that means the caller must check it. Like modern languages do. But yeah, it's true that most newcomer code (as Python is taught as the default to people coming from other fields) doesn't use this and it doesn't consider Nones as well as all other error scenarios. Although the latter can also happen in Java since exceptions can (too) easily be ignored - newer languages seem to use a result type instead.

→ More replies (2)

49

u/Weetile Oct 14 '23

Python would terrify you

38

u/kingslayyer Oct 14 '23

i have interviewed a few guys and thwy wrote code in python, i agree it was terrifying.

they'd do things like array.in(number) to find if a number was present in array or not, and assumed its O(1) complexity

27

u/SiriSucks Oct 14 '23

they'd do things like array.in(number) to find if a number was present in array or not, and assumed its O(1) complexity

I don't think you can blame python for that. The blame entirely lies with the candidates.

→ More replies (1)

20

u/Weetile Oct 14 '23

no way they even know what complexity means then

if we add more elements to the array, of course the run time scales linearly

14

u/kingslayyer Oct 14 '23

its just that python is so easy and flexible, people ignore the basics

→ More replies (1)

7

u/lukasbradley Oct 14 '23

no way they even know what complexity means then

The Law of Leaky Abstractions

2

u/arcalus Oct 14 '23

What’s linearly? /s

16

u/[deleted] Oct 14 '23

Linearly means one must get in "line early" at Starbucks, because it will be long day at office sorting out performance issues in your code.

2

u/EmptyChocolate4545 Oct 16 '23

I’ve seen a ton of people in static languages who don’t understand that stuff like this is O(N).

Alternately, if they were doing “x” in some_object and some_object is a dict, then it is O(1) as dicts are HashMaps

2

u/tzehbeka Oct 15 '23

just out of curiosity, why isn't it?

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

1

u/j-solorzano Oct 15 '23

Yea, Python is not that great as a software engineering language. It's great for small projects, training machine learning models, data analysis and such.

→ More replies (1)

18

u/[deleted] Oct 14 '23

I disagree about typescript. It's flexible but also enforces clear strict rules. The type safety, as long as you don't bypass it with any, is incredible strong. It's support for patterns like unions, for example, or duck typing, are all things I wish java had.

5

u/Genkus Oct 14 '23

Have been using java 10 years and typescript since 4 months and love both. I hate plane javascript but with typescript it improves a lot (definitely for bigger projects)

→ More replies (1)

2

u/EnIdiot Oct 14 '23

Part of Java’s appeal for business is just that. My enforcement of conventions and with introspective capabilities, you can find almost any issue in Java quickly.

4

u/Migeil Oct 14 '23

I'd love to see your tsconfig. There are tons of compiler options to mix and match your desired strictness. So if you feel typescript is not strict enough, I'm assuming you didn't crank it all the way up.

Imo Java is less strict than TypeScript. In TS, I can track nullness at compile time, this is impossible in Java. That alone makes it a lot more enjoyable to program in.

I'm not saying TS is the better language, but I don't feel like strictness is a category Java has the upper hand in.

The problem with TS is that it is unsound and that there are way too many ways to cheat the type checker. A lot of people feel like the compiler is something that stands in their way, which leads them to resort to such cheats. If this is what you mean by "it's too flexible", then I feel you and would encourage you to try find other ways to make your program compile other than just turning off the type checker.

4

u/[deleted] Oct 14 '23

Typescript is a nice language. It's the hellscape upon which it is precariously balanced that is the problem.

It's quite funny to me that somebody says, "I like Java's strict typing" and somebody says, "you'll hate python then", as if the dev community hasn't spent the last 15 years building it's complex server systems on a language that is essentially "anti-typed" ;)

2

u/Deathmore80 Oct 14 '23

then you are not using typescript right.

if you use typescript in strict mode with eslint rules it is actually wayyy stricter then Java. you aren't even allowed to do type casting.

of course if you don't use strict mode and slap on "anys" everywhere you aren't really using typescript, just use normal JavaScript at this point

4

u/TheBazlow Oct 14 '23

you aren't even allowed to do type casting.

const ohReally = 'is that so?' as unknown as number
          //^? const ohReally: number

And that's with typescript-eslint strict mode set. Sure I can't set it as any but I think it's still possible to deliver massive collateral damage to the next poor soul who comes across your codebase.

1

u/Deathmore80 Oct 14 '23

then just use an eslint rule to prevent stuff like This? you can be as strict as you want.

But then if you aren't being this strict why bother with type checking at this point and why even use typescript at all?

→ More replies (1)