|
|
|
|
|
by kawhah
954 days ago
|
|
Hmm, no. You rewrite it as key1 = foo/bar
key2 = baz/bat
a[key1] = b[key2]
if (a[key1] == c)
I'm sure a coder who understands the context can come up with better names than key1 and key2.edit: or better yet key2 = baz/bat
normal_var = b[key2]
if (normal_var == c)
...
key1 = foo/bar
a[key1] = normal_var
|
|
You're also splitting what is intended to be essentially an atomic operation into multiple steps, which can be good if you want to analyze and tweak them in the future, but it's now no longer clear where the process begins and ends in relation to the code that comes before and after: you have to add more comments, or split the whole thing out into its own function.
I'm not saying your code is bad or wrong, just that there are downsides to any solution (including mine), and ultimately everybody has to pick whichever has the fewest negatives for their particular project.