Dolibarr / dolibarr

Dolibarr ERP CRM is a modern software package to manage your company or foundation's activity (contacts, suppliers, invoices, orders, stocks, agenda, accounting, ...). it's an open source Web application (written in PHP) designed for businesses of any sizes, foundations and freelancers.
https://www.dolibarr.org
GNU General Public License v3.0
5.46k stars 2.79k forks source link

Apply NASA's Ten Commandments of Coding #4 CommonObject Function and Generic Functions are Too Long #30045

Open JphenixB opened 4 months ago

JphenixB commented 4 months ago

Feature Request

As a developer, it is difficult to understand and maintain the code when it is too long. NASA’s ten coding commandments N°4:

No function should be longer than what can be printed on a single sheet of paper in a standard reference format with one line per statement and one line per declaration. Typically, this means no more than about 60 lines of code per function.

For example the showInputField function in commonObject has several functionalities which can be separated to be modified by inheritance :

Use case

I my case, I have to implement a new feature into commonObject (add a dependence filter with filed A that filter field B)

To do it, I have to inherit commonObject and copy and past ~800 lines of code of showInputField to simply add my own functionnality of 10 lines inside...

if the functions where separated, you only have 20 lines (set of variables and call of functions) and insert the required function or code between or override the function that need to be changed.

Suggested implementation

No response

Suggested steps

Define the global and specific functions that have a big win to be refactorised.

JphenixB commented 4 months ago

Exemple of implementation ca be download at :Liste dépendante commonobjectex.class.php