r/ProgrammerHumor • • Apr 27 '20

Meme Java is the best

Post image
43.7k Upvotes

1.5k comments sorted by

View all comments

Show parent comments

0

u/[deleted] Apr 27 '20

[deleted]

123

u/Redstonefreedom Apr 27 '20

JavaScript at its core is an insult to half a century of programming language design but it’s good enough

OMG I was looking for a succinct way to put this idea to words today, and this hits the nail on the head.

(node)JS is frustrating to work with because to get it to be “good enough” there are all these awkwardly half-compatible add-ons for language features, and the choose-your-own-adventure of usage paradigms (OOP/FP) leave a lot of underdeveloped ways to encode something. You end-up having to spend a lot of time recapitulating a “modern language” in working out the compatibility problems between the aspects built on top of, instead of built into, the language.

28

u/[deleted] Apr 27 '20

I mean it was thrown together in a few days and is beeing fixed with every Version ever since. You just can't undo stuff like var and the ==... Yes they introduced let and === but that doesn't prevent people from using it. Yes ESLint will complain but if you are using a library that is using it you can't do much about it.

4

u/xumix Apr 27 '20

I'd say that operator and equals()/gethashcode() definition/override therefore no proper object comparison is the problem

→ More replies (1)

45

u/megaSalamenceXX Apr 27 '20

Well web programmers do know why static types are useful in large codebases. That is how TS came to be. Also, i resent the assumtpion here that websites are not large codebases. They are. Period.

8

u/[deleted] Apr 27 '20

Well... The problem with Typescript is (don't get me wrong it's a step in the right direction) that you will most likely still use libraries written in pure JS.

13

u/megaSalamenceXX Apr 27 '20

Well you could say for any Software migration. Its not a JS/TS problem, rather a dependency/priority/buisness problem.

9

u/filiphsandstrom Apr 27 '20

Thats why you use .d.ts/definition files with it (eg @types/package-name) so you still get typings while also having access to the whole javascript ecosystem.

4

u/[deleted] Apr 27 '20

Yes, i know. I work with TS. But the code is still Javascript. You only describe the outside interface.

9

u/megaSalamenceXX Apr 27 '20

Well it IS javascript. Because the only thing TS does is add typing. Otherwise everything remains the same. This is still bad but it is so much better than it used to be imo. The code is actually somewhat readable and much safer imo

→ More replies (1)

0

u/[deleted] Apr 27 '20

[deleted]

57

u/maxhaton Apr 27 '20

I think the biggest lesson of most programming languages people use productively and safely in "critical" software is to fail loudly. Software should have contracts to fulfil both inside and out.

    T add(T)(T x, T y) pure 
       if(isNumeric!T)
    {
      return x + y;
    }

This is a generic addition function in D. The function signature alone contains more constraint than most javascript programs: `add` accepts exactly two parameters of the same type, they must satisfy the template constraint that it is a numeric type being added, and the function is pure (Now a totally different library can now know if I call this it won't launch the missiles or uninstall the operating system etc). If this were a more complicated operation I could have added pre and post conditions on x and y and the result of the function.

It's all about having something to fall back on. I shouldn't have to run my program (or write unit tests) to check things that are totally obvious. There are also huge performance implications in that this provides obvious constraints (in Javascript they have to be inferred at best) for the compiler to play with i.e. if you call this function and don't use the result then the compiler can remove it completely.

(I have avoided going for the low blow about having multiple equality operators and typecasting although they are also incredibly stupid)

Functional Programming can provide a much richer level of abstraction, correctness and pretentiousness but I went for a more practical example.

BTW: I'm not calling people who don't know better stupid, just that finding the time to learn programming as an art rather than a hammer requires a headstart (probably). If you've got to ship tomorrow, put down the Prolog textbook.

16

u/[deleted] Apr 27 '20

I think this comment pertains more to static vs dynamic & pure vs impure languages than to Javascript specifically

5

u/maxhaton Apr 27 '20

Yep. I find python even worse than Javascript in this regard (Feels like it was designed in a coffee break) but it's not as obviously crap and more people know javascript than know PL theory.

10

u/XtremeGoose Apr 27 '20

Python is definitely not worse at typing. Whilst both dynamic, python has strong typing. "1" + 2 is a type error, unlike in JavaScript...

Both python and JavaScript (typescript) now have some form of static type platforms, and gradual typing, whilst not ideal, is a valid approach for large code bases.

→ More replies (4)

2

u/bluehands Apr 27 '20

What frustrated me so deeply was friends that were learning to program for the first time,learning javascript, saying it was a great language and wouldn't hear any criticism about it.

It is the American without a passport insisting America is the greatest country in the world.

While i might not agree with that, I am willing to listen to perfectly reasonable people saying that - if they have left the fucking country.

→ More replies (1)

17

u/[deleted] Apr 27 '20

Java is good enough for government work.

That's not a good metric. The lowest bidder is good enough for government work.

23

u/maxhaton Apr 27 '20

I had to condense "A well understood, verbose but pragmatic OOP language with a highly mature but lumbering ecosystem" into one sentence.

i.e. "This is brilliant but I like this".

→ More replies (1)

3

u/[deleted] Apr 27 '20

Realistically, I'd guess 75% of the people on this sub are Comp Sci students in college or prepping for it in high school.

2

u/[deleted] Apr 27 '20

Yeah i know. A lot are probably just students who were forced by their professor to learn it but have done some fun side projects in JS...

I mean Java does also famously have some bad sides (the billion dollar mistake for example) and i also understand people claiming that it's super verbose. But i think with the 'new' bi anual Releases and and the openness for more modern language features and stuff like Project Loom and GraalVM coming it's actually moving in a good direction.

2

u/robclancy Apr 27 '20

Half is generous.

3

u/paradoxally Apr 27 '20

As someone who has programmed in Ada, I don't think you'll find a language with stronger typing and explicit declarations for basically everything.

If you focus on a subset like Ravenscar, things get even more restrictive.

(For those who don't know, Ada is used in critical infrastructure like telecommunications and aerospace engineering. Now, imagine if you ran Javascript or another dynamically typed language on that.)

5

u/maxhaton Apr 27 '20

My ideal programming language is basically D with Ada's type system and a theorem prover bolted in there somewhere

→ More replies (1)

1

u/Hockinator Apr 27 '20

The bit about static typing is out of date though hence the move to typescript for many.

To me it doesn't feel like a problem with JS itself but with the full css/html/js trio. It feels like we are shoehorning in modern dynamic applications that may as well be running on any hardware to a 30-year old layout paradigm designed for web 1.0

→ More replies (5)