PDA

View Full Version : Fail Coding



Smifis
29-06-11, 00:46
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

Murf
29-06-11, 07:58
Some people like to cover all their possible bases, including the highly rare and sort-after 3rd case in a bool :)

albal
30-06-11, 14:38
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.

andyn
30-06-11, 14:41
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.

DoubleTop
30-06-11, 14:42
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

andyn
30-06-11, 14:44
Indeed, as DT said, depending on how $status is used later on that code snippet might actually make perfect sense.

Peter
30-06-11, 14:52
I still prefer the old one-line-if statement myself :p


$status =($this->config->get('btc_mybitcoin_status')) ? TRUE : FALSE;

andyn
30-06-11, 14:55
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 :).

Peter
30-06-11, 15:00
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

andyn
30-06-11, 15:04
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

Pullen
30-06-11, 16:12
*Wishes I could understand PHP to join in with the bant*

albal
30-06-11, 16:19
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

albal
30-06-11, 16:30
Coding these days is just copy and paste - if you are goods at copy and paste then you are set :-/

andyn
30-06-11, 16:46
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...

Pullen
30-06-11, 16:47
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.

Smifis
30-06-11, 17:15
If $status == false though, the script isn't run,

the next line after that was if ($status) { ........

Hydey
30-06-11, 18:58
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: