Proposing changes to moodle coding style

Proposing changes to moodle coding style

by Dan Poltawski -
Number of replies: 12

If you are working on features which you are hoping to get integrated into Moodle core then you should be aware of the Moodle coding style guidelines: http://docs.moodle.org/dev/Coding_style

Every once in a while a discussion comes up about coding style where its not clear or there are requests for clarification or changes to the style. At the moment these things tend to linger on the wiki talk page and its difficult for people to follow the discussion or make a decision.

In order to improve the situation we have created a Coding style component in the tracker under the MDLSITE project. If you wish to request a change or clarification about style, please file a bug there. We hope that that this can be a place where discussions can be had and interested parties can keep informed.

I should point out that any coding style is never going to please all developers and so whilst we will strive to please everyone it is likely that the final decision will usually rest with the integration team and/or lead developer. We will also try our best to avoid bike shed painting. wink

Of course we'd be happy to hear your views on this.

thanks!

Dan & the rest of the integration team

Average of ratings: Useful (7)
In reply to Dan Poltawski

Re: Proposing changes to moodle coding style

by sam marshall -
Picture of Core developers Picture of Peer reviewers Picture of Plugin developers

Great. smile I added my two recent ones from the talk page.

In reply to sam marshall

Re: Proposing changes to moodle coding style

by Pia Liersch -

i have 2 proposal for the coding style guide. The link to the tracker in the first posting doesnt work.

  • $array = ["foo" => "bar"]; // min. php 5.4, a new array without the array word and square brackets
  • require 'config.php'; // without the bracket
In reply to Pia Liersch

Re: Proposing changes to moodle coding style

by Tomasz Muras -
Picture of Core developers Picture of Plugin developers Picture of Plugins guardians Picture of Translators

I would like to see [ ] syntax for arrays - but I'm afraid it will be hard to find volunteer to rewrite whole Moodle code to get that done...

In reply to Tomasz Muras

Re: Proposing changes to moodle coding style

by Valery Fremaux -
Picture of Plugin developers

Hi guys,

would you give some rationale to the proposals ? It could help us to support incomming ideas. If change is just for change... or for satisfying local guide styles wink , might be less pregnant.

Now there can be some : code readability, concision, better future support, (sense of the history), or ?

Cheer !


In reply to Valery Fremaux

Re: Proposing changes to moodle coding style

by Pia Liersch -

Hi,

that is a new feature on php 5.4 and the syntax is likely other programming languages ex. JavaScript (var cars = ["Saab", "Volvo", "BMW"];)

The array style is unusual and maybe not preferred at the moment.


The require/include Keyword without the bracket is PSR-0 (http://www.php-fig.org/psr/psr-0/) and that is a statement not a function.

Example Line from zend_framework (include $zf2Path . '/Zend/Loader/AutoloaderFactory.php';)

I hope this style establishment will be used everyone in the future.


Thats all recommends by me, for a perfect code style on moodle.
Sry for my english grammatic (my preferred language is german *g*)

In reply to Pia Liersch

Re: Proposing changes to moodle coding style

by Michael Aherne -
Picture of Core developers Picture of Peer reviewers Picture of Plugin developers

I don't think the coding style guidelines prevent the use of the new array literal construct, so there should be no change needed there.

In reply to Michael Aherne

Re: Proposing changes to moodle coding style

by Pia Liersch -
I have already written this and need no change at the moment. Sometime for the future maybe interesting.
But what is with the other style?
In reply to Dan Poltawski

Re: Proposing changes to moodle coding style

by Guy Thomas -
Picture of Core developers Picture of Plugin developers
This page is way out of date:


https://docs.moodle.org/dev/Javascript/Coding_Style


It's recommending the usage of YUI - it should be recommending the use of AMD modules.

In reply to Guy Thomas

Re: Proposing changes to moodle coding style

by Marcus Green -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
That documentation is a Wiki, and it would be excellent if you could update it. I always think that JQuery is replacing YUI rather than AMD, but you might be able to put me right on that.
Average of ratings: Useful (2)
In reply to Marcus Green

Re: Proposing changes to moodle coding style

by Michael Aherne -
Picture of Core developers Picture of Peer reviewers Picture of Plugin developers

For what it's worth I tend to think of jQuery / AMD together as a replacement for YUI as it had its own module system as well as the coding library that jQuery replaces.

In reply to Marcus Green

Re: Proposing changes to moodle coding style

by Dan Poltawski -

That page is not editable (please see the start of this thread for how to suggest changes to it smile)

In reply to Guy Thomas

Re: Proposing changes to moodle coding style

by Dan Poltawski -

It's recommending the usage of YUI - it should be recommending the use of AMD modules.

Can you be specific about where? There are YUI examples, but I don't see reccomendation about modules?

Note we do still have open MDLSITE-4690 'yuidoc and jsdoc, that is the question'