4 ms·
Going to copy my Reddit comment over to HN because I think it's valuable: --- One of the coolest things that's been worked on (by this same author, no less!)
by gavinray 4y ago
Going to copy my Reddit comment over to HN because I think it's valuable:
---
One of the coolest things that's been worked on (by this same author, no less!) isn't even in the article!
Per has written a pretty-printer for MemorySegments and ByteBuffers that can hex-dump memory or render memory/buffers as their "struct" representations given some MemoryLayout.
You can also customize it with your own printers, it's wicked cool and helps so much to debug buffers when working with them.
https://github.com/openjdk/panama-foreign/pull/695 https://github.com/openjdk/panama-foreign/pull/695
What do I mean by that? Have a look at this comment for an image of a raw memory structure layout I represented with MemoryLayout, and the pretty-print rendering of it:
https://github.com/openjdk/panama-foreign/pull/695#issuecomment-1237447761 https://github.com/openjdk/panama-foreign/pull/695#issuecomm...
- geokon 4y agoGenuine question, not trying to be dismissive - but why should something like a pretty printer be part of the JVM? It looks like something I'd expect to either be an external tool (like VisualVM) or part of an IDE
- jitl 4y agoHow would this work with an IDE? As part of a debugger in the IDE? Isn’t it nice that you could throw an Error with this stuff?? I don’t write Java but I do end up writing pretty printers whenever I work on a project with interesting binary data zooming around between memory, network, and disk, and it’s cool that this framework builds it in. I would love if all languages had a pretty printer this nice for their struct types.
- ohgodplsno 4y agoBecause language usefulness pretty much scales with stdlib features. Tools then get built around that pretty printer, instead of everyone having their bespoke implementation. The Java ecosystem is many things, but you cannot say it isn't homogenous. Dependency injection ? Every single project that has gone on to use annotations will be using the same @Inject. And so on, for many, many featyres.
- marginalia_nu 4y ago> Every single project that has gone on to use annotations will be using the same @Inject Except when they use @Autowired. (Ackshually aside, I do agree with the sentiment of your post. The standard library is arguably one of Java's greatest assets)
- ayewo 4y agoOff-topic: When I saw your top-level comment, I must have mixed up your name with a different Gavin [1] until a quick Google search fixed the mix up :) 1: Gavin King of Hibernate fame.
- JanecekPetr 4y agoI take issue with the thing being a part of HexFormat. It should use hexformat, optionally. What if I want to dump the memory to binary or octal instead? The hexformat class itself could have been an adjustable BaseNFormatter :(. Sorry for the tangent, it had to get out somewhere and I did not think it was worthy of an email in the actual review thread : - )