Computer
Bitcoin Sets Another Record as Bullish Bets Continue
Read more of this story at Slashdot.
How ChatGPT Brought Down an Online Education Giant
Read more of this story at Slashdot.
2024 On Track To Be Hottest Year on Record as Warming Temporarily Hits 1.5C
Read more of this story at Slashdot.
OpenAI and Others Seek New Path To Smarter AI as Current Methods Hit Limitations
Read more of this story at Slashdot.
Are America's Courts Going After Digital Libraries?
Read more of this story at Slashdot.
Firefox Gets More Investment in New Features, Prioritizing People (and Privacy) Over Profit
Read more of this story at Slashdot.
CodeSOD: Pay for this Later
Ross needed to write software to integrate with a credit card payment gateway. The one his company chose was relatively small, and only served a handful of countries- but it covered the markets they cared about and the transaction fees were cheap. They used XML for data interchange, and while they had no published schema document, they did have some handy-dandy sample code which let you parse their XML messages.
$response = curl_exec($ch); $authecode = fetch_data($response, '<authCode>', '</authCode>'); $responsecode = fetch_data($response, '<responsecode>', '</responsecode>'); $retrunamount = fetch_data($response, '<returnamount>', '</returnamount>'); $trxnnumber = fetch_data($response, '<trxnnumber>', '</trxnnumber>'); $trxnstatus = fetch_data($response, '<trxnstatus>', '</trxnstatus>'); $trxnresponsemessage = fetch_data($response, '<trxnresponsemessage>', '</trxnresponsemessage>');Well, this looks… worrying. At first glance, I wonder if we're going to have to kneel before Z̸̭͖͔͂̀ā̸̡͖͕͊l̴̜͕͋͌̕g̸͉̳͂͊ȯ̷͙͂̐. What exactly does fetch_data actually do?
function fetch_data($string, $start_tag, $end_tag) { $position = stripos($string, $start_tag); $str = substr($string, $position); $str_second = substr($str, strlen($start_tag)); $second_positon = stripos($str_second, $end_tag); $str_third = substr($str_second, 0, $second_positon); $fetch_data = trim($str_third); return $fetch_data; }Phew, no regular expressions, just… lots of substrings. This parses the XML document with no sense of the document's structure- it literally just searches for specific tags, grabs whatever is between them, and calls it done. Nested tags? Attributes? Self-closing tags? Forget about it. Since it doesn't enforce that your open and closing tags match, it also lets you grab arbitrary (and invalid) document fragments- fetch_data($response, "<fooTag>", "<barTag>"), for example.
And it's not like this needs to be implemented from scratch- PHP has built-in XML parsing classes. We could argue that by limiting ourselves to a subset of XML (which I can only hope this document does) and doing basic string parsing, we've built a much simpler approach, but I suspect that after doing a big pile of linear searches through the document, we're not really going to see any performance benefits from this version- and maintenance is going to be a nightmare, as it's so fragile and won't work for many very valid XML documents.
It's always amazing when TRWTF is neither PHP nor XML but… whatever this is.
[Advertisement] Plan Your .NET 9 Migration with ConfidenceYour journey to .NET 9 is more than just one decision.Avoid migration migraines with the advice in this free guide. Download Free Guide Now!
Can AI-Enabled Thermostats Create a 'Virtual Power Plant' in Texas?
Read more of this story at Slashdot.
Cuba's Power Grid Collapses Again After Second Hurricane. And Then an Earthquake Hit
Read more of this story at Slashdot.
How Gophers Restored Plant Life to a Volcano-Ravaged Mountain - in One Day.
Read more of this story at Slashdot.
How Gophers Restored Plant Life to a Volcano-Ravage Mountain - in One Day.
Read more of this story at Slashdot.
Generative AI Doesn't Have a Coherent Understanding of the World, MIT Researchers Find
Read more of this story at Slashdot.
Washington Post Employees Ordered Back To the Office
Read more of this story at Slashdot.
Java Proposals Would Boost Resistance to Quantum Computing Attacks
Read more of this story at Slashdot.
This Elephant Learned To Use a Hose As a Shower. Then Her Rival Sought Revenge
Read more of this story at Slashdot.
Salesforce to Hire 1,000 People for Big AI Product Sales Push
Read more of this story at Slashdot.
Free Software Foundation Plans Year of Celebrations For Its 40th Anniversary
Read more of this story at Slashdot.
NASA Investigates Laser-Beam Welding in a Vacuum for In-Space Manufacturing
Read more of this story at Slashdot.
The Team Behind GitHub's 'Atom' IDE Build a Cross-Platform, AI-Optional 'Zed Editor'
Read more of this story at Slashdot.
Rust Foundation Shares Draft of New, Simpler Trademark Policy
Read more of this story at Slashdot.