Ask HN: What are the stupid things Rails developers do?
I liked the post "How to seem good at everything: Stop doing stupid shit" [1,2] and am wondering how to apply it to take my dev skills to the next level... What is the "stupid shit" that developers do that if we were to only stop doing would make us better developers?
I'm primarily working in Rails nowadays if that makes a difference in the way you answer the question.
[1] http://jinfiesto.posterous.com/how-to-seem-good-at-everything-stop-doing-stu
[2] http://news.ycombinator.com/item?id=2848041
29 comments
[ 3.1 ms ] story [ 67.0 ms ] threadRelated to humility: Never forget the fundamentals. I'm talking about things like basic sorting, searching, and big O estimating. Know what your data structures and algorithms cost in terms of memory and performance. I'm continually surprised by how many senior developers unknowingly drift away from the fundamentals.
Definitely comes into play in good design. One of the biggest things I've found is that to constantly look at new ways to approach a problem. Don't just assume you've learned it all.
One thing I'd like to learn how to do better is to refactor better.
If you have one fat controller class, that's the worst of all worlds. If you have a plethora of thin controller classes which collectively handle most of the business logic, you still have a "fat controller" in aggregate, even if these controllers have limited, well-defined behavior and call out to each other. What you really want is a thin controller in aggregate, combined with a large but well-separated ecosystem of model classes (which, in aggregate, is going to outweigh the controllers).
I don't follow this at all.
Anyways, what I was getting at was, as jarrettcoggin posted, Single Responsibility Principle. Couldn't think of the name before.
A problem I see in Rails code is that some people think you have only three places to put code: M, V, or C. Most people know enough to avoid stuffing code in the view, so they stuff code into either a controller or a model. Not quite "god classes", but demi-god classes at least.
http://yehudakatz.com/2009/11/12/better-ruby-idioms/
And another thing that amazes me is the frequent lack of indices. You want slow searches for specific values? Okay, you got it!
I know that it's tempting to avoid SQL and leave it 100% to the code generator—but the few edge cases you have with poor(er) performance could really get a boost with even minor understanding of SQL.
You can create a Rails app without an ORM, but then you must do all your queries and migrations in your own code. This is one of the reasons people stick with the suboptimal SQL: it's faster to generate and lets you iterate more quickly.
- Long finder methods instead of using named scopes.
- Not using restful routes.
- Too much code in their views.
- After saves that should be validations or other confusing AR lifecycle mistakes/abuses.
fwiw, you can add indexes and foreign key constraints using migrations. I don't see this done much, but I think it's good practice (adding indexes and fks)