Jump to content
  • Advertisement
Sign in to follow this  
Uphoreum

[.net] [C#] Which is Preferred?

This topic is 3254 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

This question goes for a lot of things, but for example, my question right now is whether this:
public Vector Normalized
{
    get
    {
         // do normalizing stuff and return new vector
    }
}

is preferred over this:
public Vector Normalized()
{
    // do normalizing stuff and return new vector
}

Thanks!

Share this post


Link to post
Share on other sites
Advertisement
Does it matter? From a stylistic perspective I don't like either of them and would rather see something more of the form of: result = Vector.Normalize(v);. From a performance perspective, something of the form: Vector.Normalize(ref v, out result); is even better.

Share this post


Link to post
Share on other sites
You should use Eiffel, where nullary methods and properties are one and the same if I'm not mistaken.

Quote:
From a performance perspective, something of the form: Vector.Normalize(ref v, out result); is even better.

Why is that? Or do you assume Vector is a value type? Is it also more efficient if Vector is a class?

Share this post


Link to post
Share on other sites
Quote:
Original post by SamLowry
You should use Eiffel, where nullary methods and properties are one and the same if I'm not mistaken.

Quote:
From a performance perspective, something of the form: Vector.Normalize(ref v, out result); is even better.

Why is that? Or do you assume Vector is a value type? Is it also more efficient if Vector is a class?

If it's not a value type then someone screwed up horribly. As a non-value type, a 4-vector consumes 16 bytes + 8 (or 16 in x64) memory per allocation. That's extremely tiny for a reference type, and seeing as how in general where you need on vector, you need many vectors, an array of them will scatter your vectors all over memory, not to mention, temporary allocations for mathematics will fill up the GC forcing more collections and promoting just slightly longer lived items to the next generation.

Share this post


Link to post
Share on other sites
Quote:

From a stylistic perspective I don't like either of them and would rather see something more of the form of: result = Vector.Normalize(v);.


I agree with this style as well.

Share this post


Link to post
Share on other sites
What Washu said aside, I find myself preferring using properties with just getters for things that don't/hardly require any work to get, or just require accessing a database to get, no calculations. If it is something that is going to require a bit of work to get/calculate, I generally prefer using a function.

Granted, these preferences are personal preferences. If you meant industry preferences, I've not a clue. :P

Share this post


Link to post
Share on other sites
Quote:
Original post by Quat
Quote:

From a stylistic perspective I don't like either of them and would rather see something more of the form of: result = Vector.Normalize(v);.


I agree with this style as well.

I add my vote for this.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!