Reading class-based code in JavaScript makes me want to weep. class AbstractBaseWhatever { someMethod() { throw new Error('Not implemented'); } } C'mon, man... do better!
-
Show this thread
-
Meanwhile... class TheChildClass extends AbstractBase { someMethod() { this.somethingElse(); } } Uh, wait ... where is this.somethingElse() defined?! Who knows! Time to hunt through the prototype chain!
12 replies 7 retweets 79 likesShow this thread -
Replying to @mjackson
How'd this any different from: const someFunction() { somethingElse()? } And you need polymorphism, you need to pass functions around which makes looking them up harder than instance methods.
1 reply 0 retweets 4 likes -
Replying to @justinfagnani
I can go directly to the definition of somethingElse in this case. I know exactly where it is. It's night and day.
1 reply 0 retweets 1 like -
Replying to @mjackson
There could be plenty of indirection in the definition of somethingElse(): somethingElse = a.third.thing.bind(foo); Instance members are pretty trivial to look up. I do it every day.
1 reply 0 retweets 4 likes -
Replying to @justinfagnani
What I mean by "indirection" is "how easy is it to open a file and find where somethingElse is defined?" In the case of instance methods, it's not obvious. In the case of regular functions, it is.
2 replies 0 retweets 1 like -
Replying to @mjackson @justinfagnani
Not really. You still need to do a dance of "is this imported" and "where is it defined in this file". Same amount of steps to find a class method. IDE integration also makes it one ctrl+click away.
1 reply 0 retweets 3 likes -
Replying to @sebmck @justinfagnani
Nah, a class method might not even be defined in the superclass. It could be defined in *its* superclass. Potentially more steps.
2 replies 0 retweets 0 likes
Sure. An imported method could also be imported from another file too. There's the same amount of indirection, one can just be more dynamic.
-
-
Replying to @sebmck @justinfagnani
Right, but in that case you will always see the import + export right there in the file. There's a trail of explicit breadcrumbs back to the source. Inheritance is much less explicit.
2 replies 0 retweets 3 likes - 1 more reply
New conversation -
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.
he/him 