Go Back   CodingForums.com > :: Server side development > PHP > Post a PHP snippet

Before you post, read our: Rules & Posting Guidelines

Closed Thread
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-15-2005, 04:51 AM   PM User | #31
Velox Letum
Senior Coder

 
Join Date: Apr 2005
Location: Colorado, United States
Posts: 1,208
Thanks: 0
Thanked 0 Times in 0 Posts
Velox Letum is an unknown quantity at this point
I also happen to find style important...I use K&R braces, I use single quotes for anything that doesn't need to have double quootes, I enjoy well-formatted code which is why indents are built into my PHP, HTML, and HTML in PHP (such as echoes), but everyone has their style. Some use different brace types, some put spaces between a function's parenthesis and any passed variables. Nobody's style is the best, though in my opinion I'd have to say the one that promotes code-readability is the best.

This snippit of code I wrote before I even knew basename(), pathinfo(), and other such functions existed, and had I known I wouldn't have even posted this snippit, however I do find it important that programmers learn how to solve problems creatively and not just rely on functions served to them. I was working on a project that required me to parse paths and get the name of the file and extension, thus I wrote this code. I suppose it could be a lesson...there's always another way to something.
__________________
"$question = ( to() ) ? be() : ~be();"

Last edited by Velox Letum; 12-15-2005 at 04:55 AM..
Velox Letum is offline  
Old 12-15-2005, 02:04 PM   PM User | #32
marek_mar
Sensei


 
Join Date: Aug 2003
Location: One step ahead of you.
Posts: 2,815
Thanks: 0
Thanked 3 Times in 3 Posts
marek_mar is on a distinguished road
I see that I have succesfully started pretty big argument by using difficult words like "style" or "guideline"...

I just might add that you can "sense" the writers personality when you look at how he writes things. You can see if that person knows what and to whom he is writing to. Depending on the reciever the same meaning should be convaeyd in different ways. When I see someones code (though it can be normal writing aswell) I can see if the person is lazy or if he wrote it in a hurry (and some other thigns too). Make conclusions as you like.

Quote:
For example, up until 6 months ago, I didnt know you could do:
$object->function()->somethingElse()->SomethingElse;
Becuase I was told once that it was not possible, I never questioned it. I only questioned it when I saw it in a script, and found out it was possible and I had been misguided. Since then, I have done my best to ensure that misguiding information is not given out becuase it can potentially hold back someones progression. If someone comes here and gets the impression that formatting for readability is neccesary and is part of a PHP file format then they have been misguided, which is what I am trying to prevent.
I might clean that someones record. Dircet access to a method of an object returned by a function is possible from PHP5 and up. In PHP4 you would have to assign the returned object to a variabale.

BTW reading what you wrote is a good idea.
Quote:
When you talk to someone you talk to them.
I still wonder what that sentance means/does.
__________________
I'm not sure if this was any help, but I hope it didn't make you stupider.

Experience is something you get just after you really need it.
PHP Installation Guide Feedback welcome.

Last edited by marek_mar; 12-15-2005 at 02:06 PM..
marek_mar is offline  
Old 12-15-2005, 04:27 PM   PM User | #33
gsnedders
Senior Coder

 
gsnedders's Avatar
 
Join Date: Jan 2004
Posts: 2,340
Thanks: 1
Thanked 7 Times in 7 Posts
gsnedders will become famous soon enough
Quote:
Originally Posted by Element
Just as Error 404 said "guidelines/standards/whatever-you-want-to-call-it"
As my last post was trying to point out, all 3 of the examples follow the same syntax (if, bracket, if statement, bracket, curved bracket, echo, curved bracket), yet they do not follow the same guidelines.

Syntax and guidelines are two very different things.

If you break the Syntax, the code will die horribly. If you break the guidelines, it'll work fine.
__________________
Geoffrey Sneddon
gsnedders is offline  
Old 12-15-2005, 06:55 PM   PM User | #34
Element
Regular Coder

 
Element's Avatar
 
Join Date: Jul 2004
Location: Lynnwood, Washington, US
Posts: 855
Thanks: 2
Thanked 2 Times in 2 Posts
Element is an unknown quantity at this point
Okay, you guys are purposely starting up a conversation which has been over for a day now. And indeed, I know what syntax is, which is why I can use my descriptor on syntax all I want, you can't tell me otherwise. The way a format my syntax just means the way its styled. Though I never put 'guidelines' down since I'm often coding alone because my friends are the type that slack and won't even help me... even if they offer the help.

And despite what you all say anyone I talk to on messenger, they know exactly what I mean and even say syntax is the code, therefor what I say is perfectly fine. All you guys are doing is contradicting, this isn't even an argument. It has no valid or usefull point, and thus your simply telling me no to give me a bad time becaus you can't deal with the fact I can easily use "format my syntax/coding/programing/writing"

Last edited by Element; 12-15-2005 at 07:00 PM..
Element is offline  
Old 12-15-2005, 07:58 PM   PM User | #35
gsnedders
Senior Coder

 
gsnedders's Avatar
 
Join Date: Jan 2004
Posts: 2,340
Thanks: 1
Thanked 7 Times in 7 Posts
gsnedders will become famous soon enough
No, we're trying to point out syntax and coding styling are two very different things.

PHP Code:
<?php 

// Example 1 
if ($num == 0) { echo 'Bob'; } 

// Example 2 
if ($num == 0) { 
echo 
'Bob'


// Example 3 
if ($num == 0

    echo 
'Bob'


?>
These all follow the same syntax.
These all follow different coding styles.
__________________
Geoffrey Sneddon
gsnedders is offline  
Old 12-15-2005, 08:06 PM   PM User | #36
Element
Regular Coder

 
Element's Avatar
 
Join Date: Jul 2004
Location: Lynnwood, Washington, US
Posts: 855
Thanks: 2
Thanked 2 Times in 2 Posts
Element is an unknown quantity at this point
Quote:
Originally Posted by Error 404
No, we're trying to point out syntax and coding styling are two very different things.

PHP Code:
<?php 

// Example 1 
if ($num == 0) { echo 'Bob'; } 

// Example 2 
if ($num == 0) { 
echo 
'Bob'


// Example 3 
if ($num == 0

    echo 
'Bob'


?>
These all follow the same syntax.
These all follow different coding styles.
Yes I understand that, but your not thinking of it correctly. Same syntax, different format. Thus, different formatting of the same syntax. I'm not saying when I format the syntax the syntax is changed, its just formatted differently just like you showed.
Element is offline  
Old 12-15-2005, 11:15 PM   PM User | #37
missing-score
Senior Coder


 
missing-score's Avatar
 
Join Date: Jan 2003
Location: UK
Posts: 2,194
Thanks: 0
Thanked 0 Times in 0 Posts
missing-score is on a distinguished road
Quote:
Originally Posted by Element
Yes I understand that, but your not thinking of it correctly. Same syntax, different format. Thus, different formatting of the same syntax. I'm not saying when I format the syntax the syntax is changed, its just formatted differently just like you showed.
I dont believe I am having to come back here again, but if you read ralph l mayo's post, he describes is best in my opinion, and Element, all those are the same format... Please, just give it a rest and accept that you are wrong when we are talking about the meaning of formatting in the usual context. If it makes sense to you then so be it, but please stop arguing your case.
missing-score is offline  
Old 12-15-2005, 11:31 PM   PM User | #38
Element
Regular Coder

 
Element's Avatar
 
Join Date: Jul 2004
Location: Lynnwood, Washington, US
Posts: 855
Thanks: 2
Thanked 2 Times in 2 Posts
Element is an unknown quantity at this point
Quote:
Originally Posted by missing-score
I dont believe I am having to come back here again, but if you read ralph l mayo's post, he describes is best in my opinion, and Element, all those are the same format... Please, just give it a rest and accept that you are wrong when we are talking about the meaning of formatting in the usual context. If it makes sense to you then so be it, but please stop arguing your case.
Leave it up to the Europians to be as arrogant as they can. Usual contect? Serious, grab a dictionary, thats the usual context, period. Format the same? Pshaw, right.

Quote:
2 format

determine the arrangement of (data) for storage and display (in computer science)
One of the many uses of the word format, even in computer science. I'm tired of you guys making it sound like I'm wrong when you have no grounds what-so-ever considering I'm using the word correctly as a descriptor for the storage and display of my code.

If you need to read up on other uses of the word format check out: http://www.wordreference.com/definition/format
Element is offline  
Old 12-15-2005, 11:33 PM   PM User | #39
marek_mar
Sensei


 
Join Date: Aug 2003
Location: One step ahead of you.
Posts: 2,815
Thanks: 0
Thanked 3 Times in 3 Posts
marek_mar is on a distinguished road
"I format my code so it will fit my coding style."
"I have to change my coding style to fulfill the coding guidelines of my project."
How about that?
__________________
I'm not sure if this was any help, but I hope it didn't make you stupider.

Experience is something you get just after you really need it.
PHP Installation Guide Feedback welcome.
marek_mar is offline  
Old 12-15-2005, 11:36 PM   PM User | #40
Element
Regular Coder

 
Element's Avatar
 
Join Date: Jul 2004
Location: Lynnwood, Washington, US
Posts: 855
Thanks: 2
Thanked 2 Times in 2 Posts
Element is an unknown quantity at this point
Quote:
Originally Posted by marek_mar
"I format my code so it will fit my coding style."
"I have to change my coding style to fulfill the coding guidelines of my project."
How about that?
Mmm its like chocolate covered strawberries....
Element is offline  
Old 12-15-2005, 11:42 PM   PM User | #41
missing-score
Senior Coder


 
missing-score's Avatar
 
Join Date: Jan 2003
Location: UK
Posts: 2,194
Thanks: 0
Thanked 0 Times in 0 Posts
missing-score is on a distinguished road
Code:
the organization of information according to preset specifications (usually for computer processing)
Which was my whole argument with you in the first place... That tabs and indents have nothing to do with PHP file formatting... That was what I was intending to point out initially and I have already said I didnt want to spring a whole argument from it.

I'm going to ignore the whole europeans remark too.
missing-score is offline  
Old 12-16-2005, 12:16 AM   PM User | #42
Element
Regular Coder

 
Element's Avatar
 
Join Date: Jul 2004
Location: Lynnwood, Washington, US
Posts: 855
Thanks: 2
Thanked 2 Times in 2 Posts
Element is an unknown quantity at this point
Quote:
Originally Posted by missing-score
Code:
the organization of information according to preset specifications (usually for computer processing)
Which was my whole argument with you in the first place... That tabs and indents have nothing to do with PHP file formatting... That was what I was intending to point out initially and I have already said I didnt want to spring a whole argument from it.

I'm going to ignore the whole europeans remark too.
Yes, but you see, thats for format once again. The argument was about me using format. Either way the basic meanings of format is the aspect and visual aspects of something. Either or are correct, it is a word that can be used in so many different ways.

Like the styling of the code is a title for how each individual formats their code.
Element is offline  
Old 12-16-2005, 12:18 AM   PM User | #43
missing-score
Senior Coder


 
missing-score's Avatar
 
Join Date: Jan 2003
Location: UK
Posts: 2,194
Thanks: 0
Thanked 0 Times in 0 Posts
missing-score is on a distinguished road
Quote:
Originally Posted by Element
Yes, but you see, thats for format once again. The argument was about me using format. Either way the basic meanings of format is the aspect and visual aspects of something. Either or are correct, it is a word that can be used in so many different ways.

Like the styling of the code is a title for how each individual formats their code.
Yes... I understand what you are saying, as I always have. I was trying to point out that a newline and indent have nothing to do withPHP FILE FORMAT. If you are talking obout the visual format in which PHP is seen, then you are right, which I never disputed.

Last edited by missing-score; 12-16-2005 at 02:01 AM.. Reason: Fixed Grammar
missing-score is offline  
Old 12-16-2005, 01:53 AM   PM User | #44
Element
Regular Coder

 
Element's Avatar
 
Join Date: Jul 2004
Location: Lynnwood, Washington, US
Posts: 855
Thanks: 2
Thanked 2 Times in 2 Posts
Element is an unknown quantity at this point
Quote:
Originally Posted by missing-score
Yes... I understand what you are saying, as I always have. I was trying to point out that a newline and indent have PHP FILE FORMAT. If you are talking obout the visual format in which PHP is seen, then you are right, which I never disputed.
*Gets blown into his closet* I know, it wasn't really you that did, but other people just excused what I was saying without even understanding it.
Element is offline  
Closed Thread

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:03 PM.


Advertisement
Log in to turn off these ads.