Coding conventions

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

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.
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).
(#10850)
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

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. :?
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.

If they were to ever put add_slashes into php, I'd hope they'd keep addslashes and such as well.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

d3ad1ysp0rk wrote:
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. :?
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.

If they were to ever put add_slashes into php, I'd hope they'd keep addslashes and such as well.
Agreed. Arn't all usages of *_ in php prefixes for similar functions?

ie..

mysql_*
preg_*
ereg_*
socket_*
Roja
Tutorials Group
Posts: 2692
Joined: Sun Jan 04, 2004 10:30 pm

Post by Roja »

Hockey wrote:I wanna know what works for you and why...if you can even justify your answer...
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.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

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()? ;)
(#10850)
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Post by alex.barylski »

Roja wrote:
Hockey wrote:I wanna know what works for you and why...if you can even justify your answer...
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.
I'm looking into it ;)

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 :P

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

Post by alex.barylski »

Jcart wrote:
d3ad1ysp0rk wrote:
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. :?
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.

If they were to ever put add_slashes into php, I'd hope they'd keep addslashes and such as well.
Agreed. Arn't all usages of *_ in php prefixes for similar functions?

ie..

mysql_*
preg_*
ereg_*
socket_*
As far as I know all extensions use that technique...procedural namespacing...but thats not the point I was getting at...

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 :)
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

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 8O
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

write a function wrapper
Agreed. Especially with the database functions. You could even right a Regexp object modeled after JavaScript's Regexp wrapper.
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Post by alex.barylski »

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 8O
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...

Clearly if there is a problem with any given technique or convention...there is room for improvment...is all I was saying :)
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

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. :P

Stupid standards .. :lol:
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

To answer the original question:
Hockey wrote:So please, if someone has already answered with I use CAMELCASE because...
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.
(#10850)
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

arborint wrote:
Ambush Commander wrote:Well, there's some wiggle room. Like bracing.
Yes. I see code with both this

Code: Select all

if ($condition) {
    // do stuff
}
And this

Code: 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.
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 possible ;))
Post Reply