 |
Account Login
|
 |
 |
Latest Articles
|
 |
 |
IRC Channel
|
 |
 |
Associates
|
 |
 |
Associates
|
 |
|
 |
 |
|
 |
08-27-2009, 04:42 PM
|
#1 (permalink)
|
|
The Wanderer
Join Date: Aug 2009
Location: Torquay
Posts: 16
Thanks: 2
|
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
|
|
|
08-27-2009, 10:49 PM
|
#2 (permalink)
|
|
The Addict
Join Date: May 2009
Posts: 287
Thanks: 5
|
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; } }
|
|
|
|
08-27-2009, 11:04 PM
|
#3 (permalink)
|
|
The Addict
Join Date: Jun 2008
Posts: 335
Thanks: 2
|
Hungarian ( Which is CamelCase but with the datatype ) & CamelCase
|
|
|
|
09-25-2009, 11:24 AM
|
#4 (permalink)
|
|
That guy
Join Date: Sep 2009
Location: San Antonio, TX
Posts: 24
Thanks: 0
|
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;
}
}
|
|
|
|
09-25-2009, 12:13 PM
|
#5 (permalink)
|
|
The Contributor
Join Date: May 2009
Posts: 53
Thanks: 2
|
Classes: CamelCase (But their in 99/100 cases one word)
Functions: CamelCase
Strings: small_letters_with_underscores
Constants: CAPS
|
|
|
09-26-2009, 10:20 PM
|
#6 (permalink)
|
|
how quixotic are you?
Join Date: Dec 2007
Location: Lapeer, MI
Posts: 445
Thanks: 37
|
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 
|
|
|
|
09-27-2009, 02:03 AM
|
#7 (permalink)
|
|
The Contributor
Join Date: Mar 2009
Posts: 49
Thanks: 0
|
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.
|
|
|
|
09-27-2009, 04:36 PM
|
#8 (permalink)
|
|
The Addict
Join Date: May 2009
Posts: 287
Thanks: 5
|
Quote:
Originally Posted by TheOnly92
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.
|
|
|
|
09-28-2009, 12:39 AM
|
#9 (permalink)
|
|
The Contributor
Join Date: Mar 2009
Location: US
Posts: 76
Thanks: 0
|
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 {
|
|
|
|
09-28-2009, 01:12 AM
|
#10 (permalink)
|
|
how quixotic are you?
Join Date: Dec 2007
Location: Lapeer, MI
Posts: 445
Thanks: 37
|
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.
|
|
|
|
09-28-2009, 01:30 AM
|
#11 (permalink)
|
|
The Contributor
Join Date: Mar 2009
Location: US
Posts: 76
Thanks: 0
|
Quote:
Originally Posted by ETbyrne
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 
|
|
|
|
09-30-2009, 04:47 PM
|
#12 (permalink)
|
|
Wizard
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
|
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.
|
|
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|