Code Review : Question purpose

BASARAT
1 min readJan 18, 2016

--

I’ve been doing a lot of code reviews lately. Here are few snippets that help share the learnings

Here is what the final extend function looked like:

First question to ask is for the motivation. The answer was to support the following:

Needless to say it was rejected as one can already do:

So that brings me to the main tip:

Don’t have functions that do too much without a reason

You might need to ask this reason in code reviews, and there might not be a good one.

That said there might be more potential issues with the function . Here is the code again:

* Don’t create a function passed as an argument if that function is used as is

Instead the parameter `extractFields` should really be a local function (similar to extendRecursive)

* Don’t trust functions that don’t return a value

In this case the extendRecursive and the pseudo extendFields function both don’t return a value and mutate `newObj`. This is most likely wrong. But since the code was dropped anyways that didn’t play into this code review.

🌹

--

--

Responses (1)