[Vtigercrm-developers] Day 2: Modernizing your codebase

Holbok István holbok at gmail.com
Sat Dec 3 13:05:11 GMT 2016


Dear List-members, here is also some idea ...
------------------
Today we're going to dive into *Modernizing your codebase*.
 


    Coding Standard

For years, there were no uniformed standards for writing PHP code. Some
of us chose to follow Zend Framework Coding Standard, some preferred
PEAR Coding Standard, and the rest simply came out their own way of
writing PHP code.

Distributing PHP code without a coding standard is kind of mess. Since
everyone has his or her own way of formatting the source code, scanning
someone else's code becomes a hassle. By sticking to one uniformed
coding standard, we not only encourage someone else to read our code,
but also make reading someone else's code easier for ourselves.

So first step to become a modern PHP developer is to adopt a coding
standard. Currently the most updated coding standard in PHP is PSR-2
(PHP Standards Recommendations number 2).


    Autoloading

Are you tired of using statements like |include / require |whenever you
need to include classes from other files.

We had this problem in PHP for a long time. Code became cluttered and
ugly when we used this technique in our main file to include all desired
classes. Not only that, it was difficult to maintain the codebase, for
example when some classes needed to be refactored to other names.

Fortunately we have autoloader. Basically, autoloader is a technique to
load classes from file paths automatically. This magic saves us from
hard coding file paths whenever we need those classes.

So if you are writing a class or using someone else's class today, start
using PSR-4 Autoloader, which is the latest autoloading specification.


    Package management

In the old days, managing 3rd party libraries in your own codebase was
super difficult. The following was a typical scenario: you downloaded an
awesome library from the Internet and it worked great with your existing
codebase. You were happy until you needed to upgrade the library because
the server had upgraded its PHP version. The codebase started breaking
down right after you downloaded the latest version of the library. You
had no clue why it happened. You had not changed any piece of your code.
So you asked your server admin and consulted your fellow colleagues.
After half a day of digging through code, you found that one of the API
methods was removed from the latest version of the "awesome" library you
downloaded.

Does above story sound familiar to you?

Fortunately we have Composer. The de-factor package manager for PHP
codebase. It takes care of all the nitty-gritty of using a package for us.

So if you have not yet started with Composer, start using it right now!

Next up, we'll learn about *Modernizing your database handling*.
 
 
Until tomorrow,

Keep learning!
Xu
www.startutorial.com
Kindest regards:
Istvan Holbok
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.vtigercrm.com/pipermail/vtigercrm-developers/attachments/20161203/34e31d93/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: open
Type: image/gif
Size: 43 bytes
Desc: not available
URL: <http://lists.vtigercrm.com/pipermail/vtigercrm-developers/attachments/20161203/34e31d93/attachment.gif>


More information about the vtigercrm-developers mailing list