oop - Can Scala be seen as an 'Abstraction Inversion'? -
greetings,
it's provocative question, aiming open debate how abstraction inversion seen among developer community. i'm curious know think.
first, here quote abstraction inversion exemples given wikipedia: http://en.wikipedia.org/wiki/abstraction_inversion
creating object represent function cumbersome in object-oriented languages such java , c++, in functions not first-class objects. in c++ possible make object 'callable' overloading () operator, still necessary implement new class, such functors in stl.
for me functions first-class citizen in scala, when use scala generate java bytecode, scala create specific class 'on top' of java make functional programming possible... can see abstraction inversion ?
same can apply clojure or functionnal language jvm... or apache collections, exemple this:
http://commons.apache.org/collections/apidocs/org/apache/commons/collections/closure.html
btw, i'm not convinced wikipedia article objectivity. example when speaking possible abstraction inversion in micro-kernel article 'a body of opinion holds microkernel design abstraction inversion' no such statement functional type in oop
the wiki article weak (does represent abstraction inversion itself? :), , concept bit dubious. fundamental gist of seems basic element hidden abstraction, forcing users of abstraction re-implement it.
for instance, talk page, comes more interesting example. suppose cpu had tan
math function, no sin
or cos
, , programming language implemented sin
, cos
in terms of tan
, did not expose tan
itself. programmer using language forced implement tan
in terms of sin
, cos
, which, themselves, implemented in terms of tan
, therefore characterizing abstraction inversion.
so, scala. naturally, programmer using functions in scala not incurring in abstraction inversion, because not being forced re-implement functionality available primitive scala.
on other hand, 1 might claim scala's implementation of functions class instances instance of abstraction inversion. true, however, 2 things must hold true:
- there must "function" primitive available jvm.
- such primitive must have offered alternative scala doing.
what, exactly, function? function primitive like? in context, "function" means data capable of being executed. 1 might assembler code, is, in fact, data capable of being executed -- not portable, and, futhermore, not bytecode, therefore failing design principles.
on other hand, methods in java referenced identifier, through java locates code executed given object's class hierarchy. identifier not exposed, though can used indirectly through reflection. if exposed, , functionality offered "call code", function arguably constructed around that.
so, think case made 1 true. let's proceed next.
if java did offer "method" data type, scala functions cease instances of class? no, not. 1 of fundamental design aspects of scala every element of running program object. "primitives" java have presented if normal objects methods, , if there "method" primitive, it.
one possible consequence of method primitives elevate methods first class citizens, functions, themselves, hardly change.
Comments
Post a Comment