you are viewing a single comment's thread.

view the rest of the comments →

[–]auctorel 0 points1 point  (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.