TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Growing object-oriented software vs. what I would do

91 点作者 vivty将近 4 年前

13 条评论

josephg将近 4 年前
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.<p>In comparison, C programs tend not to hide this stuff. C functions are often long and complex. If you were implementing quicksort in C, you would write (more or less) one function with all the logic packed in there you can just read top to bottom. In Java it would be a nest of SortComparator interfaces and SortAlgorithm implementors, which would act to hide the algorithm itself.<p>There’s something more honest about the C style. It’s like, yeah, the algorithm is complicated. So we put it all together in one dense function. Here it is - go nuts! You don’t have to go hunting for the right implementing class. Or divine how FooFactory has configured your Foo object instance.<p>All that Java style class abstraction seems to (intentionally or otherwise) make the actual logic of your program hard to find and hard to trace. It’s coy. When I’m trying to read someone’s code, that’s simply never what I want.
评论 #28123954 未加载
评论 #28124906 未加载
评论 #28123392 未加载
评论 #28123519 未加载
评论 #28124225 未加载
评论 #28123893 未加载
评论 #28123813 未加载
PaulDavisThe1st将近 4 年前
Things I&#x27;ve learned from 25+ years of programming in C++ (and 5+ years of C before that):<p>1. not all software is about pushing and pulling to&#x2F;from a database; if yours isn&#x27;t, be sure you understand why that&#x27;s the case.<p>2. &quot;backends&quot; (not &quot;web backends&quot;, but the more general &quot;where the mechanisms are&quot;) should know nothing about &quot;frontends&quot; (again, not web, but the more general &quot;user interface of some kind&quot;). This is really just MVC in its most basic sense. One good way I&#x27;ve found to think about this is to assume that there&#x27;s always at least two UIs running simultaneously. Make sure this can work.<p>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).<p>4. single-threaded GUI code seems like a limitation but in most projects, it&#x27;s the right choice. By all means use helper threads when needed, but never allow them to use any API that&#x27;s part of your GUI toolkit. Knowing that your GUI code is ALWAYS serialized is a huge conceptual assist when reasoning about behavior.<p>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.<p>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.<p>7. lack of direct memory access for the UI(s) can significantly impede performance, but enforces a conceptual clarity that can be valuable.<p>8. when notifying the View(s) about changes in the Model(s), there&#x27;s a tradeoff between fine-grained notifications (&quot;frob.bar.baz.foo just changed&quot;) and high-level notifications (&quot;something about frob just changed&quot;). Finding the sweet spot between these two can be a challenge across the life of a long-lived piece of software.<p>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.<p>10. try to refer to as many things as possible indirectly. if something has a color, don&#x27;t make it&#x27;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.
评论 #28124216 未加载
评论 #28124544 未加载
评论 #28124099 未加载
评论 #28124301 未加载
amw-zero将近 4 年前
Here’s another review &#x2F; critique of this book, but with a full implementation based on the author’s grievances: <a href="https:&#x2F;&#x2F;enterprisecraftsmanship.com&#x2F;posts&#x2F;growing-object-oriented-software-guided-by-tests-without-mocks&#x2F;" rel="nofollow">https:&#x2F;&#x2F;enterprisecraftsmanship.com&#x2F;posts&#x2F;growing-object-ori...</a>.<p>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 &#x2F; query separation, the actual logic is trivially testable.<p>Give it a read. I love Growing Object oriented software guided by tests as well, these are all just different approaches with different mindsets.
评论 #28129377 未加载
Jtsummers将近 4 年前
&gt; I&#x27;ve quickly realized that the authors have a concrete idea of what an object means to them. I was confused why their code was always so... “callback-y” and after studying it a little more, I&#x27;ve discovered the reason. I might have missed it, but I don&#x27;t think they ever explicitly state it. All calls between objects are unidirectional: no public method of an actual object (not a plain data class) returns any value. They are always void methods. Objects don&#x27;t “call” each other. They send a message and don&#x27;t wait for a response. (Well, actually since they actually “send” it via method call, they do wait, but they pretend they don&#x27;t.<p><a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Command–query_separation" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Command–query_separation</a><p><a href="https:&#x2F;&#x2F;martinfowler.com&#x2F;bliki&#x2F;CQRS.html" rel="nofollow">https:&#x2F;&#x2F;martinfowler.com&#x2F;bliki&#x2F;CQRS.html</a><p>That sounds very much like Command-query separation or Command Query Responsibility Segregation to me. I haven&#x27;t read this particular book (and almost certainly won&#x27;t be getting to it within the next decade based on my ever increasing pile of unread books), but I wonder if they call this out. It&#x27;s a critical decision in the architecture&#x2F;design of a piece of software and it&#x27;s worth stating that it&#x27;s how they intend to design the system.<p>Coincidentally, to my mind, that model (CQS&#x2F;CQRS) fits well with the blog author&#x27;s idea of using an agent-based event system. Moving the objects into distinct threads of execution or processes, which also coincides with one of the intended ideas of OO by Alan Kay. OO-as-message-passing very much fits within the agent-based execution model.
crabmusket将近 4 年前
To the author: if you haven&#x27;t read POODR, I highly recommend that. It&#x27;s the book that felt the most &quot;real OOP&quot; to me. No `class Dog extends Animal` in sight. It&#x27;s written by one of those Smalltalkers, and I think it&#x27;s got a lot of very valuable ideas about software design, not just OOP specifically.<p>The &quot;callback-y&quot; approach in Growing Object-Oriented Software sounds fascinating.<p>&gt; 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.<p>This is a really good point.<p>EDIT: I see you really did not like 99 Bottles of OOP, which is by the author of POODR. In that case maybe her way of explaining things doesn&#x27;t agree with you and you should skip it!
评论 #28123255 未加载
评论 #28123426 未加载
jim-jim-jim将近 4 年前
&gt; does anyone really care?<p>I liked this piece. Enough to log in and comment at least. It&#x27;s the rare article where the author is open about his biases but gives an opposing approach an honest go. Reading three books about OOP is way more generous than I&#x27;d ever be. And when that approach still doesn&#x27;t make sense, he offers a better one. Always enjoy reading the informed hater&#x27;s perspective.
ratww将近 4 年前
<i>&gt; 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.</i><p>This point hits hard.<p>Managing &quot;live&quot; 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&#x27;s always a good idea to start with established frameworks that handle persistence if you&#x27;re ever gonna need it. Bolting-on is just too hard.<p>It also reminds me of my first job, in a Desktop app. State became so complex that to apply a &quot;global change&quot;, 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.<p>In the middle of my career I also worked in a very large video game. The higher ups wanted to change how &quot;game saving&quot; 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.<p>Curiously, as much as modern frontend programming is maligned, such issues are easier to solve with central state management libraries like Redux.
评论 #28123712 未加载
mistrial9将近 4 年前
&gt; does anyone care?<p>I do care and I read this with interest just now. The idea that it took three hours to write a review of a month+ of work as part of &quot;professional development&quot; and that this person must bear that costs of that education, is a tip of the iceberg indicator to me as to the difficult work world we live in today. How is it that capital owners make money while sleeping, while craftsmen intellects spend a month+ without compensation to &quot;get up to speed?&quot; I am on the tail end of this after decades and it jumps out for me now, past the OOP part.<p>Second - I learned OOP approaches long ago, have written a lot of software and have used OOP in my own ways, much like this author. I appreciate the effort here! It is an interesting, technically somewhat shallow (no code in this essay) yet as noted, good balance of critical and open mindedness.<p>I do not understand OOP-hatred past &quot;I hate the music my parents liked&quot; and &quot;Java is so tedious that it makes me hate all of the whole structure of it&quot;.<p>I used OOP code myself to separate parts in loosely coupled systems of several flavors; to make a systematic ordering of commands, to enable scripted or menu-driven command sets; and to wrap an interface around data for the convenience of other code. I feel that a strong point of OOP is to REDUCE the cognitive load for the human. Yet many snipes in articles about OOP specifically complain about the lengthy, spread-out, tedious nature of OOP code. Your mileage may vary ! Use it badly or use it well .. its not my doing.<p>The specific kind of software system described in the third book here, with messages passed without state between objects, is interesting, and reminds me to say now: I think there is vastly insufficient distinction made between software solutions, their design and implementation, in OOP criticism. What are you trying to solve? How much persisted data is there? or state, or interface to XYZ external system. This matters in design choices and I feel like OOP-critics often race to their favorite annoying thing rather than do the intellectual work of distinguishing for a reader, what the assumptions are and what the finished product requires..<p>Overall, this essay is worth reading, feels short to me despite obvious effort on the part of the author, and personally, I get a nagging feeling that people doing this kind of work should be less scammed by low-morals middlemen and more valued socially for the architects of software that they are.
Zababa将近 4 年前
The part about data is interesting. I remember than in Clean Code, Robert Martin made the distinction between &quot;data structures&quot; (objects that have lots of parameters, few functions) and &quot;objects&quot; (objects that don&#x27;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&#x2F;dataclass&#x2F;record as a basic building block too?
评论 #28123540 未加载
kazinator将近 4 年前
&gt; <i>That discovery blew my mind initially. I panicked. “OMG, is this the secret sauce? Is the joke on me?</i><p>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.
评论 #28124345 未加载
mbrodersen将近 4 年前
What an excellent read. His approach is very similar to how I have developed successful software for years. It scales from the smallest throw away code to the largest Enterprise system and is flexible&#x2F;adaptable without 27 levels of empty abstractions.
wangvnn将近 4 年前
<a href="https:&#x2F;&#x2F;twitter.com&#x2F;martinfowler&#x2F;status&#x2F;1423700358233305096?s=19" rel="nofollow">https:&#x2F;&#x2F;twitter.com&#x2F;martinfowler&#x2F;status&#x2F;1423700358233305096?...</a> This made sense for me right before I gave up on good OOP.
theteapot将近 4 年前
&gt; I&#x27;ve purchased three OOP books (in the order I&#x27;ve read them): ...<p>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.
评论 #28123536 未加载