Meaning of Leaky Abstraction?

后端 未结 11 1057
面向向阳花
面向向阳花 2020-12-23 02:33

What does the term \"Leaky Abstraction\" mean? (Please explain with examples. I often have a hard time grokking a mere theory.)

11条回答
  •  离开以前
    2020-12-23 03:20

    I'll continue in the vein of giving examples by using RPC.

    In the ideal world of RPC, a remote procedure call should look like a local procedure call (or so the story goes). It should be completely transparent to the programmer such that when they call SomeObject.someFunction() they have no idea if SomeObject (or just someFunction for that matter) are locally stored and executed or remotely stored and executed. The theory goes that this makes programming simpler.

    The reality is different because there's a HUGE difference between making a local function call (even if you're using the world's slowest interpreted language) and:

    • calling through a proxy object
    • serializing your parameters
    • making a network connection (if not already established)
    • transmitting the data to the remote proxy
    • having the remote proxy restore the data and call the remote function on your behalf
    • serializing the return value(s)
    • transmitting the return values to the local proxy
    • reassembling the serialized data
    • returning the response from the remote function

    In time alone that's about three orders (or more!) of magnitude difference. Those three+ orders of magnitude are going to make a huge difference in performance that will make your abstraction of a procedure call leak rather obviously the first time you mistakenly treat an RPC as a real function call. Further a real function call, barring serious problems in your code, will have very few failure points outside of implementation bugs. An RPC call has all of the following possible problems that will get slathered on as failure cases over and above what you'd expect from a regular local call:

    • you might not be able to instantiate your local proxy
    • you might not be able to instantiate your remote proxy
    • the proxies may not be able to connect
    • the parameters you send may not make it intact or at all
    • the return value the remote sends may not make it intact or at all

    So now your RPC call which is "just like a local function call" has a whole buttload of extra failure conditions you don't have to contend with when doing local function calls. The abstraction has leaked again, even harder.

    In the end RPC is a bad abstraction because it leaks like a sieve at every level -- when successful and when failing both.

提交回复
热议问题