• (cs) in reply to The_Assimilator
    The_Assimilator:
    TheCPUWizard:
    Actually C# allows you to switch on anything that is equatiblep (e.g. strings). For non-integral (or low density integral) this gets implemented as a chain of is/else if/else if/ else. Many developers find the swtich syntax easier to follow than having to match up the if statements.

    I believe the word you're looking for is comparable. And I love being able to switch() on strings, something that Java sadly lacks.

    When did < and > stop being comparisons?

    The phrase you want is "satisfies an equivalence relation".

  • Design Pattern (unregistered) in reply to mott555
    mott555:
    Boxing and unboxing in .NET don't quite mean the same thing as in Java. In .NET, boxing is just a way of storing a value type on the heap.
    So how's that different from boxing in Java?

    And why do you want to store a value type on the heap (to get back to the point of the OP about C# not being Smalltalk).

    In other words: Why the separation between value-types and reference-types when Smalltalk already has shown that you can do proper OO without it?

  • (cs) in reply to Anonymous
    Anonymous:
    Jaime:
    Then why does the term "boxing" exist? If the primitive int "4" is already an object, why does the system need to box it in an instance of System.Int32 in order to call ToString() on it? C# isn't Smalltalk.

    Objects in C# come in two broad flavours - Reference Types and Value Types. An Object is a reference type unless it inherits from System.ValueType.

    Boxing is used to store a subclass of ValueType in a variable expecting an Reference Type. Of course, there's only one situation this can happen - because ValueType has only one reference-type ancestor, the only time this happens is when you store a value-type in a variable of Object. (Any other reference type is a compile time error.)

    The upshot of all this was in .Net 1.0 and 1.1, you could put an 'int' (System.Int32) into an ArrayList, which was a list of Object. The runtime would (unlike Java) automatically box the primitive 'int' into a reference type so it could be treated by the ArrayList just like any other reference-type subclass of Object.

    And I don't believe that the runtime does box an int to call ToString on it because System.Int32 would directly implement ToString(..).

    So, int IS an object. The difference is that int is not a "Reference Type".

    (These days, generics generally remove the need for boxing - a System.Collections.Generic.List(Of Integer) does not have the boxing/unboxing performance overhead.)

    An int has to be boxed to be assigned to a variable of type Object. Boxing represents a value type as a reference type. We all agree on these things. The simple fact the int needs to be boxed to be assigned to a variable of type Object proves that Object is a reference type. If Object were the true base of both value and reference types, then boxing would not be required.

    C#: Console.WriteLine(4.ToString());

    IL: .custom instance void [mscorlib]System.STAThreadAttribute::.ctor() .entrypoint .maxstack 1 .locals init ( [0] int32 i) L_0000: nop L_0001: ldc.i4.4 L_0002: stloc.0 L_0003: ldloca.s i L_0005: call instance string [mscorlib]System.Int32::ToString() L_000a: call void [mscorlib]System.Console::WriteLine(string) L_000f: nop L_0010: nop L_0011: ret

    I see boxing on line 5.

  • Anonymous (unregistered) in reply to PRMan
    PRMan:
    Jellineck:
    Larry:
    TRWTF is that C-Pound allows you to use a bool in a switch statement.

    I can't wait for someone to call C# 'C-Pound' in an interview.

    You mean the interviewer? That's already happened to me.

    I prefer to call it "D-flat", myself.

  • The C-Pounder (unregistered)

    It might sound strange, but this is MAYBE not a WTF. We had issues with booleans in .NET.

    In C#, booleans are indeed 1 (true) and 0 (false), but that's not the case in IL. Not every .NET language obeys that rule, and with IL assembler you can easily cast 2 (or any integer) to a boolean value. A 2-bool (later called b2) is not false, but it is not equal to "True". The most amazing thing is that, !b2 is correctly == false, but !!b2 returns b2 (compiler optimization) and is not == true. Even funnier, the VM and the VS2008 debugger will not evaluate boolean comparisons to the same result :)

    Therefore, in a switch-case statement, a value different than 0 or 1, casted as a boolean, will reach the default clause.

    In case you want to test it, simply use the PEX automatic unit testing framework... Lovely. Nowadays 2-bools are disabled by default, but back in the days... it wasn't.

  • Java Programmer (unregistered) in reply to The C-Pounder
    The C-Pounder:
    It might sound strange, but this is MAYBE not a WTF. We had issues with booleans in .NET.

    In C#, booleans are indeed 1 (true) and 0 (false), but that's not the case in IL. Not every .NET language obeys that rule, and with IL assembler you can easily cast 2 (or any integer) to a boolean value. A 2-bool (later called b2) is not false, but it is not equal to "True". The most amazing thing is that, !b2 is correctly == false, but !!b2 returns b2 (compiler optimization) and is not == true. Even funnier, the VM and the VS2008 debugger will not evaluate boolean comparisons to the same result :)

    Therefore, in a switch-case statement, a value different than 0 or 1, casted as a boolean, will reach the default clause.

    In case you want to test it, simply use the PEX automatic unit testing framework... Lovely. Nowadays 2-bools are disabled by default, but back in the days... it wasn't.

    Not knowing C#, I'm not sure I see a problem. Reading it, the programmer understood that depending on the compiler used, a bool value may not evaluate to 0 or 1. Additionally, he understood that a bool value should be a a single bit and thus he could not do b.toString().

    Now there are easier ways to write the statement removing the case, (I assume there's a Boolean.toString(b) like in Java) but a "minor" optimization error like this does not appear worth submitting to this website?

  • (cs) in reply to Jaime
    Jaime:
    Anonymous:
    Jaime:
    Then why does the term "boxing" exist? If the primitive int "4" is already an object, why does the system need to box it in an instance of System.Int32 in order to call ToString() on it? C# isn't Smalltalk.

    Objects in C# come in two broad flavours - Reference Types and Value Types. An Object is a reference type unless it inherits from System.ValueType.

    Boxing is used to store a subclass of ValueType in a variable expecting an Reference Type. Of course, there's only one situation this can happen - because ValueType has only one reference-type ancestor, the only time this happens is when you store a value-type in a variable of Object. (Any other reference type is a compile time error.)

    The upshot of all this was in .Net 1.0 and 1.1, you could put an 'int' (System.Int32) into an ArrayList, which was a list of Object. The runtime would (unlike Java) automatically box the primitive 'int' into a reference type so it could be treated by the ArrayList just like any other reference-type subclass of Object.

    And I don't believe that the runtime does box an int to call ToString on it because System.Int32 would directly implement ToString(..).

    So, int IS an object. The difference is that int is not a "Reference Type".

    (These days, generics generally remove the need for boxing - a System.Collections.Generic.List(Of Integer) does not have the boxing/unboxing performance overhead.)

    An int has to be boxed to be assigned to a variable of type Object. Boxing represents a value type as a reference type. We all agree on these things. The simple fact the int needs to be boxed to be assigned to a variable of type Object proves that Object is a reference type. If Object were the true base of both value and reference types, then boxing would not be required.

    C#: Console.WriteLine(4.ToString());

    IL: .custom instance void [mscorlib]System.STAThreadAttribute::.ctor() .entrypoint .maxstack 1 .locals init ( [0] int32 i) L_0000: nop L_0001: ldc.i4.4 L_0002: stloc.0 L_0003: ldloca.s i L_0005: call instance string [mscorlib]System.Int32::ToString() L_000a: call void [mscorlib]System.Console::WriteLine(string) L_000f: nop L_0010: nop L_0011: ret

    I see boxing on line 5.

    What does boxing have to do with whether System.Object is the base of all objects?

    The difference between a Value type and a Reference type is that Value types are allowed to live on the stack (but, they don't have to). When a Value type lives on the heap, it's exactly the same as any other object, including having a reference to it.

    In other words, all types have to be boxed when they live on the heap. The magic is that Value types are the only ones allowed to live anywhere else.

  • (cs) in reply to DT
    DT:
    Anonymous:
    But I must say, it's cute how he provided a default path in case the bool evaluates to something other than 'true' or 'false'. You never know!

    At some point I was tought that all switches should have a default statement. Maybe the same goes for the author, don't blame a guy for paying attention in class.

    At no point where you taught to think for yourself.

  • me (unregistered) in reply to frits

    You could have just answered him without being a dick.

  • opaa (unregistered) in reply to DT
    DT:
    Anonymous:
    But I must say, it's cute how he provided a default path in case the bool evaluates to something other than 'true' or 'false'. You never know!

    At some point I was tought that all switches should have a default statement. Maybe the same goes for the author, don't blame a guy for paying attention in class.

    It is a shame that you were not taught to use the spell checker - or maybe even to spell without one.

    tought? (was that supposed to be taught or thought?)

  • Matt (unregistered)

    It's the default case that makes it art.

  • Duke of New York (unregistered) in reply to Scorekeeper

    This WTF reminds me of something I noticed interviewing people for SDE positions. When I gave someone a coding problem, and then pointed out a bug in the solution, the majority of candidates would add lines to handle the exception. I can't remember a single candidate who dared to change the lines they'd already written.

  • (cs) in reply to anon
    public static string Bool2Str(bool b) {
        return "Just use b.toString(), dumbass!";
    }
  • (cs) in reply to Anonymous
    Anonymous:
    DT:
    Anonymous:
    But I must say, it's cute how he provided a default path in case the bool evaluates to something other than 'true' or 'false'. You never know!

    At some point I was tought that all switches should have a default statement. Maybe the same goes for the author, don't blame a guy for paying attention in class.

    So you do this:

    case true:
    {
      // Do whatever for true case
    }
    case default:
    {
      // Do whatever for false case
    }
    

    Now you've satisfied your school teacher by providing a default for the case, but you don't have a useless branch that never gets called. Simple.

    ...or you could just use an if else statement like sane people...

  • NFL jerseys (unregistered)

    so good!

  • твоя мать (unregistered) in reply to nwbrown
    nwbrown:
    Anonymous:
    DT:
    Anonymous:
    But I must say, it's cute how he provided a default path in case the bool evaluates to something other than 'true' or 'false'. You never know!

    At some point I was tought that all switches should have a default statement. Maybe the same goes for the author, don't blame a guy for paying attention in class.

    So you do this:

    case true:
    {
      // Do whatever for true case
    }
    case default:
    {
      // Do whatever for false case
    }
    

    Now you've satisfied your school teacher by providing a default for the case, but you don't have a useless branch that never gets called. Simple.

    ...or you could just use an if else statement like sane people...
    What part of satisfy your school teacher do you not understand?

  • pete (unregistered)

    Smells like defensive programmnig taken a little to far.

  • Random (unregistered)

    This could have just been code to "nicely" output true and false, but was never ended up being used (replace "true" for "Yes")...... Just saying that there could be a reason for it.

  • (cs) in reply to Larry
    Larry:
    TRWTF is that C-Pound allows you to use a bool in a switch statement.

    It isn't C-Pound, its never been C-Pound. Where's the "Pound" anyway - this is a pound symbol "£". So what if some merkins use # as pound, I'm sure a lot more Chinese people use symbols no-one else uses - does that mean we should have to use them as well? No it doesn't. Don't do it again, there's a good boy.

  • Anonymous (unregistered) in reply to method1
    method1:
    Larry:
    TRWTF is that C-Pound allows you to use a bool in a switch statement.

    It isn't C-Pound, its never been C-Pound. Where's the "Pound" anyway - this is a pound symbol "£". So what if some merkins use # as pound, I'm sure a lot more Chinese people use symbols no-one else uses - does that mean we should have to use them as well? No it doesn't. Don't do it again, there's a good boy.

    You must be new here. It's a running joke:

    http://thedailywtf.com/Articles/5_years_C-pound_experience.aspx

    Flagged as spam, thanks Akismet.

  • The C-Pounder (unregistered) in reply to pitchingchris

    That is completely false. A value of 2 converted into a boolean, will evaluate to true inside a IF statement or a WHILE... However, it is NOT EQUALS to "true", and therefore will not behave as you intent in the switch-case.

    The .NET Marshalling for interop does a good job and converts Integer to a valid 1-boolean, but the example uses unsafe code to cast 2 into a boolean, and you can achieve the same with 100% safe code in assembler IL, thus involving no marshalling at all.

    As for someone patching the switch-case, you might consider

    switch(b) { case false: return Boolean.FalseString; default: return Boolean.TrueString; }

    Doing the opposite, with a "case true", will yield to incorrect results.

  • itsmo (unregistered) in reply to TheCPUWizard
    TheCPUWizard:
    Actually C# allows you to switch on anything that is equatible (e.g. strings). For non-integral (or low density integral) this gets implemented as a chain of is/else if/else if/ else. Many developers find the swtich syntax easier to follow than having to match up the if statements.

    'equitable'? - don't you mean 'equalable'?

  • Mike Caron (unregistered) in reply to method1
    method1:
    Larry:
    TRWTF is that C-Pound allows you to use a bool in a switch statement.

    It isn't C-Pound, its never been C-Pound. Where's the "Pound" anyway - this is a pound symbol "£". So what if some merkins use # as pound, I'm sure a lot more Chinese people use symbols no-one else uses - does that mean we should have to use them as well? No it doesn't. Don't do it again, there's a good boy.

    You're right, it's C-Hash.

  • Anonymous (unregistered) in reply to itsmo
    itsmo:
    TheCPUWizard:
    Actually C# allows you to switch on anything that is equatible (e.g. strings). For non-integral (or low density integral) this gets implemented as a chain of is/else if/else if/ else. Many developers find the swtich syntax easier to follow than having to match up the if statements.

    'equitable'? - don't you mean 'equalable'?

    No, he meant "equatable" - two values are considered equatable if they can equate to each other (http://www.thefreedictionary.com/equatable if you need a definition). Muphry much?

  • Anonymous (unregistered) in reply to Mike Caron
    Mike Caron:
    method1:
    Larry:
    TRWTF is that C-Pound allows you to use a bool in a switch statement.

    It isn't C-Pound, its never been C-Pound. Where's the "Pound" anyway - this is a pound symbol "£". So what if some merkins use # as pound, I'm sure a lot more Chinese people use symbols no-one else uses - does that mean we should have to use them as well? No it doesn't. Don't do it again, there's a good boy.

    You're right, it's C-Hash.

    Duh, everyone knows it's C-Octothorpe. How could anyone get that wrong?
  • itsmo (unregistered) in reply to Anonymous
    Anonymous:
    itsmo:
    TheCPUWizard:
    Actually C# allows you to switch on anything that is equatible (e.g. strings). For non-integral (or low density integral) this gets implemented as a chain of is/else if/else if/ else. Many developers find the swtich syntax easier to follow than having to match up the if statements.

    'equitable'? - don't you mean 'equalable'?

    No, he meant "equatable" - two values are considered equatable if they can equate to each other (http://www.thefreedictionary.com/equatable if you need a definition). Muphry much?

    Yes, humour - let's run through this for you: equatable - a real word and the one that should have been used (as you point out) equitable - a real word but not the correct one in this case not a real word and...

    oh I can't go on, you get the gist :)

  • itsmo (unregistered) in reply to itsmo
    itsmo:
    Anonymous:
    itsmo:
    TheCPUWizard:
    Actually C# allows you to switch on anything that is equatible (e.g. strings). For non-integral (or low density integral) this gets implemented as a chain of is/else if/else if/ else. Many developers find the swtich syntax easier to follow than having to match up the if statements.

    'equitable'? - don't you mean 'equalable'?

    No, he meant "equatable" - two values are considered equatable if they can equate to each other (http://www.thefreedictionary.com/equatable if you need a definition). Muphry much?

    Yes, humour - let's run through this for you: equatable - a real word and the one that should have been used (as you point out) equitable - a real word but not the correct one in this case not a real word and...

    oh I can't go on, you get the gist :)

    no - sh!t I mean equalable is not a real word - I've been Muphry'd

  • (cs) in reply to DT
    DT:
    At some point I was tought that all switches should have a default statement. Maybe the same goes for the author, don't blame a guy for paying attention in class.

    No, maybe not, but do blame him for not using common sense. Teachers are wrong more often than not. Especially so when they say always this or never that.

  • Ouch! (unregistered) in reply to itsmo
    itsmo:
    Anonymous:
    itsmo:
    TheCPUWizard:
    Actually C# allows you to switch on anything that is equatible (e.g. strings). For non-integral (or low density integral) this gets implemented as a chain of is/else if/else if/ else. Many developers find the swtich syntax easier to follow than having to match up the if statements.

    'equitable'? - don't you mean 'equalable'?

    No, he meant "equatable" - two values are considered equatable if they can equate to each other (http://www.thefreedictionary.com/equatable if you need a definition). Muphry much?

    Yes, humour - let's run through this for you: equatable - a real word and the one that should have been used (as you point out) equitable - a real word but not the correct one in this case

    However, TheCPUWizard wrote equatible. A simple confusion of the -able and the -ible endings (would there weren't graver errors on the intertubes). I think you've been bitten by an overzealous auto-correction department of your brain. The general shape of the word fits, there's an 'i' in it => equitable.

  • Anon Too (unregistered)

    I'm not sure that this is a WTF. More like just an F.

  • AndyC (unregistered) in reply to Design Pattern
    Design Pattern:
    So how's that different from boxing in Java?
    Until recent versions, Java forced the programmer to box things explicitly. C# doesn't, as a programmer you don't need to know when boxing occurs in order to write C# code. Boxing is not a C# concept, it is merely something that happens under the hood in CLR world. You could produce a C# compiler that just used the heap entirely, boxing would never occur and it'd still be valid.
    Design Pattern:
    In other words: Why the separation between value-types and reference-types when Smalltalk already has shown that you can do proper OO without it?
    It's purely so that better programmers can understand what's happening at a lower level and produce code that is more efficent as a result. It's like the inline keyword in C++, you can happily write C++ without ever knowing of it's existence and the semantics never change because of it's introduction.
  • nah (unregistered) in reply to The C-Pounder
    The C-Pounder:
    It might sound strange, but this is MAYBE not a WTF. We had issues with booleans in .NET.

    ...

    Even then it's still a wtf. Just one by MS not by the coder.

  • (cs) in reply to nah
    nah:
    The C-Pounder:
    It might sound strange, but this is MAYBE not a WTF. We had issues with booleans in .NET.

    ...

    Even then it's still a wtf. Just one by MS not by the coder.

    The multi-language architecture of .Net leads to a few language specific head-scratchers. It's more of a trade-off issue than a WTF. An earlier one I ran into was a commercial .Net library written in C# that exposed methods with unsigned integer parameters. It was cumbersome to use from VB.Net because early versions of VB.Net didn't have unsigned data types.

  • French Fried Potatoes (unregistered) in reply to Jaime
    Jaime:
    nah:
    The C-Pounder:
    It might sound strange, but this is MAYBE not a WTF. We had issues with booleans in .NET.

    ...

    Even then it's still a wtf. Just one by MS not by the coder.

    The multi-language architecture of .Net leads to a few language specific head-scratchers. It's more of a trade-off issue than a WTF. An earlier one I ran into was a commercial .Net library written in C# that exposed methods with unsigned integer parameters. It was cumbersome to use from VB.Net because early versions of VB.Net didn't have unsigned data types.

    It's nice how VB dumbs down the entire framework.

  • (cs) in reply to AndyC
    AndyC:
    Until recent versions, Java forced the programmer to box things explicitly.

    Your definition of "recent" amuses me.

    Java has had auto-boxing in release versions since 2004 September 30, or roughly 6 years. For a language that was released on 1996 January 23. Which means Java has had auto-boxing for 1/3 of its lifetime.

  • Procedural (unregistered)

    Looks like dead code to me that is used to shut up some warning about lack of defaults in a cheap compiler or static analysis tool; the compiler should optimize it away. It looks dumb, but is cost-free.

  • Skawt (unregistered)

    I always look forward to a long winded and likely made up story on Tuesdays and Thursdays. Apparently I had nothing to look forward to today?

  • (cs) in reply to French Fried Potatoes
    French Fried Potatoes:
    Jaime:
    nah:
    The C-Pounder:
    It might sound strange, but this is MAYBE not a WTF. We had issues with booleans in .NET.

    ...

    Even then it's still a wtf. Just one by MS not by the coder.

    The multi-language architecture of .Net leads to a few language specific head-scratchers. It's more of a trade-off issue than a WTF. An earlier one I ran into was a commercial .Net library written in C# that exposed methods with unsigned integer parameters. It was cumbersome to use from VB.Net because early versions of VB.Net didn't have unsigned data types.

    It's nice how VB dumbs down the entire framework.

    Microsoft publishes a "Common Language Specification" that defines the minimum set of features every language must implement. Unsigned integers are not on the list of data types that all .Net language are expected to support. If it was on the list, VB would have had it (it was added to VB in 2005, even though it still isn't required).

    The WTF is a component vendor exposing language-specific data types from a commercial component based on a language agnostic runtime.

  • MWF (unregistered) in reply to Anonymous
    Anonymous:
    itsmo:
    TheCPUWizard:
    Actually C# allows you to switch on anything that is equatible (e.g. strings). For non-integral (or low density integral) this gets implemented as a chain of is/else if/else if/ else. Many developers find the swtich syntax easier to follow than having to match up the if statements.

    'equitable'? - don't you mean 'equalable'?

    No, he meant "equatable" - two values are considered equatable if they can equate to each other (http://www.thefreedictionary.com/equatable if you need a definition). Muphry much?

    And BTW, he's still wrong...

    The switch statement in C# does not work for any equatable types. It requires that the type is either an integral type or that the type has an unambiguous conversion to an integral type.

    (And for those that don't work in .NET, take note that it does include a concept of equatable types; see, for instance, the System.IEquatable<T> generic interface. But that's not how switch works in C#.)

  • Azarien (unregistered)
        public static string Bool2Str(bool b)
        {
            return (from vk in new Dictionary<bool, string>()
                           {
                               {false, bool.FalseString},
                               {true, bool.TrueString}
                           } where vk.Key == b select vk.Value).First();
        }
    
  • (cs) in reply to Skawt
    Skawt:
    I always look forward to a long winded and likely made up story on Tuesdays and Thursdays. Apparently I had nothing to look forward to today?
    Shana Tova, Skawt.
  • nisl (unregistered) in reply to ContraCorners
    ContraCorners:
    Skawt:
    I always look forward to a long winded and likely made up story on Tuesdays and Thursdays. Apparently I had nothing to look forward to today?
    Shana Tova, Skawt.
    Really? Is that what this is all about? How long does this last, anyway?
  • Anonymous (unregistered) in reply to Design Pattern
    Design Pattern:
    mott555:
    Boxing and unboxing in .NET don't quite mean the same thing as in Java. In .NET, boxing is just a way of storing a value type on the heap.
    So how's that different from boxing in Java?

    And why do you want to store a value type on the heap (to get back to the point of the OP about C# not being Smalltalk).

    In other words: Why the separation between value-types and reference-types when Smalltalk already has shown that you can do proper OO without it?

    Different to Java? Perhaps not a lot (now I look at boxing in Java); the major difference is .Net has no equilivent to Integer (a 'boxed System.Int32' is the only name a boxed integer has.) Boxing was with .net since day 1, it's been grafted in to Java once they saw .net using it. (If anything, it's an automatic promotion/demotion between 'int' and 'Integer'). Because you cannot explicitly declare a boxed-integer in .Net, the possiblity of NullPointerExceptions is somewhat more apparent in your code.

    The only reason for storing a value type on the heap that I know of is when you have a system-provided polymorphic list type that works with Objects, and you want to store integers or other value types in it. (At the time, Java people could not just add an int to a List, they had to explicitly "box" it with new Integer(..)) It's the only sane use I know of, and (these days) .Net people use generics instead which don't box.

    Oh, you can do proper OO without value types. I'm guessing this is how Smalltalk does it - everything is a reference type. (In C terms, this would mean you use int* instead of int variables exclusively).

    However, even there http://www.soe.ucsc.edu/classes/cmps112/Spring03/readings/Ingalls78.html there seems to be some optimisation for integers as a performance boost.

    The main advantage of value types is performance, with a certain 'copy on assignment' semantics available if you're dealing with structs.

  • Larry (unregistered)

    TRWTF is "Integers" that don't encompass the entire range of values.

  • mh (unregistered) in reply to galgorah
    galgorah:
    I present this abomination. Feel free to modify and add even more WTF to the below code.

    public interface IBoolVal { String StringRep(); }

    public class FalseBool : IBoolVal
    {
        string IBoolVal.StringRep()
        {
            return "False";
        }
    }
    
    public class TrueBool : IBoolVal
    {
        string IBoolVal.StringRep()
        {
            return "True";
        }
    }
    
    public class BoolHelper : System.Object
    {
        public static bool ConvertStringToBool(string value)
        {
            string sTrue = ConvertBoolToString(true).ToLower();
            string sFalse = ConvertBoolToString(false).ToLower();
    
            if (sTrue == value.ToLower())
                return true;
            else 
                return false;
        }
        public static string ConvertBoolToString(bool value)
        {
            IBoolVal v;
            if (value) v = new TrueBool(); else  v = new FalseBool();
            return v.StringRep();
        }
    }</div></BLOCKQUOTE>
    

    It's missing a BoolFactory, a BoolComparerFactory, and a BoolComparerResultFactory. It sould also store "True" and "False" in an XML file. Otherwise it's fine.

  • Brian White (unregistered) in reply to Larry
    Larry:
    TRWTF is "Integers" that don't encompass the entire range of values.

    TRWTF is "Integers" period. Screw integers.

  • Tanuki (unregistered)

    A lot of talk about booleans. Can I do -this- in C#?

    int b_acc += (int) b;
    

    In where b is a bool.

  • Craig (unregistered) in reply to Procedural
    Procedural:
    Looks like dead code to me that is used to shut up some warning about lack of defaults in a cheap compiler or static analysis tool; the compiler should optimize it away. It looks dumb, but is cost-free.
    I'm inclined to disagree on your cost assessment. The biggest on cost is in developer time; more specifically the time spent reading code.

    It is the thousands of "dumb looking" snippets like that which make the majority of systems "difficult to maintain".

  • methinks (unregistered) in reply to Brian White
    Brian White:
    Larry:
    TRWTF is "Integers" that don't encompass the entire range of values.

    TRWTF is "Integers" period. Screw integers.

    So I suppose you are one of those people who invite absolute disaster into their projects by using some float type to represent e.g. money values or the like? ;oP

  • Make (unregistered) in reply to MWF

    As a Finn it constantly annoys me how some English-speaking programmer suggests that "Spell checking is easy. Just read the words file into a hash table!"

    To spell check Finnish language the open source Voikko library utilizes domain-specific language called Malaga. (Yes. The dictionary file is a computer program, a bit like Infocom games are written in Z-code.)

    Remember! Every time you roll your spell checker a natural blonde Finnish nubile babe stops using your program!

Leave a comment on “Truthful Strings”

Log In or post as a guest

Replying to comment #:

« Return to Article