This document discusses Drupal standards and best practices used by the UN World Food Programme (WFP). It outlines how WFP adopted Drupal as an organizational standard and details front-end and back-end best practices implemented, including writing understandable code, using unit tests for documentation, and ensuring documentation is clear, concise and accessible. The speaker advocates for having documented standards and processes to maintain high quality code and facilitate onboarding new developers.
5. 1) Drupal in the United Nations & the UN World Food
Programme
2) World Food Programme: Drupal Standards & Best Practices
a) Front-end Best Practices
b) Backend Best Practices
3) Questions
Overview
6. UN hosted DrupalCamp NYC in 2014
– Atefeh Riazi (OICT) gave keynote.
●
"Drupal … was adopted as a standard for the
Organization and meets our complex requirements
including security, flexibility, accessibility, support for
multilingual publishing, and publication workflow.”
- Atefeh Riazi
UN Office of Information and Communication Technology
7. ●
WFP is the world's largest humanitarian agency fighting
hunger worldwide.
●
On average, WFP reaches more than 80 million people with
food assistance in 75 countries each year.
●
WFP is funded entirely by voluntary donations.
– governments, organisations, companies, public
●
Work primarily in emergency situation
– Ebola, Syria, Iraq, Central African Republic, South Sudan
●
HQ in Rome with offices in over 80 countries
UN World Food Programme
16. Lost time
– Understanding how a project was architectured.
– Searching for the right code to change.
– Understanding what code is supposed to do.
– Building similar, yet slightly different themes.
Over 40 different external developers have worked on our
code over past 6-years
– Most have their own approach.
– Spaghetti + macaroni + risotto.
= Code not fun to develop on
UN WFP Before Best Practices
17. ●
Save money through quicker development time
●
Faster on-boarding of new developers
●
Higher quality code
●
What did we change?
– We ingrained best practices into our development cycle
●
Internally
●
.. and then with our vendors.
Importance of Best Practices
20. ●
Built a user interface guideline and development kit for all
WFP branded projects
– Branding consistency (public facing and internal)
●
Framework agnostic
– PHP
– Python
– C#
– .. any projects requiring WFP branding
Theme: UI Guideline
26. Goals
●
Maintainable code over time
●
Developer agnostic
●
Reduce bugs / increase quality
●
Faster iterations
●
Make code fun for developers to work on
●
Faster on-boarding of new developers
– Reduce time to first commit
Coding Best Practices
27. ●
Break code into small units
– better readability and unit testing
●
Writing unit tests is one of the best forms of
documentation
– Will document most execution paths
– Should how code can be used
Unit Tests as Documentation
28. ●
Use standard, sensible naming conventions
●
Enforce low cyclomatic complexity
– make code easy to understand
●
How?
– Peer review, PHP Code Sniffer, Coder,
DrupalStrict, PHPUnit etc.
– Automation: Phing + Jenkins CI, etc.
Coding Best Practices Implementation
29. ●
Write code that doesn't need comments
●
Well structured code using sensible names is a
form of commenting.
●
If you need to write a comment, perhaps the code
is too complex?
Writing Understandable Code
30. ●
Let the code comment itself
// Maximum number of items to display.
$num = 5;
$items_max = 5;
Comments
31. ●
Comments must explain the why and not the what
●
The what can be understood by looking at the code
●
What problem was being solved with this code,
why was it necessary?
Comments
32. ●
Leave advice for the next developer
/**
* @todo Rename to template_preprocess_field__comment() once
* https://www.drupal.org/node/939462 is resolved.
*/
Comments
33. ●
Be honest, let other developers know when code is
not ideal:
// Workaround to add an HTML email template.
// @todo refactor to use theme hook.
Comments
34. ●
Documentation is only as good as how quickly it can be
understood.
– Make it clear
– Make is concise
– Make it beautiful
●
DocBlocks are really important, use appropriate annotation.
– We use them even for core hooks.
Documentation
38. Have best practices
– Design / UI best practices
– Development best practices
– Process best practices
●
Ensure everyone follows them
●
Ensure everyone improves them
●
Write them down and share them with the community
Take Aways