View Full Version : Your view on coding "preference"
Hypertext
23-09-2008, 09:56 PM
Hi guys.
I'm making this thread in response to the huge mass of people responding when confronted with bad coding practices, or bad ways of doing something, who respond with "it's my preference".
It's becoming an excuse which is really invalid.
I mean theres some situations where it doesn't matter, but most of the time, it is bad.
For instance I've seen some people doing $_GET["my_property"], when you should use $_GET['my_property']. Even if you explain it to them, they just say it's "preference".
Another big one, is using parenthesis in language constructs, this is a real big one. Many people say it's down to "preference" once again, but on the PHP website (http://www.php.net/) they explain that it does slow code down. Then you'll have people retort with "only on a big website". And that's usually where it comes to a head, as there isn't much of an argument against that, of which I can see. Although I believe regardless of traffic size, it still matters.
So what are your views on this?
Charlie.
Thread Closed by MattGarner (Forum Moderator): Thread closed due to arguments.
Excellent2
23-09-2008, 10:08 PM
*Removed*
Edited by Flisker (Forum Moderator): Please do not be rude to members
Pyroka
23-09-2008, 10:13 PM
Another big one, is using parenthesis in language constructs, this is a real big one. Many people say it's down to "preference" once again, but on the PHP website (http://www.php.net/) they explain that it does slow code down. Then you'll have people retort with "only on a big website". And that's usually where it comes to a head, as there isn't much of an argument against that, of which I can see. Although I believe regardless of traffic size, it still matters.
I think Excellent, you need to *Removed* look at what he's saying there.
Edited by Flisker (Forum Moderator): Please do not be rude to other members
Excellent2
23-09-2008, 10:15 PM
I think Excellent, you need to *Removed* look at what he's saying there.No Pyroka, if you knew the slightest bit about PHP I may actually give you kudos there but you don't. People have their methods of doing things, people may like using print instead of echo? Just because it is a few MS slower doesn't mean nothing on a tiny script does it?
Pyroka
23-09-2008, 10:18 PM
No Pyroka, if you knew the slightest bit about PHP I may actually give you kudos there but you don't. People have their methods of doing things, people may like using print instead of echo? Just because it is a few MS slower doesn't mean nothing on a tiny script does it?
miliseconds turn into seconds, and if you're doing errors on a mass scale then yes it does sort of slow down a system. I know enough about PHP to know the difference between " & ', but I didn't know one processes slower than the other. I guess you have one of those 'omg i know everything lol so ****' sorts of attitudes...
Well, from what I can tell anyway, you seem to know that I don't know anything about PHP. *rolls eyes*
Hypertext
23-09-2008, 10:20 PM
No Pyroka, if you knew the slightest bit about PHP I may actually give you kudos there but you don't. People have their methods of doing things, people may like using print instead of echo? Just because it is a few MS slower doesn't mean nothing on a tiny script does it?
Your point is completely invalid, as print is different to echo in many ways. Look it up if you want. :rolleyes:
I actually talked about some peoples methods are valid, but the majority, there is a faster way to do something, which you should use.
Excellent2
23-09-2008, 10:26 PM
miliseconds turn into seconds, and if you're doing errors on a mass scale then yes it does sort of slow down a system. I know enough about PHP to know the difference between " & ', but I didn't know one processes slower than the other. I guess you have one of those 'omg i know everything lol so ****' sorts of attitudes...
Well, from what I can tell anyway, you seem to know that I don't know anything about PHP. *rolls eyes*Did you take a second to read what I put? I said SMALL scripts. If you're coding a big script then of course echo would be the best method to use. No, I just happen to know that you come into this section from your beloved spam and try act like you know how it works.
Your point is completely invalid, as print is different to echo in many ways. Look it up if you want. :rolleyes:
I actually talked about some peoples methods are valid, but the majority, there is a faster way to do something, which you should use.Print uses the same basic functions, but I guess you're going to come back saying "print can't return loads of expressions unlike echo"
Hypertext
23-09-2008, 10:30 PM
Did you take a second to read what I put? I said SMALL scripts. If you're coding a big script then of course echo would be the best method to use. No, I just happen to know that you come into this section from your beloved spam and try act like you know how it works.
Print uses the same basic functions, but I guess you're going to come back saying "print can't return loads of expressions unlike echo"
Read what I said in my "small scripts" thing, regardless, theres no point of using it, if only for aesthetics.
For starters, echo can use commas to consecutively output things, and there are a lot of others which you can read on at php.net.
Invent
23-09-2008, 10:34 PM
There is a fine line between preference and just plain doing it wrong.
For example, $variable['wat'] against $variable["wat"] is a preference. If you choose to use single quotes, then yes, that's more efficient. But it doesn't make using speech marks (") wrong.
Though on the other hand, some things people code on this forum are inefficient and sort of stupid, like when someone echoed a message and then used exit(). That's not a preference, that's an example of just coding badly ;)
Excellent2
23-09-2008, 10:35 PM
Read what I said in my "small scripts" thing, regardless, theres no point of using it, if only for aesthetics.
For starters, echo can use commas to consecutively output things, and there are a lot of others which you can read on at php.net.Print isn't really a function as it doesn't require parenthesis to work, you should know that charlie:rolleyes:
Hypertext
23-09-2008, 10:36 PM
There is a fine line between preference and just plain doing it wrong.
For example, $variable['wat'] against $variable["wat"] is a preference. If you choose to use single quotes, then yes, that's more efficient. But it doesn't make using speech marks (") wrong.
But do you think it's bad practice?
Hypertext
23-09-2008, 10:37 PM
Print isn't really a function as it doesn't require parenthesis to work, you should know that charlie:rolleyes:
print() is not actually a real function (it is a language construct) so you are not required to use parentheses with its argument list. (php.net/print)
Thats my point?
Excellent, this isn't a "coding war", I asked for opinions on coding preference, not the different between print and echo.
Invent
23-09-2008, 10:39 PM
For a smaller script, no, as with a smaller script it's going to slow the page down by a tiny percentage (I'm talking 0.x%). So using " over ' is just preference as it doesn't make any noticable differences to the page load.
Though, with a larger script, yes, of course. As there will be more things to process, thus increasing the page loading time by a higher percentage causing the page to be a bit more inefficient.
Excellent2
23-09-2008, 10:39 PM
(it is a language construct)As is echo();
EDIT: But Invent! I'm sure you know if you timed a script with 1000 lines in it (no white space) and using print(); you'd probably only see a second or so time difference?
Dentafrice
23-09-2008, 10:39 PM
Hi guys.
I'm making this thread in response to the huge mass of people responding when confronted with bad coding practices, or bad ways of doing something, who respond with "it's my preference".
It's becoming an excuse which is really invalid.
I mean theres some situations where it doesn't matter, but most of the time, it is bad.
For instance I've seen some people doing $_GET["my_property"], when you should use $_GET['my_property']. Even if you explain it to them, they just say it's "preference".
Another big one, is using parenthesis in language constructs, this is a real big one. Many people say it's down to "preference" once again, but on the PHP website (http://www.php.net/) they explain that it does slow code down. Then you'll have people retort with "only on a big website". And that's usually where it comes to a head, as there isn't much of an argument against that, of which I can see. Although I believe regardless of traffic size, it still matters.
So what are your views on this?
Charlie.
$_GET[ "header" ] and $_GET[ 'header' ] are the same things..
'' is used for simple strings, "" used as a simple string and is the only string delimiter that supports inline values.
Since PHP is derived from C, '' was originally used for one character (not even a string, as it is used in PHP.. but since PHP doesn't worry much about data types, it doesn't care)
When PHP evolved, '' was considered to be a character delimiter, whereas "" was used as a string.
It all depends on the situation, if people want to use $_GET[ "header" ] or $_GET[ 'header' ], it's their choice in this situation.
Your point is completely invalid, as print is different to echo in many ways. Look it up if you want. :rolleyes:
I actually talked about some peoples methods are valid, but the majority, there is a faster way to do something, which you should use.
How is print different to echo in many ways? Other then the params, the only difference in print returns a value..
Hypertext
23-09-2008, 10:42 PM
$_GET[ "header" ] and $_GET[ 'header' ] are the same things..
'' is used for simple strings, "" used as a simple string and is the only string delimiter that supports inline values.
Since PHP is derived from C, '' was originally used for one character (not even a string, as it is used in PHP.. but since PHP doesn't worry much about data types, it doesn't care)
When PHP evolved, '' was considered to be a character delimiter, whereas "" was used as a string.
It all depends on the situation, if people want to use $_GET[ "header" ] or $_GET[ 'header' ], it's their choice in this situation.
How is print different to echo in many ways? Other then the params, the only difference in print returns a value..
It wasn't the best example, but this still is bad coding practice as it does slow down scripts. But, yes, I admit, in that situation it probably is up to preference.
Heres a list php link to about differences between echo and print. http://www.faqts.com/knowledge_base/view.phtml/aid/1/fid/40
Pyroka
23-09-2008, 10:45 PM
Did you take a second to read what I put? I said SMALL scripts. If you're coding a big script then of course echo would be the best method to use. No, I just happen to know that you come into this section from your beloved spam and try act like you know how it works.
Just small scripts? So you're picking at Hypertext because he's generalized PHP scripts in his post, and you have to pick at it and say that he's totally wrong, it doesn't matter, few MS doesn't matter & that he should grow up... because you're just saying about small scripts.
Damn, you are more ignorant than I. Achievement + 1.
Invent
23-09-2008, 10:47 PM
...wait a second. I think we've all forgot the most important topic/question - why is Pyroka in the web dev. forums?!
Hypertext
23-09-2008, 10:48 PM
...wait a second. I think we've all forgot the most important topic/question - why is Pyroka in the web dev. forums?!
LOL!
+rep.
Pyroka was nerdy in class...but not that nerdy.
Dentafrice
23-09-2008, 10:49 PM
It wasn't the best example, but this still is bad coding practice as it does slow down scripts. But, yes, I admit, in that situation it probably is up to preference.
Heres a list php link to about differences between echo and print. http://www.faqts.com/knowledge_base/view.phtml/aid/1/fid/40
It is not "bad coding practice" to use "" instead of ''.
Here are some benchmarks:
echo:
3.1000000000003E-5 - ''
3.1000000000003E-5 - ""
3.299999999995E-5 - ('')
2.9000000000001E-5 - ("")
print:
3.7000000000009E-5 - ''
3.5000000000007E-5 - ""
3.4000000000006E-5 - ('')
3.3000000000061E-5 - ("")
$_GET[ "var" ]:
2.2000000000022E-5
$_GET[ 'var' ]:
3.3000000000061E-5
It's a matter of preference for things like this, there's times to use '', and times to use "", it's only a bad coding practice to use them irresponsibly.
I know the differences between them, and I told you.
Excellent2
23-09-2008, 10:51 PM
Just small scripts? So you're picking at Hypertext because he's generalized PHP scripts in his post, and you have to pick at it and say that he's totally wrong, it doesn't matter, few MS doesn't matter & that he should grow up... because you're just saying about small scripts.
Damn, you are more ignorant than I. Achievement + 1.He generalized coding preference between most coders. Hypertext cannot accept that using "" or '' is down to personal choice. No, a few MS does not matter unless you're some time keeper with an OCD for quickness :rolleyes:
...wait a second. I think we've all forgot the most important topic/question - why is Pyroka in the web dev. forums?!He's done enough spamming for today :)
Hypertext
23-09-2008, 10:51 PM
It is not "bad coding practice" to use "" instead of ''.
Here are some benchmarks:
It's a matter of preference for things like this, there's times to use '', and times to use "", it's only a bad coding practice to use them irresponsibly.
I know the differences between them, and I told you.
Very interesting benchmarks, +rep if I can.
That makes sense. It really shows how slow adding parenthesis when they are unneeded is.
@excellent:
Reread my post, apparently you don't get it, I didn't have a main grudge on double/single quotes, it was about general coding practices, like people using parenthesis in language constructs and every other coding practice you can think of.
Source
23-09-2008, 10:51 PM
Charlie may say this topic was not started to caus arguements, but it clearly way. Anyone with anything between their ears would know that there are alot of strong and ignorant characters on this forum and no-matter what you tell them they are right. I don't see why people care about other people's coding preferences when if they worked on their own coding skills they could be in with a decent chance of getting alot more knowledge as they spend more time educating themselves rather than caring about other peoples code.
Things have never been done perfectly, look at america, iraq, the UK government. Let people find out by themselves that they were using bad coding preferences, after all the stuff they code is generally their resposibility.
Coding preferences don't bother me for that fact unless the person in hand acts as if they know it all. *cough* , not gonna mention any names.
Pyroka
23-09-2008, 10:52 PM
...wait a second. I think we've all forgot the most important topic/question - why is Pyroka in the web dev. forums?!
OI LOL.
I'm doing serverside scripting, web management and some other crap to do with Python in College, so I guess it'd be nice to look around a few scripts.
Hypertext
23-09-2008, 10:54 PM
He generalized coding preference between most coders. Hypertext cannot accept that using "" or '' is down to personal choice. No, a few MS does not matter unless you're some time keeper with an OCD for quickness :rolleyes:
He's done enough spamming for today :)
OI LOL.
I'm doing serverside scripting, web management and some other crap to do with Python in College, so I guess it'd be nice to look around a few scripts.
God I hate Python.
I had to write a module for Trac, that wasn't fun.
Dentafrice
23-09-2008, 10:54 PM
Very interesting benchmarks, +rep if I can.
That makes sense. It really shows how slow adding parenthesis when they are unneeded is.
Either way, it's not consistent enough to say that using '' on a $_GET and "" on an $_GET is "bad coding practice".
All "" is, is an advanced ''.
Pyroka
23-09-2008, 10:55 PM
I love Python, it doesn't get in a stressy when you type 20 if statements in sequence of eachother.
Plus, I used VBA as my first coding app so I'm pretty much susceptable to anything.
Hypertext
23-09-2008, 10:56 PM
Either way, it's not consistent enough to say that using '' on a $_GET and "" on an $_GET is "bad coding practice".
All "" is, is an advanced ''.
True. One is good for one thing, and one is good for another. But sometimes people do it the wrong way.
@Pyroka: Oh lord. I have a VB class, which I just dropped for an independent study on Java. The course is Computer Science AP AB, for anyone interested go to apcentral.collegeboard.com and navigate to it. This course is really cool, regardless of it being a little boring at the start. But yes, VB is painful, and VBA is more painful, (so I've heard).
Excellent2
23-09-2008, 10:57 PM
Very interesting benchmarks, +rep if I can.
That makes sense. It really shows how slow adding parenthesis when they are unneeded is.
@excellent:
Reread my post, apparently you don't get it, I didn't have a main grudge on double/single quotes, it was about general coding practices, like people using parenthesis in language constructs and every other coding practice you can think of.So now you're agreeing with Dentafrice because he proved you wrong?:rolleyes: So your only grudge with coders on here is because they using parenthesis in language constructs, jesus boy you got problems in life.
Dentafrice
23-09-2008, 10:58 PM
If someone does this, yeah it's wrong.. why do that when you can easily use doubles.
echo 'hey der ' . $nakdlnsfs . ' wej' . $adif . 'sdkfjl' . $dsklfj . 'skfjdsklf' . 'dskfjskdlfj' . $sdkfjs;
vs
echo "hey der {$nakdlnsfs} wej {$adif} sdkfjl {$dsklfj}skfjdsklf dskfjskdlfj {$sdkfjs}";
Of course the bottom one is right.
Hypertext
23-09-2008, 11:00 PM
So now you're agreeing with Dentafrice because he proved you wrong?:rolleyes: So your only grudge with coders on here is because they using parenthesis in language constructs, jesus boy you got problems in life.
Oh for god's sake, do you need to reread every single one of my posts? I said "for parenthesis in language constructs, and other coding practices."
I swear your blind.
If someone does this, yeah it's wrong.. why do that when you can easily use doubles.
echo 'hey der ' . $nakdlnsfs . ' wej' . $adif . 'sdkfjl' . $dsklfj . 'skfjdsklf' . 'dskfjskdlfj' . $sdkfjs;
vs
echo "hey der {$nakdlnsfs} wej {$adif} sdkfjl {$dsklfj}skfjdsklf dskfjskdlfj {$sdkfjs}";
Of course the bototm one is right.
Thats what I was trying to point out, they both have their place.
As a sidenote, the link I posted earlier, I just saw, that using () in echo, removes the ability to add multiple parameters to concatenate them.
Dentafrice
23-09-2008, 11:01 PM
Oh for god's sake, do you need to reread every single one of my posts? I said "for parenthesis in language constructs, and other coding practices."
I swear your blind.
Thats what I was trying to point out, they both have their place.
You're worse then barack obama flipflopping.. you started out with a whole different opinion then you do now..
Excellent2
23-09-2008, 11:01 PM
Oh for god's sake, do you need to reread every single one of my posts? I said "for parenthesis in language constructs, and other coding practices."What other practices charlie?? Oh, the one where you use '' instead of ""? If so, you bloody hypocrite.
Hypertext
23-09-2008, 11:24 PM
You're worse then barack obama flipflopping.. you started out with a whole different opinion then you do now..
Oh, am I not aloud to change my opinion? Don't bring politics into it..
Dentafrice
23-09-2008, 11:26 PM
Oh, am I not aloud to change my opinion? Don't bring politics into it..
I'll bring politics into whatever I feel they need to be brought into.
You're only allowed to change your mind, if at the first you don't act like a total **** about it.
Excellent2
23-09-2008, 11:38 PM
For instance I've seen some people doing $_GET["my_property"], when you should use $_GET['my_property']. Even if you explain it to them, they just say it's "preference".
I didn't have a main grudge on double/single quotes
:rolleyes::eusa_clap
Hypertext
23-09-2008, 11:53 PM
:rolleyes::eusa_clap
:rolleyes: I said "for instance", not "my main grudge is".
Excellent2
23-09-2008, 11:55 PM
:rolleyes: I said "for instance", not "my main grudge is".Hold on harry, you're now saying your grudges wasn't quotes yet you posted it? THEN you say about parenthesis..
Hypertext
24-09-2008, 12:25 AM
Hold on harry, you're now saying your grudges wasn't quotes yet you posted it? THEN you say about parenthesis..
Just because I used it as an example doesn't mean it is my main "grudge".
As it happens, naming conventions probably are.
Dentafrice
24-09-2008, 01:00 AM
Just because I used it as an example doesn't mean it is my main "grudge".
As it happens, naming conventions probably are.
Quit acting like an expert.
You failed at creating an example, and just wanted to point out something that you thought was a "bad coding practice", but yet you were proven wrong.
Now you're changing sides.. and making up petty excuses to cover up something you didn't know and was wrong about.
Too bad your ego will not allow you to admit it :rolleyes:.
Excellent2
24-09-2008, 01:06 AM
To be honest parenthesis means nothing but garbage, I've said it once and I'll say it again Charlie, preference.
If someone wants to use the following:
<?php
echo "Hello";
echo 'Hello';
echo ("Hello");
?>darn god boy just let them. It does absolutely nothing to the script at all. Yes, the proper way would be to use double quotes, not singles but it works the same anyway. If you spent more time correcting your own code than others you may actually have a point.
Hypertext
24-09-2008, 02:06 AM
To be honest parenthesis means nothing but garbage, I've said it once and I'll say it again Charlie, preference.
If someone wants to use the following:
<?php
echo "Hello";
echo 'Hello';
echo ("Hello");
?>darn god boy just let them. It does absolutely nothing to the script at all. Yes, the proper way would be to use double quotes, not singles but it works the same anyway. If you spent more time correcting your own code than others you may actually have a point.
Actually in that case the proper way would be to use single quotes.
Dentafrice, I admit that I was wrong, I used a bad example, which I thought was a good example, your benchmarks showed that I was wrong.
Actually in that case the proper way would be to use single quotes.
Dentafrice, I admit that I was wrong, I used a bad example, which I thought was a good example, your benchmarks showed that I was wrong.
Well you just got an example wrong yet you made this thread making digs at the 'preferances' people use - if people are used to coding that way don't have OCD let them code like that because they're probably used to it.
Wow it slows the script down by 1 ms you say? Blimey - that's a lot. :O
Agnostic Bear
24-09-2008, 05:50 AM
Actually in that case the proper way would be to use single quotes.
Dentafrice, I admit that I was wrong, I used a bad example, which I thought was a good example, your benchmarks showed that I was wrong.
The "proper" way is to do it how you want to, if you can do it other ways and it works identically then there are no "rules" there is no "proper" way, you can do it how you goddamn like, who gives a **** if there's a .003 slowdown, good coders don't "like doing it there way" they simply don't care what you think. Also try ranting at your boss who likes using ("") when you "think" '' is right, see how quickly you find yourself out on your ass.
Stop trying to push your beliefs on other people I don't care what you think, I'm gonna use '', ('') "" and ("") just as much as I want and there's approximately 0% chance (give or take 0%) that anything you can say or do will stop me.
Excellent2
24-09-2008, 12:49 PM
Charlie you and I both know you soley created this thread to have a dig at PHP newbies on here like me etc. Infact nearly everything you've said is wrong and you've made yourself out to be some moaning little boy who wants to join the popular group.
You forget that 2-3 months ago you where still stealing Dentafrice's code and asking him silly questions. Now, because you have a low life job at a going nowhere website you think you're the best coder around - wrong sonny. Whoever told you that using "" or '' would slow down a small script rapidly or that it was wrong is also wrong, make sure you check php.net more often.
You should also concentrate more on your own code rather than others as I'm pretty sure you make a lot of mistakes.
Not to be cliche but we learn from our mistakes :)
Also, what a useless thread. This was quite obviously intended to start an argument and the stuff you have highlighted is pretty much insignificant as few people on this forum will be building big scripts which will be affected by the whether you use " or '.
:rolleyes:
Want to hide these adverts? Register an account for free!
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.