26 points · by geekfactor · 15y ago · 28 comments
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
Related 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.
- 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.
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.
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.
Posts.where("posted_on BETWEEN ? AND ?", Date.current - 2.months, Date.current)
But it still isn't the same.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.