Coding standards

We encourage users to post events happening in the community to the community events group on https://www.drupal.org.
This group should probably have more organizers. See documentation on this recommendation.

This group is dedicated to optimizing performance of Drupal with coding standards. As such it deals with particular coding guidelines, sharing knowledge and benchmarks that might be integrated into Coder module.

If you are seeking help on high performance/scalability Drupal sites and how to gain a better performance for them, you might have a look at the High Performance group.

Guidelines
  • Each coding standard gets its own Wiki page including
    • a one line synopsis in the format XY is faster than YX
    • a proper description of how it improves performance
    • benchmarks from different platforms and PHP versions
    • web links to references and additional resources
  • You may
    • suggest new optimizations by posting a story
    • comment on new optimization proposals with insightful input
    • perform benchmarks on your platform(s) for existing and new optimizations
webchick's picture

Discussion on PHPDoc summary best practices

http://drupal.org/node/487802

Since the issue is already going strong, probably discuss over there, rather than here. Just letting you know about the discussion. :)

Read more
danielb's picture

Beautifier

Just a heads up that I've been working on something of interest to this group. I am making a 'code beautifier' module privately for use by my company - we have some peculiar standards like '3 spaces' for a tab - and I know I will be inconsistent due to me switching between Drupal and other standards.

The idea is that it is a web form that you fill in and it gives you the code you need, all formatted and indented nicely.

Read more
zzolo's picture

Is there a File Name Standard or Convention?

Is there a File Name Standard or Convention?

I have set of modules that have lots of includes. Is there any written documentation on how these things should be organized. For instance with JS file I like to put in a JS folder in the module, but even then I am not sure how to name the files. I know if there is one its "modulename.js", but what if there are many?

I guess there seems to be 3 main ways of doing this:

  • Dots: modulename.function.js
  • Underscores: modulename_function.js
  • Dashes: modulename-function.js
Read more
zzolo's picture

Standards for Namespaces (Sub-Modules and Functions)

The following two things are well known conventions but I was unable to find any documentation on d.o for them:

  1. Sub-Module names.
    These are modules within modules (which are really projects on d.o). The convention, as I understand it is: {core_module_name}_{sub_module}. This basically ensures that no sub-modules will use the same namespace as contributed modules or sub-modules.
  2. Function Names.
    We know that all hooks have to be prefixed with the module name, but it is only common practice to make any other public or private function prefixed with module name (as well as the leading underscore (_) for "private" functions): {module_name}_{action}. Again, this basically handles name collisions with other contributed modules. This standard could also include how to form function names, for example as suggested by webchick: {module_name}_{verb}_{thing_being_verbed}

So, what I need from this great group is:

  1. Are these agreed upon standards?
  2. Where is the best place for this documentation?
    There is: Module Development, but even under that, there is no general module development guidelines (instead of specific version)
    And: Standards and Security
    Or: some other.
Read more
JamesAn's picture

Clarification on Doxygen formatting conventions

I posted some questions on API formatting conventions in http://drupal.org/node/422084.

webchick recommended I post them here for consideration. The discrepancies I listed are all present in the core API document in the various api.php files.

Let me know what the convention is/should be. Thanks!

Read more
sun's picture

Coding-standard for arithmetic/logical operators

Neither PEAR nor we define a clear coding-standard for the logical negation operator ("!" as in !$foo). However, to my knowledge, all of Drupal core + contrib is using:

<?php
if (!$foo) {
 
bar();
}
$c = !$a;
?>

In a code clean-up issue for Better Formats module, dragonwize proposed to use a space between the operator and following code, as we do with the concatenation operator and arithmetic operators:

<?php
if (! $foo) {
 
bar();
}
$c = ! $a;
?>
Read more
webchick's picture

Bikeshed Showdown: Figure out a "one true" DBTNG syntax

I've heard various rumblings in #drupal from people who don't like the current DBTNG code style for one reason or another. Since PDO doesn't have coding standards, we've had to make up our own. Complaints range from it being inconsistent (which wouldn't shock me, since it was decided sort of piecemeal between random conversations between Larry and myself) to not being easily formatted in tools like Coder Format and emacs (which is a big problem) to just being kind of "icky." Not having this nailed down is actively blocking issues such as porting core files to DBTNG.

So let's have it out! Here's the current syntax. Can you do better? And why?

<?php
    $result
= db_query("SELECT name FROM {test} WHERE age = :age", array(':age' => 25));
   
db_insert('test_task')
      ->
fields(array('pid', 'task', 'priority'))
      ->
values(array(
       
'pid' => $john,
       
'task' => 'eat',
       
'priority' => 3,
      ))
      ->
values(array(
       
'pid' => $john,
       
'task' => 'sleep',
       
'priority' => 4,
      ))
      ->
execute();
?>
Read more
Morbus Iff's picture

Coder Tough Love module released

Coder Tough Love is a companion to the existing Coder module by Doug Green, and its initial development has been sponsored by Trellon. Unlike Coder, which strives to follow the documented style guidelines of Drupal core, Coder Tough Love takes the tougher tactic of applying finely aged and obsessively anal wisdom from years of Drupal development and persnickety quality control.

Read more
webchick's picture

Bug: The title of this group <del>makes</del> made no sense. :)

As DamZ mentioned on IRC, this is roughly equivalent to the "Database API and square dance group." ;) There is already the HIgh Performance group for performance optimization.

How about "Coding standards and best practices" which includes coding standards as they relate to performance, security, upgrading, and all the other stuff Coder can do, as well as things it can't yet.

Thanks, this was fixed by sun. :)

Read more
webchick's picture

Casting variables

We should figure out and document a standard for this, then roll a patch to make it consistent.

Please see: http://drupal.org/node/331951

Read more

Generic module to find/add indexes

This is a wiki to plan a module to allow admins to add indexes to their site schema - this can be done easily in Drupal 6 and beyond using http://api.drupal.org/api/function/hook_schema_alter/6 - this discussion came from http://drupal.org/node/231453, where it was realized that CCK does not really have the usage context to be able to do this effectively, and also there are tables beyond CCK getting used in new ways by views and other modules that also need alternate indexes.

Read more
stella's picture

SQL coding standards and whitespace

I was just wondering if we have, or if we should have, any SQL coding standards regarding whitespace usage. For example, should we be using a space between column names in IN where clauses or have spaces on either side of comparison operators, etc.

Here are some examples to illustrate what I mean:

SELECT a,b,c FROM {table} WHERE a IN (1,2,3) AND b=4;
vs
SELECT a, b, c FROM {table} WHERE a IN (1, 2, 3) AND b = 4;

and

INSERT INTO {table} (a,b,c) VALUES(1,2,3);
vs
INSERT INTO {table} (a, b, c) VALUES (1, 2, 3);
Read more
Morbus Iff's picture

Create a README.txt template

There was a recent discussion about README.txt files in #drupal, and I figured it was time to reinvigorate the README.txt discussion. It appears, however, that one person (hello, you-know-who-you-are! ;)) has been promoting a README.txt that /is not like anything core has ever done/, as seen in the links to examples or as "an increasing list of modules" (which all happen to be maintained or contributed to by the same person, thus making the claim slightly disingenuous).

I submit that the README.txt file this person promotes is entirely wrong.

Read more
alanburke's picture

CSS Coding Standards

Hi all,
I'm at the documentation sprint.
I would like to propose some CSS coding standards, to accompany the PHP coding standards, along with the proposed Javascript standards.

I've added a handbook page at
http://drupal.org/node/302199
Discussion should be in this thread, and the handbook page updated as necessary.

Stella, the Coder module maintainer, has promised to add this to Coder module, once the dust settles on the dissussion.

Read more
Chris Charlton's picture

Post your proposed session for DrupalCampLA 2008

This is easy and quick, nothing fancy, no voting - just post your session idea (title) and your name/contact info and show up to present that day! We have sessions open from 10am-2pm each day (Saturday and Sunday) and each session should plan for 45 minutes each.

http://groups.drupal.org/node/12528 (edit wiki page)

If you can't see or edit the wiki page, be sure to join our group which may be required for editing the wiki page.

Read more
Shyamala's picture

Benchmarking in Drupal

Drupal and MySQl located in two different servers:

Configuration: Drupal server: Dual core processor, 4GB RAM
MySQL Server: Xeon Processor, 4GB RAM

MySQL Enterprise edition 5

In an exercise to Pre populate the database with 1 million records, record insertions in the tables are very slow since the requests are getting queued up in the database. Insertion is done using a special tool that records our drupal application and plays back the scripts in a loop to populate the database.

Please see the below data collected by the team.

Read more
stella's picture

"elseif" vs "else if"

In the latest code review done by chx and Morbus at http://www.drupaltoughlove.com, one of the items commented on was the usage of "else if" instead of "elseif". There's nothing in the Coding Standards doc that specifically states that one should be used over the other, however it is "implied" from the first example on indentation that "elseif" should be used. Can the Coding Standards doc be updated so that it states one way or the other? Personally I don't mind which, but I would prefer if there was consistency. Core itself has a mixture, but with a higher number of "elseif".

Read more

Doxygen @file directives

In the Doxygen formatting conventions doc, it says that files should be documented with the @file directive and gives the following example:

<?php
// $Id: theme.inc,v 1.202 2004/07/08 16:08:21 dries Exp $

/**
* @file
* The theme system, which controls the output of Drupal.
*
* The theme system allows for nearly all output of the Drupal system to be
* customized by user themes.
*/

Note the @file line in particular.

Read more

Javascript Coding Standards

More and more contrib modules are including JavaScript files, so I want to add the ability to review JavaScript files to the Coder module. However, step 1 is we need to agree on what coding standards we should be using for JavaScript.

Read more
echoditto_tom's picture

Performance Profiling System

Moved to official ideas list

Read more
Subscribe with RSS Syndicate content

Coding standards

Group organizers

Group categories

Status

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds:

Hot content this week