1. 36

A really common problem with a lot of books on coding practice / CS / engineering / whatever is that they use idealized toy models that don’t reflect “real world problems”. Obviously this is necessary to some extent, because real world problems get insane. But often the real world problem requires a totally different approach than the toy problems, making the advice hard to apply. Some examples of what I mean:

  • A super common example for “clean code” is that instead of doing p * t to add sales tax, you write price * sales_tax. I pulled up an ecommerce suite and looked how they did it. They track an array of the tax markups, one for each applicable tax, and bundle that along with the cart.
  • A common OOP demo is representing a chess game with separate objects for each piece. Competitive chess engines go to incredible lengths to minimize their memory footprint so they can search more states faster. This is what the “board” looks like to Stockfish (Bitboard is a uint64_t). The overhead of a separate object for each piece is way too much.
  • Pamela Zave’s work on feature interaction is about managing the intersections of multiple features in a telecommunications system.
  • Data migrations are a lot more complicated if you don’t get to have any downtime or degraded service.

Anyway, I’m looking for resources on how people tackle “real world” problems in software engineering: how they organize business logic, what tables they use in their database, what they do in less-than-ideal situations etc. I’m fine with it being stuff in specialized domains; I figure most of it will be in specialized domains. Thanks!

  1.  

  2. 12

    Implementing Domain-Driven Design by Vaughn Vernon goes through an implementation of an application in Java using Evans’ DDD principles. I may disagree with some of his code, and some of the “dialog” is hokey, but it is a useful read.

    I’ve been doing this coding thing for a while (30+ years) and I find it’s really difficult to convey how “real world” problems get solved, because much of the solutions are specific to the team and company culture involved, and less about the technical aspects. Yes, for those who give talks at QCon or O’Reilly conferences, they have unique problems, but 80% (if not much more) have the same issues: lack of modularity (hence monoliths), poorly written tests (let alone coverage), and a shallow understanding of the domain (which is why I talk a lot about domain-driven design).

    I really liked the Architecture of Software Applications books, because it’s one of the few places that walks through how something that you might actually be using was created, and the constraints involved.

    I also thought Practical API Design was a really good case study of writing a framework. Growing Object-Oriented Software (aka GOOS) is also a solid read (and generally matches how I think and do software development).

    Yes, many books use toy or simplistic examples, partly because it’s really hard to teach someone a non-trivial domain while at the same time teaching them something non-trivial about a certain type of problem/solution, I also find most authors aren’t able to, or don’t want to, put in the work necessary to create more realistic examples. As an author and instructor, it definitely is more work, but is also a better way to teach. Alas, the bar is pretty low for how programming is taught.

    1. 7

      Domain Driven Design by Eric Evans is a classic modeling book, but a hard read. I’ve heard that Domain-Driven Design Quickly by Abel Avram & Floyd Marinescu is a better, shorter version but haven’t read it.

      I got a lot out of Joe Celko’s Data & Databases on database design and, his puzzle books SQL for Smarties and SQL Puzzles and Answers puzzles were so fun and weird they helped me really internalize relational dbs.

      I just started Scott Wlaschin’s book Domain Modeling Made Functional and Debasish Ghosh’s book Functional and Reactive Domain Modeling. I’m only about a chapter into each, so I can’t give a significant opinion yet, but they’re both interesting takes on modeling.

      Jon Bentley’s Programming Pearls books and Writing Efficient Software have lots of the bitpacking kind of stuff you’re getting at in your mention of Stockfish.

      Sandi Metz & Katrina Owen’s book 99 Bottles of OOP breaks down a toy problem in a bunch of different directions and points out where approaches succeed and fail at responding to change or preventing bugs.

      1. 3

        I’m halfway through Scott’s book you mention. It’s really good! It gives me confidence to adopt the naming convention that I instinctively felt was right, when I saw no other comments about naming in pure FP literature or blogs. It’s my first intro to DDD, and it finally makes sense to me now. Not every app will require DDD, but it makes sense for business apps. The downside to adopting the business’s ubiquitous language is that you don’t have much opportunity to do cool stuff with FP concepts, but that’s fine, there is opportunity to use cool ideas in architecture stuff, like an algebra of domain object modifications.

        1. 1

          I just bought and read Domain Modeling Made Functional on the basis of this comment and have found it really illuminating. Despite the name I would say that a lot of the concepts in it will be very applicable even in non functional settings provided the overall architecture is more functional (i.e event based in some sense).

        2. 7

          The architecture of open source applications should be real-world enough

          1. 3

            I don’t know is AOSA is what @hwayne is looking for, but for anyone reading, its a great series of books and I’d advise everyone to check them out.

          2. 7

            So, I’ve been thinking that we really should have a wiki or book somewhere of standard business problems. Things like “this is basic inventory system”, “this is basic user manage”, and so forth, along with common design parameters and operating regimes.

            1. 1

              I really like this idea. One step more abstract: these are common parameters of a basic inventory system, here’s an implementation, and by the way here are some other tricky things that this toy system doesn’t solve. My concern with a wiki of implementations is that it would be easy for readers to turn off their brain. Including some “exercises for the reader” might help inform them of the problem space.

              1. 1

                Yeah, a book really would be more ideal.

                It’s also useful because it’s a good way of saying to a business “hey, you are business in wrong…why does our inventory system not follow normal practices?”

                1. 1

                  Yeah, a book really would be more ideal.

                  My set of encyclopedias from 1989 says otherwise.

                  I worry that something like this implies that there’s only 1 correct way to do things, when that is often not true. And in fact, if it were, I don’t think we would have seen such explosive growth in our field…

            2. 3

              A super common example for “clean code” is that instead of doing p * t to add sales tax, you write price * sales_tax. I pulled up an ecommerce suite and looked how they did it. They track an array of the tax markups, one for each applicable tax, and bundle that along with the cart.

              btw, “clean code” (I hate that name, I prefer “intention revealing code”) is much more than nicely named variables, it’s well partitioned code at multiple levels. Short methods with meaningful names, divided into classes that are cohesive, divided into modules, etc., with cohesion at each level, and each one being at the same level of abstraction.

              I took a look at the tax.php code and, while I’m no PHP developer, that’s not at all how I’d do it, because that code isn’t OO, it’s just code that happens to have method names. We can argue about OO vs. FP, but if I were to write this as OO code, I wouldn’t have code like this (in fact I’d hardly have if statements at all):

              if ($calculate != 'P' && $calculate != 'F') {
              	$amount += $tax_rate['amount'];
              } elseif ($tax_rate['type'] == $calculate) {
              	$amount += $tax_rate['amount'];
              }
              

              That’s a sign that the author doesn’t understand OOP, or didn’t want to do it.

              1. 2

                “clean code”; I hate that name, I prefer “intention revealing code”

                “Clean code” is Uncle Bob’s branded term at this point.

                I wouldn’t have code like this…

                Oh you think that’s bad. Look at how it’s called e.g. royal_mail.php

                This is a good way to make mistakes. “Clean” or not, it’s still rubbish.

                1. 1

                  “clean code”; I hate that name, I prefer “intention revealing code”

                  “Clean code” is Uncle Bob’s branded term at this point.

                  Yeah, and I never liked his brand, even before some of his recent remarks.

                  Oh you think that’s bad. Look at how it’s called e.g. royal_mail.php This is a good way to make mistakes. “Clean” or not, it’s still rubbish.

                  What’s so dismaying is that regardless, this stuff works, and that’s the feedback that most developers get: if it works, it must be OK. When they find out it’s not, i.e., find a bug, they just figure that’s the way it is.

                  1. 2

                    it works, it must be OK. … bug … [is] the way it is.

                    Agreed completely, but its not just delusional programmers: I quote three months, I hit three months; If this jackass quotes three months and runs over by six, weirdly everyone is still happy because software has this terrible reputation. Seriously. Have you tried turning it off and on?

                    Our society accepts bugs, so we’re stuck with this until that changes.

              2. 3

                I think the best way to find out how it’s really done is, as you’ve already found, to look at how it’s really done. Plenty of “real-world” implementations of solutions are open source, which not only gives you the opportunity to see their code but also to see their commit history. Maybe that chess solution started to “make it work” with a piece being an object, but by the time they got to “make it fast” went to the bitmap approach.

                Books have noddy examples not because the authors don’t know how to do tax or chess games, but because their goal is to teach something else. I once wrote a shockingly bad stack overflow browser to teach TDD, not because I wanted to demonstrate a shockingly bad stack overflow browser but because I wanted to teach TDD.

                1. 2

                  For a very good perspective of modeling complex problems outside the domain of informatics and computing infrastructure, it is worth reading (informational) parts of the manual for the Beta language, the successor to Simula. It can be found on the web.

                  It provides insight into the “programming is modeling” perspectives of the inventors of object-orientation. Interestingly, this is the same (unpopular) perspective of Domain Driven Design as promoted by its original author.