Ask HN: A Book or Course to Learn Code Quality/Structure?

I have been programming for ~15+ years on probably over 100+ different projects.

I do however work for myself, and one downside to that is I don't work on (or even SEE) other people's code hardly ever. I feel like if I worked at a big company and stared at good code all day long I would have learned a lot by now.

I've read about things like "Single responsibility principle" or "Open-Closed Principle" which... while reading about it seems nice, it's always way more tricky in real life to apply (at least for me).

Looking at very simple "make_payment(user, 1000)" examples where the payment is consolidated into one line of code never helps me... in my experience, and the thing which I feel is hardest for my brain to wrap my head around, is when some parts of code is used in multiple areas, but there is no "clean break." Like say a "quick add to cart" function on a website... it might need to do all the following:

validate the cart, use toast modal dependencies with a custom message, track all items that were added to the cart, send different params to the backend, etc etc

This may be 80% similar to the "add to cart" so there could be a series of functions that seem easily 'shared', but then of course some other edge case will come up where I need to not track something now, so now do I make another function with duplication? Do I just keep adding arguments to a large already very confusing function?

Things like this I generally fumble my way through until it "feels right," as in I have a good intuition by now what will be a headache, and what wont. But I have no method to my madness, I just try to separate things as best I can but UNDOUBTEDLY there will be 89253 different "special cases" that make it very difficult to do it cleanly without either duplication, excessive arguments, excessively long functions, etc.

I do use OOP languages, and javascript primarily.

I want to just read a book or watch a course with GOOD examples. I absolutely dont feel my code is "bad", and I have managed some complex projects, but its not exceptionally good and that's where I want it to be.

  • It's PHP, but my book [Modernizing Legacy Applications in PHP](https://leanpub.com/mlaphp) may help -- deals with code improvement, especially the organization of that code. The examples are taken from a real codebase, though the names have been changed to protect the guilty. The book is still free, so nothing lost if it's not what you're looking for.

    Good luck!

  • > I feel like if I worked at a big company and stared at good code all day long I would have learned a lot by now.

    I promise you good code is extremely developer dependent and there are many senior engineers in big valley that write horrible code.

    This guy's blog is all about writing extremely boring code (my take):

    http://misko.hevery.com/code-reviewers-guide/

    I've read pretty much everything that wasn't framework specific and it is definitely the most enlightening source of information on how to code I've ever read.

    Everything roughly boils down to one guiding principle: don't use global state.

  • Clean Architecture: A Craftsman's Guide to Software Structure and Design

    Refactoring to Patterns

    The Pragmatic Programmer