7 ms·
Directory structure: Minecraft-API |- src |- main |- java |- net |- minecraft |- workb
by TazeTSchnitzel 14y ago
Directory structure:
Minecraft-API
|- src
|- main
|- java
|- net
|- minecraft
|- workbench
Good old Java.
On my machine that means it would end up being: /home/ajf/Projects/2012/Minecraft/Minecraft-API/src/main/java/net/minecraft/workbench/
Who on earth thought deeply nested directories for packages was a good idea?
- felipemnoa 14y agoJava has nothing to do with that. If you want to you can put everything in the default package (no nesting) or in a 1000 nested directory. Java does not stop you from doing this: Minecraft-API |- src
- rcgs 14y agoSo it's a choice between bad and worse?
- felipemnoa 14y agoHow else can it be done? If you want namespaces you can use them, if not you don't.
- morsch 14y agoWell, obviously, by using them in the language without requiring them on the filesystem? I think you should be able to cat together all the .java files in your project and it should still compile. I guess you could easily do it using a very simple preprocessor.
- felipemnoa 14y agoIf you do that you will no longer be able to tell the overall structure of your project at a single glance without using an IDE like Eclipse. Adding and removing packages becomes harder without the IDE. What are the upsides? You've increased the complexity for no good reason.
- morsch 14y agoEasier rapid prototyping and exploratory programming. Edit all the classes of your small/exploratory project in a single file. If the project expands, it should be an automated refactoring to move classes to their own files. I do this all the time using static inner classes.
- morsch 14y agoThe project setup in the repository also has two "superfluous" levels of hierarchy: |- main |- java At this early stage this seems like overengineering, and if at some point the project gets code e.g. javascript, it might be worth it to add ./js-src at the top-level first.
- felipemnoa 14y agoWhich has nothing to do with Java. The developer chose that hierarchy. Correction: As per the message below I guess I should say that it has nothing to do with Java, the ecosystem, framework he is using is forcing him to use that hierarchy.
- koko775 14y agoEDIT: This is meant to be educational, not a rant. I'm hoping people take it that way. Maven requires a standard directory layout. Maven chose that hierarchy, because: 1) Namespacing. With tens or hundreds of thousands of packages out there, there needs to be an unambiguous way to refer to them separately. 2) Multiple language support. Maven can do Java, Scala, Clojure, Groovy, and so on - in the same project, even. It can even do Javascript, which isn't a JVM language, in certain cases. For the JVM languages, if you want a multi-lamguage project, there has to be an easy way to interoperate (this is enabled by namespacing). 3) Separation of test code and program code. Don't ship tests with your binary package. 4) Separation of code from data. 5) Automation - of packaging, IDE support, etc. This has to do with all of the previous ones. You want to produce a JAR, but don't want to include the default log configuration. So you package the project up. It just happens. You want to edit the code in your IDE. So you add the project. All libraries are downloaded and on your classpath. Add a few lines to your config (as a per-system-user setting or per-project setting, take your pick). Java documentation and source code for those libraries is automatically downloaded. Eclipse hooks it up for you. Suddenly, this: src/main/java src/main/scala src/main/resources src/test/java src/test/scala src/test/resources ...makes a lot more sense. It's hardly overengineering, but even then, the engineer isn't the one engineering the build system; these are details Maven takes care of. [Aside: I am appalled and flabbergasted by the ignorance typically leveled at Java by people who don't understand it✝. It has real flaws, don't get me wrong, but making dependency resolution and installation ridiculously straightforward, multi-language builds dead simple, and unit testing a core feature - these are good things.] Take a look at ant and compare it to maven and you'll see which one makes your life easier✝✝. ✝ I have worn many hats, and have experience with Python, Ruby, PHP, C, Java, and a little bit of Scala in real world contexts, among others. So I'm not a noob who hasn't experienced elegance or conciseness or performance. Java is actually an amazing language that many people don't give it credit for. Though the syntax can be pretty ugly even when the code is conceptually solid. ✝✝ Losing a bit of nuance here - ant gives you configuration. maven gives you convention. Ant is good for very custom; maven is good for straightforward processes.
- dkhenry 14y agoThis is partially due to Maven as well. Its a pretty standard convention that most IDE's can abstract around.
- csense 14y agoMaven is evil. It needs to die. Every time I've used it, it downloads hundreds of megabytes of who-knows-what from who-knows-where on the Internet. It's not like apt-get, which uses a central server where there's some level of QA to make sure all the versions of all the pieces work together. Maven just shoves 100 different components from 100 different servers on your disk. If any one of those servers happens to be down, or moved, or the organization running it dies off, there goes your build. I'll stick with Ant and manual dependency downloading, thanks. They're a pain in the arse, but at least you can keep the tarballs of the stuff you download around, and can have different library versions for different applications.
- dkhenry 14y agoIf local dependency resolution is your thing you can tell maven to use a local repository. it has the concept of multiple places to look for things, I normally set it to use my local cache first then go out to servers as it needs to. Its a little bit to wrap your head around to get started with maven. The first time I had to write a pom.xml file I almost burnt down my house. However SBT came along and fixed that problem. The only problem I have with maven now is that there is no way to tell it to make a single binary without a plugin.
- koko775 14y agoMaven looks locally first, then falls back to the internet. You can insert your own package repository in between so you control the point of failure. Configuring Artifactory to work as a transparent proxy to take care of all of this for you is a walk in the park, and is only one of its possible use cases. Maven lets you keep different library versions around for different applications. This is actually a fundamental thing I've noticed everywhere I've personally seen it used: specify the versions. However you use Maven is evil. Your usage pattern needs to be improved.
- mindcrime 14y agoWho on earth thought deeply nested directories for packages was a good idea? FWIW, if I were listing "things to criticize Java for", I can't imagine that the package mechanism would be anywhere near the top 25, top 50, or even top 100. Unless you're routinely navigating around that structure using command line tools (which I suppose some Java developers do), I don't see the problem. Pretty much any modern IDE makes it nearly painless to navigate around the source code.
- TazeTSchnitzel 14y agoI routinely navigate by command line. But yes, Java's packaging is mostly a good thing.
- sbov 14y agoI use the command line for everything, including java projects. I usually just create symbolic links: ln -s src/main/java/net/minecraft/workbench/ source
- spacemanaki 14y agoLeaving aside Java's packaging structure, if you're on Github, just use "t" and search for the filename you're looking for instead of clicking up and down the directory. hierarchy. When I found this out, it changed my life.
- angrycoder 14y agogood old hacker news. Hey, someone is doing something cool... for me to poop on.
- skeletonjelly 14y agoSo just because it's good for X means it can't be critiqued on Y?