3 ms·
While I agree that the quality of .net is impressive, I think that it follows the overall SO problem with outdated answers. Recently I ran into the 'why Boolea
by sheldor 8y ago
While I agree that the quality of .net is impressive, I think that it follows the overall SO problem with outdated answers.
Recently I ran into the 'why Boolean.toString returns an odd "True" value', I visited SO to find a terrific [1] but outdated [2] answer.
Nowadays I shift my teams away from SO. My piece of advice would be to stay away from it (especially junior devs), until they reach a level were they can evaluate and cross check what they are reading.
[1] https://stackoverflow.com/questions/491334/why-does-boolean-tostring-output-true-and-not-true https://stackoverflow.com/questions/491334/why-does-boolean-...
[2]https://msdn.microsoft.com/en-us/library/atahsch6(v=vs.110).aspx https://msdn.microsoft.com/en-us/library/atahsch6(v=vs.110)....
- MaxBarraclough 8y agoMaybe I'm missing something obvious, but what's outdated there? The correct solution remains `b ? "true" : "false"`, no? If the XML spec requires exactly those strings, why do anything cute with `ToString`?
- sheldor 8y agoThe function used to return "TrueString" or "FalseString" back then. Nowadays it returns "True" or "False".
- MaxBarraclough 8y agoAren't those identical? If I understand correctly, .Net guarantees string internment for all string literals, even across assembly boundaries, so they should end up referring to the same String instances. https://blog.jetbrains.com/dotnet/2015/02/12/string-interning-effective-memory-management-with-dotmemory/ https://blog.jetbrains.com/dotnet/2015/02/12/string-internin...
- sheldor 8y agoIt's not a matter of instance or memory. In the aforementioned example it was me trying to print valid JSON from a razor view, so the capital T in "True", was causing me headaches. I wouldn't of course use "toLower" as a workaround and actually found out the best practice. However this incident made me curious regarding this behavior and triggered my little "research".
- MaxBarraclough 8y agoI don't follow. Boolean.TrueString is "True", with a capital 'T'. I don't see that anything on SO is out of date. The StackOverflowers note that the implementation technically doesn't match the spec, but in a way which can only be observed by using reflection https://stackoverflow.com/questions/491334#comment34617036_491387 https://stackoverflow.com/questions/491334#comment34617036_4...
- deleted 8y ago[deleted]