Hacker News new | past | comments | ask | show | jobs | submit login

While I dabbled with python and Delphi for a bit,my first real development was on Salesforce platform with their proprietary language called Apex. The first thing every developer learns on thos platform is that your code has to have at least 75% test coverage before it can be pushed to production.Testing was inevitable and ultimately part of anything I had to write. With time,I started reading more and more about development, tried different languages and etc.It was really fascinating to read how a lot of people hate testing or teams skip them if the deadlines need to be met. What testing taught me is that if the test is hard to write,it means that the code is crap.Every time I wrote some quick hack,it used to take me 10 times longer to write unit test.



But what do you do if your initial codebase is crap. You literally cannot test until you refactor 50% of it into something semi-sensible.


Short version: you find very small things that you can write tests around (pulling messy logic out into testable functions, writing tested utilities that replace dirty hacks, etc.) and start building your testing framework starting with that.

Long version: Working Effectively with Legacy Code Book by Michael C. Feathers


It’s almost always bad as a new guy to come in and start refactoring.

There are lots of weird if checks to deal with a vendor that returns bad data over the api every Sunday night. Your new clean code is going to crash and burn in all of these cases.


That is not an argument against unit testing. That is an argument for applying it from the beginning…


Then refactor 50% of it.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: