Archive

Archive for the ‘php’ Category

php: Whats your commenting style?

August 14th, 2007 ^Lestat 89 comments

I was writing up a few scripts and as I was adding my commenting I noticed I tend to comment differently depending on the difficulty of the script and how many different parts or procedures there are to it. I don’t have a set convention, but I suppose as with all things it would make things easier on myself and others if I had some kind of standardization…

For larger ‘areas’ that contain functions or a series of procedures that extract or parse sections of data I’m now starting with this:

/***
*
* This is a comment.
* Here I leave notes about the section and what it does.
* I may also include notes to myself here.
* Note: This could probably be done more eficiently
*
*/

As there are more breakdowns within these sections I’m using this:

/*  [ Parse out the text file ]  */

And further drilled down I use the more inline commenting

/*  [ Print data]  */

$parts = explode("|", $the_array); // get the parts

$color = false; // set color var for shading every other row

print("<table>"); 

// loop through data & print
foreach($parts as $key => $row){ 

    // CSS Note: shading <tr>'s with css mostly works with nice browsers
    // For IE 6+ one needs to shade the <td>'s

    if($color){
        print("<tr class=\"rowColor1\"> "); // start row with color 1
        $color = !$color; // unset the color so it alternates next loop
    } else {
        print("</tr><tr class=\"rowColor2\"> "); // start row with color 2
        $color = true; // set the color so it alternates next loop
    }

    print("<td>$row[first_name]</td></tr>"); // print cell data and close the row
}

print("</td></tr></table>");

The inline comments still seem a bit ‘messy’ to me. But for now it will work.

One of the reasons I decided to standardize is because even with commenting and extra line spaces in the scripts it was still difficult to sort out what exactly was going on. Another thing that tripped my thought was having a glance at phpDocumentor. It seems to function on how you comment your code. I did try to install it but for some reason it was way over my head. It looks like a neat tool but I rarely seem to write more than 4 different files and those are often less than 300-400 lines.

I’ve yet to test it in comments but my plugin to allow code viewing is much like bbc code. [code lang="php"] // comment [/code]

So whats your style? Is there a standard? What have you seen that looks the cleanest? Leave a comment… with some comments ;-)

Update 12/3/07 Elizabeth Naramore has written a nice article on the effectiveness of comments in your code over at the Chris Shiflett blog. It’s a great read on WHY commenting is good in your code.

php, comment, code, script, php+script, php+comment

Categories: Programming, php Tags:

My Favorite Dev Tools

March 8th, 2007 ^Lestat 3 comments

I’ve recently reformatted my computer and started missing my favorite dev tools. In an attempt to record them, I can also share them with others.

A list of my current favorite web tools…

Text Editor:

Compression Utility:

  • IZARC – IMO, better than winzip

Localhost Server (Apache/mySQL):

  • Wamp – Run an Apache web server on your PC. You can configure it to run or not run on startup. It also includes mySQl and a few php extensions.

Firefox extensions:

  • measureit – Measure pixels right on your screen.
  • colorzilla – Grab colors off of web pages, zoom, and built in color picker.
  • web developer – CSS, XHTML, Screen resize, line guides, disable styles and much much more.
  • firebug – A great tool especially for pages created in php. You may have 100 lines of code before the html begins. This helps you debug xhtml issues on “line 12″ which is actually line 112. Works well with included php files as well.

IE Explorer Add On:

  • IE Dev Toolbar(For IE Similar to Firebug)
  • Tools, Dev, Developer, Dev Tools

Categories: Computing, Internet, Programming, css, php Tags:

ODBC Viewer

February 28th, 2007 ^Lestat 1 comment

I had recently been peeking into a SQL database via Microsoft Access. I got quite used to browsing all the tables and fields, seeing their data types, and visually seeing their relationships. I’ve just began a project that connects to a proprietary(aged) database that uses ODBC to connect to it. Access would not allow me to view this the same (At least I couldn’t figure it out).

After a quick search I found a freeware application called passportODBC(You can download from other locations/ sites). It does require some information from you to register it. Some basic info like your name, and email and a phone number.

passportODBC

It’s not as fast as access and SQL server 2005, but I’m suspecting a lot of that has to do that it is ODBC. It’s really quite simple to use. Choose your data source, enter some credentials and go. You can view tables, all the fields, and the field attributes.

ODBC, programming, database

Update 2/28/07 1:20PM
Embassy Software offers the download direct from their site.

Update 5/16/07
I found a more simple tool for viewing via ODBC. You can compose queries and the likes. It’s much more simple to use (for me anyways) ODBC View can be downloaded from sliksoftware.co.nz

Categories: Computing, Programming, php Tags:

REGEX Library

March 9th, 2006 ^Lestat 3 comments

I was working up a form and needed to come up with an email regex. I know by now I probably should have my own regex library, or even be able to write my own – but I haven’t exercised my regex skills enough. Often time doesn’t allow an extensive learning period when your already half way through creating a form!

I came across this great regex library at regexlib.com. It’s searchable, offers on the fly tests of user contibuted regular expresssions, rss feeds of recently added patterns, and contains a Cheat Sheet for regex reference.

Of course, programmer beware. Be careful copying and pasting code. And definately test that code before you implement it.

regex, php

Categories: Programming, php, php Snippets Tags:

php: syntax woes

January 3rd, 2006 ^Lestat No comments

Today I fought what I thought was some kind of permissions error. I was learning how to create a database table in mySQL with php.

After 3 hours I figured out my error was due to syntax.
“AUTO-INCREMENT” is not the same as “AUTO_INCREMENT”

I looked over that line at least a thousand times thinking – thats right.

When you are trouble shooting code:
Break down the elements.
Print out the variables print_r();
Put in escape messages while you are creating:

if($this_is_true){
  print("Its all good<br />");
} else {
  print("Houston, we've got a problem");
}

or print all the elements getting $_POSTED:

print_r($_POST);

or print all the elements in an array:

print_r($myArray);

…it only takes a few seconds to code that temporarily in to your code to help find problems.

Categories: Programming, php Tags: