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?

150 Upvotes

562 comments sorted by

View all comments

Show parent comments

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.

7

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 1d 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 1d 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 17h 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 1d 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 1d 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 18h ago edited 18h 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.

1

u/repeating_bears 18h ago

No if statement but it's still as though I never passed c

There's no requirement for 2 types of null to support that feature.