# This week in: Code from the Wild

**URL:** https://forum.kirupa.com/t/this-week-in-code-from-the-wild/650717
**Category:** programming
**Created:** [February 4, 2022, 11:41pm UTC](https://forum.kirupa.com/t/this-week-in-code-from-the-wild/650717 "2022-02-04T23:41:55Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![senocular](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/senocular/32/7217_2.png) [@senocular](https://forum.kirupa.com/u/senocular)
#### Post date: [February 4, 2022, 11:41pm UTC](https://forum.kirupa.com/t/this-week-in-code-from-the-wild/650717/1 "2022-02-04T23:41:55Z")

</div>

```auto
getAnimation(animation.animation)

```

What do we want!?!

Animation! ✊

Where do we get it from!?!

The animation property…

Of what!?!

The… animation…

---

<div class="post-metadata">

### Author: ![steve.mills](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/steve.mills/32/14961_2.png) [@steve.mills](https://forum.kirupa.com/u/steve.mills)
#### Post date: [February 5, 2022, 1:19am UTC](https://forum.kirupa.com/t/this-week-in-code-from-the-wild/650717/2 "2022-02-05T01:19:59Z")

</div>

😄  
You never know… it could use WAAPI.

`const animation = () => Element.animate(getAnimation(animation.animation), getAnimation(animation.timing))`

---

<div class="post-metadata">

### Author: ![senocular](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/senocular/32/7217_2.png) [@senocular](https://forum.kirupa.com/u/senocular)
#### Post date: [February 7, 2022, 5:22am UTC](https://forum.kirupa.com/t/this-week-in-code-from-the-wild/650717/3 "2022-02-07T05:22:32Z")

</div>

This one is an oldie but goldie (and I believe I may have posted it before somewhere else on kirupa), but one of my favorites and it fits the topic:

```auto
// Add one to the iterator
i--

```

---

<div class="post-metadata">

### Author: ![VaiFanatic](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/vaifanatic/32/7159_2.png) [@VaiFanatic](https://forum.kirupa.com/u/VaiFanatic)
#### Post date: [February 13, 2022, 5:18am UTC](https://forum.kirupa.com/t/this-week-in-code-from-the-wild/650717/4 "2022-02-13T05:18:21Z")

</div>

Seems intuitive enough to me. 😂

---

<div class="post-metadata">

### Author: ![senocular](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/senocular/32/7217_2.png) [@senocular](https://forum.kirupa.com/u/senocular)
#### Post date: [February 28, 2022, 9:03pm UTC](https://forum.kirupa.com/t/this-week-in-code-from-the-wild/650717/5 "2022-02-28T21:03:39Z")

</div>

Relatable

 ![image](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/8/1/8142d7a2140a44e6293a8918deba0dc7bd70eb72.jpeg)

---

<div class="post-metadata">

### Author: ![krilnon](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/krilnon/32/34_2.png) [@krilnon](https://forum.kirupa.com/u/krilnon)
#### Post date: [March 5, 2022, 9:50pm UTC](https://forum.kirupa.com/t/this-week-in-code-from-the-wild/650717/6 "2022-03-05T21:50:22Z")

</div>

I wrote some code like this recently (which I’ve stripped of its actual functionality):

```auto
func f<TType>(_ p: [TType: Float]) {
    if type(of: TType.self) == UType.Type.self) {
        // ...
    }
}

```

Definitely felt like I could have found a better way, but I unexpectedly found myself wanting to reduce code duplication when the previously nongeneric function needed to work on a new enumeration type (in the dictionary).

---

<div class="post-metadata">

### Author: ![senocular](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/senocular/32/7217_2.png) [@senocular](https://forum.kirupa.com/u/senocular)
#### Post date: [March 14, 2022, 9:20pm UTC](https://forum.kirupa.com/t/this-week-in-code-from-the-wild/650717/7 "2022-03-14T21:20:04Z")

</div>

```javascript
expect(instance.method('bad-input')).to.throw;

```

_(Some names have been changed to protect the innocent.)_

This is some test code using an assertion library called [Chai](https://www.chaijs.com/). The test this code ran in passed, but it shouldn’t have. And while the assertion looks ok, since many of the assertions in chai work this way…

```javascript
// good
expect(truthyValue).to.be.ok;

```

…the original actually has a fatal flaw: `throw` needs to be called as a method. What the code should look like is:

```javascript
// correct
expect(() => instance.method('bad-input')).to.throw();

```

In this format, it will now fail when `instance.method()` fails to throw an expected error. When `throw` isn’t called as a method, the assertion doesn’t know to try to run the expect value as a function and check for errors. That then allows for non-throwing, but should be throwing, methods to incorrectly pass the test.

This issue was picked up in a code review, so we were able to fix things up before bad code got submitted to mainline, but it can be easy for things like this to slip through. Stay vigilant!

---

<div class="post-metadata">

### Author: ![steve.mills](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/steve.mills/32/14961_2.png) [@steve.mills](https://forum.kirupa.com/u/steve.mills)
#### Post date: [March 15, 2022, 12:17am UTC](https://forum.kirupa.com/t/this-week-in-code-from-the-wild/650717/8 "2022-03-15T00:17:21Z")

</div>

You should switch to Wallaby JS mate… 😄
