Live data from Hacker News

Growing object-oriented software vs. what I would do

dpc.pw

11–20 of 99 posts

Re: Growing object-oriented software vs. what I would do

#11
> Immediately I remind myself that the implementation from the book ignores the problem of persistence completely. If you close that application it loses all the state. I think this is not an accident. This is where things go wrong for OOP really fast.

This point hits hard.

Managing "live" scattered state that is gonna go away when the program dies is hard in itself. But as soon as you have to persist it or do anything fancy with it, you pretty much have to change the whole approach of your app. This is why it's always a good idea to start with established frameworks that handle persistence if you're ever gonna need it. Bolting-on is just too hard.

It also reminds me of my first job, in a Desktop app. State became so complex that to apply a "global change", like currency or language, it was required to close the app and open again. It was something very common, seeing how many apps required such things.

In the middle of my career I also worked in a very large video game. The higher ups wanted to change how "game saving" worked and instead of having to serialise just the basic stuff (health, lives, level) we needed to change it to serialise the whole game state including enemy positions and actions. It was the biggest change we did and we ended up having to add lots of boilerplate because of the scattered state. IMO, ECS was a very interesting development purely because now state is not encapsulated anymore, making serialisation completely separate from everything else.

Curiously, as much as modern frontend programming is maligned, such issues are easier to solve with central state management libraries like Redux.

Re: Growing object-oriented software vs. what I would do

#12
Here’s another review / critique of this book, but with a full implementation based on the author’s grievances: https://enterprisecraftsmanship.com/posts/growing-object-ori....

The main point of it is to avoid testing via mocks and to also avoid interfaces that are only there for testing purposes. The end design is extremely simple, and because it has command / query separation, the actual logic is trivially testable.

Give it a read. I love Growing Object oriented software guided by tests as well, these are all just different approaches with different mindsets.

Re: Growing object-oriented software vs. what I would do

#13
post #5

This is a hot take but: I have a growing sense that one defining feature of some software engineers is that they’re embarrassed by dense logic. I think you see this in the Java world where people seem to hide the core logic of their program amidst a dizzying array of interfaces and deep function call chains. Maybe with enough DI and whatnot, the business logic itself can melt into the structure of the program. In com…

I completely agree.

Another similar issue that I see a lot in both Java and C++ codebases is "premature wrapping" of foreign APIs. Basically when building a program that has to consume a certain API that is somewhat incompatible, every single concept of this API is wrapped in a separate class before any planning, to the point each one-line procedure call turns into a 20 line class.

Of course, after the wrapper is written, the program still needs higher lever abstractions that use those wrappers. But since zero planning went into the design, now you need exactly the same call order as before, however instead of an ugly (but simple) procedure call, you have a class wrapping it, and to understand a simple workflow you have to go trough at least two layers of classes.

Re: Growing object-oriented software vs. what I would do

#14
The part about data is interesting. I remember than in Clean Code, Robert Martin made the distinction between "data structures" (objects that have lots of parameters, few functions) and "objects" (objects that don't have many parameters, lots of functions). The author seems to have rediscovered this distinction here. If people keep rediscovering it, maybe an object is a too abstract building block? Maybe languages should offer a struct/dataclass/record as a basic building block too?

Re: Growing object-oriented software vs. what I would do

#15

> I've purchased three OOP books (in the order I've read them): ... If your gonna pick three books on OOP it should include Design Patterns at the top of the list. At least if you want to understand why OO is a thing people still use and talk about.

Isn't "Design Patterns" about how to solve problems through an OOP approach, rather than about the strict benefits of OOP?

Re: Growing object-oriented software vs. what I would do

#16
post #14

The part about data is interesting. I remember than in Clean Code, Robert Martin made the distinction between "data structures" (objects that have lots of parameters, few functions) and "objects" (objects that don't have many parameters, lots of functions). The author seems to have rediscovered this distinction here. If people keep rediscovering it, maybe an object is a too abstract building block? Maybe languages sh…

Java offers Records now, which are pretty much that.

Pretty cool feature IMO: https://docs.oracle.com/en/java/javase/14/language/records.h...

Re: Growing object-oriented software vs. what I would do

#17
> That discovery blew my mind initially. I panicked. “OMG, is this the secret sauce? Is the joke on me?

Not only is that not the secret sauce, an OOP program with almost nothing but methods that return nothing (i.e. have some effect without reporting a result), is a giant red idiot flag.

Re: Growing object-oriented software vs. what I would do

#18
I found this post ridiculous indeed. Actor + event design can still be implemented with OO design as well as with any other designs. So the author is comparing apples to oranges. And the code put up on Github does not give a good example of OO design either. I agree on one point: it does not change anything.

Re: Growing object-oriented software vs. what I would do

#19
Things I've learned from 25+ years of programming in C++ (and 5+ years of C before that):

1. not all software is about pushing and pulling to/from a database; if yours isn't, be sure you understand why that's the case.

2. "backends" (not "web backends", but the more general "where the mechanisms are") should know nothing about "frontends" (again, not web, but the more general "user interface of some kind"). This is really just MVC in its most basic sense. One good way I've found to think about this is to assume that there's always at least two UIs running simultaneously. Make sure this can work.

3. if your program has a user interface, everything the user can do without further interaction should be represented by a closure that can be invoked from anywhere (but always in the correct thread).

4. single-threaded GUI code seems like a limitation but in most projects, it's the right choice. By all means use helper threads when needed, but never allow them to use any API that's part of your GUI toolkit. Knowing that your GUI code is ALWAYS serialized is a huge conceptual assist when reasoning about behavior.

5. access to an excellent cross-thread message queueing system is likely to be a must if your software uses threads. This should include a way for one thread to cause arbitrary code execution in another thread.

6. direct memory access for the UI is nice from a programming perspective (that is: just directly call methods of backend objects), but can erode the wall of separation between the UIs and the backend.

7. lack of direct memory access for the UI(s) can significantly impede performance, but enforces a conceptual clarity that can be valuable.

8. when notifying the View(s) about changes in the Model(s), there's a tradeoff between fine-grained notifications ("frob.bar.baz.foo just changed") and high-level notifications ("something about frob just changed"). Finding the sweet spot between these two can be a challenge across the life of a long-lived piece of software.

9. lifetime management will never be trivial. Accept it, and move on to thinking about how it is going to work even if it is not trivial.

10. try to refer to as many things as possible indirectly. if something has a color, don't make it's state refer to the color, but the name or ID of the color. do not over-use this pattern when performance matters, but also do not over-estimate your ability to understand when performance matters.

Re: Growing object-oriented software vs. what I would do

#20
post #15

> I've purchased three OOP books (in the order I've read them): ... If your gonna pick three books on OOP it should include Design Patterns at the top of the list. At least if you want to understand why OO is a thing people still use and talk about.

Isn't "Design Patterns" about how to solve problems through an OOP approach, rather than about the strict benefits of OOP?

More a bag of tricks to get around issues you tend to run into when doing OOP.

Bridge comes to mind, I ran into that specific example myself trying to OO-design a GUI framework with different back ends.

With a pinch of common sense stuff like Facade etc.

Much of it only makes sense for static languages such as C++ and Java.

I'd say it gets way more credit than it deserves.

Stepanov on OOP is interesting (just search for object oriented):

http://www.stlport.org/resources/StepanovUSA.html

Post reply on HN