r/programming • u/zumpiez • Dec 22 '11
The Problem with Implicit Scoping in CoffeeScript
http://lucumr.pocoo.org/2011/12/22/implicit-scoping-in-coffeescript/
83
Upvotes
r/programming • u/zumpiez • Dec 22 '11
View all comments
Show parent comment
1
u/ef4 Dec 23 '11 edited Dec 23 '11
We're manipulating three objects (ctx, source, and shader) in a multi-step dance that clearly has a lot to do with their internal implementations, yet we're doing all this from a function that's not encapsulated in any one of them.
There is no reason to say this:
when you could have implemented it like this by keeping the "[]" lookup encapsulated within the method:
And why have a separate step for setting the shaderSource:
When this too could be built into createShader, so that we'd see only:
And this is unnecessarily verbose because we're wasting the opportunity to return a value from compileShader:
It could just be this instead:
Finally, the local variable "log" that started this whole discussion doesn't need to exist at all, because it's a value that's only used once. So replace:
with:
Or better yet:
EDITED to add a summary of my version:
This is as much complexity as belongs in one function. By pushing all those other little details out into their own methods, the underlying structure of shaderFromSource is much easier to reason about.