|
|
|
|
|
by p2edwards
468 days ago
|
|
Agreed — seeinglogic's article made me think of a 3rd option: 1. Sorta long functional chain where the type changes partway through
2. Use temp variables
3. (New option) Use comments (Here's funcA from seeinglogic's article, but I added 3 comments) function funcC(graph) {
return
// target node
graph.nodes(`node[name = ${name}]`)
// neighbor nodes
.connected()
.nodes()
// visible names
.not('.hidden')
.data('name');
}
Compare to funcB which uses temp variables: function funcB(graph) {
const targetNode = graph.nodes(`node[name = ${name}]`)
const neighborNodes = targetNode.connected().nodes();
const visibleNames = neighborNodes.not('.hidden').data('name')
return visibleNames;
}
For me the commented version is easier to read and audit and it also feels safer for some reason, but I'm not how subjective that is. |
|
In this case, I'd lean towards intermediate variables, but sometimes I'll use functions or methods to group things.
I prefer function/method/variable names over comments because the are actual first class parts of the code. In my experience, people are a bit more likely to update them when they stop being true. YMMV.