A common feature of many IDE are templates, which greatly speed writing code. People often create their own "cut-and-paste" templates as well.
An important rule to remember here is that no template should ever "work" out of the box. This way, if (for whatever reason!) you don't fill it in, you know it will fail fast. This helps avoid bugs that can be quite subtle: template code which fails slowly. :)
In Java IDEs, for example, I configure the template used for new methods to throw a java.lang.UnsupportedOperationException.
When I use TDD-techniques to write code, the usual procedure is to fill out (part of) the test case, and fix the compile errors. "Fixing the compile errors" may sometimes involve creating several methods. By using the "broken" template, I can easily just run my test, and fill in the methods as I go.
Similarly, if you're using cut-and-paste (which is sometimes valid1), don't cut-and-paste something that works; cut and paste something that is blatantly wrong - make a parameter something like "CHANGE_ME", or introduce a deliberate syntax error. That way, when you customise the cut-and-paste template, you can fix the error as you go.
----
1 An example of "valid" cut-and-pasting occurs when doing TDD, particularly for testing validation rules. The tests in these scenarios are often fairly repeatitive.
Comments (1)
Same "rule" applies to copy/paste of code. The best way to do it is to copy the code and paste it into a new page in your editor, and then change everything that needs to be changed so it will not compile, then copy/paste that code into the real destination.
Posted by Mats Henricson | January 11, 2005 2:21 AM
Posted on January 11, 2005 02:21