Time-Driven Development
Katerina Trajchevska

Adeva, Engineer, Mozilla Tech Speaker

No matter the size of the company, all the same approach for evaluating new projects: development time

Overview

  1. How to design software for easy maintenance, extension

Example 1: Developing a module for managing user profiles

When remote work started up, managing users got a bit more complex. Didn't want to build something from scratch entirely though. We decided to sign up for third-party CRM where we stored data, created a simple interface against that, then set up a ZohoCandidate.php file with its own getters and setters

A bit brittle, since data managed in arrays so tightly-tied.

Candidate Controller

Red Flags

Demo #1: Changing the storage to MySQL

Started by adding models to reflect CandidateEducation, CandidateExperience, CandidateOverview

Now relying on eloquent classes instead of CRM API response fields (e.g. "first_name" instead of "First Name")

What does it take to switch the storage?

  1. Add Eloquent models,
  2. Change controller deps,
  3. Use Eloquent instead of CRM,
  4. Switch all variables to new naming convention,
  5. Change way we access data in the views

It's basically re-implementing everything that we'd done

Question is how can we save time

First thing to do is not depend on concrete implementations

Setting up CandidateRepositoryInterface. Then in CandidateController, edit method can depend on CandidateRepositoryInterface. Can delegate everything in controller to repository since we know it can handle everything we need

We don't care about how things are implemented, just that they are

Be mindful about what your program expects

So for App\Crm\Candidate.php, tried to mock the eloquent class with a Candidate class. Properties used inside, methods representing relations with other tables. Then in your profile blade file, you can use properties instead of array keys

Bind abstractions with concrete implementation

Binding it within the AppServiceProvider, bind interface with concrete repository (ZohoCandidateRepository)

Demo 2: Changing to MySQL

Another advantage of respecting open-close principle (SOLID) means you can add a DBCandidateRepository, have it chat with the database, then swap out the binding in the AppServiceProvider (from ZohoCandidateRepository to DBCandidateRepository)

Recap

Two switch the storage, added eloquent models, created database candidate repository, change binding in AppServiceProvider

Example 2: Developing a module for integrating GitHub

Wanted to pull in data from GitHub and do assessments based on that

Maybe not everything rely on controller. VersionControlFactory.php with init function . Switch with case statements (e.g. "github"), default case throws exception

AbstractVersionControl as an interface, then you can create a GitHubVersionControl

CandidateController@show, a lot of code...

The amount of code people will write to avoid writing a simple $model->save() or Model::create() is truly mind-boggling. -- @taylorotwell

You Ain't Gonna Need It

Moral of the story is to understand better whether we need to invest the time or just go and refactor in the future

Why Time-Driven Development

NOt that we will develop to save the most time, but what will make the most sense for the company/team/posterity's sake. Doing things proper way upfront saves time in the future

Why Time-Driven Development?

Software design principles are your tools, not your goals.

How to start?

adevait.com (Exclusive developers' network)