3 ms·
Finally C# will have a more idiomatic way to represent this classic code example from “The Daily WTF” in 2005 — enum Bool { True, Fa
by LeonB 4mo ago
Finally C# will have a more idiomatic way to represent this classic code example from “The Daily WTF” in 2005 —
enum Bool
{
True,
False,
FileNotFound
};
See https://thedailywtf.com/articles/what_is_truth_0x3f_ https://thedailywtf.com/articles/what_is_truth_0x3f_
- mycall 4mo agoCould False = FileNotFound and this is a case of AST symbol constraints?
- rich_sasha 4mo agoAwful as it is, I can easily imagine how it happened... Probably says more about me than the code.
- tgv 4mo agoYou're a true Romantic: Idealist and Pragmatist in one.
- t-writescode 4mo agoWhat about Microsoft's own "MsoTrioState"? https://learn.microsoft.com/en-us/dotnet/api/microsoft.office.core.msotristate?view=office-pia https://learn.microsoft.com/en-us/dotnet/api/microsoft.offic... enom MsoTrioState { Toggle, Mixed, True, False, CTrue };
- 8n4vidtmkvmk 4mo agoIs it called "trio" state because 3 of the 5 states are not supported? I also like how True is -1. Beautiful all around!
- saidnooneever 4mo agonote CTrue, the one true true
- biglyburrito 4mo agoCTRUE IS A FALSE PROPHET AND ITS WORSHIPPERS SHALL BURN FOR THEIR HERESY
- orthoxerox 4mo ago-1 means every single bit is 1, the truest possible value.
- nkrisc 4mo agoI’m having a surprisingly difficult time deciding if I strongly agree or disagree with this statement.
- orthoxerox 4mo agoI know VB used -1 as the truth value, not sure about other languages.
- deleted 4mo ago[deleted]
- dale_glass 4mo agoApparently it's sort of sensible, but weird. msoTriStateMixed applies to aggregates. Eg, text.isBold() can be true, false, or a mix. Partly bold, partly not bold. msoTriStateToggle isn't a real value but only used as a sort of flag. So eg, text.setBold(tristate), where "Mixed" would be invalid, and "Toggle" would flip the bold-ness of the text. The msoCTrue one is where it gets really weird, no clue what's that for. I suppose an ill-conceived attempt to support the other way to express True. True being -1 was a thing in Visual Basic and I suppose by some other Windows stuff. Logic being all the bits are 1.
- drdaeman 4mo agoUsual reminder that one of the hardest problems in software engineering is still naming things ;-)
- biglyburrito 4mo agoMore languages need to support enoms.
- physicsguy 4mo agoAbout 12 years ago I went to go and work on some legacy C++ software when I was very green. We had a big code base and it had enum Bool { False = 0, True = 1 } everywhere. I thought it was a good idea to rationalise this since we had conversions all over the place to the modern bool type. So I suggested it, got a PR up (bit painful) it got reviewed, went in, everything worked fine, and we came about a week towards releasing the product (6 monthly releases) before someone noticed that we couldn’t load files from previous versions. Turned out that we wrote lots of these old Bool types to binary data files and so the 4 byte data was now being read as 1 byte data. Oops. Reverted the whole lot. Lesson in humility!
- warumdarum 4mo agoAnd as always when there is a mix of state and result, i post rop https://fsharpforfunandprofit.com/rop/ https://fsharpforfunandprofit.com/rop/