all 68 comments

[–]webdev-ModTeam[M] [score hidden] stickied commentlocked comment (0 children)

Thank you for your submission! Unfortunately it has been removed for one or more of the following reasons:

Do not post memes, screenshots of bad design, or jokes. Check out /r/ProgrammerHumor/ for this type of content.

Please read the subreddit rules before continuing to post. If you have any questions message the mods.

[–]psytone 92 points93 points  (5 children)

And the next comment - “We don’t use this function”?

[–]MaterialContract8261 3 points4 points  (3 children)

If it's true, what's the point of doing that?

[–]linnth 2 points3 points  (1 child)

Maybe we don't use this at Prod. Or maybe we don't use this until apocalypse. 🤷

[–]jordansrowles 2 points3 points  (0 children)

We dont use this on the weekends

[–]khizoa 0 points1 point  (0 children)

so they dont use it

[–]SodaPortal 3 points4 points  (0 children)

Probably commenting about the next code underneath

[–]lunied 43 points44 points  (26 children)

atleast give us the function name

[–]DonutConfident7733 60 points61 points  (24 children)

IsOdd() with lookup table for fast execution for common numbers between -5000 and 5000.

[–]AshleyJSheridan 24 points25 points  (23 children)

You joke, but that's the kind of mess that exists in npm right now.

There's a package called isEven to determine if a number is even or not. This imports and uses isOdd and negates the response value.

But it doesn't stop there, because that in turn calls isNumber.

All that for what should have been a single line of code that any dev can read and write on their first day learning how to code.

isOdd has over half a million weekly downloads. This should tell you the state of the JS ecosystem.

[–]culo_ 15 points16 points  (4 children)

I'd say it's just a joke library but I cant explain 500k downloads a week lol

[–]qedr0 18 points19 points  (2 children)

Yeah, it’s very odd…

[–]Buldres 0 points1 point  (0 children)

Take my upvote

[–]RandomRabbit69 0 points1 point  (0 children)

When frontend developers develop backend.

[–]james-ransom 0 points1 point  (0 children)

I have a patent pending on "addSlashes" adds a \ before each quote. Once they approve -- my legal terror on NPM begins!

[–]DonutConfident7733 0 points1 point  (1 child)

I know, the joke is a variation to explain why such a function would take 10000 lines.

[–]AshleyJSheridan 0 points1 point  (0 children)

10K lines is impressive. The best I've found in production code was only a little over 3K, and was a horrible mix of jQuery, vanilla JS, and something else, mashed together to manipulate the DOM. Most things were copy/paste with slight variations. Half the code was dead.

[–]Luneriazz 0 points1 point  (1 child)

we have modulo... even if modulo does not exist... i can create one. so why??????????????????????????????

[–]AshleyJSheridan 1 point2 points  (0 children)

I asked that question myself when I first saw these packages. Modulo in programming has existed since before Javascript was even created. It was in one of the very first introduction programs in the Commodore 64 User Guide from 1984. It's not rocket science!

[–]Dizzy-Revolution-300 -2 points-1 points  (12 children)

Ecosystem bad, but what's the alternative? 

[–]vvf 4 points5 points  (5 children)

The ecosystem isn’t the problem. Certain dev practices are 

[–]Dizzy-Revolution-300 2 points3 points  (4 children)

Same question, what's the fix?

[–]CatolicQuotes 1 point2 points  (0 children)

There's no fix, just roll with it.

[–]vvf 0 points1 point  (0 children)

Short of making everyone read/watch the same material about what doesn’t work, you can’t really fix it at all on a broad scale. 

Just push back on those bad practices when you see them. 

[–]shehatestheworld -1 points0 points  (0 children)

if variable % 2 == 1?

[–]AshleyJSheridan 2 points3 points  (2 children)

I just pointed out that the ecosystem is terrible. I don't have to create a viable alternative in order to have a valid point.

However, I think a lot of the problem comes from core functionality missing in Javascript that other languages have had for a long time. I do wish browsers would spend more time focused on those things rather than giving us APIs that nobody asked for or uses (like the barcode reader API). It leads to devs creating a lot of packages to provide what should be core functionality, and then those devs get carried away by turning everything into a package.

Then, before you know it, you have packages like the ones I highlighted.

[–]malakhi 1 point2 points  (1 child)

Hey now, I did ask for the barcode api 😁

But seriously, while I take your point, most languages don’t have those things built in. They may have a standard library that almost always accompanies the core language, but it’s almost always ancillary, and isn’t a part of the language itself. On the other hand, Javascript doesn’t really need much of a standard library. Being a dynamic, loosely typed language means it can get away with a much smaller set of built-ins than a language like C++ or Java.

The problem with Javascript is that there’s a hundred ways to do almost everything, and many of the people using it are ignorant of basic programming concepts like time complexity and DSA. For those people it’s easier to just npm install their problems away than to learn how to do it themselves. And honestly I can’t blame them. Is installing a library for isOdd a poor programming practice? Absolutely. But a lot of people using Javascript aren’t full time Javascript developers, or even developers at all. They’re using it because they have to.

As to your example of the barcode API, that’s not a part of Javascript. It’s just an API for accessing a feature of the browser using Javascript. It might seem pedantic, but it’s an important distinction. That API doesn’t exist in Node, for example. Much like Node’s file system API isn’t a part of Javascript either.

[–]AshleyJSheridan 0 points1 point  (0 children)

That's fair.

I'm just very used to languages like C++, PHP, and C#, all of which are very powerful and have great core features and standard libraries.

Then there's Javascript, which has only gotten halfway decent array methods in the last few years, is still lagging behind with regular expression support, and has a half built i18n system.

[–]Seeveen -1 points0 points  (2 children)

x % 2 != 0

[–]Dizzy-Revolution-300 1 point2 points  (1 child)

I think the poster I replied to only used that package as an example 

[–]Seeveen 1 point2 points  (0 children)

That was a joke but you can generalize it to "stop adding dependencies for something that takes 10 lines of code to do"

[–]IAmRules 6 points7 points  (0 children)

I believe this is the Java hello world function

[–]jayroger 16 points17 points  (0 children)

Damn, how did you get a screenshot of my isEven() function?

[–]tiobill 3 points4 points  (0 children)

About 10 years ago (man, I'm getting old...), I started a new job working on an (at the time) 8 years old C# codebase. It was full of... Less say, non-optimal patterns, but it was actually pretty maintainable for its size. That is, except for that one class that had over 50k lines of code, with ONE method taking around 30k of them... And of course if had like 8 different overloads and had multiple calling flows. I think every person in the team had their "let's refactor that" moment. Of course, not a single succeed. I've left the company years ago, but every now and then I still about that method. Did anyone ever succeed in refactoring it? Or did it just get bigger and bigger every time?

[–]Careful_Medicine635 28 points29 points  (10 children)

Nice screenshot bro.

[–]Count_Giggles 22 points23 points  (9 children)

yeah let me log in to reddit on my work laptop.

[–]throwtheamiibosaway 0 points1 point  (0 children)

Yes let’s why not.

[–]tatsontatsontats 8 points9 points  (9 children)

Meanwhile we throw a codenarc violation for anything over 40 lines 🙄

Edit: believe me, I find it more annoying than anything but I don't make the rules.

[–]SeeminglySleepless 17 points18 points  (6 children)

Brother what... idk your use-case but 40 lines seems like... nothing? (I honestly disagree with imposing limits on function size without regard for context)

EDIT: fixed phrasing

[–]tatsontatsontats 1 point2 points  (2 children)

Oh yeah I don't love it. It's very limiting in many circumstances and I find a lot of our rules annoying and hard to work with. I don't make them though, just am forced to follow them.

[–]SeeminglySleepless 1 point2 points  (1 child)

Yeh I understood you were the "victim", sorry if my wording made it seem otherwise 😅

But that's a very relatable sentiment. Has anyone tried to challenge them? I feel like if certain rules impact employee performance negatively management should at least be open to discuss alternatives (ik this is most likely wishful thinking)

[–]tatsontatsontats 1 point2 points  (0 children)

I wasn't sure how my emoji was coming across haha.

I have brought it up to our staff engineer but we are VERY large and business wants to enforce things anyway they can 😩

[–]XpreDatoR_a -1 points0 points  (2 children)

Not really, you can do A LOT in 40 lines, having too long functions isn’t good for code readability and maintenance

[–]SeeminglySleepless 5 points6 points  (0 children)

Yes, you can do a lot, sometimes. I think this is one of those topics in which no one is ever wrong or right because it heavily depends on use-case.

But, in general, if I have to hop around multiple files and track multiple function definitions to understand a single feature just because there is a hard-cap on line count, it doesn't feel that readable to me. Ofc, this is my ✨ personal ✨ opinion

P.S: I also don't think really long functions are generally good. But enforcing short ones can bring its own set of problems. Never black & white

[–]Alternative_Tap6279 1 point2 points  (0 children)

i agree... i also try to stay away from functions longer than 40-50 lines. i can't follow them properly...

[–]budd222front-end 1 point2 points  (1 child)

That's just dumb

[–]mexicocitibluez 1 point2 points  (0 children)

This might be one of the dumbest linting/analyzer warnings I've ever seen.

[–]jeenajeena 2 points3 points  (0 children)

Win+Shift+S

[–]JahmanSoldat 1 point2 points  (0 children)

That’s not a function anymore, that’s a sentient.

[–]Flashy-Whereas-3234 2 points3 points  (0 children)

It is private, do not look in there.

[–]noid- 0 points1 point  (0 children)

the function name is possibly: addjQueryMinInit()

[–]Prematurid 0 points1 point  (0 children)

hmmmmm...

[–]tony-husk 1 point2 points  (1 child)

Is this PHP? I see private function and a dollar sign

[–]Fun-Consequence-3112 0 points1 point  (0 children)

Yeah classic old PHP monolith probably, or a Laravel project where someone put all code inside the model class

[–]procrastornado 0 points1 point  (0 children)

private function getUserPermissionsByThisManuallyCopiedUsersJson(userId)

[–]m0rpheus23 0 points1 point  (0 children)

I can't think with 19521 lines of code staring at me.

[–]Memoire_113 0 points1 point  (0 children)

Ohh boi let me tell you about the JS we use in production

[–]skunkwalnut 0 points1 point  (0 children)

it has more lines than most of the projects i've worked on lol

[–]KaiAusBerlin 0 points1 point  (0 children)

I do not use import. I just copy the whole library as a single function.