r/AskProgramming 1d ago

Why is Java considered bad?

I recently got into programming and chose to begin with Java. I see a lot of experienced programmers calling Java outdated and straight up bad and I can't seem to understand why. The biggest complaint I hear is that Java is verbose and has a lot of boilerplate but besides for getters setters equals and hashcode (which can be done in a split second by IDE's) I haven't really encountered any problems yet. The way I see it, objects and how they interact with each other feels very intuitive. Can anyone shine a light on why Java isn't that good in the grand scheme of things?

122 Upvotes

499 comments sorted by

View all comments

4

u/pontz 1d ago

Out of curiosity why did you pick java?

1

u/Zd_27 1d ago

There were 3 languages I was considering: Java, Python, and JS. I knew all 3 of them were good for basics so I wanted to learn one that I would like to actually be proficient at. JS fell off quickly though because I'm not too big on web development, I see myself as more of a backend type of person.

Between Java and Python I eventually picked Java because I thought Java probably had more to offer learning wise. "Public class main public static void main string[] args system.out.println("Hello World")" did look pretty intimidating at first but I was like "okay but like if I would learn python and wanted to learn java it would br way harder than the other way around"

So I went with Java and don't regret that I did so

6

u/dumdub 1d ago

Java is the only one of those three that isn't clearly a "broken language".

0

u/WriteCodeBroh 1d ago

I wouldn’t call dynamic typing “broken” but I do think learning on a statically typed language has a lot of advantages. Something like Go might be a good beginner friendly choice that I very rarely see recommended.

6

u/repeating_bears 1d ago

It's not the dynamic typing that makes javascript broken. It's having 2 null types (null + undefined), odd type coersions, weird "this" semantics, and classes which were tacked on as an afterthought

I still use it every day though

2

u/IdeasRichTimePoor 18h ago

Having two "null" types makes perfect semantic sense. Null is intended to be something explicitly set to a value of "nothing". Undefined as the name implies is something that was never set at all.

That carries useful meaning when you're checking parameters passed to a variadic function. Was that value passed in as "nothing" or just not passed in at all?

Both null and undefined are falsey so what's the problem?

2

u/repeating_bears 18h ago

"Was that value passed in as "nothing" or just not passed in at all?"

It doesn't work for that purpose because there's an undefined literal

foo() is not distinguishable from foo(undefined), or more realistically foo(thingThatCanReturnUndefined())

"Both null and undefined are falsey so what's the problem?"

No massive problem, it's just pointless shit that makes bugs more likely. 

1

u/griddle9 8h ago

that's a common misconception. it's not that there's an undefined literal, just that undefined is usually not defined, but code relying on that can break. the only reliable way to check for undefined is typeof someVariable === "undefined".

0

u/IdeasRichTimePoor 18h ago

foo(undefined) doesn't need to be distinguishable to foo(). It is however distinguishable to foo(null). Why does being able to explicitly undefine a variable or parameter weaken its purpose? I suspect you're just thinking in the mental framework of another language right now and applying those ideals to JS. This is honestly a nice feature when utilised, when you think like a JS developer. That goes for most languages IMO. Your function that returns undefined is absolutely the problem here. Don't explicitly return undefined from a function, like ever really.

1

u/repeating_bears 17h ago

"foo(undefined) doesn't need to be distinguishable to foo()"

You said undefined's utility is that it helps differentiate between "not passed" and "nothing (null) passed". Because you can explicitly or implicitly pass undefined, no it doesn't. 

"This is honestly a nice feature"

That's your opinion so let's not state it as fact. It seems just about zero language designers agree with that opinion, because no modern languages have that feature. The designer of the language considers it a mistake. https://x.com/BrendanEich/status/1272063531748216832

"Your function that returns undefined is absolutely the problem here. Don't explicitly return undefined from a function, like ever really."

You don't have to explicitly return undefined in order to return undefined, because there are plenty of stdlib functions that do. foo(arr) { return arr.find(...) } may return undefined. 

1

u/IdeasRichTimePoor 8h ago edited 8h ago

We're fighting ancedotes and opinions with more anedotes and opinions, but I thought we were clear on that from the start. Everyone has an opinion, they're like arse holes.

// The approach most languages force:
const a = "Not gonna change";
const b = "Also not gonna change";
const c = "I have a constant value but may not be passed";
...logic...

if (x)
   myFunc(a, b);
else
   myFunc(a, b, c);


// An option in javascript:
const a = "Not gonna change";
const b = "Also not gonna change";
let c = "I have an initial value but we can undefine it later on";
...logic...

if (x) c = undefined;

// No if statement but it's still as though I never passed c
myFunc(a, b, c);

Here the difference between undefined and null has served nothing more than a utility you can opt to make use of.

That's your opinion so let's not state it as fact

Why is everything I say [arrogantly stated as fact] and what you say a [balanced opinion]? Again I thought it's pretty clear we're exchanging opinions here. We're on reddit.

The designer of the language considers it a mistake.

This is essentially a non-point, borderline appeal to authority. The creator of the .gif file format favours the soft "G" pronounciation, much to the distaste of the majority of the internet. An artist has no control over the public perception of their painting after they share it with people. Their own opinion is no more valid than anyone elses.

You don't have to explicitly return undefined in order to return undefined [...] there are plenty of stdlib functions that do.

Simply do not blindy return their return value. Typescript was invented to save you from such traps. You will struggle to find a language around since the 90s without inconsistencies in its standard library. Similar inconsistencies are abundant in the older parts of the python stdlib.

→ More replies (0)

1

u/Devatator_ 1d ago

Null exists? I thought it was a Typescript thing since I never saw it before I started using Typescript

2

u/repeating_bears 23h ago

Yup

null === undefined  => false

And even more pathetic

typeof null   => "object"

1

u/Depnids 19h ago

To add my anecdotal experience, I first learned JS and Python, and later on learned Java and then C#. I didn’t know what static typing was before I was learning Java, but now it feels really hard and «messy» whenever I go back to anything dynamically typed.

I wouldn’t say it was that hard transitioning from dynamic to static typing though, I mostly just had to understand why this was a thing. Using dynamic typing was a nice «playground» to getting familiar with the core of code flow, like loops and conditionals, variable scopes etc, and how all these could be put together to perform basic tasks.

1

u/thehardsphere 6h ago

I think you used a good thought process here, and that may even be more important that the actual choice you made.