View Full Version : Fail Coding
Just found this in an extension I've just downloaded,
if ($this->config->get('btc_mybitcoin_status')) {
$status = TRUE;
} else {
$status = FALSE;
}
:scratch
FAIL, $this->config->get('btc_mybitcoin_status') is a boolean,
I hate think about the rest of the code :L
Some people like to cover all their possible bases, including the highly rare and sort-after 3rd case in a bool :)
Some people like to cover all their possible bases, including the highly rare and sort-after 3rd case in a bool :)
He didn't cover them very well! What if 'btc_mybitcoin_status' has no value, is not found or the function does not execute.
He didn't cover them very well! What if 'btc_mybitcoin_status' has no value, is not found or the function does not execute.
It's PHP, so no value would evaluate as 'false' anyway. If the function didn't exist that would cause an exception at runtime.
it's common to see, it's simple when you think about it, when you have a large script would you rather type
$this->config->get('btc_mybitcoin_status'))
or $status
Indeed, as DT said, depending on how $status is used later on that code snippet might actually make perfect sense.
I still prefer the old one-line-if statement myself :p
$status =($this->config->get('btc_mybitcoin_status')) ? TRUE : FALSE;
Never liked that, it's concise but it's not readable.
And it's no more efficient because it all gets compiled into intermediary bitecode anyway.
All a matter of taste though :).
Never liked that, it's concise but it's not readable.
And it's no more efficient because it all gets compiled into intermediary bitecode anyway.
All a matter of taste though :).
Oh I'm making no claims that it's any more efficient, I just personally feel that when coding, if I have to do an if statement with a small predicate (and by small I mean actual character length), then it's just faster and a bit less... well I don't know. I just feel that for something so small it doesn't need so much space in my PHP file. :p
Oh I'm making no claims that it's any more efficient, I just personally feel that when coding, if I have to do an if statement with a small predicate (and by small I mean actual character length), then it's just faster and a bit less... well I don't know. I just feel that for something so small it doesn't need so much space in my PHP file. :p
Well, I'm not one who should be criticising readability really, I spent about 10 years coding mainly in perl, so I've produced code which looks basically like an explosion in a punctuation factory ;).
Mr. Grapes
30-06-11, 16:11
meh... see that all the time in production code.
often a leftover from someone wanting to be able to step through the outcomes in a debugger, but more often just for readability.
i prefer the compact way tho
*Wishes I could understand PHP to join in with the bant*
You can join in. Most people who use PHP don't understand it anyway!
Mr. Grapes
30-06-11, 16:23
I don't "know" PHP, but the syntax is similar enough to C/C++ that i get what smifis is pointing out
Coding these days is just copy and paste - if you are goods at copy and paste then you are set :-/
Coding these days is just copy and paste - if you are goods at copy and paste then you are set :-/
Orly? :P.
Yeah, tbh, I just have the left hand side of my keyboard mapped to 'CTRL-C', and the right hand mapped to 'CTRL-V', and I just spend my day rolling my face on the keyboard...
Coding these days is just copy and paste - if you are goods at copy and paste then you are set :-/
Tell that to Aria and AndyN is out of a job :D
I understand what the code does by the way, but I don't get why it fails lol.
If $status == false though, the script isn't run,
the next line after that was if ($status) { ........
Orly? :P.
Yeah, tbh, I just have the left hand side of my keyboard mapped to 'CTRL-C', and the right hand mapped to 'CTRL-V', and I just spend my day rolling my face on the keyboard...
lol! I actually pictured this in my head :chairfall:
Powered by vBulletin® Version 4.1.12 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.