• puzzled (unregistered)

    static bool first = true;

    if (first) {
        first = false;
    
  • (cs)

    "of which the following code is a part of"?

  • (cs) in reply to ThomsonsPier
    ThomsonsPier:
    "of which the following code is a part of"?
    Sure - it's from the "Live and let die" school of grammar:
    The Beatles:
    But in this ever changing world in which we live in
  • puzzled (unregistered) in reply to Mel

    Sure - it's from the "Live and let die" school of grammar: [quote user="The Beatles"]But in this ever changing world in which we live in[/quote][/quote]

    The Wings, not The Beatles

  • (cs) in reply to puzzled
    puzzled:
    Mel:
    Sure - it's from the "Live and let die" school of grammar:
    The Beatles:
    But in this ever changing world in which we live in

    The Wings, not The Beatles

    Whoops

  • (cs)
    void Lib::output(Lib* self)
    {
        if (self->active != STATUS) {
            if ((self->active == false) && (STATUS == true)) {
                STATUS = false;
            } else if ((self->active == true) && (STATUS == false)) {
                STATUS = true;
            }
        }
    }

    or perhaps

    void Lib::output(Lib* self)
    {
        STATUS = self->active;
    }
  • Superdude (unregistered) in reply to Mel
    Mel:
    puzzled:
    Mel:
    Sure - it's from the "Live and let die" school of grammar:
    The Beatles:
    But in this ever changing world in which we live in

    The Wings, not The Beatles

    Whoops

    Surely just Wings (unlessmy sarcasm detector has been unplugged)?

  • (cs)
    ... marathon video game playing sessions...

    Yup, that sounds about right to me! An office that doesn't even have a single arcade machine isn't worth going to every day!

  • (cs) in reply to puzzled
    puzzled:
    Sure - it's from the "Live and let die" school of grammar:
    The Beatles:
    But in this ever changing world in which we live in

    The Wings, not The Beatles

    Wings, not The Wings. (just keeping in the nitpicky spirit of TDWTF)...

  • (cs) in reply to durnurd
    durnurd:
    void Lib::output(Lib* self)
    {
        if (self->active != STATUS) {
            if ((self->active == false) && (STATUS == true)) {
                STATUS = false;
            } else if ((self->active == true) && (STATUS == false)) {
                STATUS = true;
            }
        }
    }

    or perhaps

    void Lib::output(Lib* self)
    {
        STATUS = self->active;
    }

    That fails to account for the two other cases (when STATUS and self-active share the same status). I don't know if it's right to do so or not, mind you.

    EDIT: Rectified in my next comment. Why can't I delete my own comments? (I know, Community Server...)

  • (cs) in reply to durnurd
    durnurd:
    void Lib::output(Lib* self) {
        if (self->active != STATUS) {
            if ((self->active == false) && (STATUS == true)) {
                STATUS = false;
            } else if ((self->active == true) && (STATUS == false)) {
                STATUS = true;
            }
        }
    }

    or perhaps

    void Lib::output(Lib* self) {
        STATUS = self->active;
    }

    This won't do: it behaves correctly on the two other cases (when STATUS and self->active share the same state).

  • ingenious (unregistered) in reply to Voodoo Coder
    Voodoo Coder:
    puzzled:
    The Wings, not The Beatles

    Wings, not The Wings. (just keeping in the nitpicky spirit of TDWTF)...

    If to nitpick, then I guess the "The" in "The Wings" wasn't meant to be part of the band name, but used as a definite article.

  • (cs) in reply to Mel
    Mel:
    ThomsonsPier:
    "of which the following code is a part of"?
    Sure - it's from the "Live and let die" school of grammar:
    The Beatles:
    But in this ever changing world in which we live in
    Try this: "But if this ever-changing world in which we're living makes you give in and cry--Say 'Live and let die'."
  • Zero (unregistered) in reply to Mel

    I thought the lyric was "...world in which we're livin'". Which makes more sense.

  • Bert (unregistered) in reply to Adriano
    Adriano:
    durnurd:
    void Lib::output(Lib* self) {
        if (self->active != STATUS) {
            if ((self->active == false) && (STATUS == true)) {
                STATUS = false;
            } else if ((self->active == true) && (STATUS == false)) {
                STATUS = true;
            }
        }
    }

    or perhaps

    void Lib::output(Lib* self) {
        STATUS = self->active;
    }

    This won't do: it behaves correctly on the two other cases (when STATUS and self->active share the same state).

    Saving one redundant boolean assignement is hardly worth all of this...

  • OldCoder (unregistered)

    My head spins after reading this and trying to figure out what it's doing. Or not doing, in a very complicated fashion.

    Does this guy (the coder, not the submitter) really not understand how Object-Oriented code works?

  • puzzled (unregistered) in reply to Zero
    Zero:
    I thought the lyric was "...world in which we're livin'". Which makes more sense.

    it's

    But if this ever changin' world In which we live in Makes you give in and cry

    Say live and let die

  • stanbeard (unregistered) in reply to Mel

    Actually Paul McCartney sings "But if this ever changing world in which we're living"

    It's Axl Rose that sang "But if this ever changing world in which we live in"... and he's realised his mistake because he sung it properly at the Gunners concert I went to last year.

  • (cs)

    There are games companies which try to filter out people who don't know how to code very well at interview. I used to work for one. Unfortunately I now work for a games company which accepts anyone who knows how to write syntactically correct code.

  • Slash (unregistered) in reply to stanbeard
    stanbeard:
    the Gunners concert I went to last year.

    ^ TRWTF ist right there!

  • (cs) in reply to stanbeard
    stanbeard:
    Actually Paul McCartney sings "But if this ever changing world in which we're living"

    It's Axl Rose that sang "But if this ever changing world in which we live in"... and he's realised his mistake because he sung it properly at the Gunners concert I went to last year.

    Not as bad as David Lee Roth singing

    I don't believe you It must be true No one could look as good as you

    ...where the actual lyrics are

    I don't believe you You're not the truth No one could look as good as you

  • Thierry Henry (unregistered) in reply to stanbeard
    stanbeard:
    Actually Paul McCartney sings "But if this ever changing world in which we're living"

    It's Axl Rose that sang "But if this ever changing world in which we live in"... and he's realised his mistake because he sung it properly at the Gunners concert I went to last year.

    When did Arsenal start performing gigs. I'm intrigued, who sings; is it Wenger or is he on the drums.

  • (cs) in reply to durnurd
    durnurd:
    void Lib::output(Lib* self)
    {
        STATUS = self->active;
    }

    void Lib::output() //which is a non-static member, as it should be! { STATUS = active; }

    Would be better. It still doesn't solve the rather scare assignment of 'STATUS' there, but that would probably need a total redesign.

    Of course, it MIGHT be that 'STATUS' is actually a hardware register, in which case the original complex boolean stuff might be necessary to avoid hardware register writes if data hasn't changed (but I doubt it...)

    (PS - this is one of the first 'WTF's in a while which has actually had me issue that utterance)

  • configurator (unregistered) in reply to durnurd

    But what if self->active was FILE_NOT_FOUND

  • (cs)

    ANDY GOTH=NO

  • (cs)

    May be, just may be, this "programmer"'s first language was Lua (we are talking about game companies here after all) and he didn't grasp the concept of static vs instance methods in C++.

    To clarify - Lua doesn't have classes per se, instead there are "tables" - associative containers - that can contain functions as values. There's also some syntactic sugar to implicitly pass the containing table to a "member" function, thus emulating methods with this pointer, but there's no difference between a function declared with explicit this parameter and a function declared with the syntactic sugar/implicit this parameter. Which seems to be related to the WTF at hand. Also, the implicit "this" parameter is called "self".

  • Adrian Cheater (unregistered)

    I'm surprised that anyone expects video games to somehow magically adhere to a higher standard of code excellence. As an indie developer, I've worked with and written my share of bad code. Hopefully I'm at least trying to improve, but game development seems to get it from all angles.

    Goals are unclear: You almost never know what you're making up front, since it's hard to design 'fun' on paper. It's exploratory software, unless you're writing Madden 2K-something.

    Hardware is non-standard: PC games are a minefield of hardware issues, you often need special cases to handle the wide variety of configurations, or you limit your market appeal.

    Budgets and time lines are often rigid: As we know, if you can't wiggle on cost and speed, you end up wiggling on quality. Front end quality isn't usually too bad, but keeping all those lofty design goals you had up front start to fall aside when the crunch hits. Since games tend to be throw-away code in the end, maintenance may take a back seat to software stability.

    Oh, and we have our share of idiots. Guys and girls who 'just like' games, wanted to be a writer instead, have 'a great idea', who may or may not have learned how to code involved in the process. Software is software, and that's why I love coming here, to learn more about what does and doesn't work in other sectors.

  • (cs) in reply to Adrian Cheater
    Adrian Cheater:
    ...keeping all those lofty design goals you had up front start to fall aside when the crunch hits.
    You just reminded me of an expression I saw years ago framed on some coworker's wall: "When you're up to your ass in alligators, it's difficult to remember that your original purpose was to drain the swamp."
  • (cs)

    Some people can write Fortran in any language. This guy writes Python.

  • panschk (unregistered)

    Right now I'm in the process of teaching myself C++, and some of the stuff I do looks a lot like this. You know, trying if some expression will compile, and what happens if you write cout << &&*&varname;

    This does not look like production code that 'does' anything to me.

  • Andrew (unregistered) in reply to Mel
    Mel:
    ThomsonsPier:
    "of which the following code is a part of"?
    Sure - it's from the "Live and let die" school of grammar:
    The Beatles:
    But in this ever changing world in which we live in

    Paul McCartney's Wings sang "Live and let die".

  • Xar (unregistered) in reply to puzzled
    static bool first = true;

    if (first) { first = false;

    This is actually a known C/C++ practice: since first is declared static its value is kept across several calls to the function, so you only do the init the first time the function is called.

  • (cs) in reply to ingenious
    ingenious:
    Voodoo Coder:
    puzzled:
    The Wings, not The Beatles

    Wings, not The Wings. (just keeping in the nitpicky spirit of TDWTF)...

    If to nitpick, then I guess the "The" in "The Wings" wasn't meant to be part of the band name, but used as a definite article.

    In keeping with the spirit...

    The noun "Wings" is hardly an indefinite noun (in this context), requiring any kind of article.

    Furthermore, adding the article could lead to entirely different meaning of the noun (i.e. "Looks like The Wings might be in for another run at the Stanley Cup this year!"). While most who are familiar with Paul McCartney's post-Beatles works and/or James Bond movies featuring Roger Moore would identify either statement in the given context, a man from mars may very well wonder how a hockey team in Detroit could be responsible for such an anthem.

    </nitpicking>
  • puzzled (unregistered) in reply to Xar
    Xar:
    static bool first = true;

    if (first) { first = false;

    This is actually a known C/C++ practice: since first is declared static its value is kept across several calls to the function, so you only do the init the first time the function is called.

    I knew what the code was for, it was a comment in reply to the "FIRST" comment (I forgot to click the quote\reply button though)

  • Doc Monster (unregistered) in reply to Code Dependent
    Code Dependent:
    Not as bad as David Lee Roth singing

    I don't believe you It must be true No one could look as good as you

    Even worse is Sammy Hagar singing

    Only time will tell If our love Will stand the Test of Time

    (--Van Halen, Why Can't This Be Love?)

    Sammy needs to read the dictionary page for "tautology".

  • Andrew (unregistered) in reply to Xar
    Xar:
    static bool first = true;

    if (first) { first = false;

    This is actually a known C/C++ practice: since first is declared static its value is kept across several calls to the function, so you only do the init the first time the function is called.

    No, in this context the first flag is absolutely a bad practice. The IF-statement's body constructs the Lib object. There appears to be only one Lib object. So, why don't they construct it in the main block?

  • RBoy (unregistered)

    Andy = Nooooooooo!!!!!!

  • (cs) in reply to Matt.C
    Matt.C:
    ANDY GOTH=NO
    I know when I'm not wanted... :^(
  • Cecil (unregistered) in reply to Xar

    Except it's a horrible practice.

    Pull everything inside the "if (first)" block and move it into an Init() function.

  • z0ltan (unregistered) in reply to ThomsonsPier
    ThomsonsPier:
    "of which the following code is a part of"?

    Sir, I would upmod you if I could! ;-)

  • (cs) in reply to Mel

    I thought it was "If this ever-changing world in which we're living.." At least one online lyrics source agrees with me:

    http://www.sing365.com/music/lyric.nsf/Live-And-Let-Die-lyrics-Paul-McCartney/8479C51B2F85A57748256A4C0008CAE9

  • EFH (unregistered)

    I'm surprised noone has mentioned "self" up until now. C++ doesn't have "self", it has "this". There must be a macro someplace

    #define self this

    Clearly this programmer didn't feel at home with C++.

  • (cs) in reply to Doc Monster
    Doc Monster:
    Code Dependent:
    Not as bad as David Lee Roth singing

    I don't believe you It must be true No one could look as good as you

    Even worse is Sammy Hagar singing

    Only time will tell If our love Will stand the Test of Time

    (--Van Halen, Why Can't This Be Love?)

    Sammy needs to read the dictionary page for "tautology".

    Or Smashing Pumpkins' "what I choose is my choice." Brilliant.

  • Harrow (unregistered)

    I Googled 'The Beatles' -- wow, just wow -- Paul McCartney was in another band before Wings!

    The stuff you learn around here...

    -Harrow.

  • bob (unregistered) in reply to EFH
    EFH:
    I'm surprised noone has mentioned "self" up until now. C++ doesn't have "self", it has "this". There must be a macro someplace

    #define self this

    Clearly this programmer didn't feel at home with C++.

    look again, 'this' is used with the instance methods, the 'self' pointer was passed in to the static methods to make the pseudo-instance methods.

  • (cs) in reply to dcardani
    dcardani:
    Doc Monster:
    Code Dependent:
    Not as bad as David Lee Roth singing

    I don't believe you It must be true No one could look as good as you

    Even worse is Sammy Hagar singing

    Only time will tell If our love Will stand the Test of Time

    (--Van Halen, Why Can't This Be Love?)

    Sammy needs to read the dictionary page for "tautology".

    Or Smashing Pumpkins' "what I choose is my choice." Brilliant.

    Here ya go (reaching way back)--Bob Wills' "Cherokee Maiden":

    One night when the moon was bright on a moonlit glade

  • (cs) in reply to Code Dependent
    Code Dependent:
    dcardani:
    Doc Monster:
    Code Dependent:
    Not as bad as David Lee Roth singing

    I don't believe you It must be true No one could look as good as you

    Even worse is Sammy Hagar singing

    Only time will tell If our love Will stand the Test of Time

    (--Van Halen, Why Can't This Be Love?)

    Sammy needs to read the dictionary page for "tautology".

    Or Smashing Pumpkins' "what I choose is my choice." Brilliant.

    Here ya go (reaching way back)--Bob Wills' "Cherokee Maiden":

    One night when the moon was bright on a moonlit glade

    If you choose not to decide, you still have made a choice. Rush

  • clickey McClicker (unregistered) in reply to Voodoo Coder
    Voodoo Coder:
    a man from mars may very well wonder how a hockey team in Detroit could be responsible for such an anthem.

    </nitpicking>

    Technically it is all the same "Wings." They usually just do the music thing during the day but when they get really really mad they turn all Red(green was already taken), rip off their shirts, put on Hockey uniforms which leads to games and fighting/smashing/clobbering/pummelling. It is admirable how they bring such emotion to all their work even if it isn't always that good.

  • Queex (unregistered) in reply to KattMan
    If you choose not to decide, you still have made a choice. Rush

    I think that still makes sense, as long as 'choose' and 'decide' don't reference the same Decision object. If presented with the Decision 'You are either with us or against us' you could choose neither option (presumably by raising a FalseDichotomyException) and still have made a choice (i.e. compile without errors).

  • clickey McClicker (unregistered) in reply to KattMan
    KattMan:
    If you choose not to decide, you still have made a choice. Rush

    That isn't dumb or redundant. That is deep and full of underlying truth.

    Like my brother-in-law who quit Wal-mart so he could play games, a lot of people should hear that quote. Inaction is often worse than 'the wrong' action. His inaction is really a choice of shocking stupidity.

Leave a comment on “self->Static Anti-Pattern”

Log In or post as a guest

Replying to comment #:

« Return to Article