You are definitely on the right track. They are from general Summation Notation that, like many other mathmatical notations, worked its way into early languages -- specifically Fortran (remember its FORMula TRANSlation).Gambler wrote:I do not consider myself a newbie, but it's a tough question. My best guess would be that "i" is taken from sigma notation of Reimann sum.
Coding conventions
Moderator: General Moderators
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
(#10850)
-
d3ad1ysp0rk
- Forum Donator
- Posts: 1661
- Joined: Mon Oct 20, 2003 8:31 pm
- Location: Maine, USA
I'm not sure why you all hate that so much. I think it sorta makes sense (seperating the word 'mysql' from the actual function that it's doing (query). I almost think of mysql_ as a bunch of functions that deal with the database mysql, where add_slashes wouldn't make sense because slashes isn't a function that deals with the add class or anything like that.Hockey wrote:Like the mysql_query() or addslashes()
One OR the other please...not both...
I frequently did (and sometimes still do) the add_slashes() thing because thats how I know PHP to work...then get an error at runtime because add_slashes() doesn't exist.![]()
If they were to ever put add_slashes into php, I'd hope they'd keep addslashes and such as well.
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Agreed. Arn't all usages of *_ in php prefixes for similar functions?d3ad1ysp0rk wrote:I'm not sure why you all hate that so much. I think it sorta makes sense (seperating the word 'mysql' from the actual function that it's doing (query). I almost think of mysql_ as a bunch of functions that deal with the database mysql, where add_slashes wouldn't make sense because slashes isn't a function that deals with the add class or anything like that.Hockey wrote:Like the mysql_query() or addslashes()
One OR the other please...not both...
I frequently did (and sometimes still do) the add_slashes() thing because thats how I know PHP to work...then get an error at runtime because add_slashes() doesn't exist.![]()
If they were to ever put add_slashes into php, I'd hope they'd keep addslashes and such as well.
ie..
mysql_*
preg_*
ereg_*
socket_*
Most of the items on my coding guidelines includes a brief explanation of why I chose them. ie, I choose spaces over tabs because of the difficulties in pasting between putty sessions causing diff to show changes where there aren't any.Hockey wrote:I wanna know what works for you and why...if you can even justify your answer...
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
I agree with d3ad1ysp0rk (how do you pronounce that?) and Jcart that PHP's naming is not as bad as the complainers claim. The core group even did a survey of the whole haystack/needle complaint and I think only found one or two that were backwards. Plus, the PHP naming is very human is its evolved conisistency. And names like substr() are more core functions than extensiions like mysql_*().
Maybe we should change the constructs to loop_for(), loop_while(), conditional_if() and conditional_switch()?
Maybe we should change the constructs to loop_for(), loop_while(), conditional_if() and conditional_switch()?
(#10850)
-
alex.barylski
- DevNet Evangelist
- Posts: 6267
- Joined: Tue Dec 21, 2004 5:00 pm
- Location: Winnipeg
I'm looking into itRoja wrote:Most of the items on my coding guidelines includes a brief explanation of why I chose them. ie, I choose spaces over tabs because of the difficulties in pasting between putty sessions causing diff to show changes where there aren't any.Hockey wrote:I wanna know what works for you and why...if you can even justify your answer...
I never even thought of formalizing indices though...gotta say that was pure genius...totally gave me a solid idea...
I frequently write deeply nested for loops (nothing of practical nature yet - mostly experimental) and I always start with "i"
The it dawned on me, after reading your guidelines...it would make sense to start at "a" and count from there...totally prevents re-using a counter variable...which anyone can tell you can make for bad times and hard to find bugs
Anyways, I much appreciate that link to your specs...
Cheers
-
alex.barylski
- DevNet Evangelist
- Posts: 6267
- Joined: Tue Dec 21, 2004 5:00 pm
- Location: Winnipeg
As far as I know all extensions use that technique...procedural namespacing...but thats not the point I was getting at...Jcart wrote:Agreed. Arn't all usages of *_ in php prefixes for similar functions?d3ad1ysp0rk wrote:I'm not sure why you all hate that so much. I think it sorta makes sense (seperating the word 'mysql' from the actual function that it's doing (query). I almost think of mysql_ as a bunch of functions that deal with the database mysql, where add_slashes wouldn't make sense because slashes isn't a function that deals with the add class or anything like that.Hockey wrote:Like the mysql_query() or addslashes()
One OR the other please...not both...
I frequently did (and sometimes still do) the add_slashes() thing because thats how I know PHP to work...then get an error at runtime because add_slashes() doesn't exist.![]()
If they were to ever put add_slashes into php, I'd hope they'd keep addslashes and such as well.
ie..
mysql_*
preg_*
ereg_*
socket_*
The fact that extensions use that convention and some core functions don't...doesn't make for a very argument in that PHP is already setting a standard convention...
You should use one or the other not both...in the procedural context anyways...
add & slashes are individual words...so they should follow suit and have a '_' between them
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
The _ represent an agglomeration of similar function libraries. It has nothing to do with number of words within the function.
I do partially agree that they should use one or the other, but they chose to take a different approach at it.
The bottom line is that it is actually consistant, even though you may not agree on what naming convention used.
Personally, I hadn't even though about it until this topic, and really... does it really matter? If you hate the underscores so much write a function wrapper
I do partially agree that they should use one or the other, but they chose to take a different approach at it.
The bottom line is that it is actually consistant, even though you may not agree on what naming convention used.
Personally, I hadn't even though about it until this topic, and really... does it really matter? If you hate the underscores so much write a function wrapper
- Ambush Commander
- DevNet Master
- Posts: 3698
- Joined: Mon Oct 25, 2004 9:29 pm
- Location: New Jersey, US
-
alex.barylski
- DevNet Evangelist
- Posts: 6267
- Joined: Tue Dec 21, 2004 5:00 pm
- Location: Winnipeg
Not worth it...I'd rather put up with inconsistencies...but to be used as an example of a standard to follow Ihave a hard time with...Jcart wrote:The _ represent an agglomeration of similar function libraries. It has nothing to do with number of words within the function.
I do partially agree that they should use one or the other, but they chose to take a different approach at it.
The bottom line is that it is actually consistant, even though you may not agree on what naming convention used.
Personally, I hadn't even though about it until this topic, and really... does it really matter? If you hate the underscores so much write a function wrapper
Clearly if there is a problem with any given technique or convention...there is room for improvment...is all I was saying
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
but what I tried to say erlier is that just because it doesn't work for you doesn't mean it doesn't work for the rest of the population (lots of doesn't in that sentence)
I know there are standards that we all hate, but they arn't there for us to like them or look pretty -- they are there to make our lives easier through consistency.
Stupid standards ..
I know there are standards that we all hate, but they arn't there for us to like them or look pretty -- they are there to make our lives easier through consistency.
Stupid standards ..
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
To answer the original question:
I use camel case because almost all the code that I use from other sources (whether Java, PHP, Python, Ruby) uses camel case (initial caps) for class names and camel case (initial lowercase) for method names -- and I have much more important things to even think about than why I would want to vary from such a widely used standard as that. Experence has taught me that I have yet to come up with anything related to software development that is better than what those smart guys who write books recommend.Hockey wrote:So please, if someone has already answered with I use CAMELCASE because...
(#10850)
As long as you're using braces it shouldn't make any difference... Because a decent editor (formatter) can easily toggle between the styles and display them in whatever way you like them (btw, if you add an else switch to the statement there are even more variations possiblearborint wrote:Yes. I see code with both thisAmbush Commander wrote:Well, there's some wiggle room. Like bracing.And thisCode: Select all
if ($condition) { // do stuff }and I never hear anyone say anything one way or the other. Most of the common styles have some trivial variations that really aren't worth noting.Code: Select all
if ($condition) { // do stuff }