On Tue, Feb 22, 2011 at 6:29 AM, Dotan Cohen <dotancohen@xxxxxxxxx> wrote: > I wrote a short page on how to actually type of code that one writes, > it can be found here: > http://dotancohen.com/howto/write_code.html > > The point that I stress on the page is that first you close an > element, then you fill it's contents. The page has examples in HTML > and PHP. I would like to know what the experienced programmers here > think about this. Am I going about it wrong? I'll be the first to tell you that I'm not a great programmer, so my take may not be worth a lot. However, this is pretty close to how I write. Not exactly, but close. I also always label open and closing brackets on everything, unless the brackets are less than three lines apart. For instance, I might find myself writing: if($foo == 'bar') { # Begin foo=bar test # If foo=bar, do a lot of things. } # End foo=bar test Then I go back and fill in the conditional stuff. I've found two sets of benefits to doing things this way. 1) I don't forget to close the brackets later, and I know they're indented properly. 2) The comments mean that if I get to the beginning of a section and want to skip to the end, I can just search for whatever comes after "Begin", and know that the next instance will be the end of that section. I also tend to document my code in comments before I start writing actual code. I frequently find that that helps keep me on track, rather than getting distracted by random new features that occur to me after I start. It also means that when the time comes to document what I did, most of it is already there... that's saved me a few times. (I tend to wind up with about a 2:1 ratio of comments to code, which at least means I can figure out later what I was thinking when I wrote that horrible mess.) So I can't say whether it's worthwhile practice for a good programmer who writes on a regular basis: for someone like me, who throws together an occasional script to save time later, or a personal web-site that needs a database backend, it can save a lot of aggravation. -Alex -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php