3 ms·
I've only touched Java a bit, but AFAIK it has quite strict package hierarchy system that allows naming and grouping things nicely. Why then people keep creati
by jakubp 14y ago
I've only touched Java a bit, but AFAIK it has quite strict package hierarchy system that allows naming and grouping things nicely.
Why then people keep creating long class names in the first place? I get it that this particular example might be a generated name, but still, why not just create package hierarchy that represents the code properly?
Also wouldn't using package hierarchies automatically lead to a bit better design (more modular, more understandable)?
- i386 14y agoRefactoring tools and laziness is my best guess. Eclipse and IDEA can extract methods into new classes and suggest a name for the new class.
- 1010011010 14y agoAh, yes. Java is really just the macro language for Eclipse.
- columbo 14y agoI primarily do java work (consulting) for enterprise. I've always seen it as a combination of convention and time. There are java applications that have been around for decades. I've worked in codebases that are over twenty years old. Some of these systems are responsible for billions of dollars and have been heavily tested (the others are responsible for billions of dollars and have been barely tested). Say you are a consultant, and you're working on a shipping application that has been around since the late 90's and is responsible for moving goods where the sum total of all items in transport over a year is larger than the GDP of Taiwan. In that application there is a Warehouse interface. Simple thing, basically it has a receive() and distribute() method that moves product from one location to another (warehouse.receive(truck) or warehouse.distribute(200,truck)). Around 2000 someone needed to create an edge case because specific warehouses are only available during specific times of the year. Like black Friday to Christmas. Usually it is too much overhead to keep all these warehouses running so they are only open 1/2 the year (this doesn't happen, but work with me). So someone created class TimedWarehouse that will do this calculation (on date X no longer receive). Now it is 2012 and you are just a contractor. The big problem with the TimedWarehouse is at the end of the year you MUST VACATE ALL GOODS (because the warehouse is going to shut down). For the last couple of years product has been lingering in these warehouses keeping them open longer (costing more money). The best way to handle this is perhaps a batch process job that sends emergency shipments as it gets closer to the end of the year. So something that cleans the timed warehouses out. Now you're just a consultant, you can't rework the entire framework but you must keep with convention... what to do TimedWarehouseProcessor (nice... but doesn't indicate that it is only used towards the end of the year) TimedWarehouseYearlyCleanout (makes more sense, but is terribly specific, what about warehouses that are open twice a year) TimedWarehouseCleanoutManagementUtility (Bingo! More generic sounding, and it is a 'utility') Imagine the poor sap who might need to extend that class. The process repeats over time. More contractors following the rules of convention, larger and larger class names.
- matwood 14y agoSo true. Using your example: AbstractTimedWarehouseCleanoutManagementUtility TimedWarehouseCleanoutManagementUtilityFactory TimedWarehouseCleanoutManagementUtilityConfiguration TimedWarehouseCleanoutManagementUtilityDto etc...
- eclipticplane 14y agoI feel violent tendencies just reading that!
- ww520 14y agoYou are right. That one looks like generated class name and it's internal. Just the very nice Javadoc generator exposes all names in the Javadoc and it becomes cannon fodder for language hipsters.
- Evbn 14y agoWhy would you put something in a package, which has semantic meaning, just so you can put a dot in its name? Maybe using underscores in class names would be nice, but then it gets ambiguous how to punctuate something, which gets annoying.