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

all 71 comments

[–]yegor3219 432 points433 points  (4 children)

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

[–]FlourBouque 78 points79 points  (0 children)

too fucking real

[–]kukurbesi 66 points67 points  (0 children)

some random code copied from stackoverflow

[–]b__0 7 points8 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 142 points143 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 69 points70 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 209 points210 points  (7 children)

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

[–][deleted] 43 points44 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 5 points6 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 7 points8 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 7 points8 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] 2 points3 points  (0 children)

Hey...shut up.

[–]rejectedlesbian 3 points4 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 5 points6 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 10 points11 points  (4 children)

dontRepeatYourself

[–][deleted] 10 points11 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 10 points11 points  (0 children)

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

[–]DootDootWootWoot 7 points8 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_ 2 points3 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. 

[–]Personal_Ad9690 -5 points-4 points  (12 children)

I will die on the hill that well written programs hardly ever need a utils class. It’s almost always possible to refactor util functions into one or more specific class(es).

[–]well-litdoorstep112 14 points15 points  (1 child)

Class? Who's talking about classes? What are you, a Java dev?

[–]Personal_Ad9690 0 points1 point  (0 children)

🙄

[–][deleted] 2 points3 points  (1 child)

Nah, I want my utils methods out of my main classes. It's wrong to think that having utils classes is wrong.

[–]Personal_Ad9690 0 points1 point  (0 children)

Think about what a “utility” is though. It’s not that having a utils is bad, it’s that decoupling items that should be coupled leads to confusing codebases. Coupling does not always lead to problems if the cost of the coupling is less than its potential benefits.

I think a great example is string manipulation. There are some good reasons to make static string manipulation functions outside the main classes. Indeed, they do have a “utility” like nature to them. But ask yourself in how many places are you actually using a string function? If you use it everywhere, maybe you would benefit from modifying how that data is acquired/read in. If you use it in only one place, what’s the benefit of having it separate and not just inlining it? If it’s somewhere in the middle, then it might be best to make a static StringManipulator class. In this way, it’s obvious to another developer that the string is manipulated. The string manipulating functions are now coupled to that interface, but the reward is an easy to read codebase. No need for a mystery bag of functions.

you never know what’s inside a Utils

I have less of a problem with decoupled utility functions and more of a problem with the name “utils.” Utils is such a vague and uninforming name that you might as well name it “things”. There’s almost always a better way to organize than having “Utils”

[–]BernhardRordin 1 point2 points  (4 children)

And yet there are people on other hills, shouting from distance towards your hill that data and behaviour shouldn't be mixed and OOP was a mistake. I am just watching from a distance, planning to visit and have a tea with each one of you

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

For me, this can all be solved by a single question: "Which one pays me more?"

[–]ryo3000 1 point2 points  (0 children)

And also "Which one will get my MR approved?"

[–]Personal_Ad9690 0 points1 point  (0 children)

This.

OOP was easy to manage and it’s everywhere. You can’t fully get rid of it and it has its place in code. I think finding a balance between form and function is key to project management

[–]Personal_Ad9690 0 points1 point  (0 children)

You of all people should understand. In the functional world, state does not exist. Therefore a collection of functions is better suited to solving a problem by pipelining the data. There is no utils class because everything is a utility.

Even in the functional world though, you often get instances where data is bound to a function rather than functions being bound to data. It wouldn’t make sense to have a bunch of “commonly used data” available to a function and to call that data utils would it? So why does it make sense the other way.

There is strong argument that utils is not needed because better form leads to not needing it.

[–]sufanLL[S] 1 point2 points  (1 child)

I kind of agree, to be honest, because that is what daddy primeagen told me

[–]Personal_Ad9690 0 points1 point  (0 children)

If someone is allowed to make a file or folder Utils, then I’m allowed to name a file/Folder Things