News for hackers. Stuff that matters.
Re:The 80/24 Rule by bob1029 on Friday November 15, 2019 @05:35AM (#21543800)
I am entirely in this camp as well. I have an extremely hard time dealing with the concept of a hard line/column number limit, because everything is a grey area to me. There are cases that are obvious to most, but when you say that 100% of your codebase must comply with some arbitrary restrictions, you start to cause way more harm than good.

The approach of putting all of the logic inline into the same method is much preferable to me over the alternatives. The point at which I would turn a new method is when a block of code is executed the same way in 2 or more contexts within the same class. Otherwise, I see no reason to break out the code, unless it is making readability difficult in a fairly obvious way - e.g. an inline new List<MyParameter>() which is 100 lines long should really be under a GetMyParameters() private convenience method. Other candidates could be similar points of control (e.g. make it easier to find where to control parameter listings by having them in their own named methods), or managing wildly different levels of abstraction (mapping code vs business logic, maybe create separate mapping methods).

I've taken this a step further and started collapsing entire layers. For instance, we'd have a Repository and Service abstraction, but what ultimately happened is there was only ever 1 concrete implementation of each, so these ended up combined. Something like MyBusinessService+MyBusinessRepository were reduced to a combined MyBusinessService. This has the advantage of allowing you to see exactly how the business logic is manipulating the underlying datastore by reading a single consolidated method. The combined implementation is certainly larger overall, but taking out the context switch far outweighs this minor downside in practice.

Productivity is king. I have given up on trying to have code that looks clean simply for the sake of aesthetics.

Re:The 80/24 Rule by marcus_holmes on Friday November 15, 2019 @06:47AM (#21544100)
Upvoted for collapsing spurious layers. I've started doing this, too. Why am I writing code to allow an alternative database engine, when I'm never going to move this thing off Postgres?
Re:The 80/24 Rule by mplanchard on Saturday November 16, 2019 @10:45AM (#21553182)
One of the nice things about having a repository/store interface is that it’s easy to make an in-memory fake for testing, so you can have at least some subset of your tests that don’t need to spin up a database container/vm in order to run
Re:The 80/24 Rule by bob1029 on Saturday November 16, 2019 @12:11PM (#21553655)
Yes this is certainly a solid counterargument, but if you decompose it into its aspects I think someone could make contrary points:

1. I would always advocate for testing full-stack with the datastore in the loop. E.g. an actual API request from a test runner all the way down into a test instance of Postgres. Isolating your testing to specific layers is clever, but I find 99% of my errors come from forgetting to adjust SQL queries after migrations were performed, or other things that are not going to get caught in the BL layer. If you did your BL correctly using the latest C# 8.0 primitives, you get a lot of compile-time guarantees of correctness (e.g. null enforcement throughout), so the value of unit testing these layers is diminished from my perspective.

2. The value of architectural abstractions changes over time. I would certainly advocate for a temporary IRepository injected into a service implementation if it makes the initial 100 iterations of the code faster by way of using a LINQ-to-objects shim in place of Postgres. But, once this code has been running stable in production for months without concern, perhaps its time to take out these abstractions so that the people responsible for maintaining the code on a daily basis have less complexity to deal with.