A solid grasp of logic, I see



  • I've seen, in multiple places, code to this effect in projects at the job I'll be leaving next week.  Good riddance.

    If SomeValue = Something Then
      SomeOtherValue = True
    Else
      SomeOtherValue = False
    End If



  • Change them all to look like this: 

    SomeOtherValue = (SomeValue == Something ? true : false);



  • Duh!!!..

     Even better..

    SomeOtherValue = (SomeValue == Something);
     



  • Actually, seeing as this looks like VB, neither of those'll work -- there's no ?:, and comparison for equality is just =. I think what we need here is:



    SomeOtherValue = FileNotFound

    On Error Resume Next

    SomeOtherValue = (SomeValue = Something)

    On Error Goto 0



  • Or, even better still, use the original format, so anyone reading
    the code will know that clarity of intent is more important to you than
    trying to convince everyone how clever you are by typing less to
    generate identical compiled code.

     



  • I'm not familiar with the language, but unless the if statement is assigning Something to SomeValue then I don't see
    any WTFs. It's possibly not the fastest way to write the logic, but it is correct and not much more verbose than any alternative could be.



  • Actually, there is a tertiary (or ternary though I argue in favour of tertiary) operator in VB - it's IIf.

     

    No, I don't use VB. I loathe it. 



  • [quote user="djork"]

    I've seen, in multiple places, code to this effect in projects at the job I'll be leaving next week.  Good riddance.

    If SomeValue = Something Then
      SomeOtherValue = True
    Else
      SomeOtherValue = False
    End If

    [/quote]

    I too chuckle when I see code like above. It's not that the code is too verbose, wordy, or clear, it's more that it shows a non-comprehension of assignments and conditionals. I would be weary of a place if the production code was littered with such constructs, because who knows then what bigger monstrosities could be lurking beneath.



  • [quote user="djork"]If SomeValue = Something Then

      SomeOtherValue = True
    Else
      SomeOtherValue = False
    End If

    [/quote]

    The Real WTF is, that I don't see the WTF - but I don't do VB, so a little explanation is welcome...
    Specifically - can you do Value = (SomeValue = Something) really? What's the type of expression in par. - is it bool, or typeof(SomeValue)?

    If you can, how is first = different from the second one?

    = ... ? ... : .... syntax is not so great either - very messy.

    What's the OP's suggestion?



  • Well, I'd just do ... 


    SomeOtherValue = (SomeValue = Something)

    The other impressive one I see that makes me want to strangle someone is:

    If Something = True Then
      do stuff
    End If



  • [quote user="djork"]Well, I'd just do ... 


    SomeOtherValue = (SomeValue = Something)

    [/quote]

    What's the difference, between "=" and "=" in VB? (thinking "WTF?") 



  • [quote user="viraptor"][quote user="djork"]Well, I'd just do ... 


    SomeOtherValue = (SomeValue = Something)

    [/quote]

    What's the difference, between "=" and "=" in VB? (thinking "WTF?") 

    [/quote]

    It's a WTF in itself... there is only one "=" in VBScript, but it means assignment OR equality depending on the context.  If it's the first occurance in a statement then it's assignment, otherwise (in If, While, multiple occurances in one line, etc.) it's equality.

    Yay for VB.



  • [quote user="djork"]SomeOtherValue = (SomeValue = Something)[/quote]

    I think when you read that, you realise why the original coder wrote it the way he did. VB's overloading of = makes the one-statement common sense 'some other value gets whether these two things are equal' hard to read.

    If this was a C or Pascal family language, the original code is definitely a WTF. But here, I'm not so sure. Maybe the WTF is using VB in the first place? 



  • [quote user="JCDenton"]

    Actually, there is a tertiary (or ternary though I argue in favour of tertiary) operator in VB - it's IIf.

    [/quote]

    I was told by a former employer that I "wasn't allowed to use iif". The reason? "Because the other developers don't know what it is."



  • [quote user="adrianmw"][quote user="JCDenton"]

    Actually, there is a tertiary (or ternary though I argue in favour of tertiary) operator in VB - it's IIf.

    [/quote]

    I was told by a former employer that I "wasn't allowed to use iif". The reason? "Because the other developers don't know what it is."

    [/quote]

    The operative word there being "former."  Can't people be bothered to learn anything anymore?



  • [quote user="JCDenton"]

    tertiary (or ternary though I argue in favour of tertiary) 

    [/quote]

    Actually I don't like either of these terms. They only mean that it's an operator with three operands, they doesn't say anything about what the operator actually do. It's just a fancy word that describes a secondary characteristic of the operator.

    If you like to use fancy words to make your programming feel more important, go ahead. I don't feel that need. ;)



  • [quote user="Guffa"]

    Actually I don't like either of these terms. They only mean that it's an operator with three operands, they doesn't say anything about what the operator actually do. It's just a fancy word that describes a secondary characteristic of the operator.

    [/quote]

    Actually, there's one language, where you really use it... MetaPost. But I don't think it's used in the same context. It's not "unary, binary, tertiary", but "primary, secondary, tertiary" there. (ref: "A user's manual for MetaPost")



  • [quote user="djork"]

    It's a WTF in itself... there is only one "=" in VBScript, but it means assignment OR equality depending on the context.  If it's the first occurance in a statement then it's assignment, otherwise (in If, While, multiple occurances in one line, etc.) it's equality.

    Yay for VB.

    [/quote]

    What's wrong with an operator having several wildly different meanings, depending on context? Most VB-bashing people seem to have no problems with <<, *, () overloaded:

    cout << *f(1)*(2 << 3);


  • [quote user="Guffa"][quote user="JCDenton"]

    tertiary (or ternary though I argue in favour of tertiary) 

    [/quote]

    Actually I don't like either of these terms. They only mean that it's an operator with three operands, they doesn't say anything about what the operator actually do.[/quote]

    The C++ specification calls it the "conditional operator" and I've seen that term used elsewhere as well. I think that's a pretty good name for it.

    It bugs me when it's just called the "ternary operator".



  • [quote user="Guffa"][quote user="JCDenton"]

    tertiary (or ternary though I argue in favour of tertiary) 

    [/quote]

    Actually I don't like either of these terms. They only mean that it's an operator with three operands, they doesn't say anything about what the operator actually do. It's just a fancy word that describes a secondary characteristic of the operator.

    If you like to use fancy words to make your programming feel more important, go ahead. I don't feel that need. ;)

    [/quote]

     

    Sun itself calls it the ternary operator( http://java.sun.com/docs/books/tutorial/java/nutsandbolts/operators.html) . I do not refuse to use a term because my personal emotions stop me from liking it. Programming comes with a lot of jargon en being able to use the terminology correctly is what distinguishes a professional programmer from a student programmer. Personally I don't like having to refer to language functionalities as "you know, that funny squiggly thing". It makes a conversation with a fellow coder that much more clear when you refer to functionalities by their name. I do not use it for the benefit of my ego.

     That is not to say the name might have been a poor choice.
     

     

     



  • [quote user="JCDenton"]Sun itself calls it the ternary operator[/quote]

    They probably just inherited it from some C specification. That's what happens when you use jargon without questioning it.

    [quote user="JCDenton"]I do not refuse to use a term because my personal emotions stop me from liking it.[/quote]

    I do. I don't see any point in using a term that has no meaning, or even worse, looks like it has a meaning, but has a different meaning.

    [quote user="JCDenton"]Programming comes with a lot of jargon en being able to use the terminology correctly is what distinguishes a professional programmer from a student programmer.[/quote]

    I would like to think that's not the only difference... ;)

    [quote user="JCDenton"]Personally I don't like having to refer to language functionalities as "you know, that funny squiggly thing". It makes a conversation with a fellow coder that much more clear when you refer to functionalities by their name.[/quote]

    Yes, jargon is really useful sometimes, but that doesn't mean that all jargon is good just because it's jargon.

    Why not give it a unique name that doesn't look like it means something, like "The Efraim Operator"? That way the ternary operator can be distinguished from the other ternary operator.

    Or perhaps they should be called "The Primary Ternary Operator" and "The Secondary Ternary Operator"? ;)

     



  • There is one important difference in VB however. IIF is a function, not an operator. That means that ALL THREE expressions are evaluated and not just the condition and the part that will be actually used as in every other language. It luckily doesn't make a difference often but it can lead to interesting results if the expressions have side effects...

     

    I know I'm beating a dead horse but just for fun, if you want even more VB syntax WTFs, do a lookup on the "line", "circle", "PSet" and "print" functions...



  • [quote user="adrianmw"]

    I was told by a former employer that I "wasn't allowed to use iif". The reason? "Because the other developers don't know what it is."

    [/quote]

    Similarly, I have worked at a place that outlawed the use of the tertiary operator (or whatever you prefer to call it) in Java.  Their claim was that people might abuse it.  I guess that's one way to compensate for never having code reviews....

    The "we don't want to make developers learn anything" excuse is frequently used to justify huge ugly frameworks or wrapper libraries that are considerably worse than the APIs they attempt to replace.  As if learning somebody's ill-informed, ill-conceived, poorly-documented, ego-propping homebrew library is an easier task than learning something based on a downloadable specification which underwent months of careful review before its release.



  • [quote user="djork"][quote user="adrianmw"][quote user="JCDenton"]

    Actually, there is a tertiary (or ternary though I argue in favour of tertiary) operator in VB - it's IIf.

    [/quote]

    I was told by a former employer that I "wasn't allowed to use iif". The reason? "Because the other developers don't know what it is."

    [/quote]

    The operative word there being "former."  Can't people be bothered to learn anything anymore?

    [/quote]

     

    No, we can't. We're a nation of hand-fed idiots, and getting dumber. Tech jobs not exempt.

     



  • [quote user="unklegwar"][quote user="djork"][quote user="adrianmw"][quote user="JCDenton"]

    Actually, there is a tertiary (or ternary though I argue in favour of tertiary) operator in VB - it's IIf.

    [/quote]

    I was told by a former employer that I "wasn't allowed to use iif". The reason? "Because the other developers don't know what it is."

    [/quote]

    The operative word there being "former."  Can't people be bothered to learn anything anymore?

    [/quote]

     

    No, we can't. We're a nation of hand-fed idiots, and getting dumber. Tech jobs not exempt.

     

    [/quote]

    You forgot to write "America" using three K's in it, like every other "TEH US SI SUK" idiot.

    The problem isn't that there aren't smart people, the problem is that the dumb people are far more visible, much in the same way that a flaming wreck on the side of the highway will stand out far more than the car that just passed you. Other countries seem to try and douse those fires, while we seem to enjoy watching it burn and even encourage it by pouring fuel on it.



  • I personally hate using iif(). It wasn't supported in ASP back when I started web development years ago, so I never got into it.



  • [quote user="Bob Janova"]

    [quote user="djork"]SomeOtherValue = (SomeValue = Something)[/quote]

    I think when you read that, you realise why the original coder wrote it the way he did. VB's overloading of = makes the one-statement common sense 'some other value gets whether these two things are equal' hard to read.

    If this was a C or Pascal family language, the original code is definitely a WTF. But here, I'm not so sure. Maybe the WTF is using VB in the first place? 

    [/quote]

    Frankly, I code in VB all day, every day. The "WTF" statement is, frankly, easier to read than any of the suggested improvements, though the "Something = (oneThing = OtherThing)" does make some sense.

    The overloaded "=" is a big part of that.  But frankly, I don't mind an extra line or 3 of code if the statement is clear.  Let the compiler optimize it if it wants to.  Let the poor sod down the road be able to read it.

    Now, if it were C, Pascal, or any of a variety of other langquages, where Assignment != equality, then

    "Something := (OneThing = OtherThing)"

    might make some sense.  Iif, OTOH, just sucks.  Had to read.

    Now, setting a flag and using "Something" for decisions down the road does make good sense. Especially if the comments explain what the flag is meant to do.  We do use comments, don't we? 

    My $0.02.
     



  • [quote user="An apprentice"]What's wrong with an operator having several wildly different meanings, depending on context? Most VB-bashing people seem to have no problems with <<, *, () overloaded:

    cout << *f(1)*(2 << 3);[/quote]

    It's fine for the same symbol to have two meanings, one monadic and one dyadic (or unary and binary, or whatever the correct jargon is). Personally, I don't like the overloading of << to do different things, but you can see what it's going to do by looking at its arguments. That is, cout << "xx" will always do the same thing. The WTF with the VB approach is that SomeName = 5 does different things depending on factors outside the expression (i.e. whether there is another = to the left of it).

    On the name of the ?: thingy: tertiary makes no sense at all. That just means 'third'. Ternary isn't great either (it just means 'taking three arguments') but at least it is correct, and (currently) sufficient to determine what you're talking about as no other operation takes three arguments.


Log in to reply
 

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.