Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Soricidus
Oct 21, 2010
freedom-hating statist shill
Are there any examples of jlink actually working usefully for non-trivial projects?

Every time I’ve looked at it I’ve realised just how many of my dependencies are not modules and probably never will be modules unless I fork them and do all the work myself, and it looks like jlink is basically useless in that case as it will have no idea which modules it needs to include.

Javafx moving out of the jdk is great though, because it goes back on the class path instead of the module path so java stops complaining about all our lovely reflection hacks

Soricidus fucked around with this message at 01:16 on Feb 26, 2019

Adbot
ADBOT LOVES YOU

Soricidus
Oct 21, 2010
freedom-hating statist shill

Pedestrian Xing posted:

For example, in one interview another dev asked how the candidate would implement a queue style interface using two stacks.

I hope the correct answer was "I wouldn't"

Soricidus
Oct 21, 2010
freedom-hating statist shill

Zaphod42 posted:

I'm not wild about val / var. I shy away from it in C# code too, that feels like something that should stay in javascript and interpreted languages.

Having strong types is good and knowing those types makes your code more readable. Don't make me guess based on your bad variable names. (Are we going to return to Hungarian Notation?)

Actually they’re good and cool and everyone should use them whenever possible. They don’t take anything away, they just make it less cluttered. The type is still there and if you aren’t sure what it is then you can just ask your ide and it’ll tell you, no guessing required.

Verbose types everywhere make code harder to read, not easier, and are the reason so many people started using dynamically typed languages to begin with.

Soricidus
Oct 21, 2010
freedom-hating statist shill
*stares at screen*

var usersByUsername = new HashMap<String, User>();

*frowns, sweat beading on forehead as he struggles in vain to guess what type this variable might have*

Soricidus
Oct 21, 2010
freedom-hating statist shill
Graal is good, but it seems only to be released for lts versions. Which I guess is fine for prod but makes me sad as a dev because new features are also good. At least it does java 11 now!

Also graal ce is deliberately missing optimisations so that oracle can sell the ee as being faster, because gently caress you

Graal.js is now the best embedded scripting language though.

Soricidus
Oct 21, 2010
freedom-hating statist shill

Keetron posted:

You can be like us and just use the jsonb type of Postgres and just dump the json in a cell and hey, it is searchable as well!
Of you know, don't be like us and use a relational database as it is meant and do your json dumping in cassandra or mongo or some other shite

Elasticsearch, the database of champions

Soricidus
Oct 21, 2010
freedom-hating statist shill
so, estimating memory size of objects

there are like a billion libraries to do it, but I am struggling to find one that has ever been updated to work with java 9+. they literally all try to make fields accessible in internal jdk stuff and life's too short to write a billion --add-opens

I know it's impossible to be accurate, etc. I just want a rough idea of whether a change is decreasing memory usage measurably. I know how to do it by inspecting a heap dump in visualvm or w/e but that's a huge pita compared to if i could just System.out.println(size of some object), like all these libraries offer to let me do if i port my code back to java 8.

any suggestions?

Soricidus
Oct 21, 2010
freedom-hating statist shill
yes, like I said, I know it's impossible to be accurate in the general case.

Let me be more specific then: I want the result of walking the reference graph from a given object and summing the sizes of each object encountered, while keeping a set of visited objects to avoid cycles. Please assume that I have thought about this in the context of my application and determined that it will give me a useful number.

Plenty of tools exist to do this, but all the ones I've tried fail because they hit an object that isn't exported by some module, try to get its fields to follow their references, and die because the JVM doesn't let you do that any more.

e: for now it looks like the even less reliable "force GC, measure heap size, create object, force GC again, measure heap size again" approach is giving tolerable results for my specific use case.

Soricidus fucked around with this message at 17:09 on Mar 26, 2020

Soricidus
Oct 21, 2010
freedom-hating statist shill

Volguus posted:

(let's ignore Swing as it is quite old and not sure if even maintained anymore)

It is. All the jetbrains ides are pure swing and they look modern enough to my eye

Soricidus
Oct 21, 2010
freedom-hating statist shill

carry on then posted:

I'm assuming you have something like Map<String, Set<Integer>> wordPages ? You get the set with the map's get() method, then you can check membership with contains(), get an array of members with toArray(), or iterate using the iterator.

code:
Map<String, Set<Integer>> wordPages = new HashMap<String, Set<Integer>>();

// populate your map of sets

// Then, you can access like this
Set<Integer> pages = wordPages.get(word);
boolean firstPage = pages.contains(1);

Iterator<Integer> iter = pages.iterator();
while (iter.hasNext()) {
    System.out.println(iter.next());
}

// or just get the contents as an array
Integer[] pageNumbers = pages.toArray(new Integer[pages.size()]);
Here's the doc on a HashSet, the likely implementation of set you're using:
https://docs.oracle.com/javase/7/docs/api/java/util/HashSet.html

Wow serious old school java there, it’s been years since I saw anyone use a raw iterator when they didn’t want to call remove(), or wrote out the full generic type on both sides of an assignment

Soricidus
Oct 21, 2010
freedom-hating statist shill
Project Valhalla is still active and they’re hoping to bring value types (ish) and generic specialisation (ish) to the jvm some time this century

Soricidus
Oct 21, 2010
freedom-hating statist shill

smackfu posted:

I ran into some real library code that had an interface that looked like this:

Then in the implementation cast the value to T before returning it.

So you could do:
int i = entryAt(0);
Or
String s = entryAt(0);

No cast required, no compile time type checking, it just failed at runtime with a class cast exception if you picked wrong.

Is this as terrible as I think it is?

This trick can be useful in very limited cases as a last resort way of reducing excessive casting boilerplate, but I would never write a method that used it that did not have “unsafe” in its name.

Definitely a code smell.

Adbot
ADBOT LOVES YOU

Soricidus
Oct 21, 2010
freedom-hating statist shill
the new ui option in intellij even makes it look and feel more like vscode. it’s good

for inspect-element style visual debugging of javafx guis you want scenic-view, it’s a standalone app so you can use it alongside whatever ide you prefer

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply