State of the Values
Tom Schindl
tom.schindl at bestsolution.at
Mon May 5 15:36:24 UTC 2014
Correct me but this is not working with the proposal as i read it because all field values are final.
Tom
Von meinem iPhone gesendet
> Am 05.05.2014 um 17:02 schrieb Dan Howard <sproket at videotron.ca>:
>
> I think we have to be careful here.
>
> One of the nice features of Java is that generally you can look at piece of code and know what it's doing so I'm not sure going the C# route on value types is really worth it.
>
> Consider the following code in C#:
>
> class Program
> {
> static void Main(string[] args)
> {
>
> Account account = new Account();
> account.AcccountNumber = "1234";
> account.Name = "Savings";
> account.Balance = 10;
>
> Console.WriteLine("BEFORE: " + account);
>
> adjustAccountBalance(account, 10);
>
> Console.WriteLine("AFTER: " + account);
>
> Console.ReadLine();
> }
>
> static void adjustAccountBalance(Account account, float balance)
> {
> account.Balance += balance;
> }
> }
>
> Question: What is the result? In Java the answer is obvious but in C# the correct answer is *unknown*. It all depends on whether Account is a class or struct. It's possible in C# to simply change a class to a struct - everything will compile fine but I've potentially just introduced a mountain of Heisenbugs as developers can easily misinterpret how their "object" will behave when passed to a method.
>
> Have we considered just a simple struct like in C?
>
> // Lowercase to avoid convention collision with classes.
> struct account {
> String accountNumber;
> String name;
> float balance;
> }
>
> Wouldn't this solve the issue at hand without introducing unwanted complexity?
>
> ---
> This email is free from viruses and malware because avast! Antivirus protection is active.
> http://www.avast.com
>
>
More information about the coin-dev
mailing list