6 ms·
They are indeed scary, but one thing that can make them less so is writing them in a high level language. A nice code base to study if you're new to GCs is the
by mike_hearn 3y ago
They are indeed scary, but one thing that can make them less so is writing them in a high level language. A nice code base to study if you're new to GCs is the GenScavange module of SubstrateVM, a JVM written entirely in Java. Start here:
https://github.com/oracle/graal/blob/master/substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/GCImpl.java https://github.com/oracle/graal/blob/master/substratevm/src/...
It gets compiled to native code for use. It's actually a bit of a dialect of Java because of course, you need low level memory and stack access. So you can see at parts there is use of special APIs that get compiled to things like stack allocations, so it can avoid allocating on the heap whilst working with it. Even so the "business logic" of a GC can be easily seen here, especially if you don't know C++.
- mark38848 3y agoThere is no programming language as scary as Java
- agilob 3y agoPlease elaborate more than "haha java bad"
- otikik 3y agoJavaBadAbstractFactoryObjectFactoryException
- Geezus_42 3y agoThis is what I hate about supporting Java apps. Why are the errors so indecipherable and rarely well documented?
- mike_hearn 3y agoWell, compared to what? The alternative to exceptions is usually worse: 1. Error codes. Try debugging Win32 software and have fun working out with all those HRESULTs mean, especially as every Google hit for any given code is just endless support forums with people complaining their computer is broken. 2. Panics. You get an error message no more helpful than an exception, except with no stack trace to help you figure out what's wrong. 3. Segfaults. You get nothing. Exceptions are the best form of error handling yet invented. Making programmers more helpful is hard, but exceptions have auto-generated error messages that at least tell you where the program died, how it got there, and very often the chain of problems that led to that surface level problem (a particular weakness of error codes where causal chains are often lost). They also often have JavaDocs explaining what they mean. Although it's not really a weakness of Java or exceptions per se, I think some people don't like them because lazy devs don't bother translating them into something more user friendly (especially for developer tools). There are simple patterns that fix that though. My company makes a CLI developer tool written in Java+Kotlin running on the JVM (see bio) and it defines a dedicated UserError exception type. If an exception bubbles to the top level of the program and it descends from UserError then it's formatted nicely with colors and shown as you'd expect. If it's not then the exception is logged and a crash reporter is started, the user is asked if they'd like to report the crash. The exception details are then printed without the stack trace and polished slightly ("FooBarException: abc" -> "Foo Bar: abc") which often makes the messages good enough that the user can unstick themselves. There are utility methods to catch and rethrow exceptions as user errors when the underlying messages are already good enough, and the product is careful to rethrow manually if the messages need to be improved. There are also utilities to verify that a file/directory exists and if not, throw a special subtype of UserError that yields a spelling corrector [1] The result is that if you check our homepage, you'll see at least one customer explicitly praised our error message quality! They were very happy to never see a stack trace from a developer tool, only actionable errors that tell you what to do. So exceptions can definitely yield a great UX. You just have to care and put in a bit of effort. IntelliJ is another example of a product where the exception UX is highly polished. Its exception reporter can figure out which plugin an error comes from, route error reports automatically, deduplicate errors based on the stack traces, attach files that the exception object advertises and so on. [1] https://hshell.hydraulic.dev/14.1/user-interaction/#path-assertions https://hshell.hydraulic.dev/14.1/user-interaction/#path-ass...
- pquki4 3y agoVery well said. Parent says "errors so indecipherable and rarely well documented", when in fact Java is the better if not one of the best out there.
- whstl 3y agoSure, but GP was criticizing Java, not Exceptions. I find that JavaScript, Ruby and C# are all easier to debut in practice than Java, and all three use exceptions. IMO this is mainly due to what idiomatic Java looks like and how libraries/frameworks are structured.
- mike_hearn 3y agoHm, we've had different experiences then. My experience with languages like JS/Ruby is that exceptions are often obfuscated (for js) and will frequently be meaningless type errors like "foo is not an object". I didn't use C# but I'd guess it's similar to Java. After all, here's an exception factory library for C# (https://github.com/scionwest/ExceptionFactory https://github.com/scionwest/ExceptionFactory). What most people seem to complain about when they say "Java" is actually dependency injection frameworks, not the language or even regular libraries (which typically don't use them). I also don't like Guice so can sympathise, but DI frameworks vary in quality a lot, and you don't have to abuse them. Modern frameworks are based on code generation and check much more at compile time. My app uses a compile time DI framework to set up the build task graph, but doesn't have a factory bean anywhere and has never yielded strange errors about factories that were hard to debug.
- whstl 3y ago> What most people seem to complain about when they say "Java" is actually dependency injection frameworks This is precisely what I said with “ due to what idiomatic Java looks like and how libraries/frameworks are structured”. Sure, in a platonic ideal Java codebase, it’s all great, but I am talking about my actual practical experience, and I said as much in my message.
- 2y ago
- agilob 3y agoSo in the context of a class name `JavaBadAbstractFactoryObjectFactoryException` your problem is on a human side, your colleague using bad class and var names. Language has nothing to do with it. Ruby and C# also have VERY long class names, yet we don't talk about them so much.
- kaba0 3y agoJava’s errors are amongst the best in my experience. Do you prefer Python’s much more esoteric stack traces, or Go’s one liner zero information spam, or the traditional “SegFault”? Like honestly, which ecosystem has better exceptions/error messages, in the general case? Java pinpoints the exact source of the error with useful context. It’s as good as it can get.
- The_Colonel 3y agoSo just "haha Java bad".
- otikik 3y agoI did expand. If he wanted more, he should have assembled a better set of requirements.
- deely3 3y agoDid we started judging language by some libraries written in that language? Also, where did you encounter this exception? Im really curious.
- agency 3y agoI was a Java apologist for a long time and I still think you can write fine software in it (and the JVM is an incredible piece of engineering). But the fact that the class is the _only_ unit of abstraction is just so frustrating to me now (Yegge's Execution in the Kingdom of Nouns makes this criticism in a humorous allegory[1]). Modern Java does mitigate this somewhat. Lambdas provide nice sugar over the inline class-creation you'd have to do of yore. Records make it less of a pain to define POJOs. But I think this fundamental issue is at the root of much of the language's clunkiness. [1] http://steve-yegge.blogspot.com/2006/03/execution-in-kingdom-of-nouns.html?m=1 http://steve-yegge.blogspot.com/2006/03/execution-in-kingdom...
- neonsunset 3y agoThey were close but unfortunately went too far at being opinionated in solve the issues of using C at the time of Java's inception. Changing this now is Valhalla project which has unknown release date. Luckily, C# learned from this mistake and made a decision to follow C much closely, having integers as proper primitives and supporting structs since day 1, and only improved since then in this area (JVM needs insane pointer compression and shadow tricks to pack integers to claw back performance, and in .NET "it just works" instead). I wonder if Cassandra was written in .NET, it wouldn't have such a poor performance (though this can also be showcased by Garnet which beats competition written in C++ and C).
- mudhad 3y agoclass, interface, record, SAMs (for lamdas). Value types are in the works, and would bring it to a similar level to C# or C++.
- stingraycharles 3y agoEh, it’s not the most sexy language, because across all dimensions, there are more scary languages. C++ is much more scary than Java in a “shoot yourself in the foot” kind of way. INTERCAL is much more scary than Java in a “this is impossible to understand code” kind of way. Haskell is much more scary than Java in a “this language has FP constructs” kind of way. So why is Java scary?
- TurboHaskal 3y agoI don’t fear Java as much as I fear its acolytes.
- Traubenfuchs 3y agoWe just want to write code for money in peace.
- The_Colonel 3y agoKind of a strange comment for Java which doesn't really have a quasi-religious fanbase of e. g. Rust or Python.
- marcosdumay 3y agoA comment from an alternative reality where code patterns, crazy code generation frameworks, and crazy systems entirely based on dependency injection do not exist...
- bee_rider 3y agoOracle had employees called Java Evangelists for a while but I think that was more than a decade ago. You never know when somebody gets their stereotypes though. My memory is hazy but I think there may have been more of a cult of Java when Sun was in charge of things. They knew now to inspire a following.
- The_Colonel 2y ago> Oracle had employees called Java Evangelists Well, that's just marketing department. > I think there may have been more of a cult of Java when Sun was in charge of things. I wouldn't call it a "cult", just normal technology hype. Yeah, it was there in the late 90s, but since at least 2010s, Java is a boring enterprise platform without much hype.
- ajross 3y agoI don't love it either. But let's be brutally honest here: the single inflection point where the world of software shifted from "usually buggy, routine crashes" to "usually works, presumptively secure" was the arrival and gradual embrace of Java and its managed runtime in the late 90's and early 2000's. Were there other technologies that do the same thing? Sure. Were they better? In some cases. Was Java really the "first" by whatever metric? No. But Java is where the world changed, it just is.
- JoBrad 3y agoClearly you haven’t been part of the group that had to track down where Java could be installed in a jumble of workstations and servers, because it was installed as part of an application that may or may not have advertised Java as its third-or-fourth level dependencies. It also seems you are forgetting just how bad early Java was, from a programming and user standpoint. Java errors like NullPointerException became a meme because they were so prevalent in user space, and required so much energy and time to get things working. As a result, people typically refused to update any part of Java once their app was working, to avoid breaking things. And that was _if_ the install was registered with a package manager or Windows Update so updates could be reported.
- afavour 3y agoNothing you’ve said there actually disagrees with the parent. It was not perfect on arrival but its gradual embrace was a sea change.
- Geezus_42 3y agoAs someone who supports Java apps, I don't think the errors have improved. They are completely nonsense to non-programmers, and they rarely ever have good documentation. Most only show up in old SO post, or application specific forums, and you have to sift through a ton of crap just to hopefully find an explanation or fix.
- 3y ago
- swayvil 3y agoI have written a lot of java. I like it because it's comprehensively organized. I mean it does everything it should and does it a nice orderly way. The whole class system and c-like system, all together, works good. And addresses everything I want it to address. And it does that without adding a bunch of crap. Or at least I find that crap easy to ignore. But ya, they do seem to be adding a lot of crap. In a nutshell, it's a nice neat system. Python is a mess, comparatively. I'm looking for a new language tho. Orderly and comprehensive like Java, but succincter.
- rocqua 3y agoPerhaps go? Famous for not having 'a bunch of crap'. Alternativly python with it's typechecker in strict mode is quite organized. Though poorly typed outside dependencies are common. And ofcourse performance is much worse.
- vips7L 3y agoGo and succinct aren’t really in the same universe.
- shepherdjerred 3y agoI agree and I think this is slowly changing.
- shepherdjerred 3y agoGo and Python are both fine languages, but they aren't great replacements to Java (for me). I think Go will be a great language in 5-10 years. The authors of the language wanted to make something minimal, and they did a great job of that, but it was too barebones, though they are rectifying this by adding in critical features (like IMO, generics) I like Python for small scripts, but I feel like I'm constantly fighting the language when managing dependencies, dealing with init scripts, or figuring out which of the 10 ways I should use to perform a common task. I don't think there is a great replacement for Java. TypeScript with Bun or Deno might be the closest alternative right now, at least for me.
- apantel 3y agoJava is an extremely simple, non-scary language. It’s almost impossible to shoot yourself in the foot. The things that people build using “idiomatic Java” are scary.
- shepherdjerred 3y ago> It’s almost impossible to shoot yourself in the foot. Java is my favorite language, but this is simply untrue. Many people are confused about how object references work, problems with null are very common, generic type erasure can be _very_ confusing, and there are plenty of other rough edges. That said, Java does get a lot of undeserved hate. It's really quite a pleasant language and it has evolved a lot over the last 10 years.
- deleted 3y ago[deleted]
- bitwize 3y agoA trivia nugget often recounted here on HN is that .NET's GC was originally written in Lisp, then translated to C++.
- lloydatkinson 3y agoAnd is such a long file GitHub can’t even display it. I get collocation but is one file that’s so large it has editor problems as a result, really such a good thing?
- chii 3y agoThat says more about the browser and github than the language. Nothing wrong with a large file. The editor should be able to help you navigate and see the file without the size being a concern at all.
- johnnyanmac 2y ago>The editor should be able to help you navigate and see the file without the size being a concern at all. Jetbrains's suite has a very large but reasonable limit (500k lines IIRC) before it simply disables it code analysis/highlighting. You can increase it if you need to, but I imagine they keep that number by default for perfomance reasons.
- mattpallissard 3y agoAgreed, I love the one large file approach. :split :vsplit That said, I never use it because everyone else complains about it.
- vundercind 3y agoSame, I increasingly dislike splitting up code into separate files unless there’s a really good chance each file’s going to be imported/used independently in at least some cases. I realized I’d made this shift a couple years ago when I had a ~500 line (god, that’s not even that long) single-file program I was very happy with and thought well-organized and someone a fair bit more junior complained that it needed to be split up just because it was long. Ew. No. Thought a decade or more ago I might have thought the same thing.