DEV Community

loading...

Discussion on: Stop Using "data" as a Variable Name

Collapse
mchaitanya profile image
Chaitanya Malireddy

In this context, if this were JavaScript, I'd dispense with the 'temp' variable altogether :) Also, often it makes sense to chain operations to avoid having to name intermediate states.

[a, b] = [b,a]; // destructuring assignment
Enter fullscreen mode Exit fullscreen mode
Collapse
thebuzzsaw profile image
Kelly Brown

To me, it depends on the complexity of the intermediate state. I used to aggressively pack as many operations into a single line as possible, but more recently, I like capturing operations into local variables both for readability and for debugging (easily mouse over variables to see what the answer was). Obviously, this can be taken too far, so it's judgment call.

Thread Thread
mchaitanya profile image
Chaitanya Malireddy

Yeah I don't like to pack too much into a clever oneliner either - makes it hard to read and debug. I like chaining methods if I can, like say a bunch of array transformations. But you're right it all depends on what you're trying to do - one has to strike a good balance per usecase.

Thread Thread
thebuzzsaw profile image
Kelly Brown

Chain methods are amazing. I can put each call onto its own line, and it becomes a super clear series of steps.