• wds (unregistered) in reply to Someone who can't be bothered to login from work
    Someone who can't be bothered to login from work:
    tiller:
    frits:
    Did anybody notice that (myList.Count < 1) is significantly shorter than IsListconntSmalleThaOne(myList) ?

    Yes but in this case, using isEmpty() is better. (I asume there is an isEmpty method).

    There isn't. And it would be IsEmpty() if there were.

    Wouldn't that simply be IsEmpty?

  • Buddy (unregistered) in reply to Stevil
    Stevil:
    Our work is done on an inhouse framework (for better or worse) and has some nice simple functionality exposed to the developer, including a validity check method. For aggregated classes you just call it on all child classes and bingo, right... Not if you are our italian subcontractor:

    bool result = (CheckValidity() != false) ? false : result;

    yes, a doubly inverted comparitive self assignment, molto bene!

    I got this less-WTF but functionally equivalent code:

    if (!CheckValidity()) result = false;
    

    These multiple negates aren't restricted to computer science. I remember in biology that alcohol is an anti-diuretic hormone inhibitor - so what does it do? Baptists and Muslims had to really work it out, everyone else knew by first hand experience.

  • airdrik (unregistered)

    I know why he created this method; it is so that if the value of One ever changed, and he had to change all of those checks to Count >= 2 (or 3.34, or something) then he would have one (i.e. 1) place to change it. So, just in case he should make it more enterprisy and add an xml config to find out the number that he needs to check for, and the values to return:

    public bool IsListconntSmalleThaOne(IList<IContact> listOfResults) {
      if (listOfResults.Count >= getSettings().theListconntSmalleThaToChek)
      {
        return getSettings().retIfListconntNotSmalleTha;
      }
      else
      {
        return getSettings().retIfListconntSmalleTha;
      }
    }
    

    Captcha: illum - 1) the lack of a unit of illumination

  • Someone who can't be bothered to login from work (unregistered) in reply to Dom
    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.

  • Someone who can't be bothered to login from work (unregistered) in reply to wds
    wds:
    Someone who can't be bothered to login from work:
    tiller:
    frits:
    Did anybody notice that (myList.Count < 1) is significantly shorter than IsListconntSmalleThaOne(myList) ?

    Yes but in this case, using isEmpty() is better. (I asume there is an isEmpty method).

    There isn't. And it would be IsEmpty() if there were.

    Wouldn't that simply be IsEmpty?

    You are of course technically correct, the very best kind of correct :) .NET would almost certainly implement it as a property.

    Although this does mean you'd just have an automatically generated method in the class, with the signature "private bool get_IsEmpty()". I do love syntactic sugar though :)

  • (cs)

    Ok, just got a few free minutes:

    class FloatingIntArray {
      private List<Integer> data = new ArrayList<Integer>();
      public void add(Integer val) {
        data.add(val);
      }
      public double get(double index) {
        int signMultiplier = index >= 0.0 ? 1 : -1;
        index = Math.abs(index);
        int arrayIndex = (int) Math.floor(index);
        if (arrayIndex >= data.size()) { 
           throw new IllegalArgumentException("Index: "+index+" is out of range"); 
        }
        double origValue = data.get(arrayIndex);
        double fraction  = index - arrayIndex;
        return signMultiplier * origValue * fraction;
      }
    }
    class FloatingStringArray {
      private List<String> data = new ArrayList<String>();
      public void add(String val) {
        data.add(val);
      }
      public String get(double index) {
        boolean fromLeft = index >= 0;
        index = Math.abs(index);
        int arrayIndex = (int) Math.floor(index);
        if (arrayIndex >= data.size()) { 
           throw new IllegalArgumentException("Index: "+index+" is out of range"); 
        }
        String fullString = data.get(arrayIndex);
        double fraction   = index - arrayIndex;
        if (fraction == 0.0) {
           return "";
        }
        int tmp = (int)Math.round(fullString.length()*fraction);
        if (fromLeft) {
           return fullString.substring(0,tmp);
        } else {
           return fullString.substring(fullString.length()-tmp,fullString.length());
        }
      }
    }
    public TestBed() {
      FloatingIntArray fia = new FloatingIntArray();
      fia.add(84);
      fia.add(1337);
      System.out.println("fia.get(0.5) = "+fia.get(0.5));
      System.out.println("fia.get(1.7) = "+fia.get(1.7));
      System.out.println("fia.get(-0.5) = "+fia.get(-0.5));
      System.out.println("fia.get(-1.7) = "+fia.get(-1.7));
      
      FloatingStringArray fsa = new FloatingStringArray();
      fsa.add("Test");
      fsa.add("Truncated");
      System.out.println("fsa.get(0.5) = ["+fsa.get(0.5)+"]");
      System.out.println("fsa.get(1.22) = ["+fsa.get(1.22)+"]");
      System.out.println("fsa.get(-0.5) = ["+fsa.get(-0.5)+"]");
      System.out.println("fsa.get(-1.22) = ["+fsa.get(-1.22)+"]");
    }
    
  • (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.

    Actually, the code does work as advertised. It's ridiculous code and the author was probably typing with his/her tongue, but it does do what it says it will do.

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

    So, I nearly peed myself. Thanks! And now I am off writing my next app with ONLY recursion and exceptions. We don't need no stinkin "if"; keep your "while" to yourself, and those new-fangled loops? Shocking, just shocking.

  • 50% Opacity (unregistered)

    Maybe he wasn't allowed access to a keyboard and had to dictate his code to a blind sea slug?

  • (cs) in reply to littlebobbytables
    littlebobbytables:
    It's still better than sourcesafe.
    QFT
  • slartibartfast (unregistered) in reply to wtf

    ... but what when patties = -2?

  • shane blake (unregistered)

    Shouldn't this be an extension method?

  • Anonymous (unregistered)

    Here's my attempt at a Python list with float indexes. If the index given is not an integer, does a weighted average of the adjoining items.

    class WTFList(list):
        def __getitem__(self, index):
            if isinstance(index, int):
                return list.__getitem__(self, index)
            else:
                lower, weight = divmod(index, 1)
                return list.__getitem__(self, int(lower)) * (1 - weight) + list.__getitem__(self, int(lower) + 1) * weight
  • Slicerwizard (unregistered) in reply to pbean
    pbean:
    public bool IsListconntSmalleThaOne(IList<IContact> listOfResults)

    {

    int count = 0; foreach (IContact contact in listOfResults) { count = count + 1; }

    if (count >= 1) { return 1 != 0; // I don't trust "false" } else { return 1 == 1; // is "true" really true?? } }

    And of course we can replace all that with

    return true;

    and get the same result.

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

    This is so south park. Thx, it made me smile.

  • Buddy (unregistered) in reply to Buddy
    Buddy:
    if (!CheckValidity()) result = false;
    

    Or maybe:

    if (CheckValidity()) result = false;
    

    Ahh f**k it!

  • (cs) in reply to JamesQMurphy
    JamesQMurphy:
    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.

    Actually, the code does work as advertised. It's ridiculous code and the author was probably typing with his/her tongue, but it does do what it says it will do.

    What, exactly, does it say it will do?

    "Is" - OK, this says it's probably checking whether some condition is true

    "List" - Ah, it's checking something about a List. Except that this function name seems to be CamelCased, so I really need to be examining "Listconnt". So the function is checking something about a "Listconnt". Never heard of one of those. Lemme go check Google ... OK, there's a bunch of Asian-language pages there, with the first one showing < t clas"listConnt et">. Ah, OK, so this function is checking some property of a < t clas"listConnt et">, or possibly the < t clas"listConnt et"> property of some object. Got it.

    "Smalle" - again, never heard of this, so I'll go back to Google. AH! It's referring to Smalle lab!

    "Tha" - once again, never heard of this. But tha.com is the Tennessee Hospital Association.

    "One" - OK, that's clearly representing the number 1. Maybe it means "first"?

    OK, I think I've figured this out. IsListconntSmalleThaOne should determine whether the '< t clas"listConnt et">' property of Smalle lab is pointing to the first Tennessee Hospital Association.

    So no, it doesn't work as advertised.

  • Peter (unregistered) in reply to Someone who can't be bothered to login from work
    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
  • iToad (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.

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

  • iToad (unregistered) in reply to SR
    SR:
    Anonymous:
    Note to the submitter, maybe you should leave a McDonalds job application form on his desk, see if he gets the hint.

    Your ideas intrigue me and I would like to subscribe to your newsletter.

    CAPTCHA: conventio (a convention followed by this story's coder).

    I've actually seen that done.

  • (cs) in reply to RobFreundlich
    RobFreundlich:
    What, exactly, does it say it will do?

    "Is" - OK, this says it's probably checking whether some condition is true

    "List" - Ah, it's checking something about a List. Except that this function name seems to be CamelCased, so I really need to be examining "Listconnt". So the function is checking something about a "Listconnt". Never heard of one of those. Lemme go check Google ... OK, there's a bunch of Asian-language pages there, with the first one showing < t clas"listConnt et">. Ah, OK, so this function is checking some property of a < t clas"listConnt et">, or possibly the < t clas"listConnt et"> property of some object. Got it.

    "Smalle" - again, never heard of this, so I'll go back to Google. AH! It's referring to Smalle lab!

    "Tha" - once again, never heard of this. But tha.com is the Tennessee Hospital Association.

    "One" - OK, that's clearly representing the number 1. Maybe it means "first"?

    OK, I think I've figured this out. IsListconntSmalleThaOne should determine whether the '< t clas"listConnt et">' property of Smalle lab is pointing to the first Tennessee Hospital Association.

    So no, it doesn't work as advertised.

    I bet your coworkers love you. Particularly during requirements review.

  • (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

    Integers: 0: 84 1: 1337 2: 2147483647

    Integers[0.5] = 42 Integers[1.7] = 935.9 [/code]

    This is quite inane with strings, but potentially quite sensible with numeric types, provided that you give it a more sensible name than 'XXXList'. What you're really making is an interpolator class, which is useful. (You can even do it with arbitrary, potentially negative indexes. Crazy list, useful interpolaton. Oh, perspective.)

    eg. template<typename T> class Interpolator { private: List<Point<T,T>> known;

    public: Interpolator(); void setKnown(Point<T,T> point); T interpolate(T independent) const; T operator[](T independent) const { return interpolate(independent); } };

    The only arguable evil is the questionable operator overload ;)

  • ConanTheLibrarian (unregistered)

    Would you guys please stop picking on my code? I mean, all I'm trying to do is find out if my friend, Listconnt Smalle, is Tha One. Don't tell me I can't use ebonics in my code!

  • doh (unregistered) in reply to Buddy
    Buddy:
    These multiple negates aren't restricted to computer science. I remember in biology that alcohol is an anti-diuretic hormone inhibitor - so what does it do? Baptists and Muslims had to really work it out, everyone else knew by first hand experience.

    The hormone is called "anti-diuretic hormone". There is not such thing as the "diuretic hormone", hence the double negation is absolutely correct in that case...

    CAPTCHA: inhibeo (no, I'm not joking)

  • Bored Coder (unregistered)

    public bool IsListconntSmalleThaOne(IList<IContact> listOfResults) { if (listOfResults != null) { return !Convert.ToBoolean(listOfResults.Count); } return true; }

  • (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
    
    golf anyone? I smell the beginnings of a true programming praxis, the sort of thing that makes for an interesting exercise but provides no real benefit!
  • saluto (unregistered) in reply to wds
    wds:
    Someone who can't be bothered to login from work:
    tiller:
    frits:
    Did anybody notice that (myList.Count < 1) is significantly shorter than IsListconntSmalleThaOne(myList) ?

    Yes but in this case, using isEmpty() is better. (I asume there is an isEmpty method).

    There isn't. And it would be IsEmpty() if there were.

    Wouldn't that simply be IsEmpty?
    It really should be a static extension method that can handle null as well:

    namespace ExtensionMethods
    {
        public static class MyExtensions
        {
          public static bool IsNullOrEmpty(this List list)
          {
            if (list == null || list.Count == 0)
              return true;
            return false;
          }
        }   
    }
    

    The usage would look like this:

    if (List.IsNullOrEmpty(myList))
    {
      // something
    }
    
  • refoveo (unregistered) in reply to pbean
    pbean:
    public bool IsListconntSmalleThaOne(IList<IContact> listOfResults)
    {
    try
      {
        listOfResults[1];
        return false;
      }
      catch(IndexOutOfRangeException e)
      {
        return true;
      }
      catch(NullReferenceException e)
      {
        return FileNotFound;
      }
    }
    
    FTFY
  • Someone who can't be bothered to login from work (unregistered) in reply to Peter
    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.

  • Catch (unregistered) in reply to snoofle

    public class doubleIndexedList<T extends Number> implements Collection{

    private ArrayList<T> positiveIndices; private ArrayList<T> negativeIndices;

    private double threshold; //threshold for floating-point equality comparisons

    public static double DEFAULT_THRESHOLD = 0.00001d;

    public doubleIndexedList<T extends Number>(){ threshold = DEFAULT_THRESHOLD; positiveIndices = new ArrayList<T>(); negativeIndices = new ArrayList<T>(); }

    public doubleIndexedList<T extends Number>(double threshold){ this.threshold = threshold; positiveIndices = new ArrayList<T>(); negativeIndices = new ArrayList<T>(); }

    public T get(double index){

    if(index > 0){ if(index - Math.floor(index) < threshold){ //Whole number index return positiveIndices.get(Math.floor(index)) }else{ //Fractional index double nearest = Math.floor(index); return positiveIndices.get(nearest)(index-nearest); } }else{ index=-1; //Fix sign if(index - Math.ceil(index) < threshold){ //Whole number index return negativeIndices.get(Math.ceil(index)) }else{ //Fractional index double nearest = Math.ceil(index); return negativeIndices.get(nearest)*(index-nearest); } } } . . .

    }

  • (cs) in reply to slartibartfast
    slartibartfast:
    ... but what when patties = -2?
    You realize that your question has been checked into Visual SourceSafe. Now what will you do?
  • (cs) in reply to dkf
    dkf:
    slartibartfast:
    ... but what when patties = -2?
    You realize that your question has been checked into Visual SourceSafe. Now what will you do?

    Pin it?

  • MeBerserk (unregistered) in reply to frits

    Correction:

    (new SomeObject().IsListconntSmalleThaOne(list))

  • Whos fault is this? (unregistered) in reply to Anonymous

    Was it the person who coded it or the manager that lets staff get away with it? Or even the interviewer come to think of it.

    personally I write some shite code, but if anyone else was using it, I would follow a guide (any company developing software should have a guide on naming conventions and methods).

    So shame on you for employing him and then blaming him for being crap.

  • (cs) in reply to JamesQMurphy
    JamesQMurphy:
    dkf:
    slartibartfast:
    ... but what when patties = -2?
    You realize that your question has been checked into Visual SourceSafe. Now what will you do?

    Pin it?

    You might have to settle for 3 back points.

  • SeySayux (unregistered)

    Hmm, a double indexed list... That indeed sounds like a challenge.

    Should it be an array, vector, linked list, hash set, rb set, or anything else?

    I can probably make up something generic enough that it could officially be called a "double indexed list".

    FYI, I already made a list with complex indexes in the form of a + bi with a, b \in \mathbb{N} ;)

  • Ike (unregistered) in reply to Smitty
    Smitty:
    I see this kind of bullshit fairly regularly at my current job. Inane functions with misspelled words, random missing letters and my personal favorite, random Capitalization.
    Smitty,

    I think you meant "rAndoM caPiTAlizAtION".

  • (cs) in reply to JamesQMurphy
    JamesQMurphy:
    dkf:
    slartibartfast:
    ... but what when patties = -2?
    You realize that your question has been checked into Visual SourceSafe. Now what will you do?
    Pin it?
    +1 internets
  • Spoe (unregistered) in reply to slartibartfast
    slartibartfast:
    ... but what when patties = -2?

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

  • Neil (unregistered) in reply to dignissim
    dignissim:
    What sane language could allow mixing of boolean and integral values?
    !myList.Count just uses the boolean operator!(int) overload.
  • Kwetal (unregistered) in reply to Stevil

    Lucky you!

    Our coding standard forbids the ternary operator ?:

  • (cs) in reply to Someone who can't be bothered to login from work
    Someone who can't be bothered to login from work:
    toth:
    dignissim:
    anonymous coward:
    frits:
    Did anybody notice that (myList.Count < 1) is significantly shorter than IsListconntSmalleThaOne(myList) ?

    (!myList.Count) should do the job, assuming a sane language.

    What sane language could allow mixing of boolean and integral values?

    PHP or Perl

    Oh, sane? None.

    C and C++ will both accept it too; as boolean values are simply integers, where 0 is false and any other value is true.

    I personally don't consider it an insanity of the language, more a laziness of the people who can't be bothered to actually state what they're doing in their operation.

    The compiler not knowing the difference between an integer and a boolean maybe just a minor insanity, but it leads to plenty of larger ones. Yoda conditions, separate "logical" and "bitwise" versions of all the boolean operators, etc...

  • Anonymouse (unregistered)

    Spelling errors aside, wouldn't this make sense if it was being used in a delegate?

  • wtf (unregistered) in reply to Spoe
    Spoe:

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

    I don't like it when my cheeseburger goes the other direction...

  • JJ (unregistered) in reply to Someone who can't be bothered to login from work

    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?

  • JJ (unregistered) in reply to Someone who can't be bothered to login from work
    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?

  • (cs) in reply to Someone who can't be bothered to login from work
    Someone who can't be bothered to login from work:
    : I'm fairly sure it means exactly what I think it does, actually: Characterized by clear, precise expression in few words; concise and terse.

    I am not sure I understand your definition of succinct... can you expand on it?

  • mike (unregistered) in reply to Anonymouse
    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").

  • another anonymous coward (unregistered) in reply to anonymous coward

    This isn't even guaranteed to halt if you are programming in Haskell, since your list could be infinite. But then Haskell isn't a sane language anyway.

  • another anonymous coward (unregistered) in reply to another anonymous coward

    I meant the (!myList.Count) thing, of course.

    Forum 1 x 0 Me

Leave a comment on “IsListconntSmalleThaOne”

Log In or post as a guest

Replying to comment #:

« Return to Article