Unusually Numerous

by in Error'd on

We had an unusual number (not that unusual, it was an integer) of interesting submissions this week; some were saved for special editions, some of the others follow.

Ian C. obscured a part of his own unusual number, saying "New Scientist are taking the science a bit too far for your integer subscriber number." Just a case of better safe than sorry, or is that really a secret number, Ian?


Searching for a Perl

by in CodeSOD on

When I was young and dumb, my freshman year college CS program taught us Scheme. Now, thinking myself a rather accomplished C++ programmer by that point (I was not), I thought this was a bit of an insult. But I was still interested in learning new languages, so I chose to dabble in Perl.

And I remember having the audacity to suggest to my professors that Scheme was a terrible introduction to programming, and instead we should start the students with an easy and accessible language, like Perl.


Dented

by in CodeSOD on

At many a workplace, I've had the fortune to step into the company around when they were starting to get serious about standards, code quality, and generally pivoting into a mature development organization.

When it comes to coding standards, everyone has strong opinions, though frankly consistency matters more than the standard itself. For example, with indenting, it doesn't really matter if you're doing Allman or something more K&R. Though we can all agree that anyone using [Whitesmiths] style has been hurt, and hurt deeply.


Underscoring the Importance of Good Naming

by in CodeSOD on

An eternal problem in programming is "empty strings are basically nulls, right?" Frequently, when someone hands us "", we know that represents "no value", and thus is basically null. Well, sometimes. Other times it's not. Tracking this chaos is a common source of bugs and WTFs.

Martin's team had a problem in PHP. See, the is_null function is, well, checking for nulls. It isn't checking for empty strings. Being PHP, the empty function also doesn't check for empty strings, it checks for strings that can coerce to false (which includes the empty string, but also includes '0'). The "best" way in PHP to check for empty strings is just a direct comparison- $val == ''.


Assumption is the Mother of all Segfaults

by in CodeSOD on

We return to Stefano Z, who once upon a time was a lowly junior developer surrounded by Very Smart™ and Very Senior™ developers.

Some of their code was written in a not-C language. It had to process many hundreds of millions of data points, and while it was fast, it wasn't fast enough. The senior devs had a solution: rewrite it in C, the fastest of all languages.


My Stars

by in Error'd on

BOINC, the Berkeley Open Infrastructure for Network Computing, is a project to support public distributed computation, in service of efforts like [email protected]. Our reader Hans K. has a few grievances to share.

First, Hans complained "I'm trying to add a BOINC project. Yes, I understand the conditions, just not which radiobutton I should choose. Although, with this one the next button is disabled, so I guess it's the other."


PHP Error Logging

by in CodeSOD on

Today's anonymous submitter sends us some PHP exception logging code. This particular code shows a surprising understanding of some clever PHP tricks. Unfortunately, everything about it is still wrong.

try {
    // do stuff that might throw an exception
} catch (Throwable $th) {
    ob_start(); // start buffer capture
    
    echo($th->getMessage()); // dump the values
    var_dump($th); // dump the values
    $ob = ob_get_contents(); // put the buffer into a variable
    
    ob_end_clean(); // end capture
    
    error_log($ob); 
}

VBitMask6

by in CodeSOD on

Bitwise operations are one of those things that experienced developers find easy (if not intuitive), but are a fairly bad way to expose functionality without real careful design. After all, flags & 0x02 doesn't really mean much if you don't know what 0x02 is supposed to represent.

But with named constants and careful thought, a bitmask can be a great way to pass flags around. At least, they can be if you understand how to use your language's bitwise operators.


Archives