I know this is not the review you are looking for, but it must be said.
Please, avoid names in other languages.
It is really tempting to write variable and property names in other languages. But please, avoid it.
I am Portuguese, and can understand some of your code. Now imagine I want to change it, and will change it to my way.
Here is your original code with a tiny change to allow pounds(£
), with a bit of Portuguese in it:
class Prix
{
double valeur;
string moeda;
public Prix(double valeur, string moeda)
{
if (moeda.Equals("€") || moeda.Equals("$") || moeda.Equals("£"))
{
this.valeur = valeur;
this.moeda = moeda;
}
else
{
defaultConstr(valeur);
}
}
public Prix(double valeur)
{
defaultConstr(valeur);
}
private void defaultConstr(double valeur)
{
this.valeur = valeur;
this.moeda = "€";
}
}
"Moeda" means "coin" or "currency" in Portuguese. Is that what monnaie
? Does it mean "currency"? I have no idea, but I assume it does.
Now, look at that code. What a beautiful mess! You can't understand what's there, I can't understand what's there... Nobody can understand it!
Bottom line is: Always use English names for your code. This avoids a huge linguistic bareer and helps to keep the code clean and easy-to-understand by everybody, specially those who don't speak French.
currency
and value
would be perfect names, if that is what valeur
and monnaie
mean...
Also, there's no documentation on your code. Not even a single comment, for non-French speakers. And even for French speakers!
How will I know what can I pass to the constructor if there's no documentation? How will I know that the 2nd parameter is optional? How would I know that it expects a double
instead of a float
?
If you use this in a project, 3 months from now, you will ask "What in the name of God this needs to run!?".
So, please, add some documentation to it. Visual Studio makes it easy to document your code. Just start by writting ///<sumary>
and it will almost complete everything for you.
If you want more information, you can read @Shymep's answer on StackOverflow.
I'm just wondering if what I've done below is correct.
Is it doing what it's supposed to be doing? If it's not, it's considered broken. If you don't know, test it first. \$\endgroup\$