News for hackers. Stuff that matters.
Re:It’s strange what people put up with in C# by Someone1234 on Saturday August 15, 2020 @07:37AM (#24168134)
"Implicitly discarding information" is just outright wrong.

All calls can have side effects, even calls that return a value. And while C# did recently add the discard operator _ to throw away returned values out of an e.g. Tuple, if you did as this critique suggests and flag every "discarded information" the language would become verbose/obnoxious.

For example:

      try 
      {   
            [....]
            myFirstDatabaseTransaction.Commit(); // Compiler warning: "Discarded Information" (it returns the transaction ID, but has the side effect of committing your changes to the database).   
      } 
      catch([...])
      { [...] }

Basic programmer errors are easily caught during development, because they're immediately wrong. Unlike null reference exceptions which sometimes can only be found after extensive usage of the system (due to different states, or underlying data changing).
Re:It’s strange what people put up with in C# by rndgermandude on Saturday August 15, 2020 @08:04AM (#24168274)
And nullable helps with null references as well as intellisense warnings.

Moreover that examples the author did are likely both oversimplified and wrong.

In the first one, a bool then a string is returned which should raise a type error in most cases (unless you do an anonymous function and feed the result back into something that accepts an object-typed parameter/use an object-typed variable to store the result).

I don't even know what's up with the second one; that's simply not valid code - if it was a normal function you cannot omit the trailing semicolon, and if it was a anonymous lambda you cannot have a trailing semicolon.

Re:It’s strange what people put up with in C# by yyyk on Saturday August 15, 2020 @07:53AM (#24168205)
"All calls can have side effects" - this isn't the case for a "pure" function. What the author wants would make some code worse but is very useful for anything working with immutable collections [IMHO, reading #4 that's what's behind his complaints - working in a functional/immutable style where C# isn't entirely comfortable]. There could be a middle ground where certain function calls do warn/error on such use and most others do not.
Re:It’s strange what people put up with in C# by Smaug123 on Saturday August 15, 2020 @07:55AM (#24168221)
F# solves this by making it a compile error to fail to consume an expression that returns anything other than unit. If you really must do this, you normally use `ignore : 'a -> unit`. It's unidiomatic F# to structure your APIs in such a way that you will routinely throw away the information you're given.
Re:It’s strange what people put up with in C# by Gibbon1 on Saturday August 15, 2020 @10:22PM (#24174318)
I think really what people want are strict and sleazy compile options. Or better the ability to tell the compiler that a return value is an error. Or not. If it's not an error and it gets tossed who cares really. Sometimes you don't care if every i is dotted and every t crossed.