Hacker Newsnew | comments | show | ask | jobs | submit login

I'd argue it's better in the long term to change the API than to maintain an increasingly elaborate facade as your data structure changes. OOP doesn't solve the core problem; it just lets you sweep the issue under the carpet until it becomes too big to easily deal with.



It gives you the freedom to make a lot of smaller changes before you have to resort to explicit versioning. I think the benefits of encapsulation are pretty well established at this point.

For example, the entire Apple CoreFoundation API is exposed as operations on opaque C structs. Cocoa uses that abstraction to wrap them in a very nice, high level API. If the actual layout of those structs was exposed I can guarantee you people would start writing code that used that information directly and Apple's hands would be tied when they wanted to improve their implementations.

Where I agree with Rich is that we should work to minimize mutable state.

-----


If the only benefit of encapsulation is to make small API changes easier, is it really worth the additional complexity it adds to your architecture?

A strong theme in many of Rich's talks is that we should prefer "simple" over "easy", as the former will benefit you more in the long run even if it's harder in the short term.

You also seem to be confusing encapsulation with abstraction. Working with data structures directly does not mean you need to operate at a low level.

-----


Changing software without breaking it is the central problem of software engineering, as Rich points out himself.

In what sense can you have encapsulation when your entire data structure is exposed to every function that touches it?

-----


> Changing software without breaking it is the central problem of software engineering

But encapsulation doesn't solve that problem, except in very minor cases. Is it worth complecting the architecture of our software for the development equivalent of a bandaid?

> In what sense can you have encapsulation when your entire data structure is exposed to every function that touches it?

I'm not saying you should have encapsulation... Did you mean to say "abstraction"?

-----


But encapsulation doesn't solve that problem, except in very minor cases.

The WIN32 API has largely remained unchanged over the last 15 years while changing dramatically under the hood in its implementation. With the recent possible exception of Apple's recent bull run this is so far the most lucrative API in the history of the world. And it's made possible by the fact that all the key API elements are exposed only as opaque handles.

I could go on and on with examples like these that are about as far away from a minor bandaid as you can get.

-----


I'll give an example of what I think Hickey is talking about. In a OO API you have an

  class Employee
    private boss
    public getBoss()
What IMO Hickey thinks, is that you should have instead a map with a field boss. Yes, you can't then change that field name, in the same way you can't change the method name getBoss in the OO API. But you can change the content of that field.

-----


I'm not sure I'd classify Windows as changing dramatically in its implementation, and the cost of maintaining binary backward compatibility has been considerable. Only a company the size of Microsoft could afford to do it year after year.

There's also a difference between building good software and building profitable or even popular software. Sometimes bad design can even help maintain a product's market lead, as if a design is complex, it's hard for competition to make compatible products.

You're also still confusing abstraction and encapsulation. An API can be an abstraction over a lower-level system without being an example of encapsulation.

-----




Guidelines | FAQ | Support | API | Lists | Bookmarklet | DMCA | Y Combinator | Apply | Contact

Search: