m309

Member
Alright. So I'm finally getting around to merging in ServUO 54 into what...I think...is my version of like 49, or 50. I can't remember...I've had my face in CED+ for like 6-7 months and haven't written a line of code, much less read too much of it, other than posted changelogs, in that many months.

So my question has to do with the addition of 10 billion "this."'s. When I moved from a RunUO server to ServUO (then ForkUO 17 I think - I don't know..whenever Insanity first set it up on GitHub) it was one of the first things I noticed. I never understood why it was done. Now, in revision 54, in the server files (notably Mobile.cs - the entire file is red in BeyondCompare) I see they're pretty much all but gone.

Can someone with more coding knowledge than myself clue me (and maybe hopefully others) in on what exactly they were added for, and now why they're gone? If for no other reason I'd like to know for the simple understanding and self-gratification of learning more about C# specifically related to this (<- no pun intended) clandestine passion we all share.
 
I've also been dieing to know this and why the formatting looks different.
the this. reminds me more of standard C# code but why was it necessary to add it when it still works without it.
 
"this" is a keyword that is usually optional. It is often used for people who want to explicitly declare the class instance.

So if the script is a Zombie, then "this" used in the script is going to refer to the current instance of the class (Zombie). So you could have:

Zombie.HitsMax = 100;

or

this.HitsMax = 100;

or, because it is assumed that you are referencing the current instance, you can just have:

HitsMax = 100;

Basically, the first two explicitly declare who's HitsMax you are referring to and the last one just assumes the current instance.

The only time "this" is not optional is when there is an ambiguity within the scope:

HitsMax = HitsMax;

Must be:

this.HitsMax = HitMax;

As far as why they were removed, I imagine either Mark or Voxpire decided to clean up the code a bit. Using "this" when it is not needed will get flagged in some programs like Resharper from my understanding.

As far as the formatting, most of what I saw was about having less lines of code, using a single line of code instead of breaking it out across several lines:

Code:
public override void HitsMax { get {return 100;} }

is less lines than:

Code:
public override void HitsMax
{
	get
	{
		return 100;
	}
}
 
Last edited:
Thanks @Ravenwolfe, that certainly makes sense. The whitespace, extra spacing and/or lines part of the code never bothered me as I have BeyondCompare set to ignore it - but the lack of "this." present in the current revision definitely caught my eye.
 
I may be mistaken, but I think the less lines is not just about asthetics but is actually more efficient for the compiler to read.
 
As far as the formatting, most of what I saw was about having less lines of code, using a single line of code instead of breaking it out across several lines:

Code:
public override void HitsMax { get {return 100;} }

is less lines than:

Code:
public override void HitsMax
{
	get
	{
		return 100;
	}
}

I am using the latest release of servuo and the code has always looked like that second example. I'm aware that the first example uses less lines, which is why I like it and that is what runuo code looks like. But all the servuo Distro code I've seen is like the second example.
I was just wondering why the formatting is using the 2nd example with it all spread out on many lines.
Here is an example from a piece of armour. It all looks like this and for me it is not what I'm use to seeing format wise.
[spoilerbb=armour example]
Code:
public override int BasePhysicalResistance
		{
			get
			{
				return 6;
			}
		}
[/spoilerbb]
So why is servuo code formatted this way? I'm aware there is no difference other then it being spread out on many lines.
Now i know not every single script is this way, but there is enough examples of it to be intrusive.
Who thought,.. "you know it would make it so much easier if we make a 100 line script 400 lines! Brilliant!"
 
Last edited by a moderator:
The reason being why some formatting has been changed in ServUO is because it was ran through ReSharper a long while ago. Then as other people have worked on the project, they either didn't use ReSharper...or used different ReSharper settings.

Good news about all this though, this will all be addressed pretty soon. As we've added a source license to the repo (and I'll be adding a license page for the project here on the site soon.) I'll be applying for a team development license for ReSharper soon. Meaning everyone on the team, or anyone that wants to contribute can use ReSharper with the team development license and not have to pay for the software. Although with most good news, is bad news. Once we get the proper cleanup settings in place, it will end up modifying all files. So it will be a rather large update to pull, so I hope everyone is using Git properly.

Once I get a team license, I will be including project based ReSharper settings in the repo (the repo is currently set to ignore the files atm.) This will allow anyone to run their own code through the same cleaner settings. Or change the settings and clean the code to how they wish.

The reason why ServUO is going to use ReSharper to keep the code clean is for a few reasons. Namely, it allows for easier reading and reviewing of the code. Which makes it easier for anyone to quickly find issues, or find what they need. Instead of properties being scattered throughout a class (methods and shit in between various properties) the code cleaner moves them all together. Among other changes that make it easier to view a code.

As for the this keyword. As mentioned above, it is a keyword used to specify the following variable's scope is local to the class the code is in. Meaning if you see this.HitPoints. You know you can find the HitPoints property in the same class, and not a base class. The this keyword is not need, and can be stripped with ReSharper with a single click. Although it helps with reading and reviewing code. So I'd recommend you use it and get used to it.
 

Active Shards

Donations

Total amount
$0.00
Goal
$1,000.00
Back