News for hackers. Stuff that matters.
Re:How to Design Programs 2nd Edition by ChicagoDave on Tuesday May 02, 2023 @03:54AM (#35784582)
I would not follow any of this book anymore.

Abstractions lead to coupling and complexity.

So many outdated principles I can’t enumerate them all.

Re:How to Design Programs 2nd Edition by stinos on Tuesday May 02, 2023 @04:26AM (#35784773)
Abstractions lead to coupling and complexity.

The wrong abstractions can lead to coupling and complexity. The right ones on the other hand are all about reducing coupling and complexity.

Re:How to Design Programs 2nd Edition by ChicagoDave on Tuesday May 02, 2023 @04:35AM (#35784816)
We have a history of abstraction-based code that’s turned applications into frozen balls of mud.

We have so many tools to help write good code that the short-term savings of shared libraries is superseded by having distinct codebases that can be modified without those dependency concerns. Same is true for finding bugs in many places and easily setting those up for maintenance releases.

Re:How to Design Programs 2nd Edition by kaba0 on Tuesday May 02, 2023 @05:41AM (#35785208)
There is no going around complexity. We are absolutely standing on the shoulders of huge giants; even if you think you don’t have any dependency, behind the scenes you use many decades-old libraries dealing with the complexity of floating point arithmetics and such.

Also, Brooks paper is still true, the only real, significant productivity boost is reusing existing code. Even if you rewrite everything from scratch, you will still have to carry the exact same amount of essential complexity. Managing complexity is pretty much the most important part of CS.

Re:How to Design Programs 2nd Edition by DanielHB on Tuesday May 02, 2023 @10:38AM (#35788164)
open any network communications protocol RFC or any CPU design architecture or operating systems memory tables or operating systems filesystems with journaling or hardware I/O

it is crazy that society hasn't collapsed yet

Re:How to Design Programs 2nd Edition by DanielHB on Tuesday May 02, 2023 @10:35AM (#35788111)
Some engineer from Netflix once said something along the lines: "Microservices, not too many, mostly alongside team boundaries". Meaning most microservices should be wholly owned by a team and a team should ideally own only one microservice (but exceptions are allowed under special circumstances)

Like microservices, I feel code abstractions should be thought in a similar way, mostly a thing we use in our team, not company wide

In my own team I have to fight very hard to keep dependencies to external code down, the amount of entangling people are willing to put their code through is just crazy. An argument I often put is: "Why should we use lib X from team Y from my company if they don't even feel it is good enough to open source?". Any external code that my team imports into our project should be good enough it could be open sourced (given IP-rights allowing)

Re:How to Design Programs 2nd Edition by jasfi on Tuesday May 02, 2023 @05:19AM (#35785084)
I agree, besides, there's really no getting away from abstractions to manage complexity.
Re:How to Design Programs 2nd Edition by tephra on Tuesday May 02, 2023 @07:15AM (#35785846)
Arguably managing complexity is one of the main things you do when doing programming
Re:How to Design Programs 2nd Edition by lo_zamoyski on Tuesday May 02, 2023 @08:55AM (#35786669)
A stronger claim: everything in programming is an abstraction.

Somewhat tangential, but I sense tacitly related... I sometimes sense that many people who program adhere to a kind of computational atomism, that there is some kind of underlying "real" and that everything else is "just" some kind of arrangement of elements of the real. But that's just an implementation detail. Yes, when we implement a language that compiles to instructions or bits on a specific machine, we are indeed working to simulate that language. But computation and formal languages don't really have anything to do with physical computers. Their connection is entirely incidental. It is a matter of practicality, like the choice of using a hammer versus a rock to drive spikes of metal through wood. A computer language is the "base" language. From the formal perspective, there is no "low-level" or "high-level" language, just different languages that compilers can translate between. What is "low-level" (typically the target language) is merely low-level by convention, usually because we are targeting a given machine instruction set of some physical machine.

But even here, the notion of an "instruction" or a "bit" are abstractions. There are no "bits" in the world as ontological entities. Computation and data are abstract, full stop. All physical implementations are simply instruments for simulating that abstract model. There is no difference, in principle, between using checker pieces, differences in voltage, magnetic polarity, or thumbs up/thumbs down to represent bits.

The language should, ideally, be suited to the domain of discourse.

Re:How to Design Programs 2nd Edition by GiorgioG on Tuesday May 02, 2023 @05:51AM (#35785276)
Over time all abstractions become “wrong” as requirements change.
Re:How to Design Programs 2nd Edition by amelius on Tuesday May 02, 2023 @05:55AM (#35785299)
This is why refactoring is a thing.

Perhaps someone should write a book for managers that explains these two things.

Re:How to Design Programs 2nd Edition by mumblemumble on Tuesday May 02, 2023 @08:44AM (#35786557)
You shouldn't be baking business logic into your abstractions like that.

Or, perhaps this is a better way of putting it: if there's business logic mixed into it, it's not an abstraction, it's a concretion.

Re:How to Design Programs 2nd Edition by simplotek on Tuesday May 02, 2023 @09:04AM (#35786771)
> The wrong abstractions can lead to coupling and complexity.

This comes to the old quote:

* "Make everything as simple as possible, but not simpler.” Albert Einstein.

Abstractions undoubtedly add complexity that quickly becomes unmanageable. By now everyone is already aware of the horror that's the enterprise version of Hello World, and YAGNI/gold plating are renowned antipatterns. Many codebases have already succumbed to the perils of premature generalization, where the good old rule of 3 of refactoring serves as a shield against it.

But still some developers succumb to the siren song of abstracting away things.

Re:How to Design Programs 2nd Edition by Joker_vD on Tuesday May 02, 2023 @09:52AM (#35787388)
Okay, let's take an excerpt from one of those enterprise "hello world"s:

    IHelloWorldString helloWorldString = helloWorld.getHelloWorld();
    IPrintStrategy printStrategy = helloWorld.getPrintStrategy();
    IStatusCode code = helloWorld.print(printStrategy, helloWorldString);
Extracting two subobjects from an object to feed them back to the same very object is not an abstraction, it's merely adding a bunch of public methods (and interfaces) to the object. That may or may not help in abstracting things: and usually, the more handles and bells and whistles are available to pull and play with, the less abstracted the code actually is.
Re:How to Design Programs 2nd Edition by simplotek on Tuesday May 02, 2023 @11:15AM (#35788803)
> it's merely adding a bunch of public methods (and interfaces)

What do the interfaces represent?

Re:How to Design Programs 2nd Edition by Joker_vD on Tuesday May 02, 2023 @11:42AM (#35789316)
In this case, nothing particularly meaningful or useful, they mostly just shrink wrap the underlying (single) implementation's details and re-expose them as-is for the caller to cope with. Some people also think that that somehow helps with encapsulation too.
Re:How to Design Programs 2nd Edition by simplotek on Tuesday May 02, 2023 @02:27PM (#35792080)
> In this case, nothing particularly meaningful or useful

You're either playing dumb or weren't able to understand what was in the code. IHelloWorldString is an abstraction over the way the string was implemented, IPrintStrategy is a strategy pattern that abstracts away how the abstract hello world string is supposed to be printed, and finally IStatusCode is an abstraction over how a status code is implemented.

> they mostly just shrink wrap the underlying (single) implementation's details and re-expose them as-is for the caller to cope with.

No, not really. Their purpose is to abstract away implementations. Just because there's a single implementation that does not mean this wasn't abstracted away.

Re:How to Design Programs 2nd Edition by Tomis02 on Tuesday May 02, 2023 @05:27PM (#35794455)
There's using "abstraction" in the classical sense of "harder to understand", as in "abstract painting". In today's world, good abstractions are the exception.

> it's merely adding a bunch of public methods (and interfaces) to the object

The object is the abstraction they're complaining about. Why have an object to begin with?

Re:How to Design Programs 2nd Edition by switchbak on Tuesday May 02, 2023 @11:10AM (#35788700)
How is gold plating the same as YAGNI? They're opposites, no?
Re:How to Design Programs 2nd Edition by simplotek on Tuesday May 02, 2023 @11:14AM (#35788788)
> How is gold plating the same as YAGNI? They're opposites, no?

No, gold plating and YAGNI are two faces of the same abstraction coin.

Re:How to Design Programs 2nd Edition by switchbak on Friday May 12, 2023 @02:08PM (#35919852)
Under-engineering is not the same thing as YAGNI.

I worked at a place where the former employee had engineered his whole S3 to files synchroniztion layer. We never needed that. That's YAGNI. (And if we did, the library already has it!)

Choosing crappy overly-simple ideas for abstraction is not what YAGNI is all about. It's about pulling in overhead+complexity when it's justified, and only then.

Re:How to Design Programs 2nd Edition by atoav on Tuesday May 02, 2023 @04:03AM (#35784636)
> Abstractions lead to coupling and complexity.

So you write everything in assembly and rewrite it completely for every new target system? Seems a bit tedious to me /s

Just kidding abstraction serves it's function and the right amount of abstraction makes things better, more transferable, easier to maintain etc. I think for example about hardware abstraction layers (HAL) in embedded programming. But abstraction in programming is never a value in itself and its use needs to be weighed carefully.

I think it is best to teach people to stick to the data and to think about transformations between said data. If they don't know abstraction (aka beginner's spaghetti code) it is worth telling them about it.

Re:How to Design Programs 2nd Edition by SanderNL on Tuesday May 02, 2023 @04:32AM (#35784804)
I think ORMs fit that bill. For some reason they were (are?) incredibly popular, but I don't think they stood the test of time. In the case of SQL, it's already an abstraction. No need for elaborate wizardry to hide the fact you're about to JOIN a table or two. Just write the damn join.

Every. Single. Project. I see using ORMs resulted in a baseline 20+ queries being fired under the hood for every screen. They are not bad in and of themselves, I think that they attract or are amenable to a certain type of development mindset that ends in bad results.

I have a very hard time thinking of any kind of object oriented abstraction that turned out to be a very good idea.

Re:How to Design Programs 2nd Edition by vbezhenar on Tuesday May 02, 2023 @04:41AM (#35784852)
I've yet to encounter a single project which does not use ORM. Everyone uses it. So they definitely stood test of time. And popularity of ORMs says more about issues with bare SQL approach. IMO SQL is just bad. Developers want JSON, not CSV. Developers want to specify conditions with lambdas, not with strings.
Re:How to Design Programs 2nd Edition by SanderNL on Tuesday May 02, 2023 @05:06AM (#35785008)
I don't the "everyone uses it" argument works here. Sure, it has a lot of momentum, but I'm just not seeing the proposed productivity enhancements. I actually just spent a significant chunk of time to de-ORM a system to get some performance and, more importantly, clarity back.

IMO it's way, way easier to look at some queries instead of some leaky abstraction (on top of the already leaky abstraction that is SQL).

Again, I really don't think popularity is a sane metric anymore. (React, "Astro", Angular, web-dev in general)

Edit: I'm very much in a bubble. A lot depends on your tooling and environment. For example I can appreciate it being different in an MS environment with stuff like linq. I'm not in that environment.

Re:How to Design Programs 2nd Edition by ChicagoDave on Tuesday May 02, 2023 @04:38AM (#35784833)
Relational databases are an operational anti-pattern. ORMs have proven that.
Re:How to Design Programs 2nd Edition by barrkel on Tuesday May 02, 2023 @04:59AM (#35784966)
Relational databases have shown, and will continue to show more longevity than object orientation.

Facts and the relationships between facts is a deeper foundational principle than the concept mashup of modularity, hidden [mutable] state, dynamic dispatch and interface subtyping that object orientation is formed from. Databases are more long-lived than applications, so applications tend towards adapting to the form of the data rather than the other way around.

Re:How to Design Programs 2nd Edition by kaba0 on Tuesday May 02, 2023 @05:53AM (#35785283)
The concept of mashup of modularity, hidden mutable state and dynamic dispatch, etc also stood its time, and so do relational databases.

There is a mismatch between the two models, but it can make sense to think of the entities at hand as objects at times, and relational data at other times. That’s why ORMs are a thing, and also why most popular programming language nowadays are multi-paradigm, so they can also support a more data-oriented approach.

Re:How to Design Programs 2nd Edition by DanielHB on Tuesday May 02, 2023 @10:45AM (#35788274)
relational databases are backed by relational algebra, an actual formal math definition. You can prove theorems like the output of Query X is equal to the output of Query Y, but Query Y is likely to run faster so that is what we will run

You can't outdate math (you can outdate math notation though, finding better ways to express the same information). To be fair SQL is not 100% relational algebra compatible, but it is close enough

Re:How to Design Programs 2nd Edition by ChicagoDave on Tuesday May 02, 2023 @02:55PM (#35792434)
Modeling a business’s processes does not equate to modeling a business’s data.

Starting with modeling data will immediately cripple software engineers from building what the business needs.

Starting with business models and then deciding what data storage is appropriate is a more practical way of designing software. Operational data very often fits in schema-less document storage.

Relational databases are excellent tools for analytics and reporting.

I stopped architecting software with relational databases “first” 7 years ago and will never go back.

Document databases are highly adaptive and denormalized data is inherently faster.

I’ve since found very rare cases where a boundary requires a relational database.

Welcome to my Domain-Driven Design rant.

Re:How to Design Programs 2nd Edition by segfaltnh on Tuesday May 02, 2023 @07:04AM (#35785750)
I have the opposite feeling on RDBMS, based on my limited experience. I think you need a good reason to deviate from it, which is often very large scale. I'd say 99% of applications written are no where near this scale.
Re:How to Design Programs 2nd Edition by regularfry on Tuesday May 02, 2023 @04:42AM (#35784869)
OO abstractions are very effective in UI toolkits, but because a smaller proportion of folk are working on desktop apps any more, people tend not to get exposed to that use case.

I also think it depends on the type of ORM. Active Record? Really problematic except for simple use cases but because they make those simple cases easy they get popular on that basis. Data Mapper? Actually fine and very useful, but harder to write well and a bit harder to use.

Re:How to Design Programs 2nd Edition by SanderNL on Tuesday May 02, 2023 @07:18AM (#35785867)
Yes, that's actually a good point. UI widgets map nicely to objects, at least usually.
Re:How to Design Programs 2nd Edition by futureduck on Tuesday May 02, 2023 @04:56AM (#35784945)
I second that OO abstractions shine in UI systems. Most complex UI applications use some form of ECS these days.
Re:How to Design Programs 2nd Edition by bzzzt on Tuesday May 02, 2023 @05:39AM (#35785199)
I can't imagine programmers using reasonably well tested and documented ORMs and still firing a minimum of 20 queries would be capable of writing a nice and equally bug-free SQL interface in place of that ORM...
Re:How to Design Programs 2nd Edition by SanderNL on Tuesday May 02, 2023 @06:11AM (#35785403)
I don't think you are wrong and that's the actual cause of the problems, not the tools. But that's for another day..
Re:How to Design Programs 2nd Edition by nickpeterson on Tuesday May 02, 2023 @06:35AM (#35785570)
I think the use of ORMs by people who understand databases is fine. I think when ORMs turn into, “you don’t need to know SQL!” Is when things go off the rails.

Everyone (management) wants a way to get productivity without loads of experience and tools that promise that tend to be misleading.

Re:How to Design Programs 2nd Edition by segfaltnh on Tuesday May 02, 2023 @06:59AM (#35785723)
Are there really software jobs where managers are the ones making decisions like whether or not to use ORMs? Some of these comments make me feel like I've had a truly blessed career.
Re:How to Design Programs 2nd Edition by pdimitar on Tuesday May 02, 2023 @07:35AM (#35785991)
You better believe you have had a truly blessed career.

In most places the moment you say "this will take 67 minutes and not the 65 minutes you thought it would", all sorts of idiots that know nothing about programming will come and dispute your every technical decision.

Exaggeration of course, but not far from the truth. Worst of all are the CTOs that already sing only the CEO's tune, come and review your entire project in exhaustive detail, conclude that you did 99% of everything correctly and well and exactly how they would do it, then proceed to fire you over the missing 1%.

Again, kind of an exaggeration, but again, not far from the truth either.

In most places people are treated like interchangeable cogs. Better hold tight to your warm positions, it's not a given you'll find a better one if you figure that you must leave.

I dream of a workplace where after I prove my worth -- 1-2 months -- I'll just be left alone to produce and correct code and protect the company's interests without being second-guessed, even though I am one of the most productive devs there. I dream of that. I might cry if one day I realize that I've actually landed such a job.

And I am a senior. 21 years in the profession. Food for thought for you.

It's all about who you know and drink coffee with, apparently. Your abilities as a professional barely matter, it seems.

Re:How to Design Programs 2nd Edition by BaculumMeumEst on Tuesday May 02, 2023 @07:56AM (#35786167)
I’ve only worked in a few large companies where nobody even cared about code quality unless you brought down a production system with a bad change or something.

You’re seriously saying you’ve had 21 years of constantly being second guessed? What kinds of places are you working at?

Re:How to Design Programs 2nd Edition by pdimitar on Tuesday May 02, 2023 @08:07AM (#35786230)
I've been a contractor in the last 7 years and I've come to dearly regret it.

Never has my work been so second-guessed and ripped apart. I suppose my price was too high for them, not sure.

I'm still reflecting and have no good conclusions to offer.

(But part of the time I was in bad health and my work quality suffered. So that explains one percentage of the cases at least.)

Re:How to Design Programs 2nd Edition by MyneOutside on Tuesday May 02, 2023 @08:24AM (#35786353)
I've been doing this 15 years and I've been dealing with second guessing or managers acting like we don't know what we are doing the whole time. The problem being the managers are MBAs who know little or next to nothing about software development. They don't like being told differently from whatever narrative they come up with and primarily solely focus on cost.

The company I work for considers themself a MSP. The parent company is a sales company selling non software products.

In any case, yeah it happens.

Re:How to Design Programs 2nd Edition by nickpeterson on Tuesday May 02, 2023 @07:36AM (#35786001)
It’s usually indirect, “only use libraries from these approved internal systems”, “new projects use these templates”… etc. Eventually to go against this set of standards make you appear to be a squeaky wheel while everyone else seems to be working just fine.
Re:How to Design Programs 2nd Edition by segfaltnh on Wednesday May 03, 2023 @11:04AM (#35803251)
Right but in those cases were these libraries selected by engineering managers and not developers? I definitely appreciate being stuck in a pattern but everywhere I've worked the standards were at least set by technical contributors (competent or not).
Re:How to Design Programs 2nd Edition by nickpeterson on Thursday May 04, 2023 @10:34AM (#35816007)
At a tech-focused business, probably, but think about all the programming jobs and IT departments that ultimately roll up to very non-technical people. Often what happens is a vendor becomes the chosen vendor for some expensive tool (think Microsoft, Red Hat/IBM, Oracle, whatever), and they have a solution for almost everything (theoretically). You start having to justify why you want to use a different thing to people who don't care.

Say you have 200 windows servers, and someone wants to use linux, "Why, what are you trying to solve?" Sometimes the industry forces the issue (think marketing people using Macs), but generally people are trying to streamline things they don't care about. "Use the tools that come in this box we buy from this vendor who we pay all our bills too, everything else is a weird liability I have to worry about hiring for and keeping track of."

The end result tends to be pretty mediocre though.

Re:How to Design Programs 2nd Edition by kaba0 on Tuesday May 02, 2023 @05:46AM (#35785240)
ORMs are okay, people just don’t know when to use them. They were always meant for OLTP, not OLAP workloads.

How else would you update this record, plus 10 other record pointing to it? That’s the point of ORMs, “writing” the boilerplate SQL for you, and also the other direction, mapping records to objects.

It’s not the tools problem that people refuse to learn new things and misuse it.

Re:How to Design Programs 2nd Edition by Scarblac on Tuesday May 02, 2023 @06:01AM (#35785340)
The whole concept of a database as a separate system is an abstraction. An extremely successful one.
Re:How to Design Programs 2nd Edition by simplotek on Tuesday May 02, 2023 @09:45AM (#35787321)
> I think ORMs fit that bill. For some reason they were (are?) incredibly popular, but I don't think they stood the test of time.

I don't think there is any truth at all to this personal belief. In some domains it's unthinkable to use anything other than the standard ORM. In C# you'd need to be nuts to roll SQL by hand instead of using Entity Framework, and Django speaks for itself.

The only drawback of ORMs is that their promise is that developers don't need to learn the intricacies of SQL and SQL-related design patterns, but in practice developers need to learn the intricacies of SQL, the ORM framework, and the SQL generated by the ORM. Naive developers might believe they are better off reinventing the wheel with ad-hoc SQL stuff, but that's another problem.

Re:How to Design Programs 2nd Edition by SanderNL on Tuesday May 02, 2023 @10:43AM (#35788247)
Yeah I think you are right to add the “depending on your environment” caveat. I have no experience in the Windows domain.
Re:How to Design Programs 2nd Edition by yndoendo on Tuesday May 02, 2023 @01:35PM (#35791244)
I am nuts! I often work on two main C# projects. One uses a data adapter with data table objects. The other, is about to have EntityFramework completely removed. Reduced it to only handling database connections.

Original developers used code first. Looked into the dynamic SQL created by the framework and it was overly complex statements. Replaced with simple hand crafted SQL and Dapper, used just to bind the results to objects. This cut transaction time down dramatically, about 30 seconds down to less than two. I could still cut that down further with batch transactions that are no longer logically grouped.

Simply combining SQL, CSS, and HTML with a custom DSL allows for creating interlinked reporting. Did this on a microC II OS embedded system with SQLite running on hardware with 8mb flash and 64mb RAM. Port the DSL, keep the same table structure, and the same reports can be used in a new environment with new hardware or different database backend.

EntityFramework might be useful in some places. I have yet to work in a domain where it is.

Re:How to Design Programs 2nd Edition by taneq on Tuesday May 02, 2023 @04:34AM (#35784811)
> But abstraction in programming is never a value in itself and its use needs to be weighed carefully.

I think this generalises well to anything in (or outside) programming. Slavish adherence to any principle without consideration for the underlying merits of the situation is likely to become a negative.

Re:How to Design Programs 2nd Edition by pjmlp on Tuesday May 02, 2023 @06:00AM (#35785335)
Actually it would have to be numeric codes, as Assembly is also an abstraction. :)
Re:How to Design Programs 2nd Edition by geokon on Tuesday May 02, 2023 @04:02AM (#35784634)
I also found the outside-in way they solve problems (using stubs for inner calls) very bizarre. I could be wrong.. But I don't think anyone codes like that
Re:How to Design Programs 2nd Edition by regularfry on Tuesday May 02, 2023 @04:33AM (#35784807)
"Using stubs for inner calls" is literally a top-level description of London-style TDD.
Re:How to Design Programs 2nd Edition by kmac_ on Tuesday May 02, 2023 @05:13AM (#35785045)
Only Detroid school! Mocks should be banned (unless they mock external system). London-style tests cargo culting is one of the reasons why OOP got bad name.
Re:How to Design Programs 2nd Edition by regularfry on Tuesday May 02, 2023 @05:46AM (#35785242)
Leaving mocks in place once you're done should be banned, I agree with that. I think they're fine as an exploratory tool to figure out what an interface should look like.
Re:How to Design Programs 2nd Edition by kmac_ on Tuesday May 02, 2023 @06:33AM (#35785555)
Mocks means that there's a side effect neccessary (and that's quite rare) so the use is justified in such a case. If a stub is needed, then mostly it's gone when the code is refactored to a more functional style.

Unfortunately, most OOP developers bury side effects at the bottom of the stack, instead of passing an object that describes the side effect to happen (which it's executed at the shallow and simple application layer).

Said result object can be tested as any other function result and no mocking is required.

Re:How to Design Programs 2nd Edition by segfaltnh on Tuesday May 02, 2023 @07:08AM (#35785781)
I love this sort of approach for one-shot externalities but what about when your entire program is a conversation with external components? My current project coordinates software repositories and services within AWS and I find myself using a lot of mocks in testing.

I can return a tree of lambdas but then I have to resolve them against something and that's just replacing mocks with lambdas, really. Not sure it's any better in practice.

Re:How to Design Programs 2nd Edition by kmac_ on Tuesday May 02, 2023 @07:42AM (#35786057)
Great question! I worked with two approaches: 1. Sagas - a centralised place to handle bussines flows 2. Event system

Start with 1. and eventually (pun intended) move to 2. Both ways allow parallelized interactions with external systems, deferred decisions, etc. whatever the bussines will require.

Re:How to Design Programs 2nd Edition by segfaltnh on Wednesday May 03, 2023 @11:02AM (#35803224)
Sorry I wasn't clear, I'm talking about imperative code that coordinates multiple external actions. In a world where it's modeled as jobs in a distributed system, I agree that each job can be nicely functional (and I love this pattern).
Re:How to Design Programs 2nd Edition by regularfry on Tuesday May 02, 2023 @11:38AM (#35789241)
> Mocks means that there's a side effect neccessary

Eh, kinda. London style says to use mocks as you work down the call stack, whether or not there's a side effect. At some point you might hit an edge where you're calling into third party code for a side effect (and all side effects are calling third party code), but that's not really the point.

This is where the "never mock code you don't own" principle comes in: if you're mocking out third party code, it needs to have a wrapper of your own code to hide it, so you're in control of the interface. At least in theory. You want to be passing that thing in anyway, so for the tests you pass down a MockThing, or a NullThing, or an InMemoryThing. That way the side effect can happen at the lower level, but the choice of exactly whether there's an observable side effect is still in control of the top-level application.

Really you and I are describing two different ways of achieving the same result: moving side effects to somewhere they're easy to handle independently of the logic, whether that's functional core/imperative shell, or dependency inversion. You don't really need mocks for either because the only time you're actually testing the side effect itself is probably an integration test, but they're a useful tool to get to that point.

Re:How to Design Programs 2nd Edition by ryanjshaw on Tuesday May 02, 2023 @08:14AM (#35786276)
I code like that. I got burned one too many times spending hours/days on an inner call that turned out to be unnecessary. When you solve outside-in, you are sure you're solving the right problem in the right way without overcommitting to intermediate steps.
Re:How to Design Programs 2nd Edition by Hypergraphe on Tuesday May 02, 2023 @03:59AM (#35784622)
In fact, that could be useful to ellaborate a bit.
Re:How to Design Programs 2nd Edition by ChicagoDave on Tuesday May 02, 2023 @04:05AM (#35784650)
Primarily this book completely ignores communication with subject matter experts and the business. This is fundamentally more important than any language, process, or platform.
Re:How to Design Programs 2nd Edition by Ligma123 on Tuesday May 02, 2023 @04:34AM (#35784815)
>Primarily this book completely ignores communication with subject matter experts and the business.

Probably because this isn't an advanced book on Software Engineering, but an introductory book to programming.

Re:How to Design Programs 2nd Edition by sussmannbaka on Tuesday May 02, 2023 @08:07AM (#35786234)
This is wrong, it’s a core part of the design process as described in the book.
Re:How to Design Programs 2nd Edition by oslac on Tuesday May 02, 2023 @05:24AM (#35785112)
Having read through the old version I cannot recommend that one either.
Re:How to Design Programs 2nd Edition by ericjmorey on Tuesday May 02, 2023 @07:34AM (#35785982)
Would you care to elaborate?
Re:How to Design Programs 2nd Edition by ericjmorey on Tuesday May 02, 2023 @07:35AM (#35785993)
Could you share a few examples of what you consider outdated principles?
Re:How to Design Programs 2nd Edition by favadi on Tuesday May 02, 2023 @08:40AM (#35786511)
> Abstractions lead to coupling and complexity.

Without abstractions, we would still programming using punched cards.

Re:How to Design Programs 2nd Edition by mumblemumble on Tuesday May 02, 2023 @08:41AM (#35786525)
> Abstractions lead to coupling and complexity.

If you're in the habit of programming in anything other than machine language, I think you'll have to agree that the real story is more nuanced than that.

I haven't actually read this book so I'm not prepared to defend it. But I would happily run my mouth and say that the truth is more that abstractions are a double-edged sword. They can be very effective in skilled hands, but they are dangerous in the hands of the untrained. Unfortunately, what makes a good abstraction (IMO it's algebras or GTFO) is not something in which most of us receive sufficient training.

Re:How to Design Programs 2nd Edition by Joker_vD on Tuesday May 02, 2023 @09:43AM (#35787281)
If an "abstraction" leads to coupling, then it's not an abstraction.
Re:How to Design Programs 2nd Edition by kqr on Tuesday May 02, 2023 @12:35PM (#35790206)
Richard Gabriel coined a word for those things: compressed definitions.

When a thing looks like reuse or abstraction because it implicitly pulls in something else in a coupling way, it's really about exploiting shared context in a way that allows the new definition to be much briefer than it otherwise would have been. However, it still relies on full knowledge of the context, so in terms of conceptual load, there's no difference.

Just as with other types of compression, the shared context becomes the global coupling across definitions.

Re:How to Design Programs 2nd Edition by kaba0 on Tuesday May 02, 2023 @01:35PM (#35791253)
Could you give an example of that?
Re:How to Design Programs 2nd Edition by kqr on Tuesday May 02, 2023 @01:53PM (#35791560)
I have come across a codebase where there was an "Import data from HTTP" functionality that extended the "Import data from file" functionality in such a way that the HTTP calls were grafted onto and around the file operations. This probably made the HTTP class quicker to write, but

- Anyone wanting to make changes to the HTTP import functionality needed to also fully understand the file import functionality since basically all of it was used to import from HTTP, and

- Many changes to the file import functionality also broke usages of the HTTP import functionality. (Fortunately these breakages were always revealed by automated tests before they made it into master.)

Re:How to Design Programs 2nd Edition by mumblemumble on Tuesday May 02, 2023 @03:37PM (#35792998)
Even that's a hard statement to make in such an unnuanced way. Oftentimes the whole point of an abstraction is to couple things together in a way that happens to be useful.

Take relational databases.

The relational model is a fantastic abstraction that revolutionized data storage and allowed databases to become vastly more powerful than they were prior to the introduction of the model. But it also couples the data representation to a model that's based on sets of tuples, which is a bit of a mixed blessing. It's necessary for the algebra that makes relational databases so flexible, but it also means that the RDBMS's native data format is fundamentally incompatible with how most application programming languages like to organize things, thus creating the need for a translation layer (read: API) to bridge the gap. That is, strictly speaking, a lot of extra work compared to using a database like Gemstone, but I tend to think that it's a fair trade in large systems.

On the other hand, object/relational mapping often drives me nuts, because it introduces the wrong kinds of abstractions. It tightly couples the database's schema to the data model of the portion of the application that the person who created the table was working on at the time. This reduces the flexibility of the database. Other methods like sprocs certainly have their problems, but at least they were trying to place the abstraction in a sensible place that doesn't create the kinds of couplings that make an application resistant to change.

Re:How to Design Programs 2nd Edition by qumpis on Tuesday May 02, 2023 @10:36AM (#35788127)
This might not be a perspective of a programmer, but the code I've reviewed and tried to understand from academics is always easier to manage when it's not abstracted too deeply. Especially when reading the code is the main reason for trying to understand the underlying idea.

Unless you have an extensive (visual?) representation of how the code flows, abstracted code for beginners might be a hindrance towards understanding what's happening at the lowest level while still maintaining the contours of the whole thing.

Of course when everyone's on the same page and has similar understanding, this is no longer a concern.

Re:How to Design Programs 2nd Edition by taeric on Tuesday May 02, 2023 @11:27AM (#35789036)
Would be nice to see at least a few of the principles called out. What makes them outdated?

And coupling/complexity are a touch on the weasel word space for our domain. They can mean things, sure, but they are often used for the emotion attached more than anything else. Worse, as programs grow, they probably should be coupled heavily. Loser coupling is almost always more complex to maintain and of diminishing returns. Is why the tires on your car can't be used on another vehicle. We probably could engineer the "one true wheel", but it would be done at the expense of capability. Not in pursuit of it.