Dora's AngularJS team (previously) wanted to have their display be "smart" enough to handle whether or not you were editing a list of "Users" or just one "User", so they implemented a function to turn a plural word into a singular word.

Which, of course, we already know the WTF implementation of it: they just chop off the last letter. So "Potatoes" becomes "Potatoe", "Moose" becomes the noise cows make, and I'm just left saying "oh, gees". But they managed to make it worse than that.

The actual display might be used like so:

<label> Edit {{$ctrl.singular}}</label>

singular is a property on the controller for this component. But how does that get populated?

function getSingular(){ if($ctrl.type){ $ctrl.singular = $ctrl.type === 'details' ? $ctrl.type : $ctrl.type.slice(0, -1); } }

So, it's important to note, getSingular isn't a "get" method in the conventional sense. It populates the singular property, but doesn't return anything. Hopefully this method gets called sometime before we try and display $ctrl.singular- it won't crash or anything, but it also won't display any useful information.

For extra weirdness, though, it also has a extra gate: "details" is always plural. This means you might use it like so: Edit User {{$ctrl.singular}} to display "Edit User Details", and it will always be plural.

It's a bad implementation of a bad idea, with a confusing method name, inconvenient calling semantics, and a trap-door that could easily surprise you if you're not details oriented. That's a lot of bad code in a tight space.


Pay attention to this space over the next few days: We'll be announcing our winners of our What the Fun Holiday special, and sharing those stories.