NYCPHP Meetup

[nycphp-talk] Best practices for naming conventions & coding style?

Anthony Wlodarski ant92083 at gmail.com
Mon Apr 27 16:58:13 EDT 2009


I think this is more of a comfort issue then an issue with standards.  If
you work for a company that you would fall back to the company's best
practice's.  If you are doing freelance/consulting work then you fallback to
your own CONSISTENT practices.

I emphasize consistent because when you open up a file in VIM that was
edited with tabs one week vs. two spaces for indents another week it becomes
a real nightmare.

-Anthony

On Mon, Apr 27, 2009 at 4:51 PM, lists at nopersonal.info <
lists at nopersonal.info> wrote:

> Hi everyone,
>
> I've been making steady (if slow) progress with my understanding of
> PHP/MySQL, but now that I'm finally starting to do more complex things,
> I find that I really need to figure out a consistent naming convention &
> coding style. I've read several articles on the subject and they all
> seem to be different.
>
> Is there a de facto professional standard, or is it just whatever you
> personally prefer (provided that you're not part of a larger team with
> specific guidelines)? So far I'm doing the following:
>
> -Functions are all lower case, no numbers, underscores used to separate
> words
> -Variables (same as functions--should they be different?)
> -Constants and MySQL reserved words & functions are all upper case
> -Classes... I'm not that advanced yet!
> -Plenty of comments to help me remember what the code was for
> -Tabs for indentation
> -No echoing HTML code except where moving between it and PHP is too messy
> -Stick with single quotes for string literals where there are no
> variable substitutions and/or where there ARE variable substitutions,
> but where using double quotes would necessitate lots of escaping
>
> Two things I've read about that I don't do are 1.) put spaces before &
> after the string concatenator, and 2.) keep my opening/closing braces on
> their own lines.
>
>
> //I find it much easier to read:
>
> if ($foo == '') {
>    echo '<p id="message" class="error">'.$message.'</p>';
> } else {
>    echo '<p id="message" class="success">'.$message.'</p>';
> }
>
> //Than:
>
> if ($foo == '')
> {
>    echo '<p id="message" class="error">' . $message . '</p>';
> }
> else
> {
>    echo '<p id="message" class="success">' . $message . '</p>';
> }
>
> Are any of the things I'm doing/not doing a major no-no? It's not too
> late for me to unlearn bad habits, so I'd really appreciate any advice
> you could give.
>
> Thanks,
>
> Bev
>
>
>
>
> _______________________________________________
> New York PHP User Group Community Talk Mailing List
> http://lists.nyphp.org/mailman/listinfo/talk
>
> http://www.nyphp.org/show_participation.php
>



-- 
Anthony W.
ant92083 at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20090427/f641e7a4/attachment.html>


More information about the talk mailing list