• LCrawford (unregistered)

    It's also validating that the code is operating under Option Base 0

  • (nodebb)

    And yes, <> is the inequality operator in VB.

    Unless I'm very much mistaken, <> is the inequality operator in every dialect of Basic ever.

  • (nodebb)

    I'm still wating for VB to implement the <=> comperator.

  • Sauron (unregistered)

    TRWTF is that TheDailyWTF automatically converts "VB.net" to a URL when it is written in an article (and yes, the vb.net domain is registered and there's a website there).

  • (author) in reply to Sauron

    Actually, that's my markdown processor being "helpful", and me forgetting that it does it.

  • (nodebb) in reply to Steve_The_Cynic

    And yes, <> is the inequality operator in VB.

    Unless I'm very much mistaken, <> is the inequality operator in every dialect of Basic ever.

    It also works in T-SQL (although != also works there).

    There's no good reason not to use <> in my opinion -- before HTML/XML took over the world, that is.

  • RLB (unregistered)

    To be fair, omelettes are much tastier than wheels.

  • (nodebb)

    This is the second recent WTF when the code counts something in a loop instead of checking the count property. It's almost as if there's a class of developers who still think on preschool level - "okay Johnny, let's count, 1, 2, 3, ..."

  • (nodebb)

    Without context, I had assumed fileData was a function. It doesn't help that VB.NET uses the same syntax for function calls and array access...

  • Barry Margolin (github) in reply to tom103

    BASIC adopted parenthesis syntax for array access from Fortran, so it has decent pedigree.

    While the loop is a WTF itself, there's more WTFery in the way it loops. Try/catch should be outside the loop, so the loop ends once it discovers the error (or it should use Exit to break out of the loop in the Catch). And it should loop down from 4 so the failure is caught as soon as possible.

  • Duke of New York (unregistered)

    I am unable rightly to apprehend the confusion of ideas that could produce this code.

  • Duke of New York (unregistered)

    Being explicit about what is commonplace in the programming language may not "hurt" in a functional sense, but it's nearly always a sign of worse things to come.

  • (nodebb) in reply to RLB

    Not if they are wheels of cheese.

  • Officer Johnny Holzkopf (unregistered) in reply to Mr. TA

    One, two, three, NaN, file not found, 95, 98, 2000, 10, 11 ... is it working?

  • efahl (unregistered) in reply to Ross_Presser

    And <> used to work in Python, back in the Good Old Days.

  • (nodebb)

    Obviously, a count property is going to count out the number of items. And you can never trust the in-built functions, so it is usually best to write it out yourself, just to be safe.

  • Nick (unregistered)

    I love all the assumptions that have been added to this code to turn it into a WFT…

    Assumption 1: fileData is just an array. As other commenters have mentioned, we don’t actually know that to be the case from this code snippet, it could be a function call. Perhaps, even, at one point in the history of the codebase, it was indeed a function.

    Assumption 2: We don’t care about nulls. Why on earth would we not care about nulls? In my experience, someone stating confidently “we don’t need to worry about nulls” is basing that on the certain knowledge that the code producing the data will never return null… which might be true today, but who knows about tomorrow or yesterday?

    Assumption 3: The ToString method is boring. Well, probably… but maybe it does some validation of whatever that particular data type is, and throws an exception if the data is not valid. Let face it, this is The Daily WTF… so for all we know, ToString is implemented with a database lookup to find a “friendly name” for something that’s just numeric in memory…

  • LZ79LRU (unregistered) in reply to Ross_Presser

    Personally I much prefer proper boolean logic with an explicit NOT operator such as the C family of languages has with their !. Indeed, I would go a step further and implement that operator as an alternative to combination operators. As in !> would be equivalent to <= and !< to => (both being available).

  • (nodebb) in reply to Ross_Presser

    It also works in T-SQL (although != also works there).

    <> is the standard SQL "not equals" operator. != is a non standard extension that is probably implemented by all modern SQL implementations. Until everybody decided their language should look like C, <> was pretty much the standard inequality operator.

  • LZ79LRU (unregistered)

    Honestly I would make <> the BETWEEN operator. As in X <> (Y, Z) would be equivalent to writing Y < X < Z. And of course you'd also have >< as in X >< (Y, Z) = X > Y or X < Z and the obligatory !<> and !><.

  • RLB (unregistered) in reply to cellocgw

    Good point.

  • (nodebb) in reply to LCrawford

    [Quote=LCrawford] It's also validating that the code is operating under Option Base 0. [/Quote] In earlier versions of VB, Option Base could be used to set if array indexes start at 0 or 1. In VB.Net, all arrays begin with index 0. Option Base has been removed.

  • Tim (unregistered) in reply to tom103

    You can think of an array as a function which takes an integer and returns a value. similarly you can think of a hashmap as a function which takes a key and returns a value.

    in clojure the syntax for dereferencing an array or hashmap is the same as for calling a function, and in fact you can substitute an array or hashmap for a function as long as it contains all the keys that you need

  • (nodebb) in reply to Sauron

    Arguably, the root WTF is Microsoft thinking it was a good idea to use a domain name format for the names of a series of programming languages.

  • Alex (unregistered)

    Maybe ToString fails if fileData(fileDataCount) is misconfigured? Still WTF, but maybe?

  • Duke of New York (unregistered)

    For completeness shouldn't there also be "greater than or not equal to" and "less than or not equal to" aka "right fish" ><> and "left fish" <>< ?

  • wolferitza (unregistered)

    doesn't it also throw an exception if one of the elements of the array is null? Because they call ToString on it?

  • Craig (unregistered) in reply to Nutster
    Comment held for moderation.

Leave a comment on “Array Length Validation”

Log In or post as a guest

Replying to comment #:

« Return to Article