I have a question...

Psychicash

New Member
Jul 29, 2019
700
0
1
So I'm starting to learn java... No no, it's ok don't panic. I'm being safe. :p

Seriously though I've been reading up on a few articles concerning best practices. I would rather not develop bad habits that I will have to break later. I came across an article concerning using the constructor method or literal when creating an object.

the example they gave is below. To my understanding changing the elements of o from o.name etc. to this.name helps keep maintenance down should you have to edit/rename and so on. As is this was the first exposure to creating objects it is the default method I turn to as I'm learning. My other concern is which method is preferred in minecraft? Despite certain approaches to code in the end most people concern themselves (as I've heard) with the overall game impact in terms of system resources and the impact it has on the user. With that in mind... which is better preferred or most practiced in the community?

Also if there's any other advice the community would like to give. I'm not modding at the moment. I'm still working through fully understanding java as a language before I try to move into that realm.



Bad method

var o = new Object();
o.name = 'Jeffrey';
o.lastName = 'Way';
o.someFunction = function() {
console.log(this.name);
}

Better

var o = {
name: 'Jeffrey',
lastName = 'Way',
someFunction : function() {
console.log(this.name);
}
};
 

Strikingwolf

New Member
Jul 29, 2019
3,709
-26
1
So I'm starting to learn java... No no, it's ok don't panic. I'm being safe. :p

Seriously though I've been reading up on a few articles concerning best practices. I would rather not develop bad habits that I will have to break later. I came across an article concerning using the constructor method or literal when creating an object.

the example they gave is below. To my understanding changing the elements of o from o.name etc. to this.name helps keep maintenance down should you have to edit/rename and so on. As is this was the first exposure to creating objects it is the default method I turn to as I'm learning. My other concern is which method is preferred in minecraft? Despite certain approaches to code in the end most people concern themselves (as I've heard) with the overall game impact in terms of system resources and the impact it has on the user. With that in mind... which is better preferred or most practiced in the community?

Also if there's any other advice the community would like to give. I'm not modding at the moment. I'm still working through fully understanding java as a language before I try to move into that realm.



Bad method

var o = new Object();
o.name = 'Jeffrey';
o.lastName = 'Way';
o.someFunction = function() {
console.log(this.name);
}

Better

var o = {
name: 'Jeffrey',
lastName = 'Way',
someFunction : function() {
console.log(this.name);
}
};
that's javascript...not java...
 
  • Like
Reactions: SatanicSanta

Psychicash

New Member
Jul 29, 2019
700
0
1
Ok so I googled that... Seriously... Like no one decided hey let's not make things confusing and name everything the same... That's just frustrating
 
  • Like
Reactions: Strikingwolf

Strikingwolf

New Member
Jul 29, 2019
3,709
-26
1
Ok now I'm legitimately confused... There's a difference?
A HUGE difference

Java class
Code:
public class Dog {
  String breed;
  int age;
  String color;

  public Dog(breed, age, color) {
    this.breed = breed;
    this.age = age;
    this.color = color;
  }

  public void barking() {
    System.out.println(this.breed + " is barking and is of color " + this.color);
  }
}

Javascript equivalent
Code:
function Dog(breed, age, color) {
  this.breed = breed;
  this.age = age;
  this.color = color;
}

Dog.prototype.barking = function () {
  console.log(this.breed + " is barking and is of color " + this.color);
};
 
  • Like
Reactions: VapourDrive

Strikingwolf

New Member
Jul 29, 2019
3,709
-26
1
Ok so I googled that... Seriously... Like no one decided hey let's not make things confusing and name everything the same... That's just frustrating
The proper name of Javascript is EMCAScript, so it's not super bad :p

But yes, Java and JS are very different. And yes you would use this.variable to access one inside an object
 
  • Like
Reactions: SatanicSanta

Psychicash

New Member
Jul 29, 2019
700
0
1
Alright... So back to the old drawing board (shakes head)


So I guess that's number one on the advice for someone learning would be to learn the correct things first...
 
  • Like
Reactions: Strikingwolf

lenscas

Over-Achiever
Jul 31, 2013
2,015
1,799
248
To add to the whole learn this way or that way or neither of those ways.
THERE IS NO CORRECT WAY!

If you want to watch that video then watch that video if you want to follow a site then follow that site if you want to learn by typing random stuff then go and write random stuff as long as you have fun it doesn't matter.

I will leave now as I may or may not overreacted a bit
 

FyberOptic

New Member
Jul 29, 2019
524
0
0
%D0%91%D0%B5%D0%B7%20%D0%B8%D0%BC%D0%B5%D0%BD%D0%B8ad-1.jpg
 

Strikingwolf

New Member
Jul 29, 2019
3,709
-26
1
Don't listen to the others.

This is the exact thing you should be watching. This teacher is amazing, funny, and you not only learn programming, you learn good programming.

Watch this series. Its perfect for learning. It's how I learned.
Strange, I watched a similar series on Objective-C a while back and it was okay, but I could learn all the concepts in one hour and thirty minute lecture in 20-30 minutes, I didn't find the information was compressed enough for my needs.
 

OreCruncher

Well-Known Member
Mod Developer
May 22, 2013
312
217
73
My Chair
Besides ham, I think there are several things to mention...

So I'm starting to learn java... No no, it's ok don't panic. I'm being safe. :p

Seriously though I've been reading up on a few articles concerning best practices. I would rather not develop bad habits that I will have to break later.

Despite your best efforts you *will* learn bad habits. The key is learning from those bad habits and figuring out better ways to do things. This will happen "automagically" as you gain experience.

My other concern is which method is preferred in minecraft? Despite certain approaches to code in the end most people concern themselves (as I've heard) with the overall game impact in terms of system resources and the impact it has on the user. With that in mind... which is better preferred or most practiced in the community?

Impact on system resources is an interesting questions. It all comes down to "it depends". One tenant you will come across is this concept of "premature optimization". As you build software and gain experience you will quickly get an understanding of what not to do at the start. My recommendation is to jump right in, hit a wall, and figure a way around that wall. It's the only real way to learn.

Also if there's any other advice the community would like to give. I'm not modding at the moment. I'm still working through fully understanding java as a language before I try to move into that realm.

There was a similar question posed about a month ago. You can find it here.