Source>> stackexchange forum
Some comment: Absolutely agree it bothers me too
1. call to action notation - first word is action in lower case then camel case
collection->findFirst(...)
obj->getName()
2. No action method naming
App::log()
DB::table('users')->lastMonth()->get()
I like when lower case part is either proverb or adjective
e.g
lastMonth
firstElement
xmlPath
In method camel case first lwcase word should be specification
and last one the most general one eg (object type)
Functions:
1. Javascript style
function onSaveHanlder
2. PHP/Ruby style
send_email()
CSS
1. hyphen/slug style
class="save-btn"
id="header-container-section" // logic structure: first root element then child then child-child
Summary:
In general I like ruby naming convention and ruby approach for naming:
-readability
-clarity
-conciseness (short better then long without lose of clarity)
Not sure about snake case methods: I would use it only for properties instead of getter setter
Private fields should be prefixed with underscore :
eg: private $_items;
Both!
I do a lot of development in CakePHP, and I use either
CamelCase
or $underscored_vars
, in the following fashion (even outside CakePHP Projects):- filenames —
/lowercased_underscored.php
Typical, but worth mentioning. - classes —
class CamelCase extends ParentObject
. Note that, when usingCamelCase
, the initial character is not lowercase. I findcamelCase
to look really weird. - variables —
$are_variables_underscored === TRUE;
- variables that hold instances —
$CamelCase = new CamelCase();
//seen it in qb lib but in some languages like ruby everything is a class - array keys —
$collection['underscored_keys'];
- constants — I think everyone can agree that constants should be
ALL_CAPS_AND_UNDERSCORED
. - methods —
$CamelCase->foo_method_underscored();
- static methods —
CamelCase::just_like_regular_methods();
Some comment: Absolutely agree it bothers me too
have to agree with you, having the first character be lower case drives me crazy! I hate camelCase with a passion. – HLGEM Jan 6 '11 at 22:00
|
For programming languages I've used, like Java, Python, C++, I've adopted a clear format:
- ClassNamesArePascalCase
- methodNamesAreCamalCase
- variable_names_are_underscore
- CONSTANT_VARIABLES_ARE_CAPITAL_VARIABLES
- _private_variable_names_are_prefixed_with_an_underscore
- _PRIVATE_CONSTANT_VARIABLES_ARE_PREFIXED_WITH_AN_UNDERSCORE
Another aspect of naming convention is words order:
1. ModelCallReport or CallReportModel
create_date or date_create
In PHP main principle of global function creation in having one prefix for same group of functions
It makes it easier to search them
array_mapClass methods:
array_filter
1. call to action notation - first word is action in lower case then camel case
collection->findFirst(...)
obj->getName()
2. No action method naming
App::log()
DB::table('users')->lastMonth()->get()
I like when lower case part is either proverb or adjective
e.g
lastMonth
firstElement
xmlPath
In method camel case first lwcase word should be specification
and last one the most general one eg (object type)
Functions:
1. Javascript style
function onSaveHanlder
2. PHP/Ruby style
send_email()
CSS
1. hyphen/slug style
class="save-btn"
id="header-container-section" // logic structure: first root element then child then child-child
2. camel
name="first_name"
3. Bootstrap style (spesialization frist the most general)
class="btn btn-sm btn-default" // logic structure: type then size the color
name="first_name"
3. Bootstrap style (spesialization frist the most general)
class="btn btn-sm btn-default" // logic structure: type then size the color
Some people use camel case for css I dond like it
Summary:
In general I like ruby naming convention and ruby approach for naming:
-readability
-clarity
-conciseness (short better then long without lose of clarity)
Not sure about snake case methods: I would use it only for properties instead of getter setter
Private fields should be prefixed with underscore :
eg: private $_items;