News for hackers. Stuff that matters.
Re:It’s strange what people put up with in C# by codeulike on Saturday August 15, 2020 @06:29AM (#24167792)
The complaint about 'implicit information loss' is a bit weird, the code calls a function/method that may do other things, the compiler doesn't know whether you intend to ignore what's returned or not. To return 'true' when you meant to return the result of the function call on the previous line is just a bug. There are going to be bugs.
Re:It’s strange what people put up with in C# by frabert on Saturday August 15, 2020 @06:34AM (#24167833)
C++ introduced the [[nodiscard]] attribute for this exact use case. A C# [NoDiscard] attribute would do the same thing with the help of a Roslyn analyzer I guess.
Re:It’s strange what people put up with in C# by goto11 on Saturday August 15, 2020 @07:24AM (#24168078)
C# already by default warns on discarded return values.
Re:It’s strange what people put up with in C# by algorithmsRcool on Saturday August 15, 2020 @09:59PM (#24174192)
No it does not, unless the discarded value is a Task in an async method. (or sometimes an IDisposable depending on what analyzers you have running)
Re:It’s strange what people put up with in C# by chrisandchris on Saturday August 15, 2020 @11:07AM (#24169386)
I think what he meant is the different (implicitly assumed by human brain) output of those two statements:

someList.Add(obj); someStr.Format(„%d“);

While the first one cleary modifies the list someList, the second one only _returns_ the modified string and someStr’s value does not change. IMHO fornatted text is a different (new) object therefore I don‘t see his issue, and I also think there‘s a shift towards immutable, which would clear such a thing up.

Re:It’s strange what people put up with in C# by fireattack on Saturday August 15, 2020 @12:03PM (#24169848)
I feel like your example is talking about having the result "in-place" or not, which is an entirely different from what he's complaining (semicolon suspends output).
Re:It’s strange what people put up with in C# by chrisandchris on Saturday August 15, 2020 @12:06PM (#24169878)
> In project programming this hit me this week with a bug: > value.Format(...); > return true; > when I actually wanted > return value.Format(...); > This is "implicit information loss" [..]

I don‘t see any semicolon missing.

Re:It’s strange what people put up with in C# by fireattack on Saturday August 15, 2020 @12:11PM (#24169918)
Oh sorry, didn't notice you're talking about the first half of point #1.

To be honest, I have no idea what he's expecting with that "return true". How would that be different in any other language?

Re:It’s strange what people put up with in C# by chrisandchris on Saturday August 15, 2020 @04:55PM (#24172321)
I think he‘s expecting someStr.Format() to format the value of the object someStr _instead_ of returning a new object containing the fornatted string.