easing a hurricane called TEAM

by

RicCastelhano

university

welcome to the real world

great environment

but we also had

lack of standards

excess ownership

"works on my machine"

production deployment

legacy code

the end of the world

"university" of life

1996

extreme programming

coding standards

// BAD
echo "<a href=\"link\" title=\"some title\">Link to somewhere</a>";
// GOOD
echo '<a href="link" title="some title">Link to somewhere</a>';


// BAD
$my_array = array(
  'first'  => 1,
  'second' => 2,
  'third'  => 3
);
// GOOD
$my_array = array(
    'first'  => 1,
    'second' => 2,
    'third'  => 3,
);


// BAD
$my_array=array(1,2,3,4);
$my_var=10;
// GOOD
$my_array = array( 1, 2, 3, 4 );
$my_var   = 10;

it may be simple as this

PHP Standards Recommendations (PSR)

http://www.php-fig.org/

WordPress Coding Standards

https://make.wordpress.org/core/handbook/best-practices/coding-standards/

PHP only?

airbnb javascript style guide

https://github.com/airbnb/javascript

log coding standards

https://github.com/log-oscon/Standards

code review

the good

the bad

the ugly

static analysis vs manual review

test driven development

the good

the bad

/**
 * Get a post's permalink, then run it through special filters and trigger
 * the 'special_action' action hook.
 *
 * @param  int       $post_id The post ID being linked to.
 * @return str|bool           The permalink or a boolean false if $post_id does not exist.
 */
function my_permalink_function( $post_id ) {

    $permalink = get_permalink( absint( $post_id ) );
    
    $permalink = apply_filters( 'special_filter', $permalink );

    do_action( 'special_action', $permalink );

    return $permalink;

}

the ugly



public function test_my_permalink() {

    WP_Mock::userFunction( 'get_permalink', array(
        'args'   => 42,
        'times'  => 1,
        'return' => 'http://example.com/foo'
    ) );
    
    WP_Mock::passthruFunction( 'absint', array( 'times' => 1 ) );

    WP_Mock::onFilter( 'special_filter' )
        ->with( 'http://example.com/foo' )
        ->reply( 'https://example.com/bar' );

    WP_Mock::expectAction( 'special_action', 'https://example.com/bar' );

    $result = my_permalink_function( 42 );

    $this->assertEquals( 'https://example.com/bar', $result );

}

the ugly

PHPUnit

http://phpunit.de/

WordPress API
Mocking Framework

https://github.com/10up/wp_mock

Codeception

https://codeception.com/

continuous integration

the good

the good

the bad good

Man is the only animal for whom his own existence is a problem which he has to solve and from which he cannot escape.

Erich Fromm
(1900 - 1980)

Q&A

easing a hurricane called TEAM

by

RicCastelhano

Easing a Hurricane called TEAM

By Ricardo Castelhano

Easing a Hurricane called TEAM

"Do you need a dictionary to read and understand a colleague's code On the eve of a production rollout, is it the hell on Earth? Do you run for your life any time it is necessary to maintain legacy code? If you answered "Yes" to any of those questions, this session is for you. Having a group of webdesigners and developers together does not mean they are a team. With these questions comes concepts such as Code Review, TDD and CI-CD to help out your team communication, stress, trust and knowledge."

  • 1,339