6 ms·
AI to name your Java Classes
- siva7 4y agoFunny as this idea would do on a real try a much better job than most software developers are doing without such assistance. I wish to run such tools over most projects i've encountered to clean up the crap colleagues (and myself) have come up with.
- jeroenhd 4y agoThe next step would be dumping out partial UML diagrams for a whole set of names so you can get a quick overview of how TransactionalWrapper, ClientTransactionalWrapper, and PrototypeClientTransactionalWrapper interact with ThreadVisitor, InfoThreadVisitor, and PrinterInfoThreadVisitor.
- Waterluvian 4y agoWow. I’m impressed at how lean your architecture is. No Factories?
- jraph 4y agoThey must be using injectors, of course. No need for factories. 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).
- ape4 4y agoNow if it could automatically rename the classes in my many LOC project!
- pharmakom 4y agoThe mistake Java makes is to make everything a noun. Types should have short names. Functions should have long descriptive names. Variables can have single letter names.
- manmal 4y agoEverytime I see i,j,k as variable names, I wonder if the original author will be able to understand their own code in a few weeks.
- dtech 4y agoProbably the worst example since those are pretty canonical as loop counters. Try a,c,w,z.
- ajross 4y agoCome on, folks. It's a culture thing. If your loop body is 20 lines, fits trivially on a single editor window, and starts with a declaration of a counter named "w" (for "worker", or "width" or whatever obvious thing it's referencing), that's Just Fine. No reasonable reader is going to have trouble with that, and you know it. Decades and decades of extremely maintainable[1] code has been written in that style. Aesthetics are just aesthetics. Write to the style of the project you're maintaining, and just let the argumentation go. [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?
- manmal 4y agoI agree that one letter variable names sometimes make sense. I’d use w for width if the function is short, has a very limited number of variables, w is limited to the scope of the function and not an input parameter, and w is used multiple times.
- twic 4y agoI had an annoying bug a couple of weeks ago. I had an array of ongoing events, and an array of time windows (roughly, quarters or years). I wanted to generate the cross-product of events and windows, evaluate some metric for each combination, and total the metric per time window. So, i wrote a pair of nested loops over the two arrays, calculated the metric in the inner loop, and accumulated it into a third array with a slot per time window. 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.
- thejackgoode 4y agoWhat’s the name of design principle: “If you can’t name it, it shouldn’t exist”?
- xwdv 4y agoNames are mostly for humans. In functions with limited scopes there should be no need for names beyond single letters. Even functions don’t need names once they are small and pure enough. Alas, we still cling to names.
- ghqst 4y agohow do you plan to refer to these nameless functions when they are reused multiple times?
- yCombLinks 4y agoIs the function doing something I care about? If yes, the name should tell me what that is. If not, why's it there at all?
- xwdv 4y agoYou tell me. Seems like most functions can be eliminated and just replaced by comprehensions or a series of map, reduce, filters, sort, comparisons, etc, with small operations applied per element.
- yCombLinks 4y agoSure, they could. But I find naming these things explains to future users the point of why you're applying all of these functions. A chain of 10 filters / maps / comparisons / etc... do 0 to explain why a program cares about doing those things.
- xwdv 4y agoIf it is a true pure function that has already been proven and tested to be correct, you only need to be concerned with the output. The function itself will never have side effects you need to understand nor will it ever change.
- losvedir 4y agoI was disappointed to see this is just a cheap joke. I'd actually be interested to see how well one of the new LLMs does, if you give it a description and some of the code and ask it to name the class for you. 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.
- karmakaze 4y agoThe reason naming is hard is because the author didn't know what they were making as they were making it. For the AI to name it well it would first have to rewrite it and separate distinct salient concerns which spans both the implementation and real-world domain spaces.
- gs17 4y agoI could see it operating on a natural language description of what you're going to write. I just tested this with ChatGPT and it was able to give me a set of design pattern-based classes that would probably fit in enterprisey Java codebases.
- lbalazscs 4y agoHere's a tested ChatGPT prompt: 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.
- huskyr 4y agoSurprised to see a project i made twelve(!) years ago on the front page today. Just to make it clear: this was most definitely a joke, and not an AI at all. It's just random words thrown together, which was kind of the point i was trying to make about some Java developers naming their classes ;)
- sorokod 4y agoTo paraphrase Marx, "AI fads appears twice, first as comedy, then as tragedy"
- marginalia_nu 4y agoAI basically just means software at this point.
- thih9 4y agoSuch a missed opportunity, the project itself could have had a name like AIGeneratedJavaClassNameFactoryImplementation.
- drtz 4y agoI first saw this years ago, shortly after starting my first professional Java dev job, and I thought it was hilarious at the time. 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
- huskyr 4y agoThanks!