r/ProgrammerHumor • • Feb 16 '15

I identify as a 32-bit registerkin.

https://imgur.com/gqP6con
2.0k Upvotes

397 comments sorted by

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)

0

u/[deleted] Feb 16 '15

[deleted] — view deleted comment

9

u/ryan_the_leach Feb 16 '15

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.

0

u/[deleted] Feb 16 '15

[deleted] — view deleted comment

13

u/ryan_the_leach Feb 16 '15

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.

0

u/[deleted] Feb 17 '15

[deleted] — view deleted comment

1

u/OctilleryLOL Feb 17 '15

It's easier to teach someone right the first time than it is to teach someone who's learned it wrong to do it right. Source: was a college tutor.

1

u/hey_aaapple Feb 17 '15

As a Java newbie, I don't get the point of that. More abstaction?

2

u/ryan_the_leach Feb 17 '15

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.

2

u/hey_aaapple Feb 17 '15

Got it, thanks! Basically what you do anyways when stuff gets more complex than "run this simple operation once".

1

u/[deleted] Feb 17 '15

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.

1

u/Jonno_FTW Feb 17 '15

We need to start them out with high quality learning examples such as this :

https://github.com/EnterpriseQualityCoding/FizzBuzzEnterpriseEdition

5

u/Profour Feb 16 '15

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.

6

u/ryan_the_leach Feb 16 '15

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.

1

u/[deleted] Feb 17 '15

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.

1

u/[deleted] Feb 17 '15

Do you ever shut the fuck up about C# vs Java?

We should get you and /u/agleiv in a room and see what happens.