Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Or if you're an Android developer then main doesn't exist at all and never has

But yeah I don't understand why the author is so excited about this. How "ugly" a trivial "Hello, World!" does not really matter much and isn't a good indication of anything about the language's ability to handle more than "Hello, World!"



I think it does say something about what a language thinks is important.

Java (historically) is famous for going a bit too hard core into overly abstract & verboseobject oriented design patterns - create a factory to get another factory to get a different factory and whatnot. The hello world is where java shows that style of code is what historical java felt was the ideal.


That is just a coding style. I don't use factories in Java, they are just confusing when there are simpler ways to get the job done.


Factories are a pattern that is not unique to Java. They're used prolifically in C++ at least, and I'm sure in other languages.

The factory pattern is tightly coupled with polymorphism. If you're not using polymorphism, then you may not typically need factories. But if you are, then at some point you're going to have some conditional logic about what concrete type of class you're going to create of a particular interface.

Modern Java is lending itself more towards data oriented programming, and coders are trending in that direction. This may or may not last, like every trend. But even then, at the moment this tends to still involve using sealed interfaces and records, so you still have some form of instance creation and polymorphism.

How do you avoid factories? Doesn't you code end up littered with worse code?


Thanks for the explanation, very detailed.

> How do you avoid factories? Doesn't you code end up littered with worse code?

Easier for me to use "public abstract class" and then leave open methods inside like "protected abstract doAction();" that are forcefully implemented on each variation of that class.

There is still just one base implementation, I guess the main difference is using strong typed classes that keep the specific code inside specific classes. With factories one tends to end up with a very large source code file that details with too many specific different topics, was making maintenance and testing harder afterwards.

Or maybe I just never really understood properly the value of factories.


Yeah sorry, I don't mean to cause offense but that doesn't make sense. If you've got abstract methods that require implementation in concrete classes, you've got polymorphism, and at some point you're going to be choosing which concrete class to instantiate.

If you always know which concrete class to instantiate and use at each point in the code, it doesn't sound like you need polymorphism in the first place.

Or I could just be missing something.


Usually when I have polymorphism I have some algorithm that operates on an array or graph of mixed instances of BaseClass. For any particular graph I know statically which concrete nodes I want and their arrangement. Factory really only made sense to me if you want to delay the actual creation of the array members, if the decision comes from something external, or if their creation is deeply entangled with their environment in a way you couldn't otherwise avoid repeating.


Fair, that makes sense.


I agree that you can write java any way you want. My point is that the protypical hello world is a cultural artifact representing the cultural ideals of the java language designers. Its symbolic of what they thought was good programming at the time the language was designed. So it says something about both the language design and the culture surounding the language. Or at least it did 20 years ago. That doesn't mean every java program follows that ideal.


the verbosity is a feature not a bug

that's why java programmers are the most productive programmers ever

if you count productivity by lines of code


>How "ugly" a trivial "Hello, World!" does not really matter much and isn't a good indication of anything about the language's ability to handle more than "Hello, World!"

Sure, but for beginner programmers who don't have the discipline down yet, it's unnecessarily hard. I bought a Java programming book as a kid and got stuck because of a typo that produced an error message I couldn't understand. This was the time before StackOverflow and Reddit. In retrospect, this delayed my programming journey by at least a year.

Longer Hello Worlds make frustration and getting stuck like this more likely.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: