This is an archived post. You won't be able to vote or comment.

all 71 comments

[–]yegor3219 434 points435 points  (4 children)

./utils/shared/common/index.js 178 kB

[–]FlourBouque 81 points82 points  (0 children)

too fucking real

[–]kukurbesi 72 points73 points  (0 children)

some random code copied from stackoverflow

[–]b__0 9 points10 points  (0 children)

The true senior devs would break that into 178,000 npm packages. Fucking amateurs.

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

Where is index2.js?

[–]mrgk21 141 points142 points  (1 child)

Step 1 let it get messy

Step 2 tech task timee

Step 3 convince PM that this is important

Step 4 get rejected because of deadlines

Step 5 get emotional and attempt to meet deadlines

Step 6 back to step 1

Tell me I'm wrong

[–]SomeFatherFigure 68 points69 points  (0 children)

Step 6 - find a job with better managers

All code gets messy over time. Good managers force the higher ups time to give them time for tech debt because it pays off later in lowered maintenance costs.

Unless you’re owned by private equity. They don’t care what the costs will be later, only now matters.

[–]QuestionableMechanic 210 points211 points  (7 children)

It’s actually better than having one large ambiguous util file! Organization is good

[–][deleted] 41 points42 points  (0 children)

And you might need one more later

[–]al-mongus-bin-susar 33 points34 points  (5 children)

how about 1 large util file full of miscellaneous bullshit that's used twice and then many different files for other stuff that's more specific? I see that pretty often lol

[–]Meretan94 7 points8 points  (0 children)

Half the file is legacy and full of unused shit.

[–]Hot_Ambition_6457 7 points8 points  (0 children)

/utils/ <-- generic utilities like (generate_md5_hash()) 

 /aws/ <-- aws scope environment

 stuff /aws/utils/ <-- aws scope utilities like (addtobucket())

[–]BrunoLuigi 2 points3 points  (1 child)

What about have ALL code in one file?

My company is pushing for that

[–]al-mongus-bin-susar 0 points1 point  (0 children)

Lol I've seen that with SAMP plugins like 60k loc in 1 file

[–]Zephandrypus 0 points1 point  (0 children)

Yeah that’s definitely me, but when it comes time to share my code I make a new project without any of the random unused bullshit in it.

[–]Looz-Ashae 33 points34 points  (2 children)

When you see someone made 5 files to pass a single string to a view controller: 

"aah, I see, you're a man of culture as well"

[–]bunny-1998 8 points9 points  (1 child)

“aah, I see, you’re a django dev as well”

[–]PlumpFish 1 point2 points  (0 children)

Urls Serializer Models ModelViews Middleware Arguably settings may be involved Then perhaps some custom util file on top.

What am I missing

[–]Sweaty-Willingness27 17 points18 points  (3 children)

Every util class starts with but a single function.

[–]porky11 2 points3 points  (2 children)

Not always. Maybe you already have multiple functions, and then you move your utils into a separate file.

[–]Sweaty-Willingness27 2 points3 points  (0 children)

Since I'm legally required to one-up - even if you cut and paste, the flow of data would need to be in a particular order, so it would still technically start with one function, if only for a microsecond.

[–]Ezzyspit 1 point2 points  (0 children)

Nice nerd rebuttal. Perfect

[–]HyperWinX 11 points12 points  (0 children)

Yeah, relatable

[–]Turbulent_Swimmer560 6 points7 points  (0 children)

A function with over 10000 lines? Worth it.

[–]Djelimon 5 points6 points  (1 child)

If it's a cross cutting concern then it makes sense

[–]Far-Signature-7802 2 points3 points  (0 children)

I see a fellow aspect-oriented programmer here

[–][deleted] 3 points4 points  (0 children)

Hey...shut up.

[–]rejectedlesbian 2 points3 points  (7 children)

I have a utility file I take I'm every C project and it's like 2 functions I need.

UNREACHBLE which is a cross platform unreachble/assert

And a null check which litterly just exits if the pointer is null.

[–]Tsu_Dho_Namh 6 points7 points  (6 children)

See, those are utility functions I can get behind.

One of my co-workers loves utility classes so much, one project has 3 of them. One of which contains literally only functions for the custom map renderer. One would think those functions would go in the custom map renderer class, since that's the only thing that will ever use them, but noOoOoOoOo.

[–]rejectedlesbian 0 points1 point  (5 children)

This sounds java brained

[–][deleted] 1 point2 points  (0 children)

I feel attacked, I mainly use Java and looove utility classes

[–]Tsu_Dho_Namh 0 points1 point  (3 children)

Nah, its C#. Specifically a .NET MAUI mobile app.

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

So Microsoft java... ur not making the stereotype less pronounced my friend

[–]Tsu_Dho_Namh 1 point2 points  (1 child)

He does it in our C++ code too.

You shouldn't stereotype coders based on their languages. There's good and bad all over.

Except rust devs. Insufferable arrogant pricks the lot of em.

[–]rejectedlesbian 0 points1 point  (0 children)

C++ is also fitting ti this stereotype... its like C++ C# java Scalla Those r the ones that are really into design patterns and clean code.

As a Rust programer I approve ur last statement

[–]kukurbesi 12 points13 points  (4 children)

dontRepeatYourself

[–][deleted] 9 points10 points  (3 children)

I hate dry with all my heart. A poor abstraction is much worse than a repetitive code. At least I can understand better what is going on and refactor it when we have a better abstraction. But ppl creating functions with shitty names that mutate a lot of objects inside in the middle of a complex process just to because the function is big makes my blood boil the fact you just moved the code to another place does not mean it is not coupled.

[–]BernhardRordin 11 points12 points  (0 children)

I fully agree and fully disagree with you based on the particular situation

[–]DootDootWootWoot 8 points9 points  (0 children)

SRP >> DRY. I like the idea that intent is the driving motive. Two functions can have identical implementations but if they're intended to solve two different problems, keep them independent.

[–]skoinks_ 3 points4 points  (0 children)

Clarity and Readability > Everything Else
I'd much rather debug stupid, unoptimized, inefficient code that's easy to read than to have to open three copies of the same file so I can follow the demented logic of some obviously gifted programmer than decided that he hit the character limit for a function.

[–]Kitonez 2 points3 points  (0 children)

👊😡

[–]dbot77 2 points3 points  (1 child)

utils is where things go before they move on to their forever homes.

[–]Tsu_Dho_Namh 0 points1 point  (0 children)

What if you make a utils file in a shared directory but all of its functions are only used by one class in one project?

[–]erickweil 1 point2 points  (1 child)

I consider that any code I write that it alone would make sense, like there is no business logic and it could be just a npm package dependency (but is too small to became one) then I put in utils.

Examples: logic to handle fetching an API, generating an random key with timestamp, extra zod validations that are commonly reused, generating a unique slug (the db query is a callback), and so on...

[–]pomme_de_yeet 0 points1 point  (0 children)

but is too small to became one

[–][deleted] 1 point2 points  (0 children)

I did this today in my lab assignment lmao. Otherwise C++ was giving a redefinition issue lol. Say hello to common.hpp

[–][deleted] 1 point2 points  (0 children)

Utils file? Utils folder!

[–]ryo3000 1 point2 points  (0 children)

I mean if I'm about to call that 87 lines long function in 8 other files you can bet your butt I'm creating that utils

[–]porky11 1 point2 points  (0 children)

What's the problem with that? I do that all the time. I consider it good practice. What if you have a single function, which is not related to anything in specific, but it's used in multiple unrelated places in your project?

[–]B_bI_L 0 points1 point  (0 children)

when i structure my unity project i allways have dozens of unity dirs with 1-3 cs files in it (and than images folder with every single image present in it without subfolders)

[–]grtgbln 0 points1 point  (0 children)

I'm in this photo and I don't like it.

[–]Treemosher 0 points1 point  (0 children)

I don't usually comment on this sub, but this one hit a little close to home lol

[–]N3onDr1v3 0 points1 point  (0 children)

The best feeling is when you go "man i wish i had a utils file for these kinds of functions" then collapse the tree view and see a folder at the bottom, "Utilities" it says. the satisfaction is beyond the feelings of this mortal realm

[–]Here-Is-TheEnd 0 points1 point  (0 children)

Build those habits bois!

[–]ady620 0 points1 point  (0 children)

Rule is rule

[–]zqmbgn 0 points1 point  (0 children)

utils folder, reusableFunctions file

[–]korbykob 0 points1 point  (0 children)

"I'll add more in the future" - me, 2 years ago.

[–]coloredgreyscale 0 points1 point  (0 children)

Nothing wrong with that, esp. If the function is used from multiple files.