News for hackers. Stuff that matters.
Re:New Features in C# 7.0 by louthy on Thursday March 09, 2017 @11:41PM (#13836430)
> int x, int y = p.GetCoordinates;

Obviously this can be done with the new tuple syntax, but in general I totally agree with everything you've said about 'out'. It is one of the ugliest language features ever, sometimes I wish MS would just say "To hell with backwards compatibility", and throw 'out' on the fire.

    // Function definition
    (int x, int y) GetCoordinates() =>
        (100, 200);

    // Invocation
    var (x, y) = GetCoordinates();
Re:New Features in C# 7.0 by pmarreck on Thursday March 09, 2017 @11:57PM (#13836493)
Well, to be charitable, fortunately you can use a style like you propose where values only flow as I've indicated... but you'd still have to contend with OPC (Other People's Code) and if the language allows it, you just know it will turn up somewhere and ruin your day! ;)
Re:New Features in C# 7.0 by louthy on Friday March 10, 2017 @12:05AM (#13836523)
Indeed. Although 'out' is rare, it occasionally does ruin my day. So I have created a set of extension methods [1][2] to remove them from my life (because it does physically enrage me whenever I see the need to use it).

[1] https://github.com/louthy/language-ext/blob/master/LanguageE...

[2] https://github.com/louthy/language-ext/blob/daa5a10028e9637b...

Re:New Features in C# 7.0 by mercurial on Friday March 10, 2017 @12:49AM (#13836676)
> but you'd still have to contend with OPC (Other People's Code) and if the language allows it, you just know it will turn up somewhere and ruin your day! ;)

Yes, like the standard library's Dictionary.TryGetValue()...

Re:New Features in C# 7.0 by yread on Friday March 10, 2017 @03:44AM (#13837223)
you can do

if (dict.ContainsKey(key)) return dict[key] else return null;

the only place where you can't avoid them are TryParse. And there it sort of makes sense - the value is sort of side effect

Re:New Features in C# 7.0 by louthy on Friday March 10, 2017 @06:43AM (#13837879)
> if (dict.ContainsKey(key)) return dict[key] else return null;

Which isn't thread-safe. So it's not always a better option.

Re:New Features in C# 7.0 by ygra on Friday March 10, 2017 @08:54AM (#13838546)
But Dictionary<TKey,TValue> isn't thread-safe anyway, unless not modified.
Re:New Features in C# 7.0 by louthy on Friday March 10, 2017 @09:04AM (#13838612)
Calling TryGetValue will either return a value or not. Calling ContainsKey, followed by an index read can lead to a race condition that means the value isn't there any more.
Re:New Features in C# 7.0 by ygra on Friday March 10, 2017 @10:21AM (#13839219)
If I'm reading the source correctly you could still get the bucket index and before you return true and the value, have that value removed from the dictionary. There is no synchronization going on, so concurrent modifications are just as much a problem with TryGetValue as with other approaches. TryGetValue is not atomic either.
Re:New Features in C# 7.0 by louthy on Friday March 10, 2017 @01:06PM (#13840642)
Ok, fair enough. My mistake. Glad I don't use the BCL collection types any more and stick to immutable maps, lists, and sets :)
Re:New Features in C# 7.0 by pmarreck on Friday March 10, 2017 @10:04AM (#13839076)
This is correct (and unfortunate).
Re:New Features in C# 7.0 by mrits on Friday March 10, 2017 @12:39AM (#13836645)
I feel like out was important for marshalling into C++ code?