Translink vs. Translink

Translink, May 23 2012:

With fare gates coming into operation at SkyTrain and Canada Line stations next year, TransLink has yet to smooth out potential wrinkles in the new system.

One involves a particular benefit enjoyed by riders with prepaid passes. On Sundays and holidays, two adults and four children aged 13 and under can travel on a single TransLink adult monthly fare card or West Coast Express 28-day pass, or an annual employer transit pass.

“All we can tell you right now is that the offering will still be there,” spokesperson Ken Hardie told the Straight by phone. “How it will work—at this point, we don’t have that detail for you.”

Translink, July 30 2013:

After a review of discounts and programs in its tariff, TransLink will make changes that will affect customers. As part of the changes, several programs will be discontinued.

As approved by the TransLink Board, the changes to the tariff include the discontinuation of:

Free travel for family members of monthly pass holders on Sundays and holidays effective January 1, 2014.

Huh.

Cycling on sidewalks in New Westminster

Did you know that it’s perfectly legal to ride your bicycle on the sidewalk in New Westminster?

Well, strictly speaking that’s not true, but it’s perfectly legal to ride your bicycle on most of the sidewalks in New Westminster.

British Columbia’s Motor Vehicle Act Section 183(2)(a) states:

A person operating a cycle must not ride on a sidewalk unless authorized by a bylaw made under section 124 or unless otherwise directed by a sign.

Section 124(1)(v) states:

The council of a municipality may, by bylaw not inconsistent with or derogatory to this Part, provide for the following:

the use, in places, under conditions and in circumstances specified by the bylaw, of sidewalks and crosswalks by persons riding cycles.

That means that municipalities in British Columbia have the power to allow people to ride their bicycle on sidewalks. New Westminster exercises this power through the Street Traffic Bylaw No. 6027, 1991. Sections 501.2 and 501.3 state:

501.2 A person operating a cycle on any sidewalk, footpath, or walkway in the City shall operate the cycle only in such a way that it will not interfere with a pedestrian lawfully on or using said sidewalk, footpath or walkway.

501.3 No person on a cycle shall operate the cycle on any sidewalk, footpath, or walkway set out in a Schedule attached to and forming part of this bylaw.

So there you have it. Section 501.2 states that you can operate a cycle (which in New Westminster is defined as “a device having any number of wheels that is propelled by human power and on which a person may ride”) on any sidewalk in New Westminster, as long as you don’t interfere with pedestrians.

But there’s also Section 501.3 which refers to a Schedule attached to the bylaw. That would be Schedule 7 – Sidewalks, Footpaths and Walkways Where Cycling, Roller Skating and Skateboarding is Prohibited. There are nine stretches of street listed in that Schedule. Instead of listing them, I made this handy Google Map showing the roads along which you are not allowed to cycle on the sidewalks.

The roads are mostly in commercial areas with high foot traffic. The only exceptions to this are the small stretch of Twentieth Street (there are some small strip malls here but hardly any foot traffic) and the Waterfront Esplanade, which strictly speaking isn’t a road or a sidewalk.

There you have it. You’re allowed to cycle on most of the sidewalks in New Westminster. Just remember that pedestrians have the right-of-way, so don’t go mowing people down. And pedestrians, remember that for most of the streets in New Westminster bicycles are allowed, so don’t get shirty when you see one coming towards you.

When is an Array not an Array?

Short answer: When it’s a JavaScript
arguments
object.

Long answer:

In a JavaScript package I’m writing, I have a function that returns an object.
There’s a bug in it where in certain situations it returns the JavaScript value
true.

I have a test framework set up with Mocha using the Chai assertion library. With
it, I can do

1
expect(result).to.eql(expected);

This means that the result I get back from my function should deeply equal the
expected value. “Deeply equal” means that the objects being compared are
identical — they’re the same type of object and store the same information.

In JavaScript, one would not expect an
Array to be deeply equal to an Object
because they’re different types of objects.

But in the Chai assertion library, an empty Array is deeply equal to an empty Object. This assertion passes when it shouldn’t:

1
expect({}).to.eql([]);

Similarly, but even more confusingly, both an empty Array and an empty Object
are considered to be deeply equal to the JavaScript true value:

1
2
expect(true).to.eql({});
expect(true).to.eql([]);

Both of these assertions pass.

When I was writing a test to ensure that my function wasn’t returning true,
but instead should be returning {}, I was expecting the assertion to fail. It
didn’t.

Since Chai is open source, I forked it, patched it, and submitted a pull request
to get the fix into the main Chai repository. It makes sure that when deep
equality is done, the types of both objects have to be the same.

This was over a month ago, and my pull request hasn’t been accepted.

Why? Because of
arguments.

See, JavaScript has a builtin arguments object, which is “Array-like” in that
it’s an ordered list of values. When you call a function, it’s the list of
arguments that you passed to that function:

1
2
3
4
5
function dumpArgs() {
    for (var i = 0; i < arguments.length; i++) {
        console.log(i + " : " + arguments[i]);
    }
}

This object is kind of like an Array, but the only Array method you can call on it is
length. It’s not an Array object, it’s an Arguments object.

I’m of the opinion that “deeply equals” means that if the objects are different,
they’re not deeply equal. The string "4" might look like it contains the same
value as the integer 4, but you wouldn’t expect them to be deeply equal, because
they’re different types of objects.

My patch hasn’t been pulled because the guy doing the pulling disagrees, which
you can see at the pull request comments. But
only for non-primitive types. “4” is still not deeply equal to 4, but if
arguments is [1,2,3] then that’s equal to the Array [1,2,3].

The Mozilla Developer Network docs say

The arguments object is not an Array. It is similar to an Array, but does not
have any Array properties except length. For example, it does not have the pop
method. However it can be converted to a real Array.

I could change my patch so that if the arguments object is one of the values
being tested, it could be converted to a real Array before doing the check, but
that goes against the concept of deep equality. Two objects of different types
shouldn’t be deeply equal.

So if you’re using the Chai assertion library, and you discover that an empty
Array is equal to true, you’re getting that result because one of the Chai
developers thinks that deeply equals is only applicable some of the time,
because it’s “subtle”.