Jump to content

Recommended Posts

Posted (edited)

Hey,

So when I code I find that certain given parameters and method parameters have the suffix "In" at the end. For instance, "worldIn," "playerIn," "xIn," "yIn..."

This might be a silly question, but does anyone know why they have these "Ins" at the end? And why do some parameters have that while others do not?

Thanks!

Edited by Differentiation
Posted

The parameters that have "In" at the end, have been named so by users who added them to the MCP mappings. It's just the code style they use. You can change them to anything you like if you want.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Posted
1 hour ago, larsgerrits said:

The parameters that have "In" at the end, have been named so by users who added them to the MCP mappings. It's just the code style they use. You can change them to anything you like if you want.

Ohhh xD

Thanks!

I adopted their style I guess, until today I asked myself: Why am I even writing that extra "In?" xD

Posted (edited)

A parameter name is very limited in scope so doesn't matter too much as long as its meaning is understandable. Like if you're passing an integer that represents a color it is better to call that parameter an "int color" rather than "intIn".

 

Now an important thing is that in many situations, especially "setter" methods and constructors, the parameters are usually copied to fields that have similar meaning. So there are two coding styles for that. One is to name them the same but use the "this." reference to indicate the field. For example:

public void setColor(int color)
{
     this.color = color;
}

 

The other style is to always name the parameters something slightly different (but consistent) to identify it as the parameter. I personally tend to use a prefix "par" for parameters so I would have:

public void setColor(int parColor)
{
     color = parColor;
}

 

Many people who have contributed to MCP mappings and also to Forge like to do a similar thing but instead use a suffix "In" as you noticed. So it would be:

public void setColor(int colorIn)
{
     color = colorIn;
}

 

All three styles are fine, they are just a matter of personal preference. The main thing is that in each case they are readable, and they also prevent mistakes by making it harder to mix up the parameter with the class field.

Edited by jabelar

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Posted

That only makes me think of How to Write Unmaintainable Code

Quote

Insist on carrying outright orthogonal information in your Hungarian warts. Consider this real world example "a_crszkvc30LastNameCol". It took a team of maintenance engineers nearly 3 days to figure out that this whopper variable name described a const, reference, function argument that was holding information from a database column of type Varchar[30] named "LastName" which was part of the table's primary key.

 

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

Its decompiled code, seriously. Naming isn't perfect. However this is a community standard because of how the code is decompiled.

Local variables can get the name of classes. 'World world = null;' And ints can get i, j, k, etc.. See here for more information.

So to prevent parameters from colliding with Fernflower's local variable names people don't use class names directly.

I do Forge for free, however the servers to run it arn't free, so anything is appreciated.
Consider supporting the team on Patreon

Posted
6 hours ago, jabelar said:

A parameter name is very limited in scope so doesn't matter too much as long as its meaning is understandable. Like if you're passing an integer that represents a color it is better to call that parameter an "int color" rather than "intIn".

 

Now an important thing is that in many situations, especially "setter" methods and constructors, the parameters are usually copied to fields that have similar meaning. So there are two coding styles for that. One is to name them the same but use the "this." reference to indicate the field. For example:


public void setColor(int color)
{
     this.color = color;
}

 

The other style is to always name the parameters something slightly different (but consistent) to identify it as the parameter. I personally tend to use a prefix "par" for parameters so I would have:


public void setColor(int parColor)
{
     color = parColor;
}

 

Many people who have contributed to MCP mappings and also to Forge like to do a similar thing but instead use a suffix "In" as you noticed. So it would be:


public void setColor(int colorIn)
{
     color = colorIn;
}

 

All three styles are fine, they are just a matter of personal preference. The main thing is that in each case they are readable, and they also prevent mistakes by making it harder to mix up the parameter with the class field.

 

3 hours ago, LexManos said:

Its decompiled code, seriously. Naming isn't perfect. However this is a community standard because of how the code is decompiled.

Local variables can get the name of classes. 'World world = null;' And ints can get i, j, k, etc.. See here for more information.

So to prevent parameters from colliding with Fernflower's local variable names people don't use class names directly.

Ahh, I understand!

It's basically for no-confusion purposes.

Thanks guys! :)

Posted
6 hours ago, LexManos said:

Its decompiled code, seriously. Naming isn't perfect. However this is a community standard because of how the code is decompiled.

Local variables can get the name of classes. 'World world = null;' And ints can get i, j, k, etc.. See here for more information.

So to prevent parameters from colliding with Fernflower's local variable names people don't use class names directly.

Oh I get why it's done, Lex. Minecraft has its limitations because of the decompile and deobf process.

All I meant was that I, as a coder, wouldn't have chosen those names for my own functions.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted
7 hours ago, Draco18s said:

Oh I get why it's done, Lex. Minecraft has its limitations because of the decompile and deobf process.

All I meant was that I, as a coder, wouldn't have chosen those names for my own functions.

Well you shouldn't. Anyone who takes code style from decompiled code is batshit insane... Write clean code. Decompiled code is NOT clean code.

I do Forge for free, however the servers to run it arn't free, so anything is appreciated.
Consider supporting the team on Patreon

Posted
40 minutes ago, LexManos said:

Well you shouldn't. Anyone who takes code style from decompiled code is batshit insane... Write clean code. Decompiled code is NOT clean code.

Well, obviously...

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.