• (cs) in reply to mike
    mike:
    Anonymouse:
    Spelling errors aside, wouldn't this make sense if it was being used in a delegate?

    The real WTF, as usual, is that only one person recognizes that there may be a perfectly valid reason for doing something, while everyone else is bickering about a side topic (in this case, the definition of "succinct").

    A better solution would probably involve anonymous methods or lambda expressions.

    <pendantry>By your count, only two people recognize that there may be a perfectly valid reason for doing something.</pendantry>

    <just_plain_jerkiness>By my count, it's still zero.</just_plain_jerkiness>

  • Falgund (unregistered) in reply to Your Name
    Your Name:
    pbean:
    Strings:
    0: Test
    1: Truncated
    2: List
    

    Strings[0.5] = "Te" Strings[1.22] = "Tr"

    Yeah, THAT makes sense!

    Strings[0.25] = "T" Strings[0.5] = "Te" Strings[0.75] = "Tes" Strings[1] = "Truncated"

    Exactly what I'd have expected!

    Of course, to obtain "Test" you have to do: String[0.99999999] = "Test"

    And now you have the evidence that 0.9999999 != 1.

  • (cs) in reply to Nick
    Nick:
    Knux2:
    final static String TCAR = "t";
    final static String RCAR = "r";
    final static String UCAR = "u";
    final static String ECAR = "e";
    

    public boolean isFlse (boolean bolean) { if (bolean.toString().equals(TCAR + RCAR + UCAR + ECAR) { return false; }else{ return true; } }

    Don't forget to handle case sensitivity.

    final static String TCAR = "t";
    final static String RCAR = "r";
    final static String UCAR = "u";
    final static String ECAR = "e";
    final static String TCARCAP = "T";
    final static String RCARCAP = "R";
    final static String UCARCAP = "U";
    final static String ECARCAP = "E";
    
    public boolean isFlse (boolean bolean) {
        if (bolean.toString().equals(TCAR + RCAR + UCAR + ECAR) {
              return false;
        }else if(bolean.toString().equals(bolean.toString().equals(TCARCAP + RCARCAP + UCARCAP + ECARCAP){
              return false;
        }    
        }else{
              return true;
        }
    }
    

    Wow, that's a lot of CARCAP!

  • BigWigBossMan! (unregistered) in reply to pbean
    pbean:
    public bool IsListconntSmalleThaOne(IList<IContact> listOfResults)
    {
    try
      {
        listOfResults[1];
        return false;
      }
      catch(IndexOutOfRangeException e)
      {
        return true;
      }
    }
    

    Best code I have ever seen! You are Hired!

  • AdT (unregistered) in reply to JJ
    JJ:
    That's basically the definition of "terse," isn't it: short?

    terse is not the same as short. Have you ever tried to declare an

    unsigned terse t;

    in C? And there is no

    #define terse short

    in the standard headers either. What I suggest is something like this:

    #define terse short #define gesticulated signed #define vaporific volatile

    vaporific gesticulated terse t;

    Try this in your own code and I promise its maintainers to be will love you.

  • someGuy (unregistered) in reply to Kwetal
    Kwetal:
    Lucky you!

    Our coding standard forbids the ternary operator ?:

    seriously????

  • (cs) in reply to AdT

    just thread in a noodle and jam it.

  • mike (unregistered) in reply to frits
    frits:
    mike:
    Anonymouse:
    Spelling errors aside, wouldn't this make sense if it was being used in a delegate?

    The real WTF, as usual, is that only one person recognizes that there may be a perfectly valid reason for doing something, while everyone else is bickering about a side topic (in this case, the definition of "succinct").

    A better solution would probably involve anonymous methods or lambda expressions.

    I'm not sure why people are so fond of anonymous methods. Just give it a good name and it's almost always clearer IMHO.

  • (cs) in reply to mike
    mike:
    frits:
    mike:
    Anonymouse:
    Spelling errors aside, wouldn't this make sense if it was being used in a delegate?

    The real WTF, as usual, is that only one person recognizes that there may be a perfectly valid reason for doing something, while everyone else is bickering about a side topic (in this case, the definition of "succinct").

    A better solution would probably involve anonymous methods or lambda expressions.

    I'm not sure why people are so fond of anonymous methods. Just give it a good name and it's almost always clearer IMHO.

    They're more succinct when used for one-line delegates.

  • EngleBart (unregistered) in reply to RogerC
    RogerC:
    wtf:
    Anonymous:
    Oh my God that hurts. This is exactly the sort of shoddy coding that pisses me off the most. Atrocious spelling, useless method name, pointless functionality and it doesn't even work as advertised. But what really compounds the WTF is that this is so damn simple. When you screw up this badly doing something this simple, it's time to seriously consider whether software development is your calling in life. Note to the submitter, maybe you should leave a McDonalds job application form on his desk, see if he gets the hint.

    public boolean isDoubleCheeseBruger(int patties) { if (patties * patties == 4) return true; else return false; } }

    Wonderful! You give me two patties and I will then inform you that I've handed you a double cheesebruger. Win-win.

    Clearly a security hole. I can order a double cheeseburger with 3 (or 4...) patties and only get charged for a !double-cheeseburger which must mean it is a single cheeseburger. (I am inferring WTFs in the bolt-on rules engine)

    Of course, if I try to be too clever and order a cheeseburger with -2 (negative two) patties, I will end up having to give them the 2 patties out of my own pocket as well as pay for a double cheeseburger.

  • Zog (unregistered)

    I read this code for a moment and realised it was truely stupid; then I saw something deeper in it and realised that the idiot who wrote it needs, not to be shot, but --- actually I can not think of a punishment severe, painful and slow enough to inflict...OK then, make him listen to Celine Dion...

    ...I have a colleague who writes almost as bad code...that's isn't a compliment however...

  • (cs) in reply to EngleBart
    EngleBart:
    RogerC:
    wtf:
    Anonymous:
    Oh my God that hurts. This is exactly the sort of shoddy coding that pisses me off the most. Atrocious spelling, useless method name, pointless functionality and it doesn't even work as advertised. But what really compounds the WTF is that this is so damn simple. When you screw up this badly doing something this simple, it's time to seriously consider whether software development is your calling in life. Note to the submitter, maybe you should leave a McDonalds job application form on his desk, see if he gets the hint.

    public boolean isDoubleCheeseBruger(int patties) { if (patties * patties == 4) return true; else return false; } }

    Wonderful! You give me two patties and I will then inform you that I've handed you a double cheesebruger. Win-win.

    Clearly a security hole. I can order a double cheeseburger with 3 (or 4...) patties and only get charged for a !double-cheeseburger which must mean it is a single cheeseburger. (I am inferring WTFs in the bolt-on rules engine)

    Of course, if I try to be too clever and order a cheeseburger with -2 (negative two) patties, I will end up having to give them the 2 patties out of my own pocket as well as pay for a double cheeseburger.

    What else do you have in your pocket?

  • (cs) in reply to dignissim
    dignissim:
    What sane language could allow mixing of boolean and integral values?

    I have never had a problem with C# not allowing this, I do however, wish that C# would equate null to false.

    Customer cust = GetCustomerById(235); if (cust) { //yay! I saved time! }

  • distracted (unregistered) in reply to JJ
    JJ:
    Someone who can't be bothered to login from work:
    Peter:
    Someone who can't be bothered to login from work:
    "if (!myList.Count)" and "if (myList.Count == 0)" are functionally equivalent. The latter, however, is far more succinct, even if more verbose.
    I don't think "succinct" means what you think it means. I will, however, agree that the latter is clearer

    I'm fairly sure it means exactly what I think it does, actually: Characterized by clear, precise expression in few words; concise and terse.

    My example used no terms than were necessary to fit the criteria, hence succinct. I could have written it a shorter manner, but it would have ceased to be clear, concise and terse.

    [What the hell? I hit Quote but nothing got quoted. 2nd try....]

    How can it possibly be "far more succinct" (i.e., concise and/or terse) than the physically shorter "(!myList.Count)"? That's basically the definition of "terse," isn't it: short? So you're saying, "This version is shorter than that version, even though it's longer." Wut?

    Actually, all of those words have a meaning closer to "clear, but without wasted words".

    Adding "== 0" is not "wasting" a word (it expresses the idea that what is being checked is the number 0, not the boolean false), and it improves clarity, therefore, while longer, the expression is more concise/succinct/terse.

  • ARMed but harmless (unregistered) in reply to toth
    toth:
    myList.Count == 0

    OTFY

    Unless, of course, you're dealing with weird, unnatural, abomination-before-God data structures that allow lists with negative or non-integral numbers of elements.

    I want to see a list whose count is 0.5.

    Useless stone age computer fact: The Camputer Lynx BASIC interpreter accepted floating point line numbers:

    10 FOR i=1 TO 10 10.5 PRINT i 10.1237843 NEXT i

  • Joe (unregistered) in reply to iToad
    iToad:
    toth:
    I want to see a list whose count is 0.5.
    

    It can have a count of 0.5 if you use fuzzy integers.

    Oh, so now we're talking about nondeterministic computing?

    Sometimes a[0.5] returns a[0], sometimes a[1].

    --Joe

  • Ryan (unregistered) in reply to Falgund
    Falgund:
    Your Name:
    pbean:
    Strings:
    0: Test
    1: Truncated
    2: List
    

    Strings[0.5] = "Te" Strings[1.22] = "Tr"

    Yeah, THAT makes sense!

    Strings[0.25] = "T" Strings[0.5] = "Te" Strings[0.75] = "Tes" Strings[1] = "Truncated"

    Exactly what I'd have expected!

    Of course, to obtain "Test" you have to do: String[0.99999999] = "Test"

    And now you have the evidence that 0.9999999 != 1.

    I would suggest slightly different behavior so that the results are more continuous:

    1: Test 2: Truncated 3: List

    Strings[0] = "" Strings[0.5] = "Te" Strings[1] = "Test" Strings[1.00001] = "" Strings[1.22] = "Tr"

  • (cs) in reply to Ryan
    Ryan:
    I would suggest slightly different behavior so that the results are more continuous:

    1: Test 2: Truncated 3: List

    Strings[0] = "" Strings[0.5] = "Te" Strings[1] = "Test" Strings[1.00001] = "" Strings[1.22] = "Tr"

    "Should array indices start at 0 or 1? My compromise of 0.5 was rejected without, I thought, proper consideration."

    • Stan Kelly-Bootle
  • unekdoud (unregistered)

    3 things:

    1. the try block with listofResults[1] will fail epicly in C.
    2. shouldn't a[0.5] be "Testcated"?
    3. patties * patties == 4 is good, until someone turns up with INT_MAX-2 patties. Way to go, making an epic loss on the other INT_MAX-4 patties.
  • Matt Williams (unregistered) in reply to pbean

    This works for strings, numerics, and arrays:

    class TruncatedList < Array
      alias :oldref :[]
    
      def [](arg)
        x=oldref(arg.floor)
        (arg == arg.floor) ? x : range(x,arg - arg.floor)
      end
    
      private 
    
      def range(arg,portion)
        case 
        when arg.instance_of?(Numeric)
          arg * portion
        when arg.instance_of?(String), arg.instance_of?(Array)
          n=(arg.length * portion).floor
          n=(n>0)?(n-1):0
          arg[0 .. n]
        else
          arg
        end
      end
    
    end
    

    I expect I could write it more succinctly, but it works....

  • Buddy (unregistered) in reply to Ryan
    Ryan:
    I would suggest slightly different behavior so that the results are more continuous:

    1: Test 2: Truncated 3: List

    Strings[0] = "" Strings[0.5] = "Te" Strings[1] = "Test" Strings[1.00001] = "" Strings[1.22] = "Tr"

    For numeric values, I would expect the entries represent known points in a function.

    points[-1.0] = 5.8 points[ 0.5] = -1.9 points[10.2] = 8.5

    Then points[0.0] is an interpolation between (-1.0, 5.8) and (0.5, -1.9).

    E.g. simplest linear interpolation:

    a = (y2 - y1)/(x2 - x1) b = ((y2 - a * x2) + (y1 - a * x1)) / 2 return a * x + b;

    Can use linear, polynomial, cubic spline, etc. interpolation.

  • J (unregistered)

    return !myList.Any();

  • Pete (unregistered) in reply to J
    J:
    return !myList.Any();

    I always feel that that method should return a random element from the list rather than a boolean.

  • (cs) in reply to pbean
    pbean:
    toth:
    myList.Count == 0

    OTFY

    Unless, of course, you're dealing with weird, unnatural, abomination-before-God data structures that allow lists with negative or non-integral numbers of elements.

    I want to see a list whose count is 0.5.

    Kudos to the first to implement a TruncatedList collection class where you can index with floats and it somehow cuts the elements in pieces

    Examples:

    Strings:
    0: Test
    1: Truncated
    2: List
    
    Strings[0.5] = "Te"
    Strings[1.22] = "Tr"
    
    Integers:
    0: 84
    1: 1337
    2: 2147483647
    
    Integers[0.5] = 42
    Integers[1.7] = 935.9
    

    +1

  • (cs) in reply to Your Name
    Your Name:
    pbean:
    Strings:
    0: Test
    1: Truncated
    2: List
    

    Strings[0.5] = "Te" Strings[1.22] = "Tr"

    Yeah, THAT makes sense!

    Strings[0.25] = "T" Strings[0.5] = "Te" Strings[0.75] = "Tes" Strings[0.99999 (recurring)] = "Test" Strings[1] = "Truncated"

    Exactly what I'd have expected!

    FTFY

  • (cs) in reply to Spoe
    Spoe:
    slartibartfast:
    ... but what when patties = -2?

    Vectors, man. Vectors! It's still a double cheeseburger, just going the other direction.

    bwe-e-erp, glug, splash.

  • (cs) in reply to Anonymous
    Anonymous:
    Oh my God that hurts. This is exactly the sort of shoddy coding that pisses me off the most. Atrocious spelling, useless method name, pointless functionality and it doesn't even work as advertised. But what really compounds the WTF is that this is so damn simple. When you screw up this badly doing something this simple, it's time to seriously consider whether software development is your calling in life. Note to the submitter, maybe you should leave a McDonalds job application form on his desk, see if he gets the hint.

    Fuck that... I don't want this clown making my QPWC. He'd probably dip it in mop bucket water first.

  • (cs) in reply to Zog
    Zog:
    I read this code for a moment and realised it was truely stupid; then I saw something deeper in it and realised that the idiot who wrote it needs, not to be shot, but --- actually I can not think of a punishment severe, painful and slow enough to inflict...OK then, make him listen to Celine Dion...

    ...I have a colleague who writes almost as bad code...that's isn't a compliment however...

    Ooh, Celine Dion! My favorite wallpaper!

  • (cs) in reply to Mason Wheeler
    Mason Wheeler:
    Ryan:
    I would suggest slightly different behavior so that the results are more continuous:

    1: Test 2: Truncated 3: List

    Strings[0] = "" Strings[0.5] = "Te" Strings[1] = "Test" Strings[1.00001] = "" Strings[1.22] = "Tr"

    "Should array indices start at 0 or 1? My compromise of 0.5 was rejected without, I thought, proper consideration."

    • Stan Kelly-Bootle

    Squirted coffee through nose, fortunately missing keyboard but drenching cat.

  • Catch (unregistered) in reply to SQLDave
    SQLDave:
    Anonymous:
    Oh my God that hurts. This is exactly the sort of shoddy coding that pisses me off the most. Atrocious spelling, useless method name, pointless functionality and it doesn't even work as advertised. But what really compounds the WTF is that this is so damn simple. When you screw up this badly doing something this simple, it's time to seriously consider whether software development is your calling in life. Note to the submitter, maybe you should leave a McDonalds job application form on his desk, see if he gets the hint.

    Fuck that... I don't want this clown making my RWC. He'd probably dip it in mop bucket water first.

    FTFY (portability)

  • Mr.'; Drop Database -- (unregistered) in reply to Nick
    Nick:
    anonymous coward:
    (!myList.Count) should do the job, assuming a sane language.
    That's only if you want to look 1337 by showing off your ability to treat integers as booleans. The rest of us would just use a form of !myList.isEmpty(), which is much more clear and, depending on the internal implementation of myList, may well get better performance.
    The performance point is a surprisingly interesting one. If a linked list provides a method to remove a range of values (between two iterators), then the implementer must choose between having a constant-time remove(start, end) method or a constant-time Count property.

    Even in a non-garbage-collected language, a similar argument can apply, such as with C++'s list::splice function.

  • Sean Connery (unregistered) in reply to frits
    frits:
    Did anybody notice that (myList.Count < 1) is significantly shorter than IsListconntSmalleThaOne(myList) ?
    It appears to be C#, So the correct way is
    if( !myList.Any() )

    Noting that it's even more readable, and shorter yet.

  • Channel6 (unregistered) in reply to frits
    frits:
    mike:
    frits:
    mike:
    Anonymouse:
    Spelling errors aside, wouldn't this make sense if it was being used in a delegate?

    The real WTF, as usual, is that only one person recognizes that there may be a perfectly valid reason for doing something, while everyone else is bickering about a side topic (in this case, the definition of "succinct").

    A better solution would probably involve anonymous methods or lambda expressions.

    I'm not sure why people are so fond of anonymous methods. Just give it a good name and it's almost always clearer IMHO.

    They're more succinct when used for one-line delegates.

    And you can use local variables

  • Skye (unregistered)

    I want to cry. I seriously want to cry. I can feel the tears forming in my ducts, ready to stream out.

  • roy ashbrook (unregistered)

    this broke my mind....

  • Burpy (unregistered) in reply to pbean
    pbean:
    public bool IsListconntSmalleThaOne(IList<IContact> listOfResults)
    {
    try
      {
        listOfResults[1];
        return false;
      }
      catch(IndexOutOfRangeException e)
      {
        return true;
      }
    }
    

    I wish this was only a joke, but I've seen it too often in real production code (no longer than last week in fact)

    Just a little mistake though, usually people who write that don't use advanced uber techniques like "IndexOutOfRangeException" but just stick to "Exception"

  • DonaldK (unregistered) in reply to Smitty

    Please please please tell me we don't fight holy wars over VB.

  • AdT (unregistered) in reply to Nick
    Nick:
    The rest of us would just use a form of !myList.isEmpty(), which is much more clear and, depending on the internal implementation of myList, may well get better performance.

    Except that you erroneously negate the result. :P

  • (username *)me (unregistered) in reply to slartibartfast
    slartibartfast:
    ... but what when patties = -2?

    If you can teach him to keep his bodily fluids off the food then the patties will be unsigned.

  • mos (unregistered) in reply to pbean

    [quote user="pbean Kudos to the first to implement a TruncatedList collection class where you can index with floats and it somehow cuts the elements in pieces[/quote]

    At least he should have the decency to name it HideousList. What in the name of Hades...

  • storray expert (unregistered)

    public bool isCommentFrist(IList<Comment> listofComments) { if (listOfComments.Count >= 1) { return false; } else { return true; } }

    CAPTCHA: conventio

    ... almost convention but not quite.

  • Steve Urkel (unregistered) in reply to Anonymous

    Or just mail him a link to TheDailyWTF.com, and hope that it gives him a few hints on how NOT to code, rather than giving him even more "clever" ideas.

  • Reinier (unregistered)

    The pattern I recognize here is "on the job self-training".

    This person was obviously hired into a job (s)he doesn't know how to do, so the only way out of it (except resignation) is to try and learn. And an easy way to do that is writing wrappers around existing functionality and calling them, or tweaking existing code just a little bit, and see what happens.

    I find myself doing that when I'm faced with a code base I don't know. I start refactoring, systematic rewrites, and adding wrappers, to make the code clearer and easier to use. The end result may not in fact be clearer or easier for another programmer but it will be for me because I have now ploughed through the whole code base and learnt what everything means. It's a process of digestion. We're seeing the same thing here.

  • Better be safe than sorry (unregistered)

    Recommend to add some security code.

    public bool IsListconntSmalleThaOne(IList<IContact> listOfResults) {
      if (listOfResults.Count >= 1)
      {
        return false;
      }
      else
      {
        return true;
      }
      else 
      {
        throw new UnhandledException();
      }
    }
  • Someone Awful (unregistered) in reply to AdamK
    AdamK:
    What about the obvious FILENOTFOUD?
    Didn't you mean FILENOTFOOD?
  • Someone Awful (unregistered) in reply to Nick
    Nick:
    Knux2:
    final static String TCAR = "t";
    final static String RCAR = "r";
    final static String UCAR = "u";
    final static String ECAR = "e";
    

    public boolean isFlse (boolean bolean) { if (bolean.toString().equals(TCAR + RCAR + UCAR + ECAR) { return false; }else{ return true; } }

    Don't forget to handle case sensitivity.

    final static String TCAR = "t";
    final static String RCAR = "r";
    final static String UCAR = "u";
    final static String ECAR = "e";
    final static String TCARCAP = "T";
    final static String RCARCAP = "R";
    final static String UCARCAP = "U";
    final static String ECARCAP = "E";
    
    public boolean isFlse (boolean bolean) {
        if (bolean.toString().equals(TCAR + RCAR + UCAR + ECAR) {
              return false;
        }else if(bolean.toString().equals(bolean.toString().equals(TCARCAP + RCARCAP + UCARCAP + ECARCAP){
              return false;
        }    
        }else{
              return true;
        }
    }
    

    And you are missing the Scr1pT K1dD13s which mix upper- and lowercase. :)

  • Banking Contractor (unregistered)

    IsBrillanterThanOne

  • Anon (unregistered) in reply to Reinier
    Reinier:
    It's a process of digestion.

    Unfortunately, what we have here is the very final stage of digestion.

  • Halo (unregistered) in reply to Someone who can't be bothered to login from work
    Someone who can't be bothered to login from work:
    Dom:
    The real WTF is that this is not an extension method.

    You're assuming they're using version 3.0 or newer of the framework. We're still using 2.0 at work; I would love the ability to use extension methods.

    Hell we still have POS code written in 1.1. Kill me?

    Of course, I'm assuming it's C#, it certainly looks like it.

    Actually, you can, assuming that your project allows you to use Visual Studio 2008 targeting .NET Framework 2.0.

    It's true that the ExtensionAttribute used by the compiler to note extension methods is within System.Core.dll, which is a part of .NET Framework 3.5. However, the C# 3.0 compiler doesn't actually confirm where the attribute exists, only that it does exist. By defining an attribute of the same namespace and name within your project you can use extension methods freely:

    using System;
    using System.Collections;
    using System.Collections.Generic;
    
    namespace System.Runtime.CompilerServices
    {
        [AttributeUsage(AttributeTargets.Method, Inherited = true)]
        public sealed class ExtensionAttribute : Attribute { }
    }
    
    public static class ListExtensions
    {
        public static bool IsNullOrEmpty(this
    IList list)
        {
            return (list == null || list.Count == 0);
        }
    }
    
    static class Program
    {
        static void Main
        {
            List<int> list = new List<int>();
            bool empty = list.IsNullOrEmpty();
        }
    }
    
  • c0d3rg1rl (unregistered) in reply to pbean

    BRILLANT!

Leave a comment on “IsListconntSmalleThaOne”

Log In or post as a guest

Replying to comment #:

« Return to Article