Just two weeks ago I was searching for a good CMS. I found a lot of people saying how good and easy-to-use WordPress is. So I downloaded and played a few days with it, and then gave up.
I turned to Joomla, and found nothing can match this beauty!
I have written C++ for nearly 30 years. I am a person to go for Qt. I think the mainly Joomla contributors very likely also comes from C++. I use doxygen to generate doc out of this framework. I love it!
Looking at the codes, I do have some small suggestions:
1. For class member variables, prepend "m_" to the variables, such as $m_connection, so people immediately know it is a class member variable.
2. Make all member variable private and have "get" and "set" methods. Of course for C++ this is a must for me, because I use 'ddd' to track who use those member variables (when needed) by putting a debug break in the "get" or "set" method. But not sure how I can debug php and set break points...I currently use printf or var_dump to debug....extremely inefficient...
3. Whenever possible, give a data type to the arguments or function return, such as
public function foo( array& $inputs, string $str ) : array
I am coming from C++ and still learning php, so I could be wrong...
I just wonder why some people say WordPress is better. I guest they are just bloggers and have no knowledge of coding...
Suggestions for coding practices for Joomla 4
-
- Joomla! Enthusiast
- Posts: 128
- Joined: Fri Jul 02, 2021 10:34 pm
Suggestions for coding practices for Joomla 4
Last edited by toivo on Sun Jul 04, 2021 3:07 am, edited 1 time in total.
Reason: mod note: moved from 4.x General Questions, retitled
Reason: mod note: moved from 4.x General Questions, retitled
- pe7er
- Joomla! Master
- Posts: 24982
- Joined: Thu Aug 18, 2005 8:55 pm
- Location: Nijmegen, Netherlands
- Contact:
Re: Suggestions for coding practices for Joomla 4
Good to hear that you like the Joomla code. Thank you for your recommendations!
And only use some public functions that are able to access the private methods.
That way you have more control over what your class is able to do.
Regarding debugging of PHP: you could use Xdebug to debug your PHP code.
It works with most IDEs (PHPStorm, Visual Studio, Netbeans, Eclipse).
I use PHPStorm (commercial software) in combination with
https://xdebug.org/
If you use another IDE then you could install PHP Code Sniffer (phpcs) in combination with the Joomla code standards, and you will get those suggestions as well.
More info:
https://developer.joomla.org/coding-standards/html.html
https://docs.joomla.org/Joomla_CodeSniffer
I think that it's a general PHP recommendation to make your methods private as much as possible.vicn1222 wrote: ↑Sat Jul 03, 2021 3:59 pm2. Make all member variable private and have "get" and "set" methods. Of course for C++ this is a must for me, because I use 'ddd' to track who use those member variables (when needed) by putting a debug break in the "get" or "set" method. But not sure how I can debug php and set break points...I currently use printf or var_dump to debug....extremely inefficient...
And only use some public functions that are able to access the private methods.
That way you have more control over what your class is able to do.
Regarding debugging of PHP: you could use Xdebug to debug your PHP code.
It works with most IDEs (PHPStorm, Visual Studio, Netbeans, Eclipse).
I use PHPStorm (commercial software) in combination with
https://xdebug.org/
Actually, that's only possible with the latest PHP versions (since somewhere in the 7.x series) and my PHPStorm does code suggestions for those changes.3. Whenever possible, give a data type to the arguments or function return, such as
public function foo( array& $inputs, string $str ) : array
If you use another IDE then you could install PHP Code Sniffer (phpcs) in combination with the Joomla code standards, and you will get those suggestions as well.
More info:
https://developer.joomla.org/coding-standards/html.html
https://docs.joomla.org/Joomla_CodeSniffer
Kind Regards,
Peter Martin, Global Moderator
Company website: https://db8.nl/en/ - Joomla specialist, Nijmegen, Netherlands
The best website: https://the-best-website.com
Peter Martin, Global Moderator
Company website: https://db8.nl/en/ - Joomla specialist, Nijmegen, Netherlands
The best website: https://the-best-website.com
-
- Joomla! Enthusiast
- Posts: 128
- Joined: Fri Jul 02, 2021 10:34 pm
Re: Suggestions for coding practices for Joomla 4
Hi,pe7er wrote: ↑Mon Jul 05, 2021 6:35 amRegarding debugging of PHP: you could use Xdebug to debug your PHP code.
It works with most IDEs (PHPStorm, Visual Studio, Netbeans, Eclipse).
I use PHPStorm (commercial software) in combination with
https://xdebug.org/
Thank you for the information.
Is there an open source php debugger with gui, like ddd for C/C++?
I install xdebug, but it doesn't seems to have a gui? It probably is like gdb, which we have to use command line to interact with?
I am using CentOS 8.
Thank you.
-
- Joomla! Enthusiast
- Posts: 128
- Joined: Fri Jul 02, 2021 10:34 pm
Re: Suggestions for coding practices for Joomla 4
Actually I don't use any IDE. I use "vi". Very original way...
- pe7er
- Joomla! Master
- Posts: 24982
- Joined: Thu Aug 18, 2005 8:55 pm
- Location: Nijmegen, Netherlands
- Contact:
Re: Suggestions for coding practices for Joomla 4
I don't know.
Xdebug is open source. It is indeed without a GUI.
It interacts between your local web server and your IDE (which usually is a GUI)
I use Ubuntu 20.4 with a LAMP stack for the website, PHPStorm (commercial software), XDebug, and a browser (with XDebug plugin) to trigger XDebug on page requests.I install xdebug, but it doesn't seems to have a gui? It probably is like gdb, which we have to use command line to interact with?
I am using CentOS 8
Kind Regards,
Peter Martin, Global Moderator
Company website: https://db8.nl/en/ - Joomla specialist, Nijmegen, Netherlands
The best website: https://the-best-website.com
Peter Martin, Global Moderator
Company website: https://db8.nl/en/ - Joomla specialist, Nijmegen, Netherlands
The best website: https://the-best-website.com
- brian
- Joomla! Master
- Posts: 12787
- Joined: Fri Aug 12, 2005 7:19 am
- Location: Leeds, UK
- Contact:
Re: Suggestions for coding practices for Joomla 4
Well the first recommendation would be to get an IDE. Working with a single file editor is not a good coding practice for non-procedural code
"Exploited yesterday... Hacked tomorrow"
Blog http://brian.teeman.net/
Joomla Hidden Secrets http://hiddenjoomlasecrets.com/
Blog http://brian.teeman.net/
Joomla Hidden Secrets http://hiddenjoomlasecrets.com/