Guild Wars 2 Source Code

Screen Shot 2014-08-03 at 21.57.19 1Today while playing Guild Wars 2, my game crashed and I got a small look into the coding style used in their engine.

The class member prefix of m_ is something I used myself a while back, its quite a good one since you don’t have to worry about making the first letter automagically uppercase when it represents something in lower case.
I eventually stopped doing it though, I don’t think there was a specific reason, I just preferred it without the underscore. Maybe it was my adoption of in/out for function parameters, I no longer needed to prefix local variables with underscore to differentiate them.

They also put rounded brackets around their logic, I have seen code that doesn’t do this numerous times. You may think it is fine to ignore the brackets, and in some cases it probably is, however as soon as you add a logical or to a bunch of logical ands, or a logical and to a bunch of logical ors, not deciphering what is happening is a pain.

Consider this

(x1 >= x2) OR (x2 <= x3) AND (x4 == x5)

 

Now does this mean,

(X1 >= X2 ) OR ((x2 <= x3) AND (x4 == x5))

 

or does it mean

(x1 >= x2) OR ((x2 <= x3) AND (x4 == x5))

 

Sure, there is an order of operations, but what does the programmer intend.

This is less annoying that if the value being compared is already a boolean and has no rounded brackets at all. I’ve only seen this done a few times, usually by non-coders.

x1 == x2 OR x2 == x3

Now you’re in question as to whether they mean

(x1 == x2) OR (x2 == x3)

or

x1 == (x2 OR x2) == x3

It is probably the former, but remember “Don’t assume you know how someone else’s code work