Why try when it's easier to fail?
-
foo.TryGetValue("bar", out object value);
var somestr = value.ToString();Sort of defeats the purpose of the try when foo doesn't have the key "bar" or even if it does, the value might be null. :sigh: If I show this to the person who wrote it, do you think they'll suggest a try-catch block to not break the rest of the code? :rolleyes:
Latest Article - A 4-Stack rPI Cluster with WiFi-Ethernet Bridging Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny Artificial intelligence is the only remedy for natural stupidity. - CDP1802
-
foo.TryGetValue("bar", out object value);
var somestr = value.ToString();Sort of defeats the purpose of the try when foo doesn't have the key "bar" or even if it does, the value might be null. :sigh: If I show this to the person who wrote it, do you think they'll suggest a try-catch block to not break the rest of the code? :rolleyes:
Latest Article - A 4-Stack rPI Cluster with WiFi-Ethernet Bridging Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny Artificial intelligence is the only remedy for natural stupidity. - CDP1802
-
foo.TryGetValue("bar", out object value);
var somestr = value.ToString();Sort of defeats the purpose of the try when foo doesn't have the key "bar" or even if it does, the value might be null. :sigh: If I show this to the person who wrote it, do you think they'll suggest a try-catch block to not break the rest of the code? :rolleyes:
Latest Article - A 4-Stack rPI Cluster with WiFi-Ethernet Bridging Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny Artificial intelligence is the only remedy for natural stupidity. - CDP1802
At least he tried ;p
Best, Sander sanderrossel.com Continuous Integration, Delivery, and Deployment arrgh.js - Bringing LINQ to JavaScript Object-Oriented Programming in C# Succinctly
-
foo.TryGetValue("bar", out object value);
var somestr = value.ToString();Sort of defeats the purpose of the try when foo doesn't have the key "bar" or even if it does, the value might be null. :sigh: If I show this to the person who wrote it, do you think they'll suggest a try-catch block to not break the rest of the code? :rolleyes:
Latest Article - A 4-Stack rPI Cluster with WiFi-Ethernet Bridging Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny Artificial intelligence is the only remedy for natural stupidity. - CDP1802
A classic case of "when a little knowledge is a dangerous thing". They understood that they needed to use TryGetValue() but not how to use it.
"There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult." - C.A.R. Hoare Home | LinkedIn | Google+ | Twitter
-
foo.TryGetValue("bar", out object value);
var somestr = value.ToString();Sort of defeats the purpose of the try when foo doesn't have the key "bar" or even if it does, the value might be null. :sigh: If I show this to the person who wrote it, do you think they'll suggest a try-catch block to not break the rest of the code? :rolleyes:
Latest Article - A 4-Stack rPI Cluster with WiFi-Ethernet Bridging Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny Artificial intelligence is the only remedy for natural stupidity. - CDP1802
Prolog has the notion of "fail" and handles this gracefully (Visual Prolog in the example below):
facts % key_value lookup table
key_value : (string Key, integer Value).predicates
tryGetValue : (string Key) -> integer Value determ.
clauses
tryGetValue(K) = V :-
key_value(K, V), % FAILs here if undefined key_value/2
!. -
foo.TryGetValue("bar", out object value);
var somestr = value.ToString();Sort of defeats the purpose of the try when foo doesn't have the key "bar" or even if it does, the value might be null. :sigh: If I show this to the person who wrote it, do you think they'll suggest a try-catch block to not break the rest of the code? :rolleyes:
Latest Article - A 4-Stack rPI Cluster with WiFi-Ethernet Bridging Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny Artificial intelligence is the only remedy for natural stupidity. - CDP1802
-
foo.TryGetValue("bar", out object value);
var somestr = value.ToString();Sort of defeats the purpose of the try when foo doesn't have the key "bar" or even if it does, the value might be null. :sigh: If I show this to the person who wrote it, do you think they'll suggest a try-catch block to not break the rest of the code? :rolleyes:
Latest Article - A 4-Stack rPI Cluster with WiFi-Ethernet Bridging Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny Artificial intelligence is the only remedy for natural stupidity. - CDP1802
They were probably so thrilled with using inline type declaration they thought their job that day was done
-
foo.TryGetValue("bar", out object value);
var somestr = value.ToString();Sort of defeats the purpose of the try when foo doesn't have the key "bar" or even if it does, the value might be null. :sigh: If I show this to the person who wrote it, do you think they'll suggest a try-catch block to not break the rest of the code? :rolleyes:
Latest Article - A 4-Stack rPI Cluster with WiFi-Ethernet Bridging Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny Artificial intelligence is the only remedy for natural stupidity. - CDP1802
var somestr = foo.TryGetValue("bar", out var value) ? value?.ToString() : null;
Would that be better?! :o
A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!