AI to name your Java Classes
projects.haykranen.nl
projects.haykranen.nl
Naming is hard. I think it'd be pretty neat to write the code with a placeholder for the tricky names and then let an AI suggest them once it's done.
Suggest better variable and method names in the following Java code. Don't list the new code, only the changes, in the format "oldName" => "newName". You can also suggest multiple alternatives in the format "oldName" => "newName1" or "newName2"
In my experience, 90% of the proposed changes are bad, but occasionally it does have good ideas.
Of course, you shouldn't upload your company's code to OpenAI, but you can try it out on open source or experimental projects.
I don't think Java has a naming problem per se, I think the focus on inheritance and other OOM principles just make it very easy to overengineer your solutions.
Things like getters and setters (and the fact Lombok still isn't just part of the language itself) annoy me much more. At least records fix some pain points.
(Currently replacing a Java application with one written in Go).
They can types, but most of these "classes with funny names" are more often than not just a logical grouping of functions.
It's probably more informative to view them as a bundle of parametrized functions, than as a record of data.
[1] And more to the point: extremely maintained. You're really going to put the code quality of your Java WhateverFactoryListenerRepository class, that will probably be rewritten by some new hire in 2025, down against a Linux kernel file that has been under continuous improvement since 1997? Because of variable names?
Except i had called the loop variables i and j, forgot which way round i had nested the loops, and used the index into the event array to select a slot in the accumulation array. I was baffled as to why my results were completely wrong, but totalled to the right amount!
Once i realised what i had done, i renamed the loop variables to eventIdx and windowIdx. This is far better.
and
Since they get used as loop counters so much you at least know that they're being used in a loop. It's not much info, but at least it's something. (The grandparent's suggestion of 'a, c, w' (or whatever) tells me _nothing_ :) )
> I wonder if the original author will be able to understand their own code in a few weeks
As the original author of plenty of this code, I'm reporting no problems 1300 weeks in.
var v = new VeryLongClassName();
v.op1();
v.op2();
Alternatively: var v = new VV();
v.veryLongMethodName1();
v.veryLongMethodName2();
More code for the second option, doesn't increase readability.What alternatives do you have in mind?
been a while since I read the BNF of Java, don't seem to recall this.
I have since found that Java itself steers developers in this direction and this type of naming is actually quite natural when working with Java.
That being said, I still find it really amusing. Kudos to the person who made it
Even functions don’t need names once they are small and pure enough.
Alas, we still cling to names.
I more surprised by the absence of XXXManager, XXXStore, XXXProvider, and also AbstractXXX, not to mention XXXStoreProvider and XXXStoreManager, and maybe DefaultXXXManager too (which is the default implementation of XXXManager (which is an interface), and also the only implementation of XXXManager that will ever exist by virtue of XXXManager being incredibly specific anyway).