Efficiency is for losers



  •  So there I was browsing through the SVN commits when I noticed the following:

    $this->_userLogged = $userAccess->userLoggedIn() ? $userAccess->getUserID() : 0 ;

    I was overjoyed; not only is my colleague using the ternary operator, but there's also no comparing the result of userLoggedIn(), which returns a boolean, to true or false.

    Unfortunately, I then decided to scroll down and find the only place where $this->_userLogged is used...

    if ($this->_userLogged) {

       //do whatever

    }




  • Just another battle in the ongoing "Hunt the dead code" war?



  • I'm assuming that $userAccess is still in scope by the time it reaches the conditional? Otherwise I don't see much of a WTF. I mean, sure, getUserID() is unnecessary, but perhaps it's leftover from earlier code that actually did use the user ID.

    Of course, if that's the case, then TRWTF is using 0 as a dummy value representing no ID, as opposed to null. The legacy code I deal with does that all the time and it pisses me off. But at least the developers of that (kind of) have an excuse in that they're using VB.NET and apparently Nullable<int> (or Nullable(Of Integer)) is too difficult to use.

    I just wish they wouldn't do it in the database as well.



  • @toth said:

     But at least the developers of that (kind of) have an excuse in that they're using VB.NET and apparently Nullable<int> (or Nullable(Of Integer)) is too difficult to use.

    Why, I use c# and it doesn't seem particulary hard to do or perhaps you were being sarcastic: int as opposed of int? is not that big of a change

    Are there no aliases in VB.Net?



  • @toth said:

    Of course, if that's the case, then TRWTF is using 0 as a dummy value representing no ID, as opposed to null.

    PHP would print a warning when it runs the code in the [code]if[/code] if you did that.

    Assuming this [b]is[/b] PHP, that is.  Everything in this code would work in both Perl and PHP.



  • @serguey123 said:

    Why, I use c# and it doesn't seem particulary hard to do or perhaps you were being sarcastic: int as opposed of int? is not that big of a change

    Yes, I left out the sarcasm tag. I was hoping it would come across without it, but I guess not. I'm slightly bitter about the code that I have to deal with.

    @serguey123 said:

    Are there no aliases in VB.Net?

    Not typically being a VB.NET developer (I'm C# unless I'm forced to use VB.NET), I'm not sure, but a very cursory Google seems to indicate "no".



  • @powerlord said:

    PHP would print a warning when it runs the code in the <font face="Lucida Console" size="2">if</font> if you did that.

    What do you mean? Conditionals on null generate a warning in PHP? I thought PHP just happily used it as a false value.



  • @toth said:

    Of course, if that's the case, then TRWTF is using 0 as a dummy value representing no ID, as opposed to null.
    The theme in our codebase is to use 1/0 as opposed to true/false. It's like my colleague has a blind spot when it comes to booleans, which ticks me off to no end. And there's not much I can do about it, because I don't want to be the nazi dev that's constantly tweaking everyone's code to fit his own taste.

    You'd think using a primitive that's been present in computer languages since the dawn of time would come naturally to a programmer, as opposed to making an integer pretend to be a boolean. Instead I get stuff like this

       $myVal= $someBoolean ? 1 : 0;

       if($myVal>0)  {

          //do something

       }

     

    @powerloard said:

    Assuming this is PHP, that is
    It is



  • @DOA said:

    You'd think using a primitive that's been present in computer languages since the dawn of time would come naturally to a programmer, as opposed to making an integer pretend to be a boolean
     

    Did they switch over from C?



  • @toth said:

    @serguey123 said:
    Are there no aliases in VB.Net?
    Not typically being a VB.NET developer (I'm C# unless I'm forced to use VB.NET), I'm not sure, but a very cursory Google seems to indicate "no".

    Sorted it for you, retarded but is there.

    Regards



  • @powerlord said:

    PHP would print a warning when it runs the code in the <font face="Lucida Console" size="2">if</font> if you did that.

    Actually, no it won't - seems there's a slight difference between setting a variable to null versus unset()ting it, in that only the latter will generate an "Undefined variable" notice (not a warning), and only if you've got your error level set to include E_NOTICE.



  • I also agree with whatever Quietust posted above.



  • I agree with whatever Zecc posted above.



  • I agree with whatever I'm posting right here.

     



  •  I don't agree with that silly balloon on that sad man.



  • @serguey123 said:

    @toth said:

    @serguey123 said:
    Are there no aliases in VB.Net?
    Not typically being a VB.NET developer (I'm C# unless I'm forced to use VB.NET), I'm not sure, but a very cursory Google seems to indicate "no".

    Sorted it for you, retarded but is there.

    Regards

    That is for specifying another name for a dll import. Has nothing to do with int <-> int?



  • @DOA said:

     So there I was browsing through the SVN commits when I noticed the following:

    $this->_userLogged = $userAccess->userLoggedIn() ? $userAccess->getUserID() : 0 ;

    I was overjoyed; not only is my colleague using the ternary operator, but there's also no comparing the result of userLoggedIn(), which returns a boolean, to true or false.

    Unfortunately, I then decided to scroll down and find the only place where $this->_userLogged is used...

    if ($this->_userLogged) {

       //do whatever

    }


    There's technically nothing wrong with this code. There's no need to compare userLoggedIn() to true/false when that is all it. Is returning, as all comparison operators just evaluate down to a boolean anyway. It's like using a ternary operator to evaluate to a true or false anyway (condition ? true : false). Redundant.

    The only "huh" I see here is calling it 'userLogged' instead of loggedUserId or something more specific.

    Nope, sorry, you're TRWTF here, calling attention to such a small and harmless bit of logic.



  • @XIU said:

    @serguey123 said:

    @toth said:

    @serguey123 said:
    Are there no aliases in VB.Net?
    Not typically being a VB.NET developer (I'm C# unless I'm forced to use VB.NET), I'm not sure, but a very cursory Google seems to indicate "no".

    Sorted it for you, retarded but is there.

    Regards

    That is for specifying another name for a dll import. Has nothing to do with int int?

    That is why I said it was retarded, the fact that it does it for this case but not for the other cases is the reason why I said that



  • @Zimzat said:

    Nope, sorry, you're TRWTF here, calling attention to such a small and harmless bit of logic.
     

    It's symptomatic for idiot code.



  • @dhromed said:

     I don't agree with that silly balloon on that sad man number 6.

     

    PTFY.



  •  Things's clearing up now.



  • @Someone You Know said:

    @dhromed said:

     I don't agree with that silly balloon on that sad man number 6.

     

    PTFY.

    You know a show is good when they can make a weather balloon terrifying. (It's named Rover.)



  •  A terrible weather balloon named Rover.

     

    That's it, I'm fucking watching some clips. This had better not be all campy shit that only programmers without a sense of aesthetics enjoy.

     

    If it is, I'm banning blakey, DaveK and the pedantic dickweed.

     



  • Yeah okay so it is all campy shit that only programmers without a sense of aesthetics enjoy.

     



  • @dhromed said:

    Yeah okay so it is all campy shit that only programmers without a sense of aesthetics enjoy.

     

    Without a sense of aestethics? Back in the late-60s, The Prisoner DEFINED cool.



  • @blakeyrat said:

    @dhromed said:

    Yeah okay so it is all campy shit that only programmers without a sense of aesthetics enjoy.

     

    Without a sense of aestethics? Back in the late-60s, The Prisoner DEFINED cool.

    Holy crap, you're posting from beyond the bannedyard!



  • @toth said:

    @blakeyrat said:
    @dhromed said:

    Yeah okay so it is all campy shit that only programmers without a sense of aesthetics enjoy.

     

    Without a sense of aestethics? Back in the late-60s, The Prisoner DEFINED cool.

    Holy crap, you're posting from beyond the bannedyard!

    The Prisoner is so cool it's given me superhuman abilities!

    Either that, or the "ban" feature works about as well as every other feature in Community Server.



  • @blakeyrat said:

    @dhromed said:

    Yeah okay so it is all campy shit that only programmers without a sense of aesthetics enjoy.

     

    Without a sense of aestethics? Back in the late-60s, The Prisoner DEFINED cool.
    \

    They even made a remake.

    The '60 sense of pretty much everything was wretched (hippies, fashion sense, etc)



  • @dhromed said:

    Yeah okay so it is all campy shit that only programmers without a sense of aesthetics enjoy.
    Last time I fell for the hype I spent about 20 minutes of my life trying not to fall asleep watching Citizen Kane. I don't doubt it was brilliant when it came out, but it's 2010 now. Hell, even some of the cool stuff that aired after I was born is unwatchable now. Have you tried watching MacGyver recently?
                    </p>


  • @DOA said:

    Hell, even some of the cool stuff that aired after I was born is unwatchable now. Have you tried watching MacGyver recently?
     

    No, but what does that have to do with cool stuff?



  • @DOA said:

    @dhromed said:
    Yeah okay so it is all campy shit that only programmers without a sense of aesthetics enjoy.
    Last time I fell for the hype I spent about 20 minutes of my life trying
    not to fall asleep watching Citizen Kane. I don't doubt it was
    brilliant when it came out, but it's 2010 now.

    It's still brilliant. The reason you're unimpressed is that (almost literally) every movie since Citizen Kane has ripped-off their innovative techniques, camera angles, effects, etc. EVERY MOVIE. That's actually the reason why Citizen Kane is considered so brilliant: it basically invented cinematography. (Not solely of course; even Citizen Kane was building on the innovation of earlier films, like Metropolis and Birth of a Nation.) The newsreel scene where the reporters are all talking over each other? Something like that had never been done in film before Citizen Kane... before it dialog was delivered one line at a time.

    The side effect of this is that you've already seen everything that makes Citizen Kane so creative and brilliant a million times, in other films. That doesn't mean the quality of Citizen Kane has gone down, that means the quality of the entire industry has gone up.

    @DOA said:

    Hell, even some of the
    cool stuff that aired after I was born is unwatchable now. Have you
    tried watching MacGyver recently?

    The first season of MacGyver was awful by any metric. Especially the episode that stole stunt footage from The Italian Job, and just spliced-in the bad MacGyver TV actors. However, the quality of the show got much, much better over time.

    Still, it never hit the heights of Airwolf.



  • @blakeyrat said:

    @DOA said:
    Last time I fell for the hype I spent about 20 minutes of my life trying not to fall asleep watching Citizen Kane. I don't doubt it was brilliant when it came out, but it's 2010 now.

    It's still brilliant. The reason you're unimpressed is that (almost literally) every movie since Citizen Kane has ripped-off their innovative techniques, camera angles, effects, etc. EVERY MOVIE. That's actually the reason why Citizen Kane is considered so brilliant: it basically invented cinematography. (Not solely of course; even Citizen Kane was building on the innovation of earlier films, like Metropolis and Birth of a Nation.)

     

    I love it when people drag Metropolis and Birth of a Nation into a discussion of cinematic innovation when really everything they did was just building on the innovations of The Great Train Robbery and Le Voyage Dans La Lune made years before.



  • @da Doctah said:

    I love it when people drag Metropolis and Birth of a Nation into a discussion of cinematic innovation when really everything they did was just building on the innovations of The Great Train Robbery and Le Voyage Dans La Lune made years before.

    Yah, and you know The Great Train Robbery and Le Voyage Dans La Lune are just ripping off Stargate.



  • @toth said:

    Of course, if that's the case, then TRWTF is using 0 as a dummy value representing no ID, as opposed to null. The legacy code I deal with does that all the time and it pisses me off. But at least the developers of that (kind of) have an excuse in that they're using VB.NET and apparently Nullable<int> (or Nullable(Of Integer)) is too difficult to use.

     

    I have always found asigning null to int value be a VERY ugly solution. When I have to assign an id to an object, then I default it to -1. That ways if I have say an object, I know if it's in the database by checking if it's >= 0.



  • @TheThing said:

    @toth said:


    Of course, if that's the case, then TRWTF is using 0 as a dummy value representing no ID, as opposed to null. The legacy code I deal with does that all the time and it pisses me off. But at least the developers of that (kind of) have an excuse in that they're using VB.NET and apparently Nullable<int> (or Nullable(Of Integer)) is too difficult to use.

     

    I have always found asigning null to int value be a VERY ugly solution. When I have to assign an id to an object, then I default it to -1. That ways if I have say an object, I know if it's in the database by checking if it's >= 0.

    Ugh, so it's people like you that inflict these things on me. Why would it be "VERY ugly" to allow a property that may not have a meaningful value to be null? And how is it easier to check if it's >=0 than to check if it's null? Are you using some bizarre DBMS that has no concept of "null"? You prefer to establish a new no-value convention? What the hell?



  • Well, you have to remember that on his projects data can never be negative.



  • @Sutherlands said:

    Well, you have to remember that on his projects data can never be negative.
     

    Are you positive?



  • @b-redeker said:

    @Sutherlands said:

    Well, you have to remember that on his projects data can never be negative.
     

    Are you positive?

    ba-dum *tch*

Log in to reply