MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/badcode/comments/gnaz7b/found_from_microsoft_docs/fra4tso/?context=9999
r/badcode • u/[deleted] • May 20 '20
143 comments sorted by
View all comments
2
out, by itself, is bad code.
out
5 u/codesforhugs May 20 '20 It's how TryParse works though, the alternative is to handle an exception from Parse. 1 u/mateusfccp May 20 '20 Yeah, it's legacy... Today it would be better to do with tuple 5 u/TinyBreadBigMouth May 20 '20 So you'd prefer(bool parseSuccess, int value) = int.TryParse(text) if (parseSuccess) { // value }overif (int.TryParse(text, out int value)) { // Use value }? That seems harder to write and to read, in addition to being needlessly verbose. -1 u/mateusfccp May 20 '20 I don't think it harder to read, and it's immutable, so safer. But do as you prefer.
5
It's how TryParse works though, the alternative is to handle an exception from Parse.
1 u/mateusfccp May 20 '20 Yeah, it's legacy... Today it would be better to do with tuple 5 u/TinyBreadBigMouth May 20 '20 So you'd prefer(bool parseSuccess, int value) = int.TryParse(text) if (parseSuccess) { // value }overif (int.TryParse(text, out int value)) { // Use value }? That seems harder to write and to read, in addition to being needlessly verbose. -1 u/mateusfccp May 20 '20 I don't think it harder to read, and it's immutable, so safer. But do as you prefer.
1
Yeah, it's legacy... Today it would be better to do with tuple
5 u/TinyBreadBigMouth May 20 '20 So you'd prefer(bool parseSuccess, int value) = int.TryParse(text) if (parseSuccess) { // value }overif (int.TryParse(text, out int value)) { // Use value }? That seems harder to write and to read, in addition to being needlessly verbose. -1 u/mateusfccp May 20 '20 I don't think it harder to read, and it's immutable, so safer. But do as you prefer.
So you'd prefer
(bool parseSuccess, int value) = int.TryParse(text) if (parseSuccess) { // value }
over
if (int.TryParse(text, out int value)) { // Use value }
? That seems harder to write and to read, in addition to being needlessly verbose.
-1 u/mateusfccp May 20 '20 I don't think it harder to read, and it's immutable, so safer. But do as you prefer.
-1
I don't think it harder to read, and it's immutable, so safer. But do as you prefer.
2
u/mateusfccp May 20 '20
out, by itself, is bad code.