r/programmingcirclejerk • I've never used generics and I’ve never missed it. • Apr 16 '21

This cannot be understated: Java simply feels good to write

https://jackson.sh/posts/2021-04-java-underrated/

[removed] — view removed post

79 Upvotes

35 comments sorted by

126

u/alibix Apr 16 '21 edited Apr 16 '21

I love Java's verbosity. It makes code very easy to read and makes it clear what is happening. Consider the following examples:

Rust (🤮)

struct Unjerk {
   username: String,
   upvotes: f64,
   content: String
}

Java (😍)

public class Unjerk {
    private String username;
    private int upvotes;
    private String contents;

    public Unjerk(String username, int upvotes, String contents) {
        this.username = username;
        this.upvotes = upvotes;
        this.contents = contents;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public int getUpvotes() {
        return upvotes;
    }

    public void setUpvotes(int upvotes) {
        this.upvotes = upvotes;
    }

    public String getContents() {
        return contents;
    }

    public void setContents(String contents) {
        this.contents = contents;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Unjerk unjerk = (Unjerk) o;

        if (getUpvotes() != unjerk.getUpvotes()) return false;
        if (!getUsername().equals(unjerk.getUsername())) return false;
        return getContents().equals(unjerk.getContents());
    }

    @Override
    public int hashCode() {
        int result = getUsername().hashCode();
        result = 31 * result + getUpvotes();
        result = 31 * result + getContents().hashCode();
        return result;
    }

    @Override
    public String toString() {
        return "Unjerk{" +
                "username='" + username + '\'' +
                ", upvotes=" + upvotes +
                ", contents='" + contents + '\'' +
                '}';
    }
}

Notice how the Java version's verbosity lets a programmer know exactly what is going on. There is no hidden ivory tower implicit magic like in the Rust code! With Java, what you see is what you get.

73

u/DumpsterDoofus loves Java Apr 16 '21

You fool, the Java version is missing null guards.

2

u/alibix Apr 16 '21

Make your zeros useful

23

u/Grodesby Apr 16 '21

It is just as well Java feels good to write, given the amount of writing you need to do. Imagine if it felt as bad to write as Rust!

18

u/ProfessorSexyTime lisp does it better Apr 16 '21

lol no Lombok

8

u/hernytan What’s a compiler? Is it like a transpiler? Apr 16 '21

Lol imagine using a library that the Oracle Java team is actively fighting against

6

u/ProfessorSexyTime lisp does it better Apr 16 '21

lol imagine taking sides with Oracle

35

u/wonderb0lt loves Java Apr 16 '21

Or, like, ya know

public record RealUnjerk(String username, Integer upvotes, String content) {}

40

u/alibix Apr 16 '21

Looks like language bloat.

8

u/segv Apr 16 '21

Like generics in Go?

34

u/pythonesqueviper Do you do Deep Learning? Apr 16 '21

>Implying Java 9+ adoption rates aren't abysmal

25

u/Grodesby Apr 16 '21

Out of preview since Java SE 16, last month, I see.

11

u/BufferUnderpants Gopher Pragmatist Apr 16 '21

Getting bought by Oracle was the best thing that could happen to Java, the original authors were Lisp weenies that thought you were dumber than a gopher and made C like language for morons.

8

u/hernytan What’s a compiler? Is it like a transpiler? Apr 16 '21

dumber than a Gopher

Insert Rob pike quote here

12

u/wonderb0lt loves Java Apr 16 '21

Yeah, you can't say they don't try to make shit a bit less shitty.

7

u/ProfessorSexyTime lisp does it better Apr 16 '21

lol tfw most of everyone is still on Java 8 or 11.

14

u/hyperion2011 Apr 16 '21

upvotes: f64,
int upvotes

🤔

4

u/alibix Apr 16 '21

Rust strives to be correct.

59

u/tesch34 Apr 16 '21

Java is criminally underhyped

Is this jerk?

30

u/muntaxitome in open defiance of the Gopher Values Apr 16 '21

Probably just a youngster that missed a full decade of java hype by two decades.

15

u/0dyl There's really nothing wrong with error handling in Go Apr 16 '21

pub const Unjerk = struct {

In the about me OP describes themselves as a "4th year computer science student." So, yeah.

};

43

u/[deleted] Apr 16 '21

Nominal typing saves time

lol?

Type guards are my least favorite TypeScript feature. They're essentially duck typing that you have to implement yourself and trust that they're implemented correctly.

As we know, no Java program uses reflection to simulate duck typing.

There's something about declaring a type AND having to write validation logic for said type that really rubs me the wrong way.

As we know, no Java program uses instanceof and upcasting to do basically the same thing as in the example (that's called flow-sensitive typing btw).

Turns out statically typed languages are slightly better than webshit with a linter like TypeScript and Python, who would have thought!

33

u/mizzu704 uncommon eccentric person Apr 16 '21

The perspective of an ignorant computer science undergrad

There's literally rules against this

20

u/[deleted] Apr 16 '21

Rules in this sub or rules in life? Who knows, this guy could be the next 10xer at your job

34

u/VeganVagiVore what is pointer :S Apr 16 '21

Vote no on letting children exist

4

u/PthariensFlame uncommon eccentric person Apr 17 '21

Ah, I see you’re part of the Arkansas state legislature.

26

u/xigoi log10(x) programmer Apr 16 '21 edited Apr 16 '21

When consuming third-party libraries in Java, you always know exactly what types need to be passed to a method. Most importantly, incorrect usage of a function will result in red squigglies in your editor. Given that heavy library usage is in, I think more people should be excited about Java.

This just in: Java is the only statically typed language in the world.

When a developer has to refer back to the implementation of a method to figure out which types to pass it, that's a waste of time.

Documentation? I've never heard that word.

How many languages can you think of that meet the following conditions?

  1. Quality package manager and build system (I 💚 Maven)

  2. Nominal typing

  3. Large community

  4. Hands-off optimization

You know you want to say the R-word.

15

u/Erelde Considered Harmful Apr 16 '21

Racket ?

14

u/n3f4s WRITE 'FORTRAN is not dead' Apr 16 '21

I'm not sure R has any of that

6

u/RoutineTension Apr 16 '21

You have a point, Ruby on Rails is quite nice in this regard.

18

u/Hueho LUMINARY IN COMPUTERSCIENCE Apr 16 '21

https://jackson.sh/about/

Hi! My name is Jackson Roberts. I'm a 4th year computer science student at the University of Colorado Boulder.

17

u/NynaevetialMeara Apr 16 '21

This fills my private static void with warmth.

8

u/hernytan What’s a compiler? Is it like a transpiler? Apr 16 '21

As jerkable as this is, this violates the rule of enthusiastic youngsters.

8

u/Evinceo Software Craftsman Apr 16 '21

Don't kink shame

4

u/camelCaseIsWebScale Just spin up O(n²) servers Apr 16 '21

.... After writing COBOL.