5 ms·
Refactoring breaks a lot of test cases (mostly with renaming variables). This is a red flag to me. Your tests should not know or care what variable names are
by mcantor 16y ago
Refactoring breaks a lot of test cases (mostly with renaming variables).
This is a red flag to me. Your tests should not know or care what variable names are used by your code.
It sounds in general like you might not be doing TDD correctly. Your test cases shouldn't be slow to run, either. Are you actually hooking up with the database in your tests, or are you isolating them properly?
- MartinCron 16y agoThe other red flag: This is 2011, there are good automated refactoring tools out there that make renaming variables/methods/classes trivial.
- mcantor 16y agoYeah, there's one built into Vim! :bufdo %s/^R-w/new_name/gc
- billmcneale 16y agoThis is exactly the kind of action that leads to build breaks. Don't do it, use a real IDE.
- dasil003 16y agoUnless you're using Smalltalk, then no, I'm not willing to use a watered down language for the simple ability to make variable renames bulletproof.
- xiongchiamiov 16y agoRefactoring support has nothing to do with IDEs. Nothing. An IDE is, well, an integrated development environment - I find the idea of mashing my editor, VCS, build system, debugger, etc. into one tool to be incredibly distasteful. What you want is a competent editor. Unfortunately, most editors that provide support for things like automated refactoring are bundled into IDEs, hence your confusion.
- billmcneale 16y ago> Refactoring support has nothing to do with IDEs. Nothing. Uh? The strength of an IDE is that it understands your code. It knows what a method, a class, a variable, a package is. Because of that, it can give you more assistance in writing your code than any editor that bases its highlighting on regular expressions ever will.
- IgorPartola 16y agoSorry but you are wrong. Every IDE I've seen is big, bloated and the useful features it provides are more cumbersome that sed, grep and find. OTOH vim is fast, universally available, and because of it's nature much faster to code in. I look at it this way: when you first switch to vim, you will be working WAY slower than in your favorite IDE. Take one hour to learn the basics. Then you will be just as fast. Then, anything new you learn is just going to give you that much more speed over your old way. Also, in general, it doesn't matter what you program in: be it an IDE, vim, cat, or a magnetized needle. A good hacker finds a way to write good code.
- billmcneale 16y agoIf you are writing Java code in vim, I guarantee you that you will be faster and more productive with an IDE. I can't believe you actually think that typing all these characters (imports, renaming by hand, creating methods by hand, etc..), navigating between classes, finding symbols is making you faster. vim is great for general text editing, but for Java, nothing can beat an IDE. Try it, you'll be surprised.
- IgorPartola 16y agoHeh. True, I do most of my development in Python, PHP, JavaScript, and C. vim is all about saving you keystrokes though. NERDTree is for navigating files, and autocomplete plugins are abound.
- bdclimber14 16y agoI used the term variables to include a lot like attributes, and even some methods. If you are testing a model's attribute, then the test case definitely needs to know about it. Technically, they are hooking up with the database since the attributes are automagically generated from the DB schema (using ActiveRecord on Rails). Maybe there's a better way? I'd love to know.
- ollysb 16y agoI love developing in rails but let's be clear, refactoring ruby is just painful at the moment. Yesterday I decided to rename a model, it took over an hour to get the tests passing again. Ok there's rubymine but it's only partially effective, it misses things like renaming relationships and references in templates. Given the difficulty of static analysis I've been wondering if a refactoring tool might look a little different with a dynamic language. Given that refactorings are effectively replacement patterns perhaps a find/replace workflow tool would be the way to go. The workflow might go something like: specify broad regex which matches all potential changes. View matches and then partition them with further rules like file type and tighter regexes. Once you've grouped the matches provide appropriate replacements. Run tests. Refine if required. Obviously you could follow this workflow using command line tools but the refinement process is difficult because you don't retain any of the context. Having said that it wouldn't be too hard to use existing commands to put something like this together. Looks I've got a project for this afternoon.
- jasonkester 16y agoThat there is the big reason I can never convince myself to stick with a language like Ruby or Python. I do about one project a year in one or the other, and am always re-amazed at the lack of proper tools. It's a shame, because in other ways they're so good. The refactor you mention is single right click in C# (with ReSharper, and without the frankly terrifying idea of using Regexes to do it). Compounding matters is the fact that a huge portion of your unit tests simply evaporate once you realize that you simply can't have typos or type mismatches in an old dinosaur language like C#. So it's entirely possible that that big suite of testcases it took so long to refactor would not be necessary at all (replaced instead by the occasional int x;). Once somebody gets the tools together so I can be as productive in Rails as I am in ASP.NET, I'm jumping ship. Until then, I'm hanging tight.