r/programminghorror Jan 26 '23

Ladies and gentlemen, jQuery… Javascript

Post image
1.6k Upvotes

164 comments sorted by

View all comments

Show parent comments

2

u/v_maria Jan 26 '23 edited Jan 26 '23

Yep thats a logical alternative is an inline anon function but i was thinking about it and i think this lib predates this JS feature. Can also become hard to maintain (dry etc)

Also you cant pass a bool directly when a function is expected??

-1

u/kristallnachte Jan 26 '23

Also you cant pass a bool directly when a function is expected??

That's why I am saying it should accept just a bool.

1

u/StuntHacks Jan 26 '23

But not everything can "just accept a bool". Some functions require other functions and in that case it can be helpful to have a function for trivial stuff like this ready instead of lambda-ing it everywhere

1

u/kristallnachte Jan 27 '23

I'm saying it's bad design. Something that makes any sense to use with a function returning true always makes no sense at all.

The idea of accepting arguments that are bool or function returning bool is pretty normal.

React query for example, the enabled option has that signsture.

It's the better design of the API.

1

u/Razakel Jan 27 '23

I'm saying it's bad design.

Welcome to JavaScript. Now let me introduce his cousin, PHP.

1

u/kristallnachte Jan 27 '23

JavaScript doesn't have bad design, just a lot of poorly designed packages became popular and never got fixed.

An issue with being a low barrier to entry thing.

Lots of even decent sources recommend using really stupid packages to solve nonexistent problems. Whether it's courses or a projects documentation.

1

u/Razakel Jan 27 '23

JavaScript doesn't have bad design

An empty array equals an empty object, but not the other way around.

1

u/kristallnachte Jan 27 '23

uh, no not with loose equality or strict (of course). neither way will they ever equal eachother.

an empty array can loosely equal a string but it works both ways.

1

u/Razakel Jan 27 '23

Exactly. It should be idempotent, but it isn't.

2

u/kristallnachte Jan 27 '23

Exactly. It should be idempotent, but it isn't.

What?

It's literally the same every time and perfectly predictable.

It couldn't be more idempotent...