Yet another inexplicable js error!

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Patrick Stone

    #1

    Yet another inexplicable js error!

    Here's a reason why javascript sucks so bad. The following *SIMPLE*
    piece of code will not work properly. Jesus, how I yearn for the day
    when a real programming language can be substituted for this patched
    together scripting horror. I suspect the string object's methods are
    simply not robust enough for this because neither of the strings
    appear to have the value they should when this loop runs. Perl would
    handle this kind of thing with no problem. Javascript definitely needs
    to catch up. (Sorry about the rant, but for a long-time programmer
    this is terribly frustrating!)

    -----------------

    for (x=0; x<=theStr.lengt h; x++);
    {
    theNewStr += theStr.charAt(x );
    }

    -----------------

    --pstone
  • KC Wong

    #2
    Re: Yet another inexplicable js error!

    > Here's a reason why javascript sucks so bad. The following *SIMPLE*[color=blue]
    > piece of code will not work properly. Jesus, how I yearn for the day
    > when a real programming language can be substituted for this patched
    > together scripting horror. I suspect the string object's methods are
    > simply not robust enough for this because neither of the strings
    > appear to have the value they should when this loop runs. Perl would
    > handle this kind of thing with no problem. Javascript definitely needs
    > to catch up. (Sorry about the rant, but for a long-time programmer
    > this is terribly frustrating!)
    >
    > for (x=0; x<=theStr.lengt h; x++);
    > {
    > theNewStr += theStr.charAt(x );
    > }[/color]

    Notice that there's a semi-colon after the for statement? I hope it's a
    typing error when you're posting...


    KC


    Comment

    • Lee

      #3
      Re: Yet another inexplicable js error!

      Patrick Stone said:[color=blue]
      >
      >Here's a reason why javascript sucks so bad. The following *SIMPLE*
      >piece of code will not work properly. Jesus, how I yearn for the day
      >when a real programming language can be substituted for this patched
      >together scripting horror. I suspect the string object's methods are
      >simply not robust enough for this because neither of the strings
      >appear to have the value they should when this loop runs. Perl would
      >handle this kind of thing with no problem. Javascript definitely needs
      >to catch up. (Sorry about the rant, but for a long-time programmer
      >this is terribly frustrating!)
      >
      >-----------------
      >
      >for (x=0; x<=theStr.lengt h; x++);
      >{
      > theNewStr += theStr.charAt(x );
      >}[/color]

      It's interesting that the more a person rants about the lousy
      programming language, the more obvious the coding errors are.
      There are two pretty obvious errors in those few lines. We
      can only guess what you've done wrong in your other code.

      for (x=0; x<theStr.length ; x++)
      {
      theNewStr += theStr.charAt(x );
      }

      I don't want to know why you would ever copy a string one
      character at a time.

      Comment

      • Spamless

        #4
        Re: Yet another inexplicable js error!

        In article <f24660dd.03092 32148.1b437bc7@ posting.google. com>, Patrick Stone wrote:
        [color=blue]
        > Perl would handle this kind of thing with no problem.[/color]

        No it wouldn't.

        Perl would require the for loop to have a bracket expression
        before terminating:

        for (x=0; x<=theStr.lengt h; x++){};

        instead of your

        for (x=0; x<=theStr.lengt h; x++);

        (if you want to terminate the for loop before
        doing anything, as you are doing)
        [color=blue]
        > -----------------
        >
        > for (x=0; x<=theStr.lengt h; x++);
        > {
        > theNewStr += theStr.charAt(x );
        > }
        >
        > -----------------
        >
        > --pstone[/color]

        Comment

        • Grant Wagner

          #5
          Re: Yet another inexplicable js error!

          Patrick Stone wrote:
          [color=blue]
          > Here's a reason why javascript sucks so bad. The following *SIMPLE*
          > piece of code will not work properly. Jesus, how I yearn for the day
          > when a real programming language can be substituted for this patched
          > together scripting horror. I suspect the string object's methods are
          > simply not robust enough for this because neither of the strings
          > appear to have the value they should when this loop runs. Perl would
          > handle this kind of thing with no problem. Javascript definitely needs
          > to catch up. (Sorry about the rant, but for a long-time programmer
          > this is terribly frustrating!)
          >
          > -----------------
          >
          > for (x=0; x<=theStr.lengt h; x++);
          > {
          > theNewStr += theStr.charAt(x );
          > }
          >
          > -----------------
          >
          > --pstone[/color]

          In addition to everything everyone else has said, I'd like to point out
          that JavaScript is hardly a "patched together scripting horror", and if it
          *were*, this is certainly not evidence of it. The loop as written above
          would do precisely the same thing in C, C++, C# and Java (assuming you
          modified the code to conform to the particular nuances of the language you
          choose), and none of those languages are "patched together scripting
          horrors".

          As for your suspicion that it has to do with some "lack of robustness" in
          the String objects methods, try again. The String object has a
          full-featured set of methods which do a fine job of even extremely complex
          string manipulations.

          By the way, your code, as written above, is equivilent to:

          theNewStr = theStr;

          If you are processing the string one character at a time in order to
          identify and manipulate specific characters, there's probably a myriad of
          better ways of doing it then by chugging through the string one character
          at a time. Want to capitalize the first character of every word?

          String.prototyp e.toMixedCase = function() {
          function toUpper(sChar) { return sChar.toUpperCa se(); }

          return this.toLowerCas e().replace(/\b(.)/g, toUpper);
          }

          theNewStr = theStr.toMixedC ase();

          Want to remove all the spaces from the string?

          theNewStr = theStr.split(' ').join('');

          // or

          theNewStr = theStr.replace(/ /g, '');

          Want to identify the '#' character and everything that comes after it, but
          only if you find it in the string?

          if (/#(.*)/.test(theStr)) {
          alert('theStr contained a # and ' + RegExp.$1 + ' came after it');
          }

          So yeah, I guess you're right, JavaScript is just a non-functional mess
          that can't do anything. Better go back to Perl where you can loop through
          every character in a string to accomplish the same goals.

          --
          | Grant Wagner <gwagner@agrico reunited.com>

          * Client-side Javascript and Netscape 4 DOM Reference available at:
          *


          * Internet Explorer DOM Reference available at:
          *
          http://msdn.microsoft.com/workshop/a...ence_entry.asp

          * Netscape 6/7 DOM Reference available at:
          * http://www.mozilla.org/docs/dom/domref/
          * Tips for upgrading JavaScript for Netscape 7 / Mozilla
          * http://www.mozilla.org/docs/web-deve...upgrade_2.html


          Comment

          • Zac Hester

            #6
            Re: Yet another inexplicable js error!

            Grant Wagner wrote:
            [color=blue]
            > Patrick Stone wrote:
            >
            >[color=green]
            >>Here's a reason why javascript sucks so bad. [snippy-snip][/color]
            >
            > So yeah, I guess you're right, JavaScript is just a non-functional mess
            > that can't do anything. Better go back to Perl where you can loop through
            > every character in a string to accomplish the same goals.
            >[/color]

            The irony here is that Perl is built around complex string manipulation
            and has a lot more string methods than JavaScript. Why he would ever
            try to evaluate a string one character at a time in Perl is something
            far beyond the grasp of any mortal programmer. Your arguments
            supporting JavaScript apply to Perl in every way. In Perl, he should be
            using:

            $TheNewString = $TheString;

            I've even found it more combersome to switch back to C-style string
            manipulation (one character at a time) in Perl than to just RTM and find
            out how to use one of the hundreds of string manipulation features.

            I know how it feels to do everything the hard way for a while until I
            crack open a book and say, "Oh, so that's how you do it..." I would
            suggest to the OP a trip to the nearest bookstore that sells any
            O'Reilly and Associates books. (Maybe "Programmin g Perl" would also be
            a good buy alongside the venerable "JavaScript : The Definitive Guide.")

            Happy reading,
            Zac

            Comment

            Working...