News for hackers. Stuff that matters.
Re:How A Pull Request Rocked My World by lincolnq on Saturday February 02, 2013 @03:32PM (#5157226)
I don't love this refactor. I especially don't like how it generates names from other names -- e.g., given 'switch'/'submit', appends '_row', and then converts it to CamelCase so you get 'SwitchRow'/'SubmitRow', then instantiates the class named that.

Here's why: When I am maintaining somebody else's code, even if I guess that this is going on, I rarely trust these kinds of name-generation tricks. When I need to change some code, I'm going to grep the codebase for 'SwitchRow' and add a new line in whatever conditional to instantiate my new class. When grep can't find any instances of SwitchRow's constructor being called, I become suspicious and it costs me more time, because I am making sure I properly understand what is actually going on.

Re:How A Pull Request Rocked My World by rosser on Saturday February 02, 2013 @04:32PM (#5157414)
...I rarely trust these kinds of name-generation tricks.

So you're probably not a big fan of Rails, then?

Re:How A Pull Request Rocked My World by potatolicious on Saturday February 02, 2013 @07:22PM (#5157954)
I'm actually not a huge fan of implicit name-generation tricks, but I'm also not entirely opposed to them.

The trick here I think is consistency - is name-generated type dispatch the standard across the entirety of the codebase? If it is, go wild. If it's not then I'd be much more wary of it.

Consistency and building correct expectations for future maintainers is pretty important. Doing a smart trick in one place but failing to do it in other places where it makes sense IMO tends to create a bigger mess than doing it the dumb-but-safe way everywhere.

Re:How A Pull Request Rocked My World by SoftwareMaven on Saturday February 02, 2013 @08:08PM (#5158071)
I so agree with you. There are few programming mistakes that consistency in use does ameliorate. On the other hand, no matter how "good" the code, if it's inconsistent, it's bad.
Re:How A Pull Request Rocked My World by Arelius on Sunday February 03, 2013 @11:43AM (#5160108)
I disagree. Consistency is only valuable so long as it helps clarity and understanding. While that is most often the case, there are exceptions.
Re:How A Pull Request Rocked My World by justincormack on Sunday February 03, 2013 @04:57PM (#5161358)
Agree. Names should not matter. You are going to have to document name construction. If your library users use IDEs you are going to have to get them to understand names.
Re:How A Pull Request Rocked My World by hnewser1 on Saturday February 02, 2013 @04:52PM (#5157497)
and what does `trust` mean? You don't trust that correct object won't be given back to you?
Re:How A Pull Request Rocked My World by andreasvc on Sunday February 03, 2013 @06:54AM (#5159398)
I suppose more like trust whether the resulting code will always be correct.
Re:How A Pull Request Rocked My World by diminish on Saturday February 02, 2013 @07:00PM (#5157891)
what about using a multiline YAML text to be loaded with automatic generation of objects from class name strings? (reminder!)
Re:How A Pull Request Rocked My World by scrid on Saturday February 02, 2013 @04:56PM (#5157521)
This is especially true for those of us who do application support.

When we are investigating application stack traces from production for a large application, it is awful when you discover that the developers decided to be clever with dynamic function names, making a large code base very difficult to support based on available logs.

If you think you're being clever you're probably just being a dick.

Re:How A Pull Request Rocked My World by FuzzyDunlop on Saturday February 02, 2013 @05:06PM (#5157564)
Given this is ruby code, I think it's acceptable, and well-structured enough to be understandable.

While the implementation itself might be a bit 'eugh' because of the meta-programming involved, there was enough thought put into code organisation to allow you to grep `RowType` to find the module that namespaces all these dynamically instantiated classes.

Hell, if the code in the tree was arranged correctly, then `tree | grep row_type` would give you the folder where they all lived.

Re:How A Pull Request Rocked My World by tantalor on Saturday February 02, 2013 @04:35PM (#5157428)
Agreed. This "refactor" is actually a hack. It shouldn't pass code review.