Thoughts

HATE TIME

December 2, 2013

Things in the source code I hate perhaps the most in my everyday work

There’s things which one can tolerate. And there’s things which just choke you down and turn your brain inside out and you suddenly jump up and start screaming and throwing things to other things. Here’s my list.

display_errors, 0

Holy crap, the MOST irritating is to see the following:

// ...some global init...
ini_set('display_errors', 0);
// ...some other global init...

That’s making me facepalm every time I see it. I mean, what the fuck? You are DEVELOPER, muthafucka! You MUST see the errors while you are working, how the hell you are supposed to debug anything without error reporting?!

The only place where you should put such an embarassing shit like the above is the bootstrap script at your PRODUCTION, just ONE of your deployment environments!

Here’s how you supposed to do it, you moron!


if (PRODUCTION_MODE) ini_set('display_errors', 0);

Even better with feature-detecting instead of environment-detecting and proper code style:

if ($app->isAfraidOfSniffers())
  $app->shutUpErrorReporting();

ALL OTHER TIME IT’S MEANINGLESS TO DISABLE ERROR REPORTING, REMEMBER IT, FUCKER!! I see even the freaking web frameworks doing this idiotic shit and inventing some crazy nonsense like their own debugging facilities with their own flag constants. JUST WRITE EVERYTHING YOU CAN TO ME IN CASE OF ERROR, YOU WORTHLESS PIECE OF CRAP.

E_STRICT ignorance

Second is, of course, the following shit.

$arr = ['first' => 1, 'third' => 3];
echo $arr['second'];

BLAM! PHP Notice about access to undefined hashmap key.

YES SONUVABITCH I WORK WITH E_STRICT ENABLED because I do care about any possible sign that I screwed somewhere.

Here’s the most usual usage of this shit:

public function run()
{
  /** @var array $data */
  $data = $this->makeData();
  $this->render($data);
}

public function render($data)
{
  require ('view.php');
}
/**
 * Holy crap, we have $data array available here!
 */
//... some other shit ...
echo $data['nonexistent key']
//... some other crucial UI shit ...

PHP Notice in that view file means the user got the whole page crashed because of a single nonexistend data item, and all we wanted to do with that data item is render it, it wasn’t something mission-critical.

If you want to write possibly nonexistent data just prepend a fucking @ that’s all!.

Unnecessary strict comparison

That is, $some_fetch_result === null crap.

Yeah, that’s right! Why the fuck you want to know whether the result of fetching something from somewhere is exactly null? What if someone who wrote that API method decided to return false in case of empty result? Even if there’s an empty array (in which case even I agree that it should not be considered same as null) what are you going to do with it, anyway?

Just forget about this brain-hurting nonsense:

$records = $modelRepository->fetchRecords($query);
if (null === $records) // HOLY CRAP, NO!
  throw LogicException;

Write the fucking !$records and that’s all! By doing that === crap you stress out that null is of significant value having a special meaning, when it obviously isn’t, you just wanted to check whether we failed to return anything.

I DON’T EVEN START TO TALK ABOUT NOT RETURNING NULL VALUES THERE, YOU MORON STILL STUCK IN 90’S.

Prefixes before object properties

OMG, words can’t describe the amount of disgust I experience when seeing the piece of crap like the following:

class Model
{
  public $public;
  private $_private;
}

Freaking degenerates coming to PHP from C/C++ completely missed the whole point with m_ prefix before member variables here. Remember, you brainless ape!

class Counter
{
  private:
    int m_counter;
}

int Counter::count(counter)
{
  int counter = counter++;
  m_counter += counter;
  return counter + m_counter;
}

MEMBER VARIABLES, DO YOU GET THEM NOW?

We can’t differentiate between member and other local variables without special cues like the proper naming or FQN, so the m_ convenience was invented. In PHP we always refer to member variables from $this object so we always know what variable is internal to class and what variable conforms to fucking Demeter’s Law.

There’s nothing uglier in PHP code than $this->_shit. WTF is this ->_ noise, are we in Perl now? HATEHATEHATE

Previous: On Clean Coders episodes 6 through 8 Next: On the Theory of Deploy