Note:

If you want to create a new page for developers, you should create it on the Moodle Developer Resource site.

Talk:Coding style: Difference between revisions

From MoodleDocs
No edit summary
m ((keeping talk page clean))
 
(93 intermediate revisions by 16 users not shown)
Line 1: Line 1:
== PHP5 constructor ==
<p class="note">Note: Please avoid using this talk page to propose changes to the coding style. Instead [https://tracker.moodle.org/secure/CreateIssueDetails!init.jspa?pid=10020&issuetype=1&components=12132&summary=coding%20style%20change file a coding style bug]. See the forum discussion [http://moodle.org/mod/forum/discuss.php?d=202406 Using Moodle: Proposing changes to moodle coding style] for more details.</p>
 
Should we enforce the PHP5 constructor __construct() instead of $classname() [[User:Nicolas Connault|Nicolas Connault]] 19:55, 19 May 2009 (UTC)
:+1. I think we agreed about that some time ago (when igniting some 2.0 developments) --[[User:Eloy Lafuente (stronk7)|Eloy Lafuente (stronk7)]] 00:03, 20 May 2009 (UTC)
 
== Inline comments ==
 
I have been using since ages ago "///" with outer alignment (I think that it was caused by some agreement long time ago, not my decision), for example:
 
<code php>
function check_moodle_environment(..., ..., ..., ...) {
 
    $status = true;
 
/// This are cached per request
    static $result = true;
    static $env_results;
    static $cache_exists = false;
 
/// if we have results cached, use them
    if ($cache_exists) {
        $environment_results = $env_results;
/// No cache exists, calculate everything
    } else {
    /// Get the more recent version before the requested
        if (!$version = get_latest_version_available($version, $env_select)) {
            $status = false;
        }
        ....
        ....
</code>
Is that allowed, or only the "//" with inner alignment as commented at [[Coding style#Inline comments|inline comments]] --[[User:Eloy Lafuente (stronk7)|Eloy Lafuente (stronk7)]] 00:03, 20 May 2009 (UTC)
 
==Trailing spaces==
 
"Lines should not contain trailing spaces. In order to facilitate this convention, most editors can be configured to strip trailing spaces, such as upon a save operation. However, if you are editing an existing Moodle file and are planning to submit your changes to CVS, please switch off that feature so that whitespace changes do not pollute CVS history (other developers will have trouble viewing what you've done if every other line has been edited for whitespace)."
Wouldn't the CVS history only get 'polluted' when someone fetched a file that DIDN'T follow this principle and returned it following the principle? Isn't that the price that has to be paid to clean things up? Otherwise this is pretty scary for someone who feels: "Great I can turn on my editor to autostrip those when saving. BUT I have to remember to turn that off if submitting it! (Or become a 'polluter'!)"
And what happens if I have already saved it locally while working on (and striped those trailing spaces) and later try to commit it. Maybe my ignorance about CVS is making me pose a "silly" question. [[User:Jeff Forssell|Jeff Forssell]] 07:17, 27 May 2009 (UTC)
 
: Jeff, the point with coding guidelines is that all new code must follow all the guidelines. With old bad code, mostly it is better to make the smallest change necessary when, for example, you fix a bug. That makes it clearest what the purpose of your change was. However, any line you do change while fixing the bug, you can then improve the coding style on that line.  
 
: Really good editors actually have an option "Strip trailing whitespace when saving a file - but only from lines that I have edited", which is what you really want.
 
: The real way to avoid being a CVS polluter is to follow the best practice and always do a cvs diff and review all your changes (and if necessary amend them) before you do a CVS commit.--[[User:Tim Hunt|Tim Hunt]] 03:52, 1 June 2009 (UTC)

Latest revision as of 14:49, 30 September 2016

Note: Please avoid using this talk page to propose changes to the coding style. Instead file a coding style bug. See the forum discussion Using Moodle: Proposing changes to moodle coding style for more details.