this post was submitted on 21 Apr 2024
244 points (96.6% liked)

Programmer Humor

32000 readers
1744 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 5 years ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 17 points 5 months ago (3 children)

I spent way too long today figuring out why my app was doing something that it's NOT supposed to do on weekends.

I read Luxon's docs (pretty cool lib tbh) again and again, and tried everything I could think of to get isWeekend to return a sane result.

Turns out I was pulling a somewhat older version of Luxon, where isWeekend didn't exist. In any sane language, I expect I'd get a huge warning about a property that doesn't exist, but alas...

Typescript helps me keep my sanity, but juuuuust barely.

[–] [email protected] 18 points 5 months ago* (last edited 5 months ago)

If isWeekend doesn't exist, then the weekend doesn't exist, so it's naturally false.

That's why JavaScript gets pushed so hard - it's part of the capitalist agenda to keep us working 7 days a week

[–] [email protected] 5 points 5 months ago

That's fair. Typescript has to cook with the existing js ecosystem.

[–] [email protected] 4 points 5 months ago (2 children)

Weren't you getting runtime errors for the function not being found?

[–] [email protected] 7 points 5 months ago (1 children)

No, they were probably getting false every time

[–] [email protected] 1 points 5 months ago* (last edited 5 months ago) (1 children)

Falsy* because it was undefined

However, their IDE should have highlighted it as an unknown property. Guess this guy is coding in notepad or vi.

[–] [email protected] 2 points 5 months ago (1 children)

Yep, thanks for correcting me. In fact, if they write something like

if (day.isWeekend) {...}

The block will never be executed with the old version of library

[–] [email protected] 2 points 5 months ago (1 children)

Yeah that's exactly what I think happened to him. He needs a better IDE and/or needs to stop copy/pasting code from stackoverflow or documentation that doesn't match his library version.

[–] [email protected] 0 points 4 months ago

My dude, you need to understand that all that anger and resentment, it is not you. It's the years of JavaScript poisoning your mind.

In any case, that goes to my point. I would have to be saved by my IDE, when any sane language will blow up in your face as soon as you try to run it.

[–] [email protected] 2 points 5 months ago (1 children)

I don't know how luxon works, but isWeekend could be a property instead of a function

[–] [email protected] 2 points 4 months ago

It is. It also happens to be undefined, and checking that for truth is how I was bitten.