Dashboard > OFBiz Project Administration Workspace > Apache OFBiz Contribution and Development > Coding Conventions
  OFBiz Project Administration Workspace Log In | Sign Up   View a printable version of the current page.  
  Coding Conventions
Added by Jacopo Cappellato, last edited by Jacques Le Roux on Dec 16, 2007  (view change)
Labels: 
(None)

General Formatting Conventions

The Open For Business projects follows the Sun coding standards for Java source code.
For information regarding this standard please visit http://java.sun.com/docs/codeconv/html/CodeConvTOC.doc.html

In accordance with this standard we use 4 space indention rather than tabs, and set the tab size to 8 spaces to make code with tabs easier to pick out. Make sure no code contains tab characters.
For XML/HTML/FTL files we follow the standard XML/HTML/FTL format (TODO: add link to a reference here); as well as use 4 space indention rather than tabs (note some HTML/FTL files may use 2 spaces instead of 4, but they should all really use 4 spaces).

HTML code should be XHTML compliant.

BSH files should follow the same convention as Java files.

Entity Definitions

Entity Names

Entities are named in accordance with the Java naming conventions for classes (e.g. ExampleEntity).
The physical database names are generated by the system by applying the Java naming convention of constants to the entity names (e.g. ExampleEntity => EXAMPLE_ENTITY).
Important: database table names should never be longer than 30 characters, so you have to keep this in mind when you define a new entity name.
For example: the entity name "AnExampleOfALongEntityName" (that is is 26 characters long) is transformed into the database table name AN_EXAMPLE_OF_A_LONG_ENTITY_NAME, that is 32 characters long and exceeds the maximum length of 30 characters and so it is not a good choice.

Entity Field Names

Entity fields are named in accordance with the Java naming conventions for fields (e.g. exampleField). They have the same length constraint than above : 30 characters max (including "_" separators)
TODO: pk/fk names (including maximum length)

Foreign Keys names have a length constraint of 18 characters (including "_" separators). It's better to set them by hand, to avoid indesirable effects. These constraints do not come from OFBiz but from some DB. To be able to use any DB those constraints should be respected to allow DB portability.
 

TODO: view-entity names and conventions 

Service Definitions

Best Practices

Apache OFBiz Best Practices Guide

License Headers

Each and every source file should contain the ASL2.0 header:

http://svn.ofbiz.org/svn/ofbiz/trunk/APACHE2_HEADER

Adding author information to source files (.e.g. using the @author tag) is a discouraged practice: clearer information about the contributors of a file should be derived from the commit logs.

Naming Conventions for Artifacts and controller entries

TODO: controller's request and view naming conventions

TODO: conventions for screen names (top-level screens, included screens, decorators)

TODO: conventions for form names 

TODO: conventions for menu names

TODO: conventions for artifacts names such as ftl templates and bsh scripts

We don't want tab characters in text files in SVN, because different editors and tools interpret tabs differently. All indentation should be done purely with spaces.

To change tabs to spaces in Eclipse, change these preferences in Window -> Preferences ->

  1. Java -> Code Style -> Code Formatter -> Show... -> Java Conventions [built-in] -> Indentation, select Tab policy as "space only". Enter a new name for this profile and click "OK".
  2. Java -> Editor -> Typing, and check "Insert spaces for tab".
  3. Ant -> Editor -> Formatter, and uncheck "Use tab character instead of spaces".
  4. If you installed Colorer, Colorer Library Editor -> Uses spaces instead of tabs.
  5. If you installed XML Buddy, XMLBuddy -> Formatting -> Uses spaces instead of tabs.
  6. Unfortunaltely neither of the 2 main FreeMarker pluggin have similar functionnality yet. But there is a solution :
  7. Install AnyEdit plugin (http://andrei.gmxhome.de/eclipse/) and set its parameters in General -> Editors -> AnyEdit Tools

Dont' forget to use Ctrl+I to be sure of correct indentations.

Posted by Jacques Le Roux at Nov 14, 2006 00:29 | Permalink

Beware when using AnyEdit plugin. If you want to strip trailing blanks, please use this functionnality with care. We don't  recommendits use but eventually in 2 cases : when creating new files or when applying on a patch. Even in the last case this may show up changes in patches that are formatting only and that make it harder to see functionality changes... (So perhaps it's even better to never use this feature : you will not have to worry about it)

Posted by Jacques Le Roux at Nov 14, 2006 15:01 | Permalink

hi there,

  anyedit is at http://andrei.gmxhome.de/anyedit/ and not at the url given above.

thanks and regards,

anjan bacchu

Posted by anjan bacchu at Nov 16, 2006 02:23 | Permalink

Anjan,

Yes sure, the above link is to install from within Eclipse using "Find install plugin" option in Help Menu.

Thanks 

Posted by Jacques Le Roux at Nov 17, 2006 01:42 | Permalink
Site powered by a free Open Source Project / Non-profit License (more) of Confluence - the Enterprise wiki.
Learn more or evaluate Confluence for your organisation.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.2.10 Build:#528 Nov 29, 2006) - Bug/feature request - Contact Administrators

Hosting and maintenance for this site brought to you by:

With both OFBiz project creators on our executive team, and by leading teams comprised of many of the most talented OFBiz developers anywhere, HotWax Media is uniquely positioned to help our clients succeed with Open For Business. From large multinational public companies to a variety of smaller businesses, we expertly support our clients as they harness the world-class systems in OFBiz.

Contegix keeps your servers running all day, every day. Intelligent Routing, secure power supplies, and a 100% uptime guarantee give you peace of mind for your complete managed hosting solution. More than hosting. More than application support. Our engineers support your business.