UN World Food Programme Standards & Best Practises (European Drupal Days 2015)

40
© Ibuildings 2014/2015 - All rights reserved #DrupalDaysEU UN World Food Programme: Standards & Best Practices

Transcript of UN World Food Programme Standards & Best Practises (European Drupal Days 2015)

© Ibuildings 2014/2015 - All rights reserved

#DrupalDaysEU

UN World Food Programme:Standards & Best Practices

#DrupalDaysEU

© Ibuildings 2014/2015 - All rights reserved

Gold Sponsors

#DrupalDaysEU

© Ibuildings 2014/2015 - All rights reserved

Media Sponsors

Silver Sponsors

Speaker InfoAndrew HolgateLead Drupal Developer

[email protected]@andrewholgate

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

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

● 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

WFP.org

Give

Freerice

Quiz Platform

The FACTory

IT Communities

Food Security Cluster

Logistics Cluster

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

● 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

Measuring Code Quality

https://github.com/andrewholgate/un-wfp-drupal7-standards-best-practice

WFP Drupal Standard & Practices

● 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

Colours

Icons

UI Toolkit

WFP.org – old theme

WFP.org – new theme

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

● 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

● 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

● 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

● Let the code comment itself

// Maximum number of items to display.

$num = 5;

$items_max = 5;

Comments

● 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

● Leave advice for the next developer

/**

 * @todo Rename to template_preprocess_field__comment() once

 * https://www.drupal.org/node/939462 is resolved.

 */

Comments

● 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

● 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

Doxygen

Bootstrap

Read The Docs

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

Questions?

Speaker InfoAndrew HolgateLead Drupal Developer

[email protected]@andrewholgate