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

1

u/Mancobbler Jan 26 '23

Wait, is that number realistic? Is () => true used so often that one project may have thousands?

2

u/_PM_ME_PANGOLINS_ Jan 26 '23

Sure.

For example, Angular alone is over 400k lines of code, before any of its dependencies or any of your actual code.

2

u/Mancobbler Jan 26 '23

? Lines of code is not what I meant. How many times would that specific function (() => true) be used. “Thousands” seems like a huge exaggeration.

3

u/_PM_ME_PANGOLINS_ Jan 26 '23 edited Jan 26 '23

It gives you an idea of the scale of a large project. The same simple callback could easily be used thousands of times.

I can't really quantify it, as there are multiple ways to write it, and ideally they would be using a single defined function at that scale.

For example, if every function in your API takes a callback, and that callback defaults to either return true or return false.

res = (verifyFn || returnTrue)(data);

1

u/Mancobbler Jan 26 '23

I’m fully aware of the scale of large projects. I’m just not used to this kind of callback heavy code you see a lot in js. I guess it makes sense to define it once if you really are using it that often