5 Replies Latest reply on Aug 26, 2007 9:21 PM by Newsgroup_User

    Does php brace balancing work properly in CS3?

    Level 7
      The thing that causes me the most grief in PHP programming is the lack of a
      robust flow control mechanism. I am forever cursing Dijkstra for his paranoia
      which resulted in the blacklisting of the immensely useful goto statement.

      I find the if then else while maybe mess that results whenever I try to do
      anything moderately complex extremely hard to debug, and it is made much harder
      in Dreamweaver 8 because the brace balancing procedure accepts any brace, even
      it if it is in a comment or carelessly embedded in HTML.

      Consequently I am forever trying to find out why PHP is complaining that there
      are too few or too many braces, or I have got an infinite loop, when according
      to Dreamweaver all my braces are balanced nicely.

      Is CS3 any better?

      Clancy
        • 1. Re: Does php brace balancing work properly in CS3?
          Level 7
          On 23 Aug 2007 in macromedia.dreamweaver, Clancy wrote:

          > I find the if then else while maybe mess that results whenever I try
          > to do anything moderately complex extremely hard to debug, and it is
          > made much harder in Dreamweaver 8 because the brace balancing
          > procedure accepts any brace, even it if it is in a comment or
          > carelessly embedded in HTML.
          >
          > Consequently I am forever trying to find out why PHP is complaining
          > that there are too few or too many braces, or I have got an infinite
          > loop, when according to Dreamweaver all my braces are balanced
          > nicely.
          >
          > Is CS3 any better?

          I just took this block of code:

          switch ($theType) {
          case "text":
          $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
          break;
          case "date":
          $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
          break;
          }

          If I start with the cursor in one of the $theValues and do brace
          balancing as it is, it correctly goes to the () and then the {}. If I
          insert a } somewhere inside the (), DW CS3 selects from the opening {
          to the (incorrectly placed) }.

          --
          Joe Makowiec
          http://makowiec.net/
          Email: http://makowiec.net/contact.php
          • 2. Re: Does php brace balancing work properly in CS3?
            Level 7
            Clancy wrote:
            > The thing that causes me the most grief in PHP programming is the
            > lack of a robust flow control mechanism. I am forever cursing
            > Dijkstra for his paranoia which resulted in the blacklisting of the
            > immensely useful goto statement.
            >
            > I find the if then else while maybe mess that results whenever I try
            > to do anything moderately complex extremely hard to debug, and it is
            > made much harder in Dreamweaver 8 because the brace balancing
            > procedure accepts any brace, even it if it is in a comment or
            > carelessly embedded in HTML.
            >
            > Consequently I am forever trying to find out why PHP is complaining
            > that there are too few or too many braces, or I have got an infinite
            > loop, when according to Dreamweaver all my braces are balanced nicely.
            >
            > Is CS3 any better?
            >
            > Clancy

            When I learnt to program about 25 years ago we were told that a well
            structured program doesn't need any 'Go to' statements; and in the
            intervening time, I haven't seen anything to disavow that comment.

            I have never used the 'Balance Braces' procedure, so can't comment on how
            well (or not) it works, but when coding in PHP, I put in the braces as soon
            as I code the construct

            e.g if I'm writing a switch statement, I'll start with (using Joe's example)

            switch ($theType) {
            case "text":
            case "date":
            default:
            }

            ..then I'll go back and fill the gaps, knowing that my structure is in
            place.

            Regards,

            Pete
            --
            Peter Connolly
            http://www.acutecomputing.co.uk
            UK


            • 3. Re: Does php brace balancing work properly in CS3?
              Level 7
              .oO(Clancy)

              >The thing that causes me the most grief in PHP programming is the lack of a
              >robust flow control mechanism. I am forever cursing Dijkstra for his paranoia
              >which resulted in the blacklisting of the immensely useful goto statement.

              You should think in a more structured way and not in spaghetti code.
              A 'goto' is really ugly and hardly ever necessary, except in Assembler.

              >I find the if then else while maybe mess that results whenever I try to do
              >anything moderately complex extremely hard to debug

              Not really. Don't use just these language constructs, but also think
              about functions and procedures. A properly structured program is really
              not that difficult to debug (PHP doesn't even require a real debugger,
              although it would make things even more easier and convenient), but
              finding an error in a long spaghetti code is nearly impossible. Often
              you can't even easily grasp the control flow in such a mess.

              >, and it is made much harder
              >in Dreamweaver 8 because the brace balancing procedure accepts any brace, even
              >it if it is in a comment or carelessly embedded in HTML.

              That's not a problem with the code, but with the tool you use.

              >Consequently I am forever trying to find out why PHP is complaining that there
              >are too few or too many braces, or I have got an infinite loop, when according
              >to Dreamweaver all my braces are balanced nicely.

              If you don't like the way DW handles your code, why not have a look at
              another editor/IDE for writing PHP code? It also helps to properly
              indent your code and always write pairs of braces. If you open a block,
              also write a closing brace immediataly before adding any code between
              them. The same applies to string delimiters - write them both first,
              then add the text.

              Some IDEs like Eclipse/PDT for example do such things automatically.

              Micha
              • 4. Re: Does php brace balancing work properly in CS3?
                Level 7
                Joe Makowiec <makowiec@invalid.invalid> wrote:

                >If I start with the cursor in one of the $theValues and do brace
                >balancing as it is, it correctly goes to the () and then the {}. If I
                >insert a } somewhere inside the (), DW CS3 selects from the opening {
                >to the (incorrectly placed) }.

                Thanks. So updating to CS3 won't do me any good so far as this is concerned.

                Clancy
                • 5. Re: Does php brace balancing work properly in CS3?
                  Level 7
                  "PeteC" <noemailrequired@nospamrequired.co.uk> wrote:
                  Pete wrote:

                  >When I learnt to program about 25 years ago we were told that a well
                  structured program doesn't need any 'Go to' statements; and in the
                  intervening time, I haven't seen anything to disavow that comment.

                  Micha wrote

                  > You should think in a more structured way and not in spaghetti code.
                  > A 'goto' is really ugly and hardly ever necessary, except in Assembler.

                  The logic which led to the banning of the Goto is the same logic which ensures
                  that we use rubber cutlery to eat our meals on planes and, (if things continue
                  as they are going), will have us flying nude in a few years.

                  It is also used by my wife, who refuses to use my sharp knives because they make
                  it much easier to cut yourself. You CAN do most jobs with blunt implements, but
                  once you have learnt how to use them, you will find that they are much easier if
                  your tools are sharp.

                  A situation where
                  {
                  $i = 0; while ($i < 99)
                  {
                  {
                  }
                  ( lots of stuff)
                  }
                  }
                  }
                  $i++;
                  }

                  works as intended,
                  but
                  {
                  $i = 0; while ($i < 99)
                  {
                  {
                  }
                  ( lots of stuff)
                  }
                  }
                  }
                  }
                  $i++;

                  is an infinite loop, is inherently fragile.

                  It also amuses me that the same people who ban the Goto permit a Break
                  instruction. When I said 'Break' at the end of a lecture the students would
                  disappear. I had no idea where most of them went, and I was never quite sure if
                  I ever see some of them again. I have little more faith in the Break
                  instruction in computing. Execution disappears somewhere else, but if I am
                  doing anything remotely complex I find it almost impossible to predict where it
                  will eventually turn up.

                  However
                  xyz_1: Do xyz_9 (I =0,99,1)
                  [some stuff]
                  if (??) Goto xyz_9 elseif (??) Goto xyz_6
                  [some more stuff]
                  xyz_6:
                  [some more stuff]
                  xyz_9:

                  is inherently robust, and far less liable to fall in a big heap if you get
                  something slightly wrong in the middle.

                  I started programming 40 years ago using Fortran. That version provided an
                  assigned Goto, which, as I soon discovered, really was an invention of the
                  devil. Despite this I wrote an extremely complicated program for analysing
                  electronics circuits, which used its own interpretive language, but would run on
                  a computer with 32 K of 24 bit words.

                  In 1989 , while I was lecturing at a second-rate College of advanced
                  engineering, I wrote a simple assembler program to remove one virus from floppy
                  and hard disk boot sectors, and I gave it to my students as shareware. Nine
                  years later my program would detect , and usually remove, some thousands of
                  viruses. It could detect viruses in Word and Excel documents, in packed files,
                  with polymorphic encryptors and all manner of other nasty tricks to hide
                  themselves. It also allowed patches for new viruses to be plugged into the
                  existing engine from update files.

                  I was still responsible for the engine architecture, and it was still written in
                  assembler. My job would have been immeasurably more difficult if I had not been
                  able to use the robust control structure provided by Gotos.

                  And I wrote this message to get rid of some of my frustration, after spending
                  several hours working how to do something which would have been relatively
                  trivial using Gotos.

                  Clancy