With clause syntax errors but how do I fix it?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dr John Stockton

    #16
    Re: With clause syntax errors but how do I fix it? (correction)

    JRS: In article <bj02q2$bi1$1@n ews.eusc.inter. net>, seen in
    news:comp.lang. javascript, DU <drunclear@hotR EMOVEmail.com> posted at
    Mon, 1 Sep 2003 14:23:00 :-[color=blue]
    >
    >Finally, please avoid top-posting in this newsgroup.[/color]

    The term "top-posting" should not be used to a newcomer, since it will
    not be understood by the average innocent top-poster.

    Something like "responses should follow trimmed quotes" does not take
    much longer to type.

    Alternatively, if "top-posting" is used, the term should be defined in
    the FAQ, and "; see FAQ" added. Plus, preferably, a link to the FAQ.



    IMHO, javascript 'with' is a useful tool which can readily be misused.
    IMHO, it can be good to use it when anyone reading the code for the
    first time will, having not noticed the 'with', be able to deduce it.

    with (document) {
    write('This<br> ')
    write(That, [them])
    }

    with (MyDate)
    document.write( getFullYear()+'/'+LZ(getMonth() +1)+
    '/'+LZ(getDate()) )

    Where the contents of the with parentheses would be lengthy, the
    alternative of using an auxiliary variable is that a new variable,
    probably terse, will remain in scope until the end of the block; a human
    author might reuse it without remembering to give it a new value.

    --
    © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
    <URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang. javascript
    <URL:http://www.merlyn.demo n.co.uk/js-index.htm> JS maths, dates, sources.
    <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/JS/&c., FAQ topics, links.

    Comment

    • Douglas Crockford

      #17
      Re: With clause syntax errors but how do I fix it? (correction)

      > I don't know what is more unreadable, how you view a "with" clause, or this:[color=blue]
      >
      > document.alertF orm.elements[i].options[document.alertF orm.elements[i].select
      > edIndex].value
      >
      > I think that is utterly unreadable myself! I was trying to come up with an
      > elegant and readable solution to parse through form elements for client-side
      > validation. :([/color]

      The with statement should be avoided. Use a var to do what you would do with
      with.

      var e = document.alertF orm.elements[i];
      ... e.options[e.selectedIndex].value ...

      The var lets you be explicit, while the with can have surprising and seemingly
      random behavior. The appearance of with in the language was well intentioned,
      but it was a mistake and it should be removed.



      Comment

      • DU

        #18
        Re: With clause syntax errors but how do I fix it? (correction)

        Dr John Stockton wrote:
        [color=blue]
        > JRS: In article <bj02q2$bi1$1@n ews.eusc.inter. net>, seen in
        > news:comp.lang. javascript, DU <drunclear@hotR EMOVEmail.com> posted at
        > Mon, 1 Sep 2003 14:23:00 :-
        >[color=green]
        >>Finally, please avoid top-posting in this newsgroup.[/color]
        >
        >
        > The term "top-posting" should not be used to a newcomer, since it will
        > not be understood by the average innocent top-poster.
        >[/color]

        How do you figure out who is a newcomer in a newsgroup? How can you
        reasonably do that?
        [color=blue]
        > Something like "responses should follow trimmed quotes" does not take
        > much longer to type.
        >
        > Alternatively, if "top-posting" is used, the term should be defined in
        > the FAQ, and "; see FAQ" added. Plus, preferably, a link to the FAQ.
        >
        >[/color]

        I'm all for defining "top-posting" in this newsgroup FAQ and I'm all for
        explaining why top-posting just makes reading posts, replies and threads
        harder for others.
        Top-posting is not the natural reading direction for 99.99% of users in
        this newsgroup... unless you really read from bottom to top (like
        ancient Chinese).
        Top-posting destroys chronological order of posts in threads.
        Top-posting destroys logical reading context.
        Top-posting makes others constantly scroll up and down to figure out
        what was said and then what was replied: there is no book, document,
        paper anywhere which goes like that. No one reads a book from end to
        start. No one reads an interview in a magazine by first reading the
        answers to questions. No one reads solutions first and then problem
        descriptions. I don't video-tape a movie from end to start.
        Top-posting generally makes it harder to understand message posts context.

        DU
        --
        Javascript and Browser bugs:

        - Resources, help and tips for Netscape 7.x users and Composer
        - Interactive demos on Popup windows, music (audio/midi) in Netscape 7.x


        Comment

        • Phil Powell

          #19
          Re: With clause syntax errors but how do I fix it? (correction)

          Thanx for your help.

          "DU" <drunclear@hotR EMOVEmail.com> wrote in message
          news:bj2jv8$aq1 $1@news.eusc.in ter.net...[color=blue]
          > Dr John Stockton wrote:
          >[color=green]
          > > JRS: In article <bj02q2$bi1$1@n ews.eusc.inter. net>, seen in
          > > news:comp.lang. javascript, DU <drunclear@hotR EMOVEmail.com> posted at
          > > Mon, 1 Sep 2003 14:23:00 :-
          > >[color=darkred]
          > >>Finally, please avoid top-posting in this newsgroup.[/color]
          > >
          > >
          > > The term "top-posting" should not be used to a newcomer, since it will
          > > not be understood by the average innocent top-poster.
          > >[/color]
          >
          > How do you figure out who is a newcomer in a newsgroup? How can you
          > reasonably do that?
          >[color=green]
          > > Something like "responses should follow trimmed quotes" does not take
          > > much longer to type.
          > >
          > > Alternatively, if "top-posting" is used, the term should be defined in
          > > the FAQ, and "; see FAQ" added. Plus, preferably, a link to the FAQ.
          > >
          > >[/color]
          >
          > I'm all for defining "top-posting" in this newsgroup FAQ and I'm all for
          > explaining why top-posting just makes reading posts, replies and threads
          > harder for others.
          > Top-posting is not the natural reading direction for 99.99% of users in
          > this newsgroup... unless you really read from bottom to top (like
          > ancient Chinese).
          > Top-posting destroys chronological order of posts in threads.
          > Top-posting destroys logical reading context.
          > Top-posting makes others constantly scroll up and down to figure out
          > what was said and then what was replied: there is no book, document,
          > paper anywhere which goes like that. No one reads a book from end to
          > start. No one reads an interview in a magazine by first reading the
          > answers to questions. No one reads solutions first and then problem
          > descriptions. I don't video-tape a movie from end to start.
          > Top-posting generally makes it harder to understand message posts context.
          >
          > DU
          > --
          > Javascript and Browser bugs:
          > http://www10.brinkster.com/doctorunclear/
          > - Resources, help and tips for Netscape 7.x users and Composer
          > - Interactive demos on Popup windows, music (audio/midi) in Netscape 7.x
          > http://www10.brinkster.com/doctorunc...e7Section.html
          >[/color]


          Comment

          • Lasse Reichstein Nielsen

            #20
            Re: With clause syntax errors but how do I fix it? (correction)

            "Douglas Crockford" <nospam@laserli nk.net> writes:
            [color=blue]
            > The var lets you be explicit, while the with can have surprising and
            > seemingly random behavior.[/color]

            Can you give examples of deliberate use of "with" that has surpricing
            and seemingly random behavior?
            [color=blue]
            > The appearance of with in the language
            > was well intentioned, but it was a mistake and it should be removed.[/color]
            [color=blue]
            > http://www.crockford.com/javascript/survey.html[/color]

            (where all you say is "The with statement should be avoided" :))
            /L
            --
            Lasse Reichstein Nielsen - lrn@hotpop.com
            Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
            'Faith without judgement merely degrades the spirit divine.'

            Comment

            • Laurent Bugnion, GalaSoft

              #21
              Re: With clause syntax errors but how do I fix it? (correction)

              Hi,

              Lasse Reichstein Nielsen wrote:
              [color=blue]
              > "Douglas Crockford" <nospam@laserli nk.net> writes:
              >
              >[color=green]
              >>The var lets you be explicit, while the with can have surprising and
              >>seemingly random behavior.[/color]
              >
              >
              > Can you give examples of deliberate use of "with" that has surpricing
              > and seemingly random behavior?
              >
              >[color=green]
              >>The appearance of with in the language
              >>was well intentioned, but it was a mistake and it should be removed.[/color]
              >
              >[color=green]
              >>http://www.crockford.com/javascript/survey.html[/color]
              >
              >
              > (where all you say is "The with statement should be avoided" :))
              > /L[/color]

              Here is a very simple example to illustrate the problem:

              var name = "Laurent Bugnion";

              with ( document.formNa me )
              {
              alert( name );
              }

              This very simple example is already confusing, because I am not supposed
              to know that there is a property called "name" in the Form object. I
              cannot know that a property named like this exists in the object without
              reading the API documentation.

              This very simple example is not very confusing, however, because it
              deals with an object and a property that we all know well. However, I
              can do that with any other object, for which an API documentation might
              not be available, might be more or less readable, etc...

              Besides, "with" statements can be replaced by local variables, who have
              all the advantages and none of the inconvenients. The readability will
              be much better (you can event comment in the code why you feel the need
              to replace one construct by another one, etc...).

              Not even mentioning the fact that others stated, that "with" is slow,
              memory intensive, etc..., I find that it complicates the code without
              being useful. Since it is always good to make the readibility of your
              code better, I would really recommend dropping "with" statements and
              using explicit local variable declaration (and duly commented too) instead.

              Hope that helps,

              Laurent
              --
              Laurent Bugnion, GalaSoft
              Webdesign, Java, JavaScript: http://www.galasoft-LB.ch
              Private/Malaysia: http://mypage.bluewin.ch/lbugnion
              Support children in Calcutta: http://www.calcutta-espoir.ch

              Comment

              • Lasse Reichstein Nielsen

                #22
                Re: With clause syntax errors but how do I fix it? (correction)

                "Laurent Bugnion, GalaSoft" <galasoft-LB@bluewin_NO_S PAM.ch> writes:
                [color=blue]
                > Here is a very simple example to illustrate the problem:
                >
                > var name = "Laurent Bugnion";
                >
                > with ( document.formNa me )
                > {
                > alert( name );
                > }
                >
                > This very simple example is already confusing, because I am not
                > supposed to know that there is a property called "name" in the Form
                > object. I cannot know that a property named like this exists in the
                > object without reading the API documentation.[/color]

                The point is that you should not use the "with" statement without
                knowing your object. I can see that that makes it a dangerous
                construction for beginners. It also means that you should either
                use "with" on objects you have created yourself, and when using
                it on other objects, don't access other variables directly.
                [color=blue]
                > This very simple example is not very confusing, however, because it
                > deals with an object and a property that we all know well. However, I
                > can do that with any other object, for which an API documentation
                > might not be available, might be more or less readable, etc...[/color]

                Yes, know your object, or don't "with" it! :)
                [color=blue]
                > Besides, "with" statements can be replaced by local variables, who
                > have all the advantages and none of the inconvenients. The readability
                > will be much better (you can event comment in the code why you feel
                > the need to replace one construct by another one, etc...).[/color]

                That is a point. There is not much saved between writing
                objProperty
                and
                o.objProperty
                [color=blue]
                > Not even mentioning the fact that others stated, that "with" is slow,
                > memory intensive, etc...,[/color]

                Blame the implementation, not the language! :)
                [color=blue]
                > I find that it complicates the code without being useful. Since it
                > is always good to make the readibility of your code better, I would
                > really recommend dropping "with" statements and using explicit local
                > variable declaration (and duly commented too) instead.[/color]

                That is a much better argument. Readable code saves more developer
                time than code optimizations save running time :)

                /L
                --
                Lasse Reichstein Nielsen - lrn@hotpop.com
                Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
                'Faith without judgement merely degrades the spirit divine.'

                Comment

                • Dr John Stockton

                  #23
                  Re: With clause syntax errors but how do I fix it? (correction)

                  JRS: In article <bj2jv8$aq1$1@n ews.eusc.inter. net>, seen in
                  news:comp.lang. javascript, DU <drunclear@hotR EMOVEmail.com> posted at
                  Tue, 2 Sep 2003 13:28:06 :-[color=blue]
                  >Dr John Stockton wrote:
                  >[color=green]
                  >> JRS: In article <bj02q2$bi1$1@n ews.eusc.inter. net>, seen in
                  >> news:comp.lang. javascript, DU <drunclear@hotR EMOVEmail.com> posted at
                  >> Mon, 1 Sep 2003 14:23:00 :-
                  >>[color=darkred]
                  >>>Finally, please avoid top-posting in this newsgroup.[/color]
                  >>
                  >> The term "top-posting" should not be used to a newcomer, since it will
                  >> not be understood by the average innocent top-poster.
                  >>[/color]
                  >
                  >How do you figure out who is a newcomer in a newsgroup? How can you
                  >reasonably do that?[/color]

                  If it is not a newcomer, then it is clearly a person who is not worth
                  bothering with, or a person who needs a detailed explanation. However,
                  one can recognise many non-newcomers by name, and many newcomers by what
                  they write.

                  [color=blue]
                  >--[/color]
                  DSS & STL.

                  --
                  © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 MIME. ©
                  Web <URL:http://www.merlyn.demo n.co.uk/> - FAQish topics, acronyms, & links.
                  Proper <= 4-line sig. separator as above, a line exactly "-- " (SonOfRFC1036)
                  Do not Mail News to me. Before a reply, quote with ">" or "> " (SonOfRFC1036)

                  Comment

                  Working...