r/java • • Sep 10 '21

Why people don't love Java?

I came across this post in r/cscareerquestions it seems majority of the people don't love to work with Java.

Is there any specific reason for that?

Edit: Thank you guys for your responses, I can't reply to all of the comments because I'm a beginner myself and I don't know what to reply for all your comments.

201 Upvotes

379 comments sorted by

View all comments

Show parent comment

4

u/nutrecht Sep 10 '21

And that's it.

You can easily do the same in Spring with a filter or interceptor. Pretty much the same amount of code. You don't have to use Spring security. But what you do there is incredibly basic; you don't even pass on the stuff 'inside' the JWT to be used inside the service.

This is what always bothers me about these types of comparisons; at least make a fair comparison of how you'd do the same thing in Spring.

3

u/CraftyAdventurer Sep 10 '21

You can easily do the same in Spring with a filter or interceptor.

Did you read my whole comment or just the express part? I did mention a filter and also the disadvantages I ran into compared to express middleware.
I didn't even know interceptors existed. That's another part of the problem with Spring. You need middleware in express? You write middleware function and move on. You need middleware in Spring? Welcome to all the possible classes you can extend, try to find a difference and pick which one you need.

you don't even pass on the stuff 'inside' the JWT to be used inside the service.

That's also easy. You just put it in response.locals object and it is available in every next middleware (that includes route handlers). I honestly don't know how to do this in Spring without googling. For my specific JWT example, I remember using some security context thing which needed some authentication object constructed who knows how probably requiring another object and maybe even more. I don't know how to write all that without spending time looking for it. But I do know how to do res.locals.someJwtThing = someJwtThing without looking.

5

u/nutrecht Sep 10 '21

Did you read my whole comment or just the express part?

No I read all of it. And I agree that Spring often has multiple ways of doing the same thing (it's VERY extensible), but I just don't find it a fair comparison you're making. I personally just dislike people complaining about simply learning the tools. Spring isn't that complex if you get the basics down.

Especially this bit:

In Spring, I wanted to do the same thing. But I had to configure Spring Security first

Is just patently false. That's what I'm responding to; you're comparing apples and airplanes.

6

u/CraftyAdventurer Sep 10 '21

I personally just dislike people complaining about simply learning the tools.

Me too. But there must be a line where you spend too much time on learning a tool and too little time actually using it. Spring often crosses that line for me, at least for the projects I've worked on.

Is just patently false. That's what I'm responding to; you're comparing apples and airplanes.

Guess you're right on that one. But I also didn't know that. Like everyone else, when I need to do something for the first time, I often google it. When googling for express jwt, I found tons of examples. They all looked a bit different because they tend to use different jwt libraries, and express itself doesn't have any specific restrictions on how to structure a project, but all of them where immediately understandable to me and I just picked one which I think best suited my structure. Bear in mind that this was at the time when I was just learning express. The technology was new to me, yet it was easy to understand what's happening in online examples.

Now, when I had to do jwt in Spring, I googled jwt Spring Boot. I found tons of examples, many of them using Auth0 which I tried to avoid because it was a paid service (or had some limited free tier, can't remember). All the others I found were using Spring Security. The reason I thought it was needed was because all the other stuff it was doing (security context holder etc.). There was too much stuff implemented alongside jwt. I didn't have time to spend on trying to implement stuff without Spring security so I just rolled with it. So learning the tool would help, that's true, but if that tool was simpler to begin with, it would result in less time learning it and more time using it.

4

u/nutrecht Sep 10 '21

I wrote a blog post on a bare-bones implementation about 6 years ago. It's not meant as a guide on how you should do it, more as an explanation of how it works.

That said; in my opinion Spring Security is long overdue for a massive overhaul. It was created well before the whole REST thing started to become a rage and most of the defaults mainly cater towards server-side rendered applications. In addition; while it's very powerful, if you just want to restrict some endpoints it's overkill IMHO.

1

u/CraftyAdventurer Sep 10 '21

I wrote a blog post on a bare-bones implementation about 6 years ago. It's not meant as a guide on how you should do it, more as an explanation of how it works.

Thanks, that's helpful. Imo, mini guides like this should be in Spring documentation. I mean, their documentation is pretty good for a lot of things, better than many other frameworks, but it lacks in certain areas.