Jordi Boggiano
@seldaek


Five Weird Tricks to
Become a Better Developer

Photo CC BY-NC-SA 2.0 flickr.com/photos/n-ino/43767475

Building the internet for over 10 years
  → seld.be

Symfony core team, Composer lead and more OSS
  → github.com/Seldaek

Symfony, app architecture & performance consulting

Dev at Teamup.com

0. FOREWORD

Photo CC BY-NC-SA 2.0 flickr.com/photos/mtsofan/10337390256
SOLID Testing Object Calisthenics Dependency Injection Continuous Deployment Virtualization Containerization Performance Optimization

NOT THE WHOLE STORY

Any developers in the room?

Whose job is it to type on a keyboard?

We are paid to
solve problems.

Not just hammer
code out.

Photo CC BY 2.0 flickr.com/photos/raindrift/7095238893

Photo CC BY-SA 2.0 flickr.com/photos/dougbelshaw/4157880455

1. REFLECT

To think seriously; to ponder or consider.

Photo CC BY 2.0 flickr.com/photos/pokerbrit/9786570463

Let's talk about adaptability.

SURVIVAL

Photo CC BY-NC-SA 2.0 flickr.com/photos/baronreznik/13920981383
Photo CC BY-NC-SA 2.0 flickr.com/photos/kitetraveller/7101340995

SURVIVAL

Photo CC BY-NC-SA 2.0 flickr.com/photos/kitetraveller/7101340995

FAIR ENOUGH

Photo CC BY-NC-ND 2.0 flickr.com/photos/so8/8161891893

PLEASE :(

Do not learn
the broken away.

Learn to identify it.

Identify both when designing and using software.

Report minor issues
to all projects.

(c.f. DX initiative)

Ask why

Photo CC BY-NC-ND 2.0 flickr.com/photos/abidk/6019013292

You can not solve a problem you do not understand.

BDD/DDD principles can help.

Do your developers understand the business impact of the feature they are working on?

And far more importantly, do they believe it? - Anthony Ferrara

Tell why

What

// Collapse all spaces.
$result = str_replace(' ', '', $selected);
                
// Grab the next character in the string
$char = substr($json, $i, 1);
                

Why

// If it is the same package, compare the versions to make the order deterministic
return strcmp($a['version'], $b['version']);
                
// manually rewind $other to previous key, since iterator_count moves pointer
if ($key !== null) {
    $other->rewind();
}
                

Writing readable
code is great,
but it is still the
what and not the why.

Code-burns can help you reflect and explain why X to your team.

2. EMPATHIZE

To understand and share the feelings of another.

Photo CC BY-NC-SA 2.0 flickr.com/photos/doug88888/5730746409

Empathy towards users

Users (or developers) are affected by every decision you take

Developer

class Foo
{
    public function __construct($doThis, $notThat = false, $lights = true, $engines = null)
    {
    }
}
                

User

new Foo('lala', true, true, '3');
                

Empathy towards
your team

Photo CC BY-NC-ND 2.0 flickr.com/photos/demandaj/7287174776

Showing empathy makes for more positive discussions and arguments

Showing empathy makes for less negative discussions and arguments

How to empathize:

Learn to listen

Waiting to speak is not listening

Ask if something was not clear to you

Repeat the message so they can verify you got it

How to empathize:

Care about people, ask how they are,
do not judge

Understand what drives them and
how they work

Complain from their perspective

See also:
nonviolent communication

3. TAKE THE SCENIC ROUTE

Photo CC BY-ND 2.0 flickr.com/photos/tambako/6929837367

Are you experiencing:

Stress?

Exhaustion?

Lack of motivation?

Interpersonal problems?

You may be burning out.

Photo CC BY-ND 2.0 flickr.com/photos/dskley/14692471997

Open Sourcing Mental Illness

Ed Finkler / Funkatron

(http://youtu.be/4tswmjhA7Ws)

I can now see that my productive work — at least the good stuff, comes from my unproductive time, from my empty yearning to understand the world.

Against Productivity by Quinn Norton

If you are stuck, try another approach or take a break.

4. BE PRAGMATIC

The pursuit of practicality
over aesthetic qualities.

Photo CC BY-NC-ND 2.0 flickr.com/photos/sea-turtle/7423022786
































Beyond Clean Code by Anthonny Ferrara

Working software over not working software.

Code adaptability is what matters for businesses.

Who is paid to produce beautiful abstractions?

class Csv implements FormatterInterface
{
    const LINE_DELIMITER = "\r\n";
    private $separator = ',';
    private $enclosure = '"';
    /**
     * {@inheritdoc}
     */
    public function getMimeType()
    {
        // @see RFC 4180 - http://tools.ietf.org/html/rfc4180
        return 'text/csv';
    }
    /**
     * {@inheritdoc}
     */
    public function getExtension()
    {
        return 'csv';
    }
    /**
     * Define the record separator
     *
     * @param string $separator
     */
    public function setSeparator($separator)
    {
        $this->separator = $separator;
    }
// ...
                
// ...
    /**
     * Define the enclosing character each value
     *
     * @param string $enclosure
     */
    public function setEnclosure($enclosure)
    {
        $this->enclosure = $enclosure;
    }
    /**
     * {@inheritdoc}
     */
    public function format(array $data)
    {
        // well, that's a shame.
        if (empty($data)) {
            return;
        }
        $output = array();
        // Header with field names
        $output[] = $this->processRecord(array_keys($data[0]));
        foreach ($data as $record) {
            $output[] = $this->processRecord(array_values($record));
        }
        return implode(static::LINE_DELIMITER, $output);
    }
// ...
                
// ...
    /**
     * Processes $values into a csv line
     *
     * Note: Since the fields are enclosed with a delimiter, then
     *       the output of this function might generate more than one line.
     *
     * @param  array  $values [description]
     * @return string
     */
    private function processRecord(array $values)
    {
        $values = array_map(array($this, 'escape'), $values);
        return implode($this->separator, $values);
    }
    /**
     * Escapes a csv value according to http://tools.ietf.org/html/rfc4180#page-3
     *
     * @param  string $value
     * @return string
     */
    private function escape($value)
    {
        $value = str_replace('"', '""', $value);
        return "{$this->enclosure}{$value}{$this->enclosure}";
    }
}
                

Beautiful.

foreach ($data as $record) {
    fputcsv($handle, $record);
}
                

Functional and adaptable.

Do not write things now that may not be needed later.

Premature architecting is also evil.

Avoid pedantry.

Get things done.

How to review code:

1. Is the code's purpose worthy?

2. Is it actually doing what it says?

3. Will it adapt over time?

4. Is it visually appealing?

Got ugly code? PHP-CS-Fixer it.

Don't argue about tech.

Use whatever works
for you.

Use what fits the job.

Analyze the risks of
old stable vs new shiny.

The most vocal and excited database companies kept coming to us saying they'd solve all of our scalability problems.

But nobody told us of the virtues of MySQL, probably because MySQL just works, and people know about it.

Pinterest Engineering Blog

New Shiny

Advertised as magically better/faster/...

Can solve old problems in a new way, or perhaps solve new problems

Old Stable

Proven to scale and has many features

You already know how to fix it when it breaks

New ideas may not need new solutions

5. MAKE TRADE OFFS

Photo CC BY 2.0 flickr.com/photos/procsilas/1393467292

Memory usage vs. CPU load

Storage space vs. Image quality

Silver bullets do not exist.

Beware of the magic kool-aid.

Look at all the
shades of gray.

Nothing is perfect but
not all options are good.

Photo CC BY-NC-SA 2.0 flickr.com/photos/_boris/2406608333

Let's sum up!

Photo CC BY-NC-SA 2.0 flickr.com/photos/mattbeckwith/9660627644
Photo CC BY-NC-ND 2.0 flickr.com/photos/scottrsmith/8724990478
Photo CC BY-NC-ND 2.0 flickr.com/photos/pearlsareanuisance/9537371391

Be humble and pragmatic.

Take absolutes with some perspective.

And take the scenic route
every now and then...

Thank you!

Questions?

@seldaek

slides.seld.be


Feedback:

joind.in/talk/4b317