random code 8: urrgggh

:: CodeCritic, Programming Languages

By: John Clements

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php


namespace Symfony\Component\Form\Tests\Extension\Core\Type;

use Symfony\Component\Form\FormError;

class DateTimeTypeTest extends LocalizedTestCase
{
    public function testSubmit_dateTime()
    {
        $form = $this->factory->create('datetime', null, array(
            'data_timezone' => 'UTC',
            'user_timezone' => 'UTC',
            'date_widget' => 'choice',
            'time_widget' => 'choice',
            'input' => 'datetime',
        ));

        $form->bind(array(
            'date' => array(
                'day' => '2',
                'month' => '6',
                'year' => '2010',
            ),
            'time' => array(
                'hour' => '3',
                'minute' => '4',
            ),
        ));

        $dateTime = new \DateTime('2010-06-02 03:04:00 UTC');

        $this->assertDateTimeEquals($dateTime, $form->getData());
    }

    public function testSubmit_string()
    {
        $form = $this->factory->create('datetime', null, array(
            'data_timezone' => 'UTC',
            'user_timezone' => 'UTC',
            'input' => 'string',
            'date_widget' => 'choice',
            'time_widget' => 'choice',
        ));

        $form->bind(array(
            'date' => array(
                'day' => '2',
                'month' => '6',
                'year' => '2010',
            ),
            'time' => array(
                'hour' => '3',
                'minute' => '4',
            ),
        ));

        $this->assertEquals('2010-06-02 03:04:00', $form->getData());
    }
...
}

Okay, let me be frank; I really can’t stand PHP.

Actually, neither can other people; Googling for “worst programming language ever” yields a (closed) stackoverflow poll where PHP is the runaway “winner”, with more than twice as many votes as the runner-up.

I’m not sure that post really captures what’s wrong with the language, though. My impression, as I write code, is that it’s the worst at what it needs to be good at, which is helping people to write correct back-end web code.

To pick on the single most obvious thing, the way that PHP programs assemble HTML from scraps of strings is totally appalling. This language has learned exactly nothing from the work of John McCarthy. Which is now fifty years old.

RIP.

I’m also intrigued by the fact that git gists provide no syntax coloring for PHP, and I wonder whether maybe there’s an interesting reason for that.

What do I notice about this code? Well, for one thing, there are two function definitions in it, and they overlap hugely. This suggests to me that either PHP has terrible abstraction facilities, or that this code was written by someone who just didn’t care. Or, possibly, that it was generated automatically; I don’t recall seeing a note to that effect.