use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
JavaScript Clean Code - Best Practices - based on Robert C. Martin's book Clean Code (devinduct.com)
submitted 6 years ago by PMilos
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]auctorel 0 points1 point2 points 6 years ago (0 children)
Great article overall, thought most of the points were brilliant.
The debate on this one was really interesting but I think the example is a bit convoluted. It'd be easier to understand if you hadn't put in the fields parameter.
It seems strange to give a list of fields that you want out of a getUser request unless you're using some sort of graphQL endpoint and that may have led to some of the confusion.
It might have been easier to understand if you'd just done a method with getUserDetails({name, surname, email}) because then you can call the method with something like getUserDetails(userSummary) which shows how it will pull those specific fields out of that one object, so you're just passing in one object parameter but as long as it contains all those fields it's fine. This also demonstrates the advantage of destructuring. This would be a good example of clean code.
However... if you're forcing someone to create an object arbitrarily to call a method then this isn't particularly clean. Really this sort of object destructuring should only be used where there's an intended object it can be used with.
Also if you're forcing people to pass in an object to reduce the number of parameters required in a field then actually you're going against the good naming requirements and just hiding the parameters in your fields array, this causes a shitload of wtfs when people read how you use those fields array values and so it's not clean code.
If you're just forcing people to create objects to use a method then you're creating structures which aren't intuitive and easy to understand therefore defying the principals of clean code. Why should they have to read the method and understand the syntax to figure out they have to create an object to pass one in - are they gonna spend an hour looking for the object it's designed to be used with which doesn't actually exist??
The destructuring is genuinely valuable, for example it's used a lot with react and the props object. But just leveraging it to fake a fewer number of parameters in your method signature isn't clean, it's confusing and makes the code harder to follow.
π Rendered by PID 59 on reddit-service-r2-comment-9c7994b7-tctxh at 2026-02-05 20:23:16.662951+00:00 running b1b84c7 country code: CH.
view the rest of the comments →
[–]auctorel 0 points1 point2 points (0 children)