3 ms·
Here are my Reddit comments on this story: I've always programmed thus: * Try to assimilate a mental model of the bit I'm working on, and as much of that bit'
by bitwize 12y ago
Here are my Reddit comments on this story:
I've always programmed thus:
* Try to assimilate a mental model of the bit I'm working on, and as much of that bit's dependencies as is practical, into my head. This may involve fiddling with the code and seeing how it breaks when I do certain things to it, or hammering at it inside a REPL or similar. The bit that I'm concerned about could be a single method, but is usually larger.
* Try to develop a mental model of the bit as it _should_ be. Do a diff between the 'is' and 'ought', make code changes as necessary, fiddle with the new code to make sure the shape of its function is roughly the 'ought' shape.
* Update the unit tests with specific tests for the 'ought' case, run tests, fix failures.
* Check in or submit code for review.
This is not how software is written now. How software is written now is a hill-climbing algorithm where each cycle is one "red-green-refactor" sequence. Write a tiny failing test which no matter how small or trivial still has a few lines of setup/teardown boilerplate, make the smallest possible code change to make the tiny test pass (change minus sign to plus sign?), run the ENTIRE test suite to make sure that your sign flip didn't break anything anywhere else, if the code needs to be refactored do so and run the entire test suite again, fucking repeat. There are a number of theoretical advantages to this from a management perspective:
* Developers produce working code quickly in the early stages of the lifecycle, whereas with the slow approach you do a lot of sittin' and thinkin' up front without much to show for it -- maybe some design documents or UI mockups, I dunno.
* Development no longer relies on developers' internal mental models of the code. Developers now code against a model which is incarnate in the test suite -- itself a deliverable, documentable artifact.
* Because programmers no longer work from internal mental models but the single-bit state of "do the tests as written pass or fail?", the concept of "code ownership" -- along with related management problems of coders waxing territorial over the pet modules they've spent days or weeks ruminating over in order to understand deeply enough to change -- evaporates.
* Programmers look busy all the time, because they are constantly typing out test code to exercise even the most trivial of changes.
* Thanks to pair programming, you no longer need worry about the "guy in a room" problem. Your dev team is always seen to be interacting with one another.
But I hate it because it is incompatible with my temperament. I like to think about _what_ it is I intend to write, before hammering out test cases to exercise it.
- pandler 12y agoThis rings true with me. Some of my best work has been done laying on my bed (working from home) staring at the ceiling. On one project, we initially gave ourselves a ridiculous deadline and subsequently made a lot of ad-hoc "fuck it" decisions without properly thinking out the consequences. The system is sufficiently complex that we ended up with something that _barely_ did what it said on the box (if it worked at all). I dreaded even adding the simplest of features, because I could just feel how fragile the whole thing was. We ultimately made the decision to scrap the project (and piss off or outright lose some customers waiting to pay us money) and restart from scratch, and I spent a few months part-time just building up a mental model of the system and stress-testing it against all of the different requirements and scenarios we had to handle. I went through a couple of notebooks in that time, but I didn't write a single line of code. For me, it was a lesson in the importance of deliberation and knowing what you should be building before building. As my uncle liked to say when we built houses together, "measure twice, cut once."
- einhverfr 12y ago> - Development no longer relies on developers' internal mental models of the code. Developers now code against a model which is incarnate in the test suite -- itself a deliverable, documentable artifact. And yet I have run into too many people who valued using the test suites for documentation. IMO test suites should test that the software implements the documentation. Nothing more and nothing less.
- kendallpark 12y agoThis, exactly. When DHH lambasted TDD at Rails Conf earlier this year I felt vindicated. TDD enthusiasts market the practice like TDD is a one stop shop for better code. Fad diet style. IT WORKED FOR ME, IT'LL WORK FOR YOU. THIS ONE WEIRD TRICK WILL GET YOU PROGRAMMING BETTER. I think TDD works great for certain personality types. Definitely not mine. (I'm like you, as far as I can tell.) I find that writing tests first inherently makes assumptions about the shape of the code that I'm going to write. I so often zoom out and say "no, no, no, I'm going at this all wrong" and completely change the way I'm structuring my code. If I've written test-first, then that's two places (my code and the tests) that I need to completely redo the structure. And 2x the programming time for refactoring. I will advocate TDD for debugging. Test-first is wonderful for isolating software bugs and resolving them.