Dear Rubyists,
I just lost a contract because of my code in a Rails project.
The specific code in question is related to a "posting a comment" feature. Here are the details:
In this project, "posting a comment" does not simply entail inserting a row into the database. It involves a procedure to yes, insert a row, but also detect its language, check for spam, send emails, and "share" it to Twitter and Facebook. I believe this algorithm should be encapsulated. I do not believe it belongs in a controller or a model. I do not believe Active Record callbacks should be used.
The "senior developer", whom is the stake holder's right hand man, said this:
All that's being accomplished is moving a few statements from the controller to the a new class and adding even more code to support the new construct. We don't have the problems that this would solve like comments being posted from multiple controllers.
What do you guys think? Am I doing it wrong?
Please leave a comment, good or bad. My motivation to continue programming is at an all time low.
Thank you.
We are not in 8th grade here.
@avdi speak for yourself! no actually I agree.
@justinko I agree with the peeps telling you that the contract-killing problem here was not design philosophy but mismanagement, but I would definitely say take anything beyond that with a grain of salt. there's people saying it was "obviously your fault" or "obviously the other person's fault" but there's absolutely no solid evidence to back up either position. people project and assume in these conversations, because people-skills problems and project-mgmt problems have a huge subjective component. you should filter their remarks accordingly.
long story short, you probably need to get better at choosing projects, and/or handling people issues within those projects. could be that the company was fucked from jump and you should have never gotten on board to begin with. could be that you mishandled it and made a mess where there didn't need to be one. only you can decide for sure.
I'd also really urge you to take DHH's aggressive attitude with a grain of salt. the guy is not always nice. everybody knows it, including him. if it helps, keep in mind that he also created a framework which transformed a lot of careers for the better, so his personal abrasiveness may be balanced out by this non-specific, impersonal generosity.
re the code, DHH's disregard for OOP is not something I endorse, and I totally disagree with his testing philosophy, but I think his version is much tidier than yours. (of course I'd also echo his caveat that things change if you re-use that logic elsewhere.)
the most important thing in my opinion is how clear the code is to read, and how easily you can test it. DHH's solution is short and concise. your code is too repetitive and has too many lines. Ruby code is usually bad when it has that many lines in it, and when they're structured that way. to be fair, however, DHH hasn't supplied the tests which would accompany his solution, and in my personal opinion, Rails controller testing is pretty dooky.
if we had a version of your code which could compete with DHH's in terms of its readability, I think this would be a very interesting debate, but right now I think arguing philosophy is pointless. you need to write succinct code before subtle distinctions between philosophies matter.