TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 08-27-2009, 04:42 PM   #1 (permalink)
The Wanderer
 
eStrategy's Avatar
 
Join Date: Aug 2009
Location: Torquay
Posts: 16
Thanks: 2
eStrategy is on a distinguished road
Default Your Naming Conventions

Please share with me you class, function and variable naming conventions.

Do you use m_ for member functions?
Propercase, lowercare etc..

Do you put a type identifier at the start of your variables?

$sString, $aArray etc..


What conventions do you use and why??

Thanks
__________________
Search Marketing
Send a message via Skype™ to eStrategy
eStrategy is offline  
Reply With Quote
Old 08-27-2009, 10:49 PM   #2 (permalink)
The Addict
 
Join Date: May 2009
Posts: 287
Thanks: 5
adamdecaf is on a distinguished road
Default

PHP Code:
define("SOME_CONSTANT"42);

class 
something_class // I always have "_class" after.
   
public var $foo_bar;

   public function 
this_function($var1$var2) {
       echo 
$var2 ' ' $var1;
   }

__________________
My Site
adamdecaf is offline  
Reply With Quote
Old 08-27-2009, 11:04 PM   #3 (permalink)
The Addict
 
Enfernikus's Avatar
 
Join Date: Jun 2008
Posts: 335
Thanks: 2
Enfernikus is on a distinguished road
Default

Hungarian ( Which is CamelCase but with the datatype ) & CamelCase
__________________
My Blog
Enfernikus is offline  
Reply With Quote
Old 09-25-2009, 11:24 AM   #4 (permalink)
That guy
 
cachepl0x's Avatar
 
Join Date: Sep 2009
Location: San Antonio, TX
Posts: 24
Thanks: 0
cachepl0x is on a distinguished road
Default

PHP Code:
# Comment with a pound

class Conf
{
    const 
name "name";
    const 
age  "20";
}

class 
Main extends Conf                    # Always capitalize class names.
{
    public 
$var      name;             # Typical
    
public $othervar age;              # No camelCase. I can't stand it.
    
    
public function FunctionName()         # Also Caps.
    
{
        echo 
$var "is " $othervar;
    }
    

cachepl0x is offline  
Reply With Quote
Old 09-25-2009, 12:13 PM   #5 (permalink)
The Contributor
 
Sirupsen's Avatar
 
Join Date: May 2009
Posts: 53
Thanks: 2
Sirupsen is on a distinguished road
Default

Classes: CamelCase (But their in 99/100 cases one word)
Functions: CamelCase
Strings: small_letters_with_underscores
Constants: CAPS
Send a message via AIM to Sirupsen Send a message via MSN to Sirupsen Send a message via Yahoo to Sirupsen Send a message via Skype™ to Sirupsen
Sirupsen is offline  
Reply With Quote
Old 09-26-2009, 10:20 PM   #6 (permalink)
how quixotic are you?
 
ETbyrne's Avatar
 
Join Date: Dec 2007
Location: Lapeer, MI
Posts: 445
Thanks: 37
ETbyrne is on a distinguished road
Default

Variable, function, and class names: lowercase with underscores
Constants: caps
Indention: tabs (doesn't work in this code editor)

PHP Code:
define('MY_CONSTANT','value');


class 
mysql
{
    private 
$con;


    public function 
__construct($host,$database,$user,$pass=NULL)
    {
        
// ...
    
}


    public function 
query($sql)
    {
        
// ...
        
return($results);
    }
}


$mysql = new mysql('localhost','mydb','root','pass');

$results $mysql->query('SELECT * FROM `mytable`'); 
I tend to avoid CamelCase because a lot of times you come across strange looking names like getId(). Then you have to decide between breaking your code convention to make it look right or just leaving it to look odd.

Plus typing all lowercase is easier on the fingers
__________________
Dingo Web Systems > http://www.dingocode.com
My Website > http://www.evanbot.com
ETbyrne is offline  
Reply With Quote
Old 09-27-2009, 02:03 AM   #7 (permalink)
The Contributor
 
Join Date: Mar 2009
Posts: 49
Thanks: 0
TheOnly92 is on a distinguished road
Default

All these are almost like religions, just find 1 that will suit for you and it will do good in your programming.
__________________
There are no noobs and pros in this world, only people who know how to use Google and those who don't.
TheOnly92 is offline  
Reply With Quote
Old 09-27-2009, 04:36 PM   #8 (permalink)
The Addict
 
Join Date: May 2009
Posts: 287
Thanks: 5
adamdecaf is on a distinguished road
Default

Quote:
Originally Posted by TheOnly92 View Post
All these are almost like religions, just find 1 that will suit for you and it will do good in your programming.
"A good programmer would be able to switch styles from project to project."

Some programmers do hold their styles to similar statuses as religious beliefs.
__________________
My Site
adamdecaf is offline  
Reply With Quote
Old 09-28-2009, 12:39 AM   #9 (permalink)
The Contributor
 
ioan1k's Avatar
 
Join Date: Mar 2009
Location: US
Posts: 76
Thanks: 0
ioan1k is on a distinguished road
Default

CamelCasing everything except for array keys there are seperated with a "_"

I also keep a very tidy codestructure ...

I do follow this religiously ... as most experienced programmers do, as far as switching when I am on another project ... I either will integrate my standard in as conventions most I see are extremely sloppy or I lead the project and I set it anyway

Quote:
I tend to avoid CamelCase because a lot of times you come across strange looking names like getId(). Then you have to decide between breaking your code convention to make it look right or just leaving it to look odd.
I too once followed the same mentality and used just about the same convention using underscores, but once you get used to CamelCasing you come to wonder why you coded that way in the first place, as i find it much much easier to read it CamelCased ... and the look doesnt have to make sense :)

php Code:
/**
     * Administration Login
     */

    public function login()
    {
        $this->view->headerTitle(__('Login'));
       
        if (!$this->session->sessionExists('admin_login_lock')) {
            $this->session->startSession('admin_login_lock');
        }

        if ($this->session->sessionExists('admin_login_lockout')) {
            $this->lock_out = true;
            $this->session->sessionDestroy('admin_login_lock');
            echo $this->view->getHtml('login');
        }

        if (!$this->request->isPost()) {
            $this->form = new Unus_Form('login_form', '');
            $username = $this->form->addElement('text', 'username');
            $username->setLabel(__('Username'))->setRequire(array(
                                                                  'msg' => array(
                                                                                 'required'     => __('Please enter your username'),
                                                                                 'minlength'    => __('Your username must be at least 4 characters'),
                                                                                 'alpha_num'    => __('I\m sorry, you are only allowed letters and numbers, please choose another')    ,
                                                                                ),
                                                                  'val' => array(
                                                                                 'required'     => 'true',
                                                                                 'minlength'    => '4',
                                                                                 'alpha_num'    => 'true',
                                                                                )
                                                                )
                                                            );
            $password = $this->form->addElement('password', 'password')->setRequire(array(
                                                                                          'msg' => array(
                                                                                                         'required' => __('Please enter you password'),
                                                                                                         //'pwd_chk' => __('Your password must must be at least 6 characters in length, contain a number, uppercase and lowercase letter') 
                                                                                                         ),
                                                                                          'val' => array(
                                                                                                         'required' => 'true',
                                                                                                         'pwd_chk' => 'true'
                                                                                                        )
                                                                                         )
                                                                                   );
            $submit = $this->form->addElement('submit', 'submit');
            $submit->setClass('key')->setValue(__('Login'))->setLabel(false);
            $button = $this->form->addElement('button', 'forgot_password');
            $button->setClass('help')->setValue(__('Lost Password'))->setLabel(false);

            $this->form->setDecorator(array(
               'form_start' => false,
               'form_end' => false,
               'row_start' => false,
               'row_end' => false,
               'label_start' => false,
               'label_end' => false,
               'element_start' => false,
               'element_end' => false,
               'element_submit_label_start' => false,
               'element_submit_label_end' => false,
               'element_submit_start' => '<div class="clear"></div>',
               'element_submit_end' => ' ',
            ));

            echo $this->view->getHtml('login');

        } else {
__________________
My Portfolio - Work - Need freelance Work?
I've been developing 5 years now, and I learn something new everyday
ioan1k is offline  
Reply With Quote
Old 09-28-2009, 01:12 AM   #10 (permalink)
how quixotic are you?
 
ETbyrne's Avatar
 
Join Date: Dec 2007
Location: Lapeer, MI
Posts: 445
Thanks: 37
ETbyrne is on a distinguished road
Default

Quote:
I do follow this religiously
I'm really hoping that's an overstatement...

Quote:
I too once followed the same mentality and used just about the same convention using underscores, but once you get used to CamelCasing you come to wonder why you coded that way in the first place, as i find it much much easier to read it CamelCased ... and the look doesnt have to make sense :)
It just comes down to personal preference. Honestly it doesn't matter which one you use, as long as it is easy for you and other programmers to follow.
__________________
Dingo Web Systems > http://www.dingocode.com
My Website > http://www.evanbot.com
ETbyrne is offline  
Reply With Quote
Old 09-28-2009, 01:30 AM   #11 (permalink)
The Contributor
 
ioan1k's Avatar
 
Join Date: Mar 2009
Location: US
Posts: 76
Thanks: 0
ioan1k is on a distinguished road
Default

Quote:
Originally Posted by ETbyrne View Post
I'm really hoping that's an overstatement...
Haha it was not :)

Standards to me are extremely important and 99% of the time will make or break wither or not I will even use code someone else has written.

A little off-topic but this is the reason that I like Python as these standards are enforced by the language...something I would like to see happen in PHP because you can't even read some php people have written
__________________
My Portfolio - Work - Need freelance Work?
I've been developing 5 years now, and I learn something new everyday
ioan1k is offline  
Reply With Quote
Old 09-30-2009, 04:47 PM   #12 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

It depends on the language I use. When I do vb at work I use camel case, but when I do C at home I tend to use underscores. I always used underscores when coding in PHP.
__________________

Village Idiot is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Coding conventions on making a small CMS Arye Advanced PHP Programming 1 08-11-2009 09:09 PM


All times are GMT. The time now is 10:12 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design