tithonium: (Default)
[personal profile] tithonium
Arcturus's second video card arrived. Whenever I get around to installing it, I think I'll put the old 17" and maybe the 15" on it, just for grins and giggles. Once the refi is finalized (we should hopefully hear about the appraisal results today) I should be able to buy the third and fourth monitors within two or three months. Whee.

Unrelatedly, what's wrong with this picture?


$result = $db->execute($sql);

$xml = dbresult_to_xml($result);

$result_simple = simplexml_load_string($xml);

foreach ($result_simple as $tag => $thing) {
  ...
}


I have no words. (I've used them all up exclaiming about this)

Date: 2008-05-13 06:12 pm (UTC)
From: [identity profile] allanc.livejournal.com
Yesterday, I got a code review that was like this

$foo = "bar\nbaz";
$foo = nl2br($foo);

When I asked the guy why he didn't just write $foo="bar<br />baz"; he responded that he didn't know that that was possible.

I really wish I could fail some people's entire employment contract instead of just their code changes sometimes.

Date: 2008-05-13 07:41 pm (UTC)

Date: 2008-05-14 01:11 am (UTC)
From: [identity profile] grymor.livejournal.com
Other than it being php, the wasteful bounce through XML, the unnecessary temporary variables... Can't say for certain, but also (likely) failure to use bind variables for the sql.

Am I missing much? Also, why do I get a strong sense of deja vu when looking at this?

Date: 2008-05-14 02:08 am (UTC)
From: [identity profile] irgth.livejournal.com
I'm almost hoping that dbresult_to_xml does more than the name of the function implies.

Of course, I just love how no checking is done to make sure that there were any results from the query, or that the xml was loaded correctly by simplexml_load_string.

Among other errors, the cast of $result_simple to an array will probably generate warnings/notices. I suspect that whoever wrote this turned display_errors and log_errors off.

Date: 2008-05-14 02:11 am (UTC)
From: [identity profile] tithonium.livejournal.com
To be fair, this is simplified. the sql is generated by a function, the db execute is checked for success and results, and it's actually iterating over ->children(). My intent was mainly to draw attention to the fact that it takes an iterable data structure, serializes it to xml (no, it doesn't do anything more than that), then immediately deserializes it again and iterates over it.

Date: 2008-05-14 06:28 am (UTC)
From: [identity profile] irgth.livejournal.com
In that case, it sounds like the codebase you are working with is in better shape than the one I'm trying to fix/maintain. I'd actually be thrilled to find code as clear as that sample the next time something breaks.

Profile

tithonium: (Default)
tithonium

February 2019

S M T W T F S
     12
3456789
10111213141516
17181920212223
2425262728  

Expand Cut Tags

No cut tags