the blog for developers

Another Rails and dynamic language fallacy concerning missing methods

Russell writes in the post The Dynamic Language Advantage: A Concrete Example:

“All you have to do is make the call to the non-existent method that contains your column names and Rails will dynamically generate the method for you.”

Though he got quite some flak for his opinion.

@cards = Card.find_all_by_cardType_and_expirationData(cardTypeId, expirationDate)

Which looks magic to most people and most impressive. But in the end it’s not more safe or magic than

Card.find("all_by_cardType_and_expirationData", cardTypeId, expirationDate);

This code can easily be written in any static language, becasuse the method missing property is no more safe or expressive than a String. The idea that parsing a method name from method missing is different than parsing a String in this case is a fallacy. I wonder why not more people use Strings like this to create finders? Perhaps because it’s not a good idea, as some comments in the mentioned post claim?

Thanks for listening.

About the author

stephan Stephan Schmidt has been working with internet technologies for the last 20 years. He was head of development, consultant and CTO and is a speaker, author and blog writer. He specializes in organizing and optimizing software development helping companies by increasing productivity with lean software development and agile methodologies. Want to know more? All views are only his own. You can find him on Google +

You can leave a Reply here. Of course, you should follow me on twitter here.

You can share this post!
Do you want to tell others about this article? Use the social bookmark icons to submit this artice to the service of your choice. Thanks.

Leave a reply.

Comments

I’d like to point out that the Parancoe framework (http://www.parancoe.org, go to http://www.parancoe.org/articles/2007/08/28/how-to-add-finder-methods-to-parancoe-daos/ for a specific example) allows you to define an interface with a statically declared method findAllByCardTypeAndExpirationData() and it gets implemented by dynamic generation of code. To me it’s the best approach if you like expressive method names, compiler safety and would like to avoid boilerplate code.

stephan

@Fabrizio: Yes, this the way I think is a good idea. Especially when the system creates a prepared statement.

In fact Parancoe is doing better than a prepared statement: it’s using pre-compiled (at application bootstrap/deploy time) named queries.

stephan

@Lucio: Is it possible to just use Parancoe daos (for JPA) without anything else?

Yes, it’s possible. It’s in the parancoe-core module. At present there is a limitation on the JPA implementation to use: it must be Hibernate. In parancoe-core the most part is the persistence DAO feature. Another interesting part is the support to unit-testing the persistence-related code.

I know a person that is using parancoe-core in a Swing application.

I’m working our next release of Parancoe (2.0), an I’m evaluating to isolate the DAO feature in a specific module with minimal dependencies.

Leave a Reply

What people wrote somewhere else:

Additional comments powered by BackType

Guide to CodeMonkeyism

Over the last 4 years I wrote many articles on this blog. To make it easier for you to find the relevant ones, I've organized them into topics.

Top 10

6 reasons why my VC funded startup did fail

Go Ahead: Next Generation Java Programming Style

Java Interview questions: Write a String Reverser

The dark side of NoSQL

7 Bad Signs not to Work for a Software Company or Startup

Is Java dead?

Scala vs. Clojure

Never, never, never use String in Java

No future for functional programming in 2008 – Scala, F# and Nu

Clojure vs Scala, Part 2

Java Developer

Is Java Dead?

Go Ahead: Next Generation Java Programming Style

Be careful with magical code

All variables in Java must be final

Never, never, never use String in Java

Bending Java: More readable code with methods that do nothing?

NoSQL Guy

NoSQL: The Dawn of Polyglot Persistence

The dark side of NoSQL

Essential storage tradeoff: Simple Reads vs. Simple Writes

Sharding destroys the goals of your relational database

The unholy legacy of databases

Startup/CTO

Development Dream Teams

6 reasons why my VC funded startup did fail

American vs. European style of Software Development

12 Things to Reduce Your Lead Time and Time to Market

The high cost of overhead when working in parallel

Essential storage tradeoff: Simple Reads vs. Simple Writes

Job Seeker

Another Good (Java) Interview Question

7 Bad Signs not to Work for a Software Company or Startup

Java Interview questions: Write a String Reverser (and use Recursion!)

Java Interview questions: Multiple Inheritance

As a Manager: What I value in developers

Top 10 Tips (+1) to Get a Pay Raise

Agilist

What Developers Need to Know About Agile

5 Practices Better to Change in Your Scrum Implementation

Scrum is not about engineering practices

ScrumMaster and ZenMaster: The joke of certification

What is Trans-Scrum?