Results of the CodeWorks code review

51 views
Skip to the first unread message

Joseph LeBlanc

unread,
6 Oct 2009, 13:50:0206/10/2009
to joomla-...@googlegroups.com
This past weekend, I attended the CodeWorks conference here in
Washington. They had a session devoted to code reviews run by
thePHP.cc (http://thephp.cc/en/site/who/). Several open-source
projects were available for the audience to choose from. Since Joomla
was one of the ones available, I requested it.

During the review, they pointed out a few things I think we can look
at, as well as several items I know are already in progress. These
guys are heavy proponents of unit testing, so many of their
suggestions were oriented around that. However, there were a few
others that I think we can fix before we get full unit testing in place.

We have a lot of functions throughout the core that are returning
references to objects, for instance:

public static function &getDocument()

However, there's no reason to return a reference in PHP unless you
have a specific reason to do so; they do not improve performance or
save memory: http://us2.php.net/manual/en/language.references.return.php

When I searched trunk for 'function &', I found 282 instances. We can
probably stand to eliminate most (if not all) of them, unless there's
a specific reason it's being done on such a widespread basis.

One of the other things they found peculiar was the DS constant we've
defined. According to them, there's no reason to do this as PHP
automatically converts / to \ when you're using Windows. They were
also puzzled as to why we had constants like JPATH_BASE without the
slash automatically appended at the end (although that probably loops
back to the DS constant issue).

Finally, require_once is a statement and not a function. I see a mix
in our codebase between require_once 'somefile.php' and
require_once('somefile.php');

They have some slides floating around with everything they found. They
were looking at 1.5.14.

I realize that some of this may seem picky, but since we're still pre-
beta on 1.6, I figure this might be a good chance to address some of
these issues. I'm willing to write patches unless there are good
reasons why we shouldn't change these things.

-Joe

Joseph LeBlanc

unread,
6 Oct 2009, 13:52:2706/10/2009
to joomla-...@googlegroups.com
One thing I just realized: changing DS right now would break a lot of
3rd party components at the moment. So we would probably hold off on
that.

-Joe

Mr Phil E. Taylor

unread,
6 Oct 2009, 13:55:2706/10/2009
to joomla-...@googlegroups.com
I think the pass by reference was required for PHP4 compatibility in the
past...

> --~--~---------~--~----~------------~-------~--~----~
> You received this message because you are subscribed to the Google Groups "Joomla! CMS Development" group.
> To post to this group, send email to joomla-...@googlegroups.com
> To unsubscribe from this group, send email to joomla-dev-cm...@googlegroups.com
> For more options, visit this group at http://groups.google.com/group/joomla-dev-cms?hl=en-GB
> -~----------~----~----~----~------~----~------~--~---
>
>

Ed Stafford

unread,
6 Oct 2009, 14:31:0606/10/2009
to joomla-...@googlegroups.com
On Tue, Oct 6, 2009 at 12:50 PM, Joseph LeBlanc <con...@jlleblanc.com> wrote:
During the review, they pointed out a few things I think we can look
at, as well as several items I know are already in progress. These
guys are heavy proponents of unit testing, so many of their
suggestions were oriented around that. However, there were a few
others that I think we can fix before we get full unit testing in place.

I've just started writing unit tests for Joomla 1.6 as I didn't see any currently available.  Is there already a suite of these for the existing codebase or would it be worth my continuing to write these?  I've started at the libraries/joomla/base/ and working my way up.  Mostly, I started this as I use Joomla a ton of places and wanted some practice with phpunit.
 
One of the other things they found peculiar was the DS constant we've
defined. According to them, there's no reason to do this as PHP
automatically converts / to \ when you're using Windows. They were
also puzzled as to why we had constants like JPATH_BASE without the
slash automatically appended at the end (although that probably loops
back to the DS constant issue).

Could you not remove DS from the core, but keep the constant defined for backwards compatibility?
 
Finally, require_once is a statement and not a function. I see a mix
in our codebase between require_once 'somefile.php' and
require_once('somefile.php');

The PHP reference describes it as require_once(), not require_once; so I would think just pick the reference standard and roll with it.

Ed Stafford

Niels Braczek

unread,
6 Oct 2009, 14:58:3406/10/2009
to joomla-...@googlegroups.com
Ed Stafford schrieb:

> Could you not remove DS from the core, but keep the constant defined for
> backwards compatibility?

+1

>> Finally, require_once is a statement and not a function. I see a mix
>> in our codebase between require_once 'somefile.php' and
>> require_once('somefile.php');
>
> The PHP reference describes it as require_once(), not require_once; so I
> would think just pick the reference standard and roll with it.

No need to repeat "bugs" from the reference. The correct syntax is
*without* parenthesis.
Another thing is, that require_once and include_once are
contraproductive, when using bytecaches. It is more appropriate to use
the autoload mechanism (spl_autoload, *not* __autoload!).

Regards,
Niels

--
| http://www.kolleg.de · Das Portal der Kollegs in Deutschland |
| http://www.bsds.de · BSDS Braczek Software- und DatenSysteme |
| Webdesign · Webhosting · e-Commerce · Joomla! Content Management |
------------------------------------------------------------------

Ian MacLennan

unread,
6 Oct 2009, 15:05:3406/10/2009
to joomla-...@googlegroups.com
On Tue, Oct 6, 2009 at 2:31 PM, Ed Stafford <ed.st...@gmail.com> wrote:


On Tue, Oct 6, 2009 at 12:50 PM, Joseph LeBlanc <con...@jlleblanc.com> wrote:
During the review, they pointed out a few things I think we can look
at, as well as several items I know are already in progress. These
guys are heavy proponents of unit testing, so many of their
suggestions were oriented around that. However, there were a few
others that I think we can fix before we get full unit testing in place.

I've just started writing unit tests for Joomla 1.6 as I didn't see any currently available.  Is there already a suite of these for the existing codebase or would it be worth my continuing to write these?  I've started at the libraries/joomla/base/ and working my way up.  Mostly, I started this as I use Joomla a ton of places and wanted some practice with phpunit.

Look in development/testing/trunk/1.6/unittest.

There are some there, lots more to do.

Some more of the 1.5 ones could possibly be ported over as well.

Ian

Mark Dexter

unread,
6 Oct 2009, 15:05:5006/10/2009
to joomla-...@googlegroups.com
Ed, you can check out the 1.6 Unit testing project here:
http://joomlacode.org/svn/joomla/testing/trunk/1.6. Mark

Ian MacLennan

unread,
6 Oct 2009, 15:25:5406/10/2009
to joomla-...@googlegroups.com
Whoops...  yeah...  what Mark said - I added the development again.

Ian

Ian MacLennan

unread,
6 Oct 2009, 15:35:4606/10/2009
to joomla-...@googlegroups.com
btw I updated the docs on docs.joomla.org to reflect some of the changes that have been recently made.

Ian

Ed Stafford

unread,
6 Oct 2009, 17:01:1506/10/2009
to joomla-...@googlegroups.com
On Tue, Oct 6, 2009 at 2:35 PM, Ian MacLennan <ian.ma...@joomla.org> wrote:
On Tue, Oct 6, 2009 at 3:05 PM, Mark Dexter <dexter...@gmail.com> wrote:

Ed, you can check out the 1.6 Unit testing project here:
http://joomlacode.org/svn/joomla/testing/trunk/1.6. Mark


Thanks.. Looks like there's a lot of opportunity for unit testing there.  I'll have to clean up the tests I've written so far and submit them.  To who or where should I send my patches/additions?

Ed

Ian MacLennan

unread,
6 Oct 2009, 17:11:2506/10/2009
to joomla-...@googlegroups.com
We're working on some infrastructure stuff atm with the hopes of opening some of our repos up.  In the meantime, send them to me and I'll commit them.

Ian

Niels Braczek

unread,
6 Oct 2009, 19:59:5906/10/2009
to joomla-...@googlegroups.com
Ed Stafford schrieb:

> I'll have to clean up the tests I've written so far and submit them. To who
> or where should I send my patches/additions?

Unit tests have their own mailinglist, although it is quite unused yet:
joomla-unit...@googlegroups.com. I think it is a good place to
gather the unit test work and discussion.

Regards,
Niels

Louis Landry

unread,
6 Oct 2009, 20:02:4506/10/2009
to joomla-...@googlegroups.com
Assuming most, if not all, of these unit tests are going to be on framework libraries can we have that discussion on the framework list?  If anyone is having trouble getting signed up on that list I will be happy to fix it.

- Louis
--
Development Coordinator
Joomla! ... because open source matters.
http://www.joomla.org

Niels Braczek

unread,
6 Oct 2009, 20:08:4706/10/2009
to joomla-...@googlegroups.com
Louis Landry schrieb:

> Assuming most, if not all, of these unit tests are going to be on framework
> libraries can we have that discussion on the framework list? If anyone is
> having trouble getting signed up on that list I will be happy to fix it.

So what is the reason for the unit test group? Will it be dropped?
That would be ok for me, but it does not make sense having an
infrastructure without using it.

Louis Landry

unread,
6 Oct 2009, 20:22:1506/10/2009
to joomla-...@googlegroups.com
As far as I know the unit test group was created before these 3 new open lists.  Shutting it down would be fine by me. I personally think that the discussion around unit tests for framework libraries is a good thing to have on the framework list but am happy to hear other's opinions on the matter.

- Louis

Andrew Eddie

unread,
6 Oct 2009, 20:36:3806/10/2009
to joomla-...@googlegroups.com
Merging UT and Framework sounds good to me. +1

Regards,
Andrew Eddie
http://www.theartofjoomla.com - the art of becoming a Joomla developer




2009/10/7 Louis Landry <louis....@joomla.org>:

Andrew Eddie

unread,
6 Oct 2009, 20:39:1706/10/2009
to joomla-...@googlegroups.com
Hi Joe

Thanks for the report. Very informative. "Most" (qualified) of the
require_once, include_once instances should be fixed in 1.6 already.

Dropping the DS (but leaving the constant) sounds great to me, as does
taking out the &'s (Phil is right, it's there for PHP 4 compat).

Regards,
Andrew Eddie
http://www.theartofjoomla.com - the art of becoming a Joomla developer




2009/10/7 Joseph LeBlanc <con...@jlleblanc.com>:

Christophe Demko

unread,
7 Oct 2009, 04:06:1107/10/2009
to Joomla! CMS Development
In fact, you have to return a reference when you want to modify the
original object. In all other cases, do a classical return.

Joseph LeBlanc

unread,
7 Oct 2009, 08:31:4007/10/2009
to joomla-...@googlegroups.com
Hi Andrew,

In that case, I'll get to work on a patch for the remaining
require_once() and include_once()'es, then another one for references.

-Joe

Joseph LeBlanc

unread,
7 Oct 2009, 12:57:1907/10/2009
to joomla-...@googlegroups.com
Patch ready for require_once, require, include, and include_once
statements:

http://joomlacode.org/gf/project/joomla/tracker/?action=TrackerItemEdit&tracker_item_id=18304

-Joe

Ercan Özkaya

unread,
7 Oct 2009, 13:44:0807/10/2009
to Joomla! CMS Development
Committed Joe, thank you!

On Oct 7, 7:57 pm, Joseph LeBlanc <cont...@jlleblanc.com> wrote:
> Patch ready for require_once, require, include, and include_once  
> statements:
>
> http://joomlacode.org/gf/project/joomla/tracker/?action=TrackerItemEd...
>
> -Joe
>
> On Oct 7, 2009, at 8:31 AM, Joseph LeBlanc wrote:
>
>
>
> > Hi Andrew,
>
> > In that case, I'll get to work on a patch for the remaining
> > require_once() and include_once()'es, then another one for references.
>
> > -Joe
>
> > On Oct 6, 2009, at 8:39 PM, Andrew Eddie wrote:
>
> >> Hi Joe
>
> >> Thanks for the report.  Very informative.  "Most" (qualified) of the
> >> require_once, include_once instances should be fixed in 1.6 already.
>
> >> Dropping the DS (but leaving the constant) sounds great to me, as  
> >> does
> >> taking out the &'s (Phil is right, it's there for PHP 4 compat).
>
> >> Regards,
> >> Andrew Eddie
> >>http://www.theartofjoomla.com- the art of becoming a Joomla  
> >> developer
>
> >> 2009/10/7 Joseph LeBlanc <cont...@jlleblanc.com>:

Joseph LeBlanc

unread,
2 Dec 2009, 15:07:0102/12/2009
to joomla-...@googlegroups.com
I worked on a patch for references over a month ago and just got around to finishing it today. Some notes about this patch:

* It primarily deals with functions in libraries/joomla. There were some instances where code elsewhere was specifically depending on references; I skipped the ones I ran into issues with. Off the top of my head, the only one I can think of that did this was JNode, which was being used to generate the backend menu.

* A few fixes for component models are mixed in as well. From what I remember, these were causing issues immediately after I made specific patches, so I just went ahead and fixed them. If we want to deal with these separately as a patch for components, I can split this patch into libraries/joomla vs. other files.

* Documentation has changed to reflect the fact that we are now returning the objects, rather than references to the objects.

The patch is attached. I can add it to the tracker if necessary.

-Joe

joomla_library_references.patch

Louis Landry

unread,
11 Dec 2009, 18:40:4611/12/2009
to joomla-...@googlegroups.com
Joe,

I downloaded the patch but cannot figure out which format it is in.  I'm unable to apply it to my copy of the tree.  Any advice on how I might be able to do that?

- Louis


-Joe


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Joomla! CMS Development" group.
 To post to this group, send email to joomla-...@googlegroups.com
 To unsubscribe from this group, send email to joomla-dev-cm...@googlegroups.com
 For more options, visit this group at http://groups.google.com/group/joomla-dev-cms?hl=en-GB
-~----------~----~----~----~------~----~------~--~---

On Oct 7, 2009, at 8:31 AM, Joseph LeBlanc wrote:

>
> --~--~---------~--~----~------------~-------~--~----~
> You received this message because you are subscribed to the Google Groups "Joomla! CMS Development" group.
> To post to this group, send email to joomla-...@googlegroups.com
> To unsubscribe from this group, send email to joomla-dev-cm...@googlegroups.com
> For more options, visit this group at http://groups.google.com/group/joomla-dev-cms?hl=en-GB
> -~----------~----~----~----~------~----~------~--~---
>


Joseph LeBlanc

unread,
11 Dec 2009, 23:08:1411/12/2009
to joomla-...@googlegroups.com
Sorry, there was a multi-fail at work there. At the very least, the file got mangled when I posted it. I've now zipped and attached.

-Joe

references.patch.zip

Louis Landry

unread,
11 Dec 2009, 23:25:2911/12/2009
to joomla-...@googlegroups.com
Rock.

Committed @ revision 13707

Thanks Joe!

- Louis

On Fri, Dec 11, 2009 at 10:08 PM, Joseph LeBlanc <con...@jlleblanc.com> wrote:
Sorry, there was a multi-fail at work there. At the very least, the file got mangled when I posted it. I've now zipped and attached.

-Joe

--

You received this message because you are subscribed to the Google Groups "Joomla! CMS Development" group.
To post to this group, send an email to joomla-...@googlegroups.com.

To unsubscribe from this group, send email to joomla-dev-cm...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/joomla-dev-cms?hl=en-GB.


--

You received this message because you are subscribed to the Google Groups "Joomla! CMS Development" group.
To post to this group, send an email to joomla-...@googlegroups.com.
To unsubscribe from this group, send email to joomla-dev-cm...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/joomla-dev-cms?hl=en-GB.


Reply all
Reply to author
Forward
0 new messages