π Spookyberb π β 14-44 Oct 13
How many paremeters would be considered bad code while passing to a function? 5? 10? Whats the unwritten rule?
18 Replies
Hello,
@βSnowberbβ very good question
Depends on your definition from clean code;
My understand is that :
- 2 is optimal
- 3 maximum
- if more than 2 or 3 , use a configuration object
I've recently become a clean code enthusiast and that's what I learned
what's a configuration object? @Liil' Boo
This is the function im talking about
I took it out of the main component to a service file to atomize and structure it better
but then I have this in the main componenet
(screenshot because its more readable)
Hmm... I'm not strong enough to explain what' a configuration object
If you do some research on : IntersectionObserver , or ResizeObserver
You'll see both take a configuration object
I'mma try to show you by refactoring your function
thank you!
Im also trying to write the cleanest code possible
A configuration object allows you to only pass in what you need and not bother about the order of arguments/parameters
Looks like you already have one for the function updateAccount
oh okay
yeah I get it now
Your original function might be missing some 'null checks' also
the whole project is missing null checks
its js not ts
xd
TS > JS
literally
try telling that to my coworkers
hard to do clean code without typescript
pretty damn hard yes
well thank you so much for the info
Javascript is like, dirty by default, and fight to make it cleaner
appreciated it
Gotta give back to the community
This thread hasnβt had any activity in 12 hours, so itβs now locked.
Threads are closed automatically after 12 hours. If you have a followup question, you may want to reply to this thread so other members know they're related. https://discord.com/channels/102860784329052160/565213527673929729/1030128979648204911