1
trabis
Coding Standards
  • 2009/3/7 20:48

  • trabis

  • Core Developer

  • Posts: 2269

  • Since: 2006/9/1 1


http://xoops.svn.sourceforge.net/viewvc/xoops/XOOPS_Coding_Standards.html?revision=2554&pathrev=2909

It is not clear to me in the "Functions example"(maybe because the example is a class method).

Someone can tell me what it is the correct way to declare a function?

function publisher_getConfig($key) {
    
$configs publisher_getModuleConfig();
    return 
$configs[$key];
}


or

function publisher_getConfig($key
{
    
$configs publisher_getModuleConfig();
    return 
$configs[$key];
}


Thanks.





2
Catzwolf
Re: Coding Standards
  • 2009/3/7 23:02

  • Catzwolf

  • Home away from home

  • Posts: 1392

  • Since: 2007/9/30


According to PEAR, the second is the more correct standard. I personally prefer the top myself.

3
trabis
Re: Coding Standards
  • 2009/3/8 1:40

  • trabis

  • Core Developer

  • Posts: 2269

  • Since: 2006/9/1 1


Thanks, well that is my problem. I use the top one but in XOOPS Core I often see the both being used. I wanted to know which one should be XOOPS STANDARD.

4
Catzwolf
Re: Coding Standards
  • 2009/3/8 2:17

  • Catzwolf

  • Home away from home

  • Posts: 1392

  • Since: 2007/9/30


Actually, the XOOPS Core is anything but standard. The whole framework is a miss-match patch work frame. There are many issues that need to be discussed regarding coding standards, and from what I can see, they are not.

For example:
$var =(isset($_GET['var']))?$var2:$var3;


Is not acceptable, why? Due to readability reasons. but the code is scattered with examples of this.

$var = ( isset( $_GET['var'] ) ) ? $var2 $var3;


To me this is much more readable and easier to understand.

Also, I believe that the use of double quotes should only be used for html and single quotes for PHP code. If you don't know why, then I suggest you read a manual.

There are loads of examples I could quote that are really not acceptable and are still being used in the code. I guess one of these is this

foreach ($_POST as $key => $var) {
   $
$key $var;
}


This is so not correct when populating variables, especially when dealing with post or get vars. but, they are still in there.

5
trabis
Re: Coding Standards
  • 2009/3/8 2:47

  • trabis

  • Core Developer

  • Posts: 2269

  • Since: 2006/9/1 1


I do not like to use so much spaces:

I would do like this:
$var = isset($_GET['var']) ? $var2 $var3;


I use single quotes almost everytime. Double quotes force php to evaluate the content right?

I use double quotes on language definitions for example.

Also I think we should deprecate the use of relative includes like '../../mainfile.php' because we never know if that file isn't going to be included by another one. I use dirname(__FILE__) and basename(dirname(__FILE__)) now and it is perfect. Take for example, if you need to include cp_header.php in yourmodule/admin/subfolder you will get an error because cp_header cannot find mainfile anymore.

There are some other things that I do not get. Why a class/xoopsstory.php and xoopstopic.php? They are bad examples on how to use xoopsObject. It is old school, they should be deprecated. Core classes should be improved to use the new XOOPS Persistable Object Handler.

There is also something about kernel/block.php and class/xoopsblock.php that sounds repeating.






6
zyspec
Re: Coding Standards
  • 2009/3/8 2:52

  • zyspec

  • Module Developer

  • Posts: 1095

  • Since: 2004/9/21


I agree with most of catzwolf_'s comments.

Quote:

Also, I believe that the use of double quotes should only be used for html and single quotes for PHP code.

My only exception to that is I tend to use double quotes for echo commands too since it allows embedding a variable in the string like:

echo "This is a $var string \n";


I just find that easier to read than
echo 'This is a ' $var ' string \n';


To quote from the online PHP documentation:
Quote:

If the string is enclosed in double-quotes ("), PHP will interpret more escape sequences for special characters


I definitely agree with your comments about $_POST variable processing - this is a very poor coding practice.

7
Catzwolf
Re: Coding Standards
  • 2009/3/8 9:58

  • Catzwolf

  • Home away from home

  • Posts: 1392

  • Since: 2007/9/30


Regarding this:

Quote:
If the string is enclosed in double-quotes ("), PHP will interpret more escape sequences for special characters


What this doesn't tell you is that using " over ' is slower, as PHP has to do the above even if there is nothing to interpret.

echo 'This is a ' $var ' string \n';


I personally find this more readable and I can easily see the variables within the line quicker than you suggest, well with my IDE anyway. Plus, the \n will just be displayed as text with your example ;)

Plus I think that this would be quicker to execute :)

echo 'This is a ' $var ' string' chr10 );


Catz

8
DuGris
Re: Coding Standards
  • 2009/3/8 20:38

  • DuGris

  • Core Developer

  • Posts: 67

  • Since: 2004/3/14


do you have read this : xoops coding standards

9
trabis
Re: Coding Standards
  • 2009/3/8 20:53

  • trabis

  • Core Developer

  • Posts: 2269

  • Since: 2006/9/1 1


Quote:

DuGris wrote:
do you have read this : xoops coding standards


Yes, have you read my first post?

10
Mamba
Re: Coding Standards
  • 2009/3/8 21:40

  • Mamba

  • Moderator

  • Posts: 11366

  • Since: 2004/4/23


Quote:
Actually, the XOOPS Core is anything but standard. The whole framework is a miss-match patch work frame.

Are there any good PHP code formatters out there? It would be useful to run the XOOPS code through such a formatter to have at least consistency in the code.
Support XOOPS => DONATE
Use 2.5.10 | Docs | Modules | Bugs

Login

Who's Online

161 user(s) are online (95 user(s) are browsing Support Forums)


Members: 0


Guests: 161


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Apr 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits