No Reservations about Keywords in Ruby on Rails

Posted by Daniel Butler Wed, 31 Jan 2007 21:05:00 GMT

Thesaurus

Have you ever had the urge to name a data model in your Ruby on Rails application something obvious, like Action, Table, File, Columns, or Database? Well, don't. Choosing a name like that might work for you in some cases, but it might fail miserably for someone else using a different database engine (i.e., MySQL verses PostgreSQL verses Oracle).

Think you can remember all the problematic names? Think again. There are at least 974 known keywords which can give you problems. I started with the ReservedWords pages on the Ruby on Rails Wiki, and pulled in and merged all the SQL-92, SQL-99, SQL-2003, PostgreSQL, MySQL, SQL Server and ODBC reserved keywords, and put them in one place, mainly for my own future reference.

So what if your data models are about Databases, Tables, Columns, and Files? Simply think of a Good Prefix™, and name all your models accordingly: DaDatabase, DaTable, DaColumn, and DaFile, with resulting table named da_databases, da_tables, da_columns, and da_files. It's easy, painless, and helps you group similarly-purposed tables and models accordingly, and you don't have to wrack your brains thinking of synonyms for obvious model names like "Action". I use Geo- for location-oriented data, Sys- for System-oriented tables, Log- for transactions, and App- for application-oriented tables.

Read on to see the full list ...

Read more...

Posted in  | 7 comments