Fork me on GitHub
#calva
<
2022-03-06
>
Cora (she/her)08:03:26

down to 333 errors for strict null checks in my current branch 😎

gratitude 3
pez08:03:14

That's quite the burn rate!

Cora (she/her)08:03:28

right?? feeling pretty good about it ☺️

Cora (she/her)08:03:30

I started at 750 or so I think?

Cora (she/her)21:03:46

btw I would love to switch to arrow functions instead of traditional functions - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions

Cora (she/her)21:03:52

(where it's appropriate, which is basically everywhere outside of classes)

Cora (she/her)21:03:01

it gets rid of a ton of potentially weird behavior around this (if it's not attached to an object via a prototype then why are you using this, UGH) and using arguments (magic!) and trying to use functions as constructors (just use class syntax and use traditional function syntax within classes) or trying to access a function's prototype

Cora (she/her)21:03:09

it basically makes functions a lot simpler, removing magic and making it super difficult to use in ways you probably don't want people using things in the first place

Cora (she/her)21:03:52

so it would move from the former to the latter:

Cora (she/her)21:03:54

export function isNonEmptyString(value: any): boolean {
    return typeof value == 'string' && value.length > 0;
}

export const isNonEmptyString = (value: any): boolean => {
    return typeof value == 'string' && value.length > 0;
}

bringe04:03:07

I thought I remembered that arrow function names wouldn’t show up in stacktraces, and that was a reason to use traditional functions where that’s important, but that doesn’t seem to be the case (at least not anymore or not in this situation in the screenshot, which is from a browser console).

bringe04:03:30

Seems like it might be good idea to use arrow functions more. I don’t really run into the issues you mentioned / do those things, but for the sake of enforcing better code quality for an open source project, it might not be a bad idea to enforce arrow function use in certain situations, if that’s possible.

pez06:03:30

JavaScript is weird. But we are not exposed to these problems anywhere in the codebase, are we? We use classes proper and all that.

pez11:03:30

Thinking a bit about this, I'm starting to think it might be a good idea to make the switch. It would codify and enforce what we are already doing. The only reason I hesitate a bit is that I think it is a bit harder to parse arrow functions than regular ones, but that's probably just a matter of practicing.

1
Cora (she/her)13:03:07

it's definitely a syntax to get used to! we don't need to move to it all at once or anything but it's something we can start using now as we add code

Lukas Domagala17:03:31

I’m also happy to move over. The Clojure part of my brain is rebelling a bit since it feels like using (def isNonEmptyString (fn [value] (…)))but JS is weird anyway 🙂

bringe17:03:27

That’s likely essentially what defn is doing anyway though, right? (Saying this without looking at its source).

Lukas Domagala17:03:06

I’d prioritize it way below the null checking though unless it’s a mostly automated switch. I think functions haven’t given us any trouble yet.

👍 1
Lukas Domagala17:03:04

@U9A1RLFNV I think some tooling has trouble with (def (fn …)) since it’s not immediately obvious that it’s a function + if you don’t name your (fn ..) you get the stacktrace problem you mentioned.

bringe17:03:23

Ah yes. I was speaking more from a “what’s actually happening when you use defn” point of view. But yeah you’re right that doing that yourself is not a good idea.

Cora (she/her)17:03:56

yeah, I'm still doing the strict null stuff first

🙏 1
Cora (she/her)19:03:30

but I've been hitting the low-hanging fruit where I can keep the same behavior

Cora (she/her)19:03:52

and then I'll probably push for dependency upgrades after all of this. we're on a pretty old typescript

gratitude 1