this post was submitted on 21 Apr 2024
717 points (97.0% liked)

Programmer Humor

32559 readers
615 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
[–] gaael@lemmy.world 96 points 7 months ago (4 children)

You'll find an npm package to help you count up to 2.

(I recently learned - maybe here - that the is-even package has over 170k weekly downloads)

[–] Drusenija@lemmy.world 83 points 7 months ago (2 children)

What's even wilder is if you look at the code of that package, all it does is include the is-odd package and then return !is-odd. And the is-odd package isn't much better, it does some basic checks on the input and then returns n % 2 === 1.

[–] NotAViciousCyborg@lemmy.world 27 points 7 months ago (3 children)

I thought I was missing something. JS is one of my main languages and I always just write the is-odd function myself since it's like 10 characters. It boggles the mind that is-even has 176k weekly downloads

[–] kevincox@lemmy.ml 19 points 7 months ago (1 children)

To be fair having a name can make things easier to read. I get that i % 2 == 0 is a common pattern and most programmers will quickly recognize what is happening. But isEven(i) is just that much easier to grok and leaves that brainpower to work on something else.

But I would never import a package for it. I would just create a local helper for something this trivial.

[–] NotAViciousCyborg@lemmy.world 10 points 7 months ago (1 children)

Exactly what I would do if I had to reuse it, especially now since I know that adding a package would actually add 2. It all just seems so...inefficient

[–] kevincox@lemmy.ml 11 points 7 months ago (1 children)

Even if the code isn't reused adding names to sub-expressions can be very valuable. Often times I introduce new functions or variables even if they are only used once so that I can give them a descriptive name which helps the reader more quickly understand what is happening.

[–] NotAViciousCyborg@lemmy.world 3 points 7 months ago

Yeah, I do that with pretty much every separate operation in c# since our solutions are pretty big. Most of my JS scripts are just done in ServiceNow which are separated and named appropriately.

[–] gaael@lemmy.world 7 points 7 months ago

Also there are 40-something packages depending on it, so I guess it gets pulled automatically when they are used.

[–] Aqarius@lemmy.world 2 points 7 months ago

If youre lazy/busy enough, doing basic checks on the input is enough boilerplate to package out.

I’ve always looked at stuff like that as much more along the lines of performance art than anything else.

[–] hemko@lemmy.dbzer0.com 25 points 7 months ago

Is-even continues to be the best joke in the industry

[–] PrettyFlyForAFatGuy@feddit.uk 11 points 7 months ago

Oh boy, this actually made me laugh out loud

[–] kamen@lemmy.world 10 points 7 months ago

This must be a "hold my beer" kind of joke and someone wanting to see how far they can take it.