For-Switch ?



  •  I don't know if this is truly WTF worthy.  But I recently started a Flex project at work, and despite my limited background with Flex still wondered at a construct my predecessor had used extensively (Lazily retyped to remove specific details):

     

    for (var i:int = 0;i<someResultArray.length;i++)

    {

      var which:String = i.toString();

      switch (which)

      {

        case "0":

          ...Stuff

        break;

        case "1":

          ...Other stuff

        break;

         case "2":

           ...Some final thing

         break;

      }

    }

     

    I'm still not entirely sure what thinking had led to the For-Switch loop, which is probably for the better.



  •  Probably meant to be run on an embedded system.



  • this is a classic wtf, which is often seen in the wilderness.It even has n own wikipedia entry:

     http://en.wikipedia.org/wiki/Loop-switch_sequence

    The loop-switch sequence is a specific derivative of spaghetti code.

     




  • @Sloloem said:

     I don't know if this is truly WTF worthy.  But I recently started a Flex project at work
    Oh, yeah.  That's definitely a WTF.



  • @lupo said:

    this is a classic wtf, which is often seen in the wilderness.It even has n own wikipedia entry:

     http://en.wikipedia.org/wiki/Loop-switch_sequence

    The loop-switch sequence is a specific derivative of spaghetti code.

     

     

    Classic and frequent enough that it's already turned up on TDWTF at least twice:

     



  • @SQLDave said:

     Probably meant to be run on an embedded system.

    I'm not sure that would help...actually, wouldn't that just make it worse?  Aside from the fact that it would mean we were running Flex on an embedded system, wouldn't a loop and a complex conditional produce useless operations vs. just accessing the wanted indices?



  • @lupo said:

    this is a classic wtf, which is often seen in the wilderness.It even has n own wikipedia entry:

     http://en.wikipedia.org/wiki/Loop-switch_sequence

    The loop-switch sequence is a specific derivative of spaghetti code.

     


     

     

    My favorite part of it is the conversion to a string before comparing.  The author of that tidbit did that in several other places...I'm not sure why he preferred switching on Strings instead of ints.  I guess it's either special coding or some weird actionscript implementation hack to get speed?



  • @Sloloem said:

    My favorite part of it is the conversion to a string before comparing.  The author of that tidbit did that in several other places...I'm not sure why he preferred switching on Strings instead of ints.  I guess it's either special coding or some weird actionscript implementation hack to get speed?
     

    More likely the author didn't realize you could switch on ints.



  • @Heron said:

    @Sloloem said:

    My favorite part of it is the conversion to a string before comparing.  The author of that tidbit did that in several other places...I'm not sure why he preferred switching on Strings instead of ints.  I guess it's either special coding or some weird actionscript implementation hack to get speed?
     

    More likely the author didn't realize you could switch on ints.

    Who is (on average) more ignorant of their own language-of-choice?

    1) ActionScript (Flash) developers?

    2) Javascript developers?

    3) PHP developers?

    Taking all bets!



  • @Heron said:

    More likely the author didn't realize you could switch on ints.
    You can switch on ints now?!  What a country!



  • @blakeyrat said:

    @Heron said:

    @Sloloem said:

    My favorite part of it is the conversion to a string before comparing.  The author of that tidbit did that in several other places...I'm not sure why he preferred switching on Strings instead of ints.  I guess it's either special coding or some weird actionscript implementation hack to get speed?
     

    More likely the author didn't realize you could switch on ints.

    Who is (on average) more ignorant of their own language-of-choice?

    1) ActionScript (Flash) developers?

    2) Javascript developers?

    3) PHP developers?

    Taking all bets!

     

     

    Speaking purely from college experience I would have to say ActionScript developers.  The new media kids were absolute masters and Copy-n-Paste coding.  Followed by JS and then PHP.  And I'm only going by people who would actually call themselves an "X developer" and not just say they "do X" or "know X".

     From work experience "Flex guys" tend to be a little better than Flash guys, but based on what my team's current Flex contractor has been putting out...I would say that doesn't extend very far.



  •  Not shown: the place where the "stuff" changes the value of i, so the cases get executed in non-sequential order.



  • @Sloloem said:

    @SQLDave said:

     Probably meant to be run on an embedded system.

    I'm not sure that would help...actually, wouldn't that just make it worse?  Aside from the fact that it would mean we were running Flex on an embedded system, wouldn't a loop and a complex conditional produce useless operations vs. just accessing the wanted indices?

    Saying something is done on embedded system is running joke around here. Probably because people tend to optimize when programming for embedded systems and premature optimization combined with bad understanding what is actually efficient is a huge source of WTF.

    On a side note, I actually did some flash programming for embedded system about two years ago. It was a gigantic WTF. It was Flash Lite 3, which only supports Flash 8 stuff (so we couldn't use Flex) and CS3 was total pain to work with in a team of 7 or so people (because the binary blobs with layout can't be merged). The resolution was 1024x768 and the company doing the porting had huge problems to adapt the player to display into an OpenGL layer needed to composite the image with output by another component in the system. So it ended up copying buffers around and swapping byte order in the process and being effing slow as a result. And the platform guys couldn't look into it, because only the Adobe-licensed company was allowed to work with the player source. It should be noted that it was slow for other reasons too, like that the Flash Lite does not have many optimization the desktop version does.



  • @blakeyrat said:

    Who is (on average) more ignorant of their own language-of-choice?
    1) ActionScript (Flash) developers?
    2) Javascript developers?
    3) PHP developers?

    Taking all bets!

     

    I have to vote for Flash devs.  Our resident Flash guy likes to tell me all the time about the 'power of ActionScript' and how the 'business scripting language known as C#' pales in comparison.  Any time you talk to this guy about programming in any sense of the word, he responds with 'use XML and a hierarchtical (intentional misspelling, he says it like this) stack'.  Also, he isn't being sarcastic.  He believes it.



  • @Smitty said:

    scripting language known as C#

    There's a scripting language called C#? That must get confused often with the compiled language called C#...

    @Smitty said:

    a hierarchtical (intentional misspelling, he says it like this) stack

    wut


  • Discourse touched me in a no-no place

    @toth said:

    @Smitty said:
    scripting language known as C#

    There's a scripting language called C#? That must get confused often with the compiled language called C#

    Indeed.



  • @Smitty said:

    Our resident Flash guy fag likes to tell me all the time about the 'power of ActionScript' and how the 'business scripting language known as C#' pales in comparison.  Any time you talk to this guy about programming in any sense of the word, he responds with 'use XML and a hierarchtical (intentional misspelling, he says it like this) stack'.  Also, he isn't being sarcastic.  He believes it.

    See, another case where an abortion should have been mandatory. Since the mandatory abortions missed this one, please kill him and any offspring it may have produced in his retarded stupor.



  • @PJH said:

    @toth said:
    @Smitty said:
    scripting language known as C#

    There's a scripting language called C#? That must get confused often with the compiled language called C#

    Indeed.

    ...Why?



  •  @toth said:

    @Smitty said:
    scripting language known as C#

    There's a scripting language called C#? That must get confused often with the compiled language called C#...

    @Smitty said:

    a hierarchtical (intentional misspelling, he says it like this) stack

    wut

    One of these days he's going to say 'hierarchtical' to me and I'm going to snap.  He also likes to remind me (often) that he doesn't have code, he has 'objects'.  That's right, Flash-weenie, keep tap-dancing on the minefield.



  • @toth said:

    @PJH said:
    @toth said:
    @Smitty said:
    scripting language known as C#

    There's a scripting language called C#? That must get confused often with the compiled language called C#

    Indeed.

    ...Why?

    Presumably for the same reason Ch (an interpreted C) exists



  • @Smitty said:

    One of these days he's going to say 'hierarchtical' to me and I'm going to snap.  He also likes to remind me (often) that he doesn't have code, he has 'objects'.  That's right, Flash-weenie, keep tap-dancing on the minefield.

    Sadly, ActionScript 3 is actually pretty damned good, leaps and bounds over AS2 at least. Not that that means Flash developers are any better...

    I'm working with this guy, installing SiteCatalyst analytics into a Facebook app he made in AS3. I sent him an email asking for the Flash source, and he sent me back this long screed about how Flash developers are idiots, he's actually a *Flex* developer. It was like 8-9 paragraphs long, I'm not even kidding.

    So when I had to send a *second* email, because he never sent the classes I requested in the first (presumably being too busy lecturing me about how different Flex and Flash are), I made sure to point out that Adobe has actually renamed "Flex Builder" into "Flash Builder." Hah!

    Idiots. I have to say, I think ActionScript developers might be the worse because, as people have mentioned, they're full of themselves. Nobody would give you a lecture of that type about Javascript or PHP. I hope!

    Also, ActionScript developers usually code in Eclipse, which is a giant bloated WTF-filled piece of crap. I downloaded it and the Flex/Flash SDK in hopes of figuring out a way of jury-rigging it to do Flash development in the way Flash Builder does without having to pay Adobe any money. (It's possible, but takes a ton of configuration.) I found a dozen bugs in seconds. Screw that, I'll just expense a copy of the Adobe version when I need it. (Not that the Adobe version of Eclipse is any less buggy, judging from their other apps.)



  • @blakeyrat said:

    Also, ActionScript developers usually code in Eclipse, which is a giant bloated WTF-filled piece of crap. I downloaded it and the Flex/Flash SDK in hopes of figuring out a way of jury-rigging it to do Flash development in the way Flash Builder does without having to pay Adobe any money. (It's possible, but takes a ton of configuration.) I found a dozen bugs in seconds. Screw that, I'll just expense a copy of the Adobe version when I need it. (Not that the Adobe version of Eclipse is any less buggy, judging from their other apps.)
     

    Funny you should mention this.  While he uses Adobe for his flash 'development', he tries all the time to convince me that Eclipse is vastly superior to Visual Studio (though he's never used either).



  • @Smitty said:

    he tries all the time to convince me that Eclipse is vastly superior to Visual Studio
    If highest memory usage is a metric, Eclipse is definitely superior.



  • @bstorer said:

    @Smitty said:

    he tries all the time to convince me that Eclipse is vastly superior to Visual Studio
    If highest memory usage is a metric, Eclipse is definitely superior.

    I also give it more points on the "home screen looks like an elementary school model of the solar system" scale. Which I just made up.



  • @blakeyrat said:

    @bstorer said:

    @Smitty said:

    he tries all the time to convince me that Eclipse is vastly superior to Visual Studio
    If highest memory usage is a metric, Eclipse is definitely superior.

    I also give it more points on the "home screen looks like an elementary school model of the solar system" scale. Which I just made up.

    Plus, searching for topics regarding Eclipse is far more likely to return websites devoted to the Twilight series.  So there's that.



  •  I've seen that done. No idea what possesses people. It was first-year programmers in my case, though, so it's forgiveable if not understandable.



  • @Arancaytar said:

     I've seen that done. No idea what possesses people. It was first-year programmers in my case, though, so it's forgiveable if not understandable.

    To be fair, I use this similar construct in my own code:

    foreach (Amazon.SimpleDB.Model.Attribute attr in attrResult.Attribute)
    {
    	switch (attr.Name)
    	{
    		case "clientName":
    			m_clientName = attr.Value;
    			break;
    		case "server":
    			m_server = attr.Value;
    			break;
    		case "database":
    			m_database = attr.Value;
    			break;
    		case "sampleRate":
    			m_sampleRate = Convert.ToSingle(attr.Value);
    			break;
    	}
    }

    The differences is, of course, that Amazon's SimpleDB doesn't guarantee a specific order when returning key/value pairs. So I'm not switching on an already-known quantity.



  • @blakeyrat said:

    @Arancaytar said:

     I've seen that done. No idea what possesses people. It was first-year programmers in my case, though, so it's forgiveable if not understandable.

    To be fair, I use this similar construct in my own code:

    foreach (Amazon.SimpleDB.Model.Attribute attr in attrResult.Attribute)
    {
    	switch (attr.Name)
    	{
    		case "clientName":
    			m_clientName = attr.Value;
    			break;
    		case "server":
    			m_server = attr.Value;
    			break;
    		case "database":
    			m_database = attr.Value;
    			break;
    		case "sampleRate":
    			m_sampleRate = Convert.ToSingle(attr.Value);
    			break;
    	}
    }

    The differences is, of course, that Amazon's SimpleDB doesn't guarantee a specific order when returning key/value pairs. So I'm not switching on an already-known quantity.

    Foreach...switch is totally legitimate when you don't know the contents of what you're iterating over. How else would you do conditional logic based on values in a collection? You could use a bunch of if statements within the loop, but that's effectively the same as a switch (assuming the conditions are all simple equality tests on the same variable).



  • @Sloloem said:

    I'm still not entirely sure what thinking had led to the For-Switch loop, which is probably for the better.

    I have actually (just once) found a use to use the FOR-CASE code in one of my programs (although it changed the loop variable and did other things too), but the example given here is double-WTF!!


Log in to reply