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

Started by
6 comments, last by Machaira 14 years, 5 months ago
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!
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.

In time the project grows, the ignorance of its devs it shows, with many a convoluted function, it plunges into deep compunction, the price of failure is high, Washu's mirth is nigh.

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?
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.

In time the project grows, the ignorance of its devs it shows, with many a convoluted function, it plunges into deep compunction, the price of failure is high, Washu's mirth is nigh.

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.
-----Quat
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
Quote:Original post by nerd_boy
Granted, these preferences are personal preferences. If you meant industry preferences, I've not a clue. :P
You could always go with the guidelines set out by Microsoft.

[Website] [+++ Divide By Cucumber Error. Please Reinstall Universe And Reboot +++]

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.

Former Microsoft XNA and Xbox MVP | Check out my blog for random ramblings on game development

This topic is closed to new replies.

Advertisement