HNHacker News
TopNewBestAskShowJobs

wrmsr

155 karma · joined May 26, 2016

submissionscomments
wrmsr··on Kotlin vs. Java
iirc scala literally began as just java with pattern matching from odersky's frustration from building javac in raw java. pattern matching is well on its way in modern java, with switch expressions and instanceof binding in jdk14 preview and more general destructuring (further enhanced by records) and guards up next.

in reality though aside from the rock/hardplace of language conservatism/fanatical back-compat i have to imagine a real reason modern java has yet to fully embrace Optional/Either over null/exceptions is lack of value types - yeah escape analysis lets you ~mostly~ not have to worry about the IdentityObjects you're returning everywhere, until you hit something it can't/won't inline or try to stuff those Optionals on heap and wind up making our already painful pointer chasing situation ten times worse. value types are also well on their way via project valhalla but have yet to actually land.

maybe ironically one of the things i recently got bitten by was the fact that MethodHandle .invoke* methods throw Throwable when used directly in plain java - the very machinery that enables the efficient composition of these kinds of functional programming styles is gated behind having to catch literally anything in the language itself. i guess the recurring theme here is java putting the horse before the cart, and that's frankly my favorite thing about the ecosystem.

wrmsr··on Half of millennials and 75% of Gen Z have left jobs for mental health reasons
Yeah, it's not downward social mobility, crippling education and medical debt, 20 years of pointless war, militarized police and active school shooter drills, impending climate crises we're politically powerless to act on, ongoing erosion of workers rights, no expectation of ever owning a home or retiring, or any other number of uniquely grim realities these generations are burdened with - naw it's smartphones, instagram, and 'not learning to take control of your own life'... and your employer's HR department is here to help.

All social media did was make people realize they're not the only one.

wrmsr··on Generating a Java program with 90% less code
Java interface methods do have globally unique* names when fully qualified, but nobody types the full thing out because namespacing is good. It is neither expected nor even desirable for readers or authors to keep resolutions of interface implementations in their heads - that would defeat the purpose of interfaces.

* jar-hell (and dll-hell) aside

wrmsr··on Ask HN: What are the “best” codebases that you've encountered?
prestodb is the best java codebase I've ever worked in, llvm is the best c++ codebase I've ever worked in.
wrmsr··on On Learning Rust and Go: Migrating Away from Python
even for the crud apps so frequently referred to in this thread the equivalent 'real code' is the sql rdbms written in c or c++ no matter what the webapp language is. i don't advocate using python in million line monoliths despite it being my favorite lang in general at the moment but the volume of cognitive dissonance and false dichotomies in this thread is crushing.
wrmsr··on Pyright: Static type checker for Python
+1. ruby is by a good degree the hardest language to statically analyze that ive ever worked significantly with. type anns fit python relatively well due to it's philosophy being pretty much the direct opposite of ruby's: "explicit > implicit" vs "having a conversation"

ed: to the degree that the man himself is adamantly against them in his language (except as perf hints) https://bugs.ruby-lang.org/issues/9999#note-13

wrmsr··on Pyright: Static type checker for Python
type annotations are actual objects instantiated at runtime, usually only done at module import for non-local annotations but done each function invocation for locals. this is nice for extensibility as it makes interacting with and extending the type system as easy as writing any other normal python but in older versions of python it was extraordinarily slow, particularly with generics (as they were previously implemented by creating new actual typeobjects each time they had arguments applied (to be usable as baseclasses) - this has been corrected in 3.7 with the addition of __mro_entries__). 3.8 is however making annotations evaluated on demand not eagerly pretty much removing all runtime performance impact.
wrmsr··on Pyright: Static type checker for Python
import typing as ta -> ta.List...
wrmsr··on Is a shared database in microservices actually an anti-pattern?
Given your statement we should all be running GHU Hurd.
wrmsr··on Low Earth Orbit billboard for 7B people
a fitting end to humanity: kessler syndrome caused not by war but by advertising
wrmsr··on We're in a Golden Age for Amateur Radio
> Finally, there's just something about breaking the silence and making that call when you're out in the middle of nowhere. Even if you're the world's biggest introvert, you might end up helping somebody by keeping your radio turned on and tuned in.

Words to live by.

wrmsr··on Reasons to Fear Another ‘Great War’
"At the end of the war if there are two Americans and one Russian left alive, we win!"
wrmsr··on Introduction to Object Oriented Programming in Python
Python's lambda is very intentionally limited precisely to steer people away from overly functional code. Don't write Haskell in Python, and equally don't write Java in Python.
wrmsr··on Oracle’s Java 11 trap
Having a self-contained single JAR that doesn't even depend on the host's ABI or OS and requires exactly one system dep - a JVM - is even nicer. And if you do want a statically linked self-contained ABI-OS specific binary Java give you that too now.
wrmsr··on Ending PHP Support, and the Future of Hack
On the flipside as I've seen from Google if you're already an attractive enough target for potential employees to pay the price of ramp-up the privacy of your stack serves to lock those employees that prove worthwhile into experience that's non-transferrable were they to explore other options. Granted G is special as anyone hiring knows but I don't imagine they're the only ones aware of and playing that game.
wrmsr··on Show HN: Py-spy – A new sampling profiler for Python programs
As a heads-up if you hadn't already seen it 3.7 added fork callbacks for stuff like this - https://docs.python.org/3/library/os.html#os.register_at_for... - much nicer than patching-and-praying.
wrmsr··on Ask HN: Why is MacOS so popular among developers?
Seconded. I grew up writing C++ on VS6 and despite its innumerable problems (which I didn't remotely care about at the time) I also grew up not knowing source indexing and visually debugging C++ were even difficult, yet the world of posix seemed ancient and impenetrable. But these were the days of mingw, cygwin, and djgpp, all of which turned me off of non-win dev until moving to the bay and forcing myself to branch out. Having dabbled with Linux numerous times and falling on my face osx at the time offered a unique bridge between the worlds for me - bare enough to be able to force it to do what I told it to as a dev but not unwrittenly expecting me to be an already acclimated greybeard like the linux distros of the era. Those times are unfortunately gone, the difference between being a dev/poweruser on osx/apple increasingly feels like the difference between usermode/kernelmode on other platforms, and it's sad, but I guess it's still making them money hand over fist and nothing lasts forever. It’s the same story with tech and money, as time goes on we’re all increasingly affected by it but individual control of it continues to become more all-or-nothing.
wrmsr··on Java’s new garbage collector promises low pause times on multi-terabyte heaps
I'm not arguing against value types as I definitely want those too but it's not that simple nowadays - a moving garbage collector (like all modern server jvm's have) can do things for locality that non-moving systems (gc'd or not) can't - https://shipilev.net/jvm-anatomy-park/11-moving-gc-locality/
wrmsr··on “I'm basically giving myself a permanent vacation from being BDFL”
And as a former motorcyclist the idea of putting a seatbelt on a bike is terrifying, but under the umbrella of 'mandatory' I'd have to risk getting cut in half in a fender bender 'because that's how it's done'. If you blindly follow guidelines without understanding why they were put in place and when they should be circumvented you do more harm than good. In this context specifically, a python thread, I've not even found formatters that 'just work' in python to the degree that they do in java - I get and support significant whitespace but that combined with the crazy calling convention frequently lead me to just have to suffix spans of lines with noqa because I'm communicating to the reader something that a dumb bot doesn't understand. And that's not even getting into the heavier stuff, I type annotate everything but mypy is beyond useless for my relevant codebases - it no longer just outputs walls of useless noise it straight up crashes, from the most minimal use of even descriptors much less metaclasses. Tools and policies are essential but at the end of the day humans and situations are still currently authoritative.
wrmsr··on “I'm basically giving myself a permanent vacation from being BDFL”
It's lisp without the curse. You have an arbitrarily dynamic runtime but enough structure and cultural idiom against abusing it that it has flourished. Compare for example type annotations in python versus those in clojure - clojure's expressivity and the culture's tendency to use it pervasively make meaningful annotations much more difficult than in python, even with python's crazy calling convention. Additionally a lot of my data processing python code winds up feeling very lispy - arbitrarily deeply nested iterator pipelines transforming dumb and often immutable data. We largely do this in python because smart objects are slow not out of any pursuit of purity, we have a thriving ecosystem of these kinds of libraries, but the end result feels vaguely similar either way.
wrmsr··on From Rails to Clojure, Then to Java, Then Back to Rails
I think what they mean by 'pythonize' is ditching fluent functional style and embracing dumb imperative mutability for the sake of efficiency. Rewriting sequence compositions as stateful for-loops. Idiomatic Python is more pragmatic than Ruby in that regard, stupid=good (yet ironically Ruby's strings are mutable and Python's aren't :p).
wrmsr··on AWS Lambda and .zip is a recipe for serverless success
It's just code in a .zip file! It's really that simple!

Hey, unrelated what does "cannot open shared object file" mean?

wrmsr··on Java call stack – from HTTP upto JDBC as a picture (2006)
Rails code can get that deep, the difference being MRI doesn't have an inlining jit...
wrmsr··on How should I learn Java Web Development?
Java is much heavier weight [1] than languages like PHP and Python, and that’s not at all a bad thing - it just changes what the language is used for [2] and what’s normal within it. As such the threshold for overengineering is significantly higher than in most other languages. Dependency injection for example is something that in the small looks like needless complexity but when used well [3] makes things that would be realistically impossible without it easy and routine.

Java is a very dumb language, and that’s also not at all a bad thing. What we get from this dumbness is best-in-class tooling. I don't think I have to say it but pick one of the 3 major IDE’s: IntelliJ, Eclipse, or NetBeans. If you have no preference IJ tends to be the modern (and my) favorite. I frankly switched from years of emacs to PyCharm for even my dynalang stuff due to the quality. Java lacks [4][5] many of the powerful and dynamic features of other languages like eval, code execution during class definition, the ability to flat lie to the type checker, et cetera. In return we have an ecosystem of tools that can nearly perfectly understand the intent of code statically - things beyond simple templated code generation like 'go to definition’ and 'find all references’ work so well that automatic refactoring can usually be done fearlessly. The downside of this is that I’ve yet to see a code review system that can gracefully handle the giant diffs these tend to create, but the end result has a vastly higher chance of success than for more expressive languages, and it’s better than the alternative of accumulating technical debt (and hey, nothing’s perfect :). Similarly get used to using the debugger. You basically never have to resort to 'printf debugging’ in Java due to the high quality tooling. To learn a codebase set breakpoints and poke around.

To your 80%/20% question: in my opinion Java’s killer feature is its unbeaten ease at handling vast codebases, which unfortunately presents a barrier to short-term entry. I think I’d say look for a Java-only library that interests you and put a web interface on it. Due in part to Hadoop there are lots of Java-only (or effectively so as a result of shoddy ports) systems that deserve an HTTP wrapper so other languages can access them (a colleague of mine wrote one for Kafka a while back as an example, and frankly things like Elasticsearch and Solr are basically this for Lucene). This will get you into exploring and getting familiar with not only the library you wrap but the webserver (like Jetty) or framework you choose. Due to its tooling I find learning large Java codebases easier than those of any other language [6] and as above to me that’s what Java is 'for’.

[1] HotSpot more or less expects to be able to use all of its host’s cores, which somewhat clashes with modern container-centric ecosystem. Containers have always meant less to Java though as it’s had things like jar shading, internal access control, and classloader isolation for many years. OSGi for example has been capable of similar multitenancy through these features. That's not to say docker isn't still remarkably useful to Java development, it just tends to be less ‘amazing’ in the context.

[2] The amount time it takes to build a simple CRUD site will likely be higher than in, say, Rails (although it’s getting better all the time), but many of the things a growing site winds up talking to (Elasticsearch, Cassandra, ZooKeeper, et cetera) are implemented in Java. Different tools and all that. I’m not discouraging its use for even smaller projects but it does tend to be more of an up-front investment than a lighter language all else equal.

[3] As a Guice fan I recommend checking out the Presto codebase ( https://github.com/prestodb/presto ) - lovely and extensive (perhaps a tad too much :) use of Guice, and extraordinarily high quality codebase in general. I’ve never used much of Spring[Boot] myself but as with Java in general many of the criticisms aimed at it are many years out of date and irrelevant.

[4] All of these things are ~possible~, just (as usual :) more involved and verbose than in many other languages, and more importantly extremely non-idiomatic (or at least considered 'big guns’). As an example in lieu of eval many systems leverage runtime bytecode generation to do things like building object proxies and computation pipelines at boot or on user input. HotSpot dutifully jits, optimizes, profiles, and inlines this with 'normal’ code resulting in usually impressive performance, but it also involves jumping through a lot of hoops to make it work right as the vm spec mandates fairly strict requirements.

[5] Notable though is Java’s extensive use of annotations - they’re used to communicate to both tools and people (though primarily the former), and you can stick them nearly anywhere. Annotations themselves do absolutely nothing - they exist purely as introspectable markers (not to be confused with similar looking Python decorators). Tools like serialization libraries, web frameworks, dependency injection systems, and thread safety analyzers scan for these and do things with them as they please. A lot tends to happen at boot and during warmup in Java systems both in the app code and in the vm, and much of it is powered by these otherwise-do-nothing purely-for-reflection annotations.

[6] The only other equal to me is C#, which is basically Microsoft Java. There are numerous differences (mostly more advanced static language features at the expense of a dumber runtime - .NET has F# but Java has Nashorn and Graal) but they share the spirit of dumb but extremely toolable 'heavy’ languages. I haven't touched Mono in quite a while though so I can’t comment on its modern usability.

wrmsr··on Show HN: Asmble – Compile WebAssembly to the JVM
It's not about converting stuff in the browser to the jvm, it's about converting existing c and c++ (and others) to the jvm via an intermediate format primarily (but not exclusively) designed for the browser. There are real reasons to 'rewrite-it-in-java' beyond just NIH, to the degree that even without this automatic transpiling it's frequently done (grpc-c vs grpc-java, all jdbc drivers, etc):

- Native transitions are expensive - not just through register saving and gc machinery but also because native code is opaque to the optimizer. Runtime virtual inlining is probably the single most important optimization hotspot does and the more frequently code it can't work with is called the worse everything gets. While it's almost certainly nothing to worry about with coarse-grained syscalls, and probably not too much to worry about with things like opengl calls, I'd be very skeptical of using, say, a native database driver involving native transitions to retrieve every field of every row of every query in a db-heavy app. This is much the same way pypy is usually much happier with pure-python code than with native code - the more your vm does for you the less happy it is when it can't do it. Furthermore, as these binaries are the compiled results of clang and llvm (just with a different backend) the normal static analysis and optimization passes are run on the c source and ir, it just gets compiled down to a simpler instruction set than most modern physical machines.

- Native deps are anathema to most clean java projects. Our de-facto dep system, maven (and compatibles), is entirely jar-centric. The 'accepted' solution for distributing something like sqlite is some poor person having compiled the native libraries on (win|lin|osx)(32|64), zipped them all up into a big ol jar, and put that single blob on maven. On boot it sees what platform its on, extracts the lib to a temp dir, loads it, then imports a jni binding for it. Inelegant to say the least, especially when java people tend to be spoiled by the notion of there being no difference between an osx or linux build or binary.

- Debugging is worlds nicer when everything's in the jvm, even before stackmaps. You only need one debugger, it's nice and graphical, you can run it remotely with no such thing as a 'debug build', it basically never segfaults, et cetera.

wrmsr··on Show HN: Asmble – Compile WebAssembly to the JVM
When I was working on it the accepted solution was to compile as linux and statically link musl into the wasm binary, leaving mostly __syscallN symbols unresolved. As such it's a matter of implementing those on an as-needed basis (in javascript for emscripten and in java here). I at least successfully got sqlite opening a database in a pure java transpile that way. While it's a possibly inelegant approach on the face of it linux does at least have an aggressive 'dont break userspace' attitude and there is longstanding prior art for this on freebsd.

see: https://github.com/kripken/emscripten/blob/6dc4ac5f9e4d8484e...

wrmsr··on Show HN: Asmble – Compile WebAssembly to the JVM
Hey, I wrote one of those too :P I went the route of compiling to java source code rather than bytecode though. I'll definitely give this a look through when I get some free time, glad to see others want it to happen (though as you allude to jvmci / truffle / sulong and friends are kind of a game changer).

* https://github.com/wrmsr/wava - be forewarned though I never got around to giving it any polish and it's based on a dated version of wasm

wrmsr··on Ruby+OMR JIT Compiler: What’s Next?
impala does.
wrmsr··on WebAssembly Specification Prototype
I've heard that native DOM interaction (no JS middle man) is on their radar via WebIDL. They don't want people reinventing the DOM via custom canvas rendering and such so making DOM manipulation painless is a priority.
wrmsr··on WAVM: standalone WebAssembly VM prototype

  in my mind, as it is aimed at replacing the sprawling forests of javascript
  many pages are powered by, wasm pretty clearly addresses your three
  points. with wasm web applications delivered to browsers can be written in
  c++, rust, haskell, whatever, and compiled and linked and optimized and
  profiled and reoptimized on developer machines before deployment to end
  users. the result of this is that performant applications won't require as
  much (or any) runtime optimization like javascript engines necessarily do now:
  
  - arbitrarily dynamic code needn't be jitted and traced and rejitted to raw
    machine code at runtime
  - object structure needn't be inferred and shared and monitored and reshaped
  - primitive types don't have to be inferred and guarded
  - functions needn't be inlined and guarded because they are all dynamically
    bound
  - objects needn't be tracked and freed and moved around
  - javascript is weird and irregular. half a point here but just look at the
    equality table.
  
  you can say that 'well formed' javascript eases the pain on these poor beasts
  but they still have to strive to support as much of the common language as
  they can, no matter how awful, because it's their job. wasm has to do exactly
  none of this:
  
  - jitting can occur once, at load, statically like the CLR not dynamically
    like HotSpot or luajit as inlining happened on some jenkins box somewhere.
  - there are no objects, there are four types and they're all 4 or 8 byte
    primitives and if you need a gc you baked it into your binary. no vm-level
    object or allocation headers, no gc-related finalizer bugs.
  - desugared there's about 20 instructions (expressions). implement those and
    you've implemented webassembly. standard lib? that was compiled into the
    binary*.
  
  because there's so much less to its job it will be safer, smaller, and more
  widely consistent than javascript. it's still young and definitely not without
  its warts but these three points are home runs.
  
  * ..ish, but it's definitely more spartan:
      https://webassembly.github.io/demo/AngryBots/Release/AngryBots.js
    ... that'll buff out :p

  edit: wow i suck at HN formatting
← PreviousPage 2 of 3Next →