3 ms·
I have ~20 years of experience as a freelancer and I don't like TDD, but I do think writing tests early is important because they give you the confidence to ref
by nickjj 7y ago
I have ~20 years of experience as a freelancer and I don't like TDD, but I do think writing tests early is important because they give you the confidence to refactor your "fun / getting it to work" code.
My workflow is basically:
- Plan the project out, but not super detailed, this is more like a high level overview of features. I did a 90 minute video live on this process once[0].
- Think about each state of what a feature could be in. Here's another video[1] showing that process.
- Design some pages around your states (if you planned a user registration system, start designing the register form)
- Dive into the code and implement one of the features (using pseudo code to help with the flow initially if needed)
- Write some tests to demonstrate that what you have works as you intended
- Heavily refactor your code if needed, leaning on your tests and refining them as you come across edge cases, etc.
Honestly the above never fails for both small and large projects. You always have something small and focused to work on and the code you produce typically ends up being in good shape by the time you reach the end of the workflow. It's a fast cycle too (easily multiple loops per day) once you have the states ironed out.
[0]: https://nickjanetakis.com/blog/live-demo-of-planning-a-real-world-web-application-from-scratch https://nickjanetakis.com/blog/live-demo-of-planning-a-real-...
[1]: https://nickjanetakis.com/blog/design-your-web-uis-faster-by-planning-out-each-different-state https://nickjanetakis.com/blog/design-your-web-uis-faster-by...
- hyperbole 7y agoCode is legacy the moment it's checked in - not writing tests is the equivalent of expecting the game of telephone to go flawlessly always and forever for every corner and major case written... This type of optimism when looked up in the OED has one definition: nope
- Sahhaese 7y agoThat is why I like Michael Feathers' definition of legacy code, which is (paraphrasing): > Legacy code is code not under test That said, I'm not against the existence of legacy code, but any bugs damn well should be written up as tests to catch regressions. That way new development can be done without tests (full TDD is tedious and often way too coupled to implementation imo) but any bugs are captured in a way that can't be tests written against the implementation and guard against regression.