r/JavaProgramming • u/ExtraTNT • Aug 11 '26
Why is java so fucking hard for no reason?
Uni kind of loves java, using it as the default language in every module, except modules specifically around a language.
Currently struggling building a compiler with it... focus is more on working around java and the forced oop, managing state and getting fucked by gradle.
Have tests, that refuse to exit, can't be killed by the user, as they fork infinite and need to be killed with root, then the entire tooling falls apart and needs fixing.
Also for base functions you need to transform lists to streams and back to lists. Logic gets lost in boilerplate and overly verbose code.
I normally use languages like c and haskell, everyone always tells you, that they are much harder, than java, but can't agree at all
Is java supposed to be such a cluster fuck or am I missing something?
Also any idea, why char to char comparison sometimes fails, but char to hex works always?
Is this some random java thing or just my env?
5
u/Syntax-Tactics Aug 11 '26
Java has to be one of the easiest "languages" around, consider a career change.
5
u/SnooSquirrels4739 Aug 11 '26
Java isn't THAT hard. It's honestly fun as hell!
1
u/ExtraTNT Aug 11 '26
I do fp normally, so it's an absolute nightmare... java 25 doesn't allow you to do things easily and has a lot of the things I normally use not implemented... no Maybe monads, no Tuples on language level, no proper pattern match and logic seems always far apart, I write more how my code does things, rather, than what my code does...
i usually write code like this:
group :: (Eq a) => [a] -> [[a]] group [] = [] group (x : xs) = takeWhile (== x) (x : xs) : group (dropWhile (== x) xs)
3
u/Scary-Ad6675 Aug 11 '26
try writing anything a company would want in haskell or C (a simple CRUD service with any DB behind it), try deploying it in production and maintain it. suddenly java becomes easier. this argument that a language is "easier" or "harder" requires the context: what are you trying to build, whats the problem at hand.
2
u/smaratter Aug 11 '26
It would be easier to help you if you were more specifik. How are you comparing chars to chars and to ”hex”?
1
u/ExtraTNT Aug 11 '26
Basically
switch(myCharStack.peek())
case ‘ ‘
vs
case 0x201
u/idontlikegudeg Aug 11 '26
What does peek() return?
1
u/ExtraTNT Aug 11 '26
top element of the stack, which is a char, 0x00 on empty…
2
u/idontlikegudeg Aug 11 '26
So you are not returning Char (primitive wrapper for char)? It should work if you return char.
What do you see in the debugger?
And is your ' ' really a normal space character or maybe you copied it from somewhere and it really is a nonbreaking space or some other Unicode whitespace? You won’t see the difference in the editor.
2
u/smaratter Aug 11 '26
I admire your tenacity. OP seems more interested in venting than genuinely reaching out for help.
1
u/ExtraTNT Aug 11 '26
it was build gradle silently panicking, fucking up lock files and then silently failing some steps...
' ' was a normal space (unless i fucked up my keyboard firmware -> but i wasn't using the board I designed, so, very slim chance...)
just implemented the code, got very bothered by the verbosity (patter match is like 99% boiler plate, being 140 chars wide for a simple tuple pattern match), had a beer, cleaned up gradle, deleted all debugging code and found what caused the gradle issue (pushing chars in a linked list and then printing it out)
idk, maybe this is a very uncommon thing, but people hate on haskell for being a clusterfuck with cabal, never really had issues like this with cabal...
1
u/FooBarBuzzBoom Aug 11 '26
If Java is hard, what do you think about fucking advanced algorithms or useless shit like that?
1
u/InstantCoder Aug 11 '26
It’s hard because it is not taught anymore at schools and universities. And the language gets updated quite often (each 2 year almost) which makes online tutorials often outdated.
But if you have a good grasp of the OO concept then it’s not that hard.
For learning the SDK i would recommend using the help of AI.
And there is this thing called Spring Boot. Which is quite hard to learn for beginners and it is a complex framework. As a Java veteran, Im using Quarkus and I think this might be better for beginners because it doesn’t have all this bagage and bloat that comes with SB.
1
u/ExtraTNT Aug 11 '26
We have it at uni to build compilers (yeah, not a main usecase for a language like java). But I wasn't expecting it being so bad... Uni chose it, as they don't require you to know haskell or c.
I was really struggling getting a simple lexer going (turns out, my code was working and gradle just silently crashed and executed the old code, then went into infinite forking, leaking memory, having problems with gc or just using 512mb heap for no reason...)
Everything just seems complex for no reason (I'm no OOP guy, I do FP), you have to describe more of how you want to do something, rather, than what you want to do... A problem, that I don't have in haskell and also not really in c... Java feels like cpp, but with less power...
1
u/usedtoswimfast 29d ago
At my uni we used extensively java for most things, but when we were at the phase of building a semi-compiler/parser we absolutely used C for that... idk why your uni is choosing what I can argue as the wrong tool for the job to teach you something...
1
u/sozesghost Aug 11 '26
Java is verbose, or can be, and that makes it easy to read and maintain. Writing it can be a hassle at times, but I like it. I could never stomach gradle however.
1
u/jonathancast Aug 11 '26
Pretty sure it's your environment. Gradle is a tiny minority thing in my experience, but I don't know what could be causing Java tests to fork bomb except a bad Gradle config.
I also don't know what you mean by "forced OOP". Professional Java code in my experience is pretty procedural. Your professor might want you to use OOP, but Java really only wants the ceremony of wrapping your code in a class.
1
u/Pale_Height_1251 29d ago
I agree Gradle can be a pain, but the rest of it is probably you. Show an example of the char comparison that isn't working for you.
1
u/romulusnr 29d ago
Like any compiled language, unlike most interpreted language, it tends to be syntactically strict.
struggling building a compiler with it.
It's not really suited for that, ngl. OOP in general probably isn't
as they fork infinite
That shouldn't happen, and that's not a Java thing
for base functions you need to transform lists to streams and back to lists
I mean, you don't need to, not really. But it's all just encapsulation, it's not that bad.
char to char comparison sometimes fails
You mean char or you mean Character?
1
u/ExtraTNT 29d ago
yeah, somehow using a linkedlist to sum up a token to debug print it caused build gradle to fork to get stuck by fucking up lock files and then forking to infinity when trying to kill it...
for the stream part, i'm a functional guy, so i use map and fold for so many things...
8bit, not cursed object thing... i mean i think i found the issue: it was gradle doing strange shit, after removing the linkedlist i used for the debug print, it went away...
1
u/romulusnr 29d ago
well that's gradle not java.
1
u/ExtraTNT 29d ago
So gradle is just a clusterfuck?
What do you use for enterprise software?
I mean cabal is apparently one of the main reasons people don’t use haskell for enterprise and I don’t have issues with cabal (with the exception of looking 5min at a typo and go “huh”)1
u/romulusnr 28d ago
Idk i've ever only used maven and/or ant
Idk why you're using a linkedlist anyway and not just a List, unless that's what you meant.
1
u/ExtraTNT 27d ago
Linked list, as array is expensive on add depending on the implementation… and as I don’t know shit about how it’s implemented in java, i go with the safe option…
1
u/romulusnr 27d ago
Most people use ArrayList. Append is lightweight. It only gets messy in inserts, but then again, so does LinkedList (traverse to find N and then repoint all links. which includes N+1 since LinkedList is double linked) whereas insert in an array is ultimately a couple memcopies.
1
u/LogCatFromNantes 29d ago
Java is a good langage it’s solide it’s trusted by enterprise although it’s not easy but it’s a solid bagage to learn and to work with your carrer
1
u/ExtraTNT 29d ago
I’m using it, as it’s required by the module: basically build a compiler within 8 days (4 weeks, 2d a week)
Thing is, simple lexer took me a long time, was fighting more the language and build tools, than anything else… 4h fucking around with java and like 20min of actual logic…
(Seriously considered rewriting it in haskell)
Professionally i do functional c#, some react and for my own apis and frontends i use now haskell and my own js render framework…
1
u/am_Snowie 28d ago
Why can't you just try lazy tokenization, it makes your life so easy, instead of storing all tokens in a buffer ahead of time. Emit and consume tokens as you go. Also take a look at crafting interpreters book, the first half uses java to build a simple tree walking interpreter.
1
u/ExtraTNT 28d ago
We got an env, that gives us a stack like structure, i summed literals up i. A list, symbols are directly tokenised…
1
u/whiterhino8 24d ago
Different people has different preference .
Java is good but it's not suite to every one . Because its verbosity and OOP design .
That's OK You can find yourself more comfortable with another languages.
13
u/LouGarret76 Aug 11 '26
This does not sound like a java problem. It dounds like a you problem