什么是“按惯例编码”? [英] What is "coding by convention"?

查看:121
本文介绍了什么是“按惯例编码”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在关注Grails上的Groovy,并注意到底部有一行代码表示:


Grails旨在将按照惯例编码范式到Groovy。

传统编码究竟是什么?



这个短语实质上意味着开发者只需要指定应用程序的非常规方面。例如,如果模型中有Sale类,则数据库中的相应表格默认称为销售。只有当人们偏离这个惯例时,例如调用表products_sold,才需要编写关于这些名称的代码。



您正在使用的工具与您想要的行为相匹配,您无需编写配置文件即可享受优势。如果您希望的行为偏离实施的惯例,那么您可以配置所需的行为。

From Convention on configuration维基百科文章


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?

解决方案

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 "Convention over configuration" article on Wikipedia.

这篇关于什么是“按惯例编码”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆