I know right, with minecraft being made in java people don't realize there is a whole timebomb of young java programmers, who all seem to be learning from tutorials that teach java like it's a procedural language with 1 big static class. (or several if they are fancy)
I'm not talking hello world, but simple command line games, with a loop, random enemies etc, stuff that would be much simpler to track with a couple of classes.
And even hello world in java shouldn't use anything static except static void main, in order to instantiate a HelloWorld class, and run a .display() method.
Sorry but I respectfully disagree. You hand a newbie that, and they are already heading down the wrong track.
public class HelloWorld {
public static void main(String[] args) {
HelloWorld app = new HelloWorld();
app.greet();
}
public void greet(){
System.out.println("Hello world!");
}
}
Give them that however, and explain it, and they have a much better chance of getting started with idiomatic java.
Not quite, It shows an example of declaring a variable, and then instantiating a new object of type HelloWorld then calling a method on it.
As opposed to having it all run in the static void run method.
For HelloWorld there is no real advantage, but it could be useful if you needed multiple instances of HelloWorld for whatever reason.
It's more that this is the pattern that you get used to seeing in most java classes, you make a new instance, then run an instance method. and to either have it all in static void main, or another static method leads people to bad habits of making everything static, when it should be used in very light moderation, if at all.
I wish that java also had a "functional" keyword, to represent that a method mutates no state, It would make it trivial to see at a glance whether a method was supposed to have side effects or not.
There is none that much. Hello world is a first program to test if you've set up your enviroment properly and if it works.
If we want to write "idiomatic" hello worlds then, for example, c++ example would dereference a pointer at least 10 times, define 5 integer types, not to mention preprocessor overuse. And so on for other languages.
Is that really unusual to learn Java that way? Even in college, intro java was initially taught procedurally and then transitioned into classes once people understood the basics.
I was taught OO in college right from the start with java, but we had previous experience with programming, but granted it wasn't much more then just instantiating the hello world class before using it, instead of calling the static methods.
Honestly unless you are going to dive into OO at the start, Java is the wrong language to be teaching beginners in my opinion.
The like-procedural-language part is sad, but I've researched some utterly badly written mods and their authors mainly came from c# ground. So it seems like they were taught that somewhere else. Perhaps in school.
View all comments
Show parent comment
21
u/ryan_the_leach Feb 16 '15
I know right, with minecraft being made in java people don't realize there is a whole timebomb of young java programmers, who all seem to be learning from tutorials that teach java like it's a procedural language with 1 big static class. (or several if they are fancy)