3 ms·
As a Rails newbie (~3 months), I found this list very useful. I'm very mindful of the difference between doing something vs. doing that thing correctly, and eve
by enraged_camel 12y ago
As a Rails newbie (~3 months), I found this list very useful. I'm very mindful of the difference between doing something vs. doing that thing correctly, and even when I write a piece of code that works, I often stop and ask myself, "OK, but is this the best way to do it?" I try to avoid dirty hacks, and if I'm on a time crunch where I don't have time to figure out the right way, I postpone the feature to the next release rather than putting in a temporary dirty implementation.
One thing I've been having trouble with as my project gets more complex is when to refactor. I guess I'm not yet at the stage where I can accurately judge the benefits of refactoring a code vs. the cost. To use an analogy, am I just re-arranging the furniture to change the look-and-feel of the room (superficial), or am I actually making it easier for the guests to make themselves comfortable (real benefit)? I've read books like Pragmatic Programming [1] that advise refactoring whenever possible to avoid technical debt build-up. But it seems to be that there are times when working on a new feature would result in more value-add for the project as a whole.
Another thing is motivating myself to write test cases. The Hartl tutorial taught TDD, but when I started my project from scratch I quickly realized that TDD would slow down my progress significantly, and I didn't yet have enough experience to assess how a feature should work to be able to write tests for it. This did bite me in the ass just last night though, as I spent three hours troubleshooting a bug that a test case would have caught. Oh well, live and learn, right? :)
- WestCoastJustin 12y ago> Rails newbie (~3 months) Don't know if you have seen http://railscasts.com http://railscasts.com yet. But it really helped me.
- enraged_camel 12y agoYeah, I love Railscasts. I'm sad Ryan stopped doing them.
- danneu 12y ago> One thing I've been having trouble with as my project gets more complex is when to refactor. I usually wait until (A) something is painful and (B) I have enough instances of that pain to see the pattern that my refactor/abstraction will address/consolidate. Else I'm just rearranging furniture or making it harder to rearrange in the future because my assumptions were wrong -- I've built a fridge and stove in a room that never became the kitchen when I could've just fetched a bucket of ice and a bunsen burner as I needed them. But now all the doors are too small to migrate my appliances because I thought this was going to be a hobbit house. Turns out the guests are only half hobbit. It's easier to refactor naive, repetitive, even dirty code than it is to refactor failed and premature refactors/abstractions. Seeking correctness is cool, but often I can't see far enough ahead to know what "correct" actually entails. Writing what feels like a simple/obvious hack now can be better down the road than trying to prematurely engineer something that seems correct.
- BrianVanLoo 12y agoGlad you found this helpful. Regarding the TDD stuff, I went through the same difficulties as you described when I was starting out too. I even had that epiphany stage where I didn't write tests for something and ended up regretting it later. I have found that over time I've gotten much more efficient writing the tests and don't necessarily write them for everything, only the things that experience now tells me are important. Also, I give myself permission to "spike out" those features I'm still trying to figure out how they should work and not write any tests for them as I figure them out. After I've got it figured out I'll do a "git stash" (usually never returned to) and start over writing the feature I now understand using TDD.