# [.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.

## 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 on other sites
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 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 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 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 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 on other sites
Quote:
 Original post by nerd_boyGranted, 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.

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

1. 1
2. 2
3. 3
Rutin
18
4. 4
JoeJ
14
5. 5

• 14
• 10
• 23
• 9
• 33
• ### Forum Statistics

• Total Topics
632633
• Total Posts
3007543
• ### Who's Online (See full list)

There are no registered users currently online

×