tags:

views:

473

answers:

6

I've been looking at Groovy on Grails and noticed a line at the bottom that says:

Grails aims to bring the "coding by convention" paradigm to Groovy.

What exactly is coding by convention?

A: 

Lots of conventions here:

  1. How to name HTML elements so they're easily accessible as parameters from the HTTP request;
  2. How to relate object attributes to table and column names in the database;
  3. How to arrange a project into directories/packages;

It's what you do when you find yourself solving a common problem in a particular style. You notice similarities and codify them into some automation scheme.

duffymo
A: 

It means if you stick to certain coding conventions as defined by whatever convention-based framework you are using, you get a lot of functionality for free. In other words, if you structure your application in accordance to what the framework expects, a lot of work can be saved.

It would be a good idea to look up the advantages and disadvantages of coding by convention.

karim79
+5  A: 

Convention over Configuration (aka Coding by convention) is a software design paradigm which seeks to decrease the number of decisions that developers need to make, gaining simplicity, but not necessarily losing flexibility.

The phrase essentially means a developer only needs to specify unconventional aspects of the application. For example, if there's a class Sale in the model, the corresponding table in the database is called sales by default. It is only if one deviates from this convention, such as calling the table "products_sold", that one needs to write code regarding these names.

When the convention implemented by the tool you are using matches your desired behavior, you enjoy the benefits without having to write configuration files. When your desired behavior deviates from the implemented convention, then you configure your desired behavior.

From Wikipedia

John
+2  A: 

In the context of Grails, "coding by convention" means that a lot of (tedious and repetitive) explicit code and/or configuration is replaced by simple naming and directory structure conventions. For example:

  • Any class whose name ends with Controller in the grails-app/controllers directory is automatically a Spring controller and closures defined in it will be bound to URLs - you don't have to configure this in an XML file as you would have to when using pure Spring.
  • The same goes for taglibs (grails-app/taglib directory) - no more tedious TLD files!
  • Domain classes in grails-app/domain probably have the most "convention magic", being automatically mapped to an automatically generated DB schema - with DB table and column names being by convention identical to the domain property names.
Michael Borgwardt
+3  A: 

Coding by convention vs coding by configuration: The idea that you have certain placing or naming conventions for stuff so you don't have to explicitly tell the program where stuff is or what it is called.
For example, in ASP.Net MVC there is a convention for where the views are stored and what they are called. This means that when your code instructs the server to return a view, the runtime will look for a view with a certain naming structure in certain folders. See page 20 in this pdf for more clarity.

Another example would be naming conventions for methods. For example, in an event-driven language you could have a choice to explicitly declare which method handles which events or you can rely on a naming convention - like ..._OnOpen or ...OnClick and then rely on the runtime to figure out the correct method to call for a given event.

Frans
+2  A: 

See Convention over Configuration. It's the concept of designing a tool or framework to have the most common configuration options as the defaults, so for the vast majority of users no configuration is required.

James Gregory