SlideShare ist ein Scribd-Unternehmen logo
1 von 57
Downloaden Sie, um offline zu lesen
Writing
                          Testable Code

                           Alvaro Videla - Cloud Foundry




Wednesday, April 10, 13
About Me


                     •    Cloud Foundry Developer Advocate

                     •    Blog: http://videlalvaro.github.com/

                     •    Twitter: @old_sound




Wednesday, April 10, 13
About Me
                          Co-author

               RabbitMQ in Action
               http://bit.ly/rabbitmq




Wednesday, April 10, 13
I’m not a:




Wednesday, April 10, 13
I’m not a:
                     • Application Testing Guru




Wednesday, April 10, 13
I’m not a:
                     • Application Testing Guru
                     • TDD Advocate




Wednesday, April 10, 13
Why is it so hard
                           to write tests?


Wednesday, April 10, 13
Unit Testing

                   The goal of unit testing is
                    to isolate each part of
                    the program and show
                   that the individual parts
                          are correct
                           http://en.wikipedia.org/wiki/Unit_testing


Wednesday, April 10, 13
Unit Testing


               […] unit testing by definition only
               tests the functionality of the units
                           themselves.



                           http://en.wikipedia.org/wiki/Unit_testing


Wednesday, April 10, 13
Unit Testing

                     […] Therefore, it will not catch
                      integration errors or broader
                       system-level errors (such as
                       functions performed across
                     multiple units, or non-functional
                     test areas such as performance)

                              http://en.wikipedia.org/wiki/Unit_testing


Wednesday, April 10, 13
Dogma
                            vs.
                          Reality

Wednesday, April 10, 13
A world of
                          Trade Offs
Wednesday, April 10, 13
What should
                       we test?
Wednesday, April 10, 13
How much
                           should
                           we test?
Wednesday, April 10, 13
“I get paid for code that works,
                 not for tests, so my philosophy is
                   to test as little as possible to
                 reach a given level of confidence”
                                                                                      – Kent Beck


                          http://stackoverflow.com/questions/153234/how-deep-are-your-unit-tests/153565#153565




Wednesday, April 10, 13
The Hidden
                            Secret
                           Of TDD



Wednesday, April 10, 13
The Secret of TDD




Wednesday, April 10, 13
The Secret of TDD




Wednesday, April 10, 13
Some books by Kent Beck




Wednesday, April 10, 13
To write good
                   tests first we need
                    to learn how to
                        program

Wednesday, April 10, 13
Wednesday, April 10, 13
We developers are
                 like those users we
                 like to complain so
                     much about

Wednesday, April 10, 13
Design evolves and
                 matures with time


Wednesday, April 10, 13
Good Code sits in
                      the small details


Wednesday, April 10, 13
TIPS



Wednesday, April 10, 13
Separate pure code
                     from impure or stateful


Wednesday, April 10, 13
Pure Functions




Wednesday, April 10, 13
Pure Functions
                     • Referential Transparency




Wednesday, April 10, 13
Pure Functions
                     • Referential Transparency
                     • Don’t modify external state




Wednesday, April 10, 13
Pure Functions
                     • Referential Transparency
                     • Don’t modify external state
                     • Don’t produce side effects




Wednesday, April 10, 13
What’s wrong with this code?


                          if($player->getScore() > 0) {
                            $player->setSwizzle(7);
                          } else {
                            $player->setSwizzle(
                               $player->getSwizzle() + 1
                            );
                          }



                          https://dl.dropboxusercontent.com/u/7810909/docs/what-does-fp-mean/what-does-fp-mean/chunk-html/ar01s05.html




Wednesday, April 10, 13
What’s wrong with this code?


         $newScore = $player->getScore() > 0
                                                ? 7
                                                : $player->getSwizzle() + 1;

         $player->setSwizzle($newScore);




                          https://dl.dropboxusercontent.com/u/7810909/docs/what-does-fp-mean/what-does-fp-mean/chunk-html/ar01s05.html




Wednesday, April 10, 13
Score calculation
                   can be moved into
                    its own function


Wednesday, April 10, 13
Score calculation
                    can be tested now


Wednesday, April 10, 13
First write
                          Pure Code


Wednesday, April 10, 13
Add impure code
                    step by step when
                         needed


Wednesday, April 10, 13
Write
                          Composable
                            Code


Wednesday, April 10, 13
Function Composition




                           http://en.wikipedia.org/wiki/Function_(mathematics)



Wednesday, April 10, 13
Function Composition




                           http://en.wikipedia.org/wiki/Function_(mathematics)


Wednesday, April 10, 13
This looks familiar



Wednesday, April 10, 13
“Many UNIX programs do quite
                    trivial tasks in isolation, but,
                   combined with other programs,
                     become general and useful
                                tools.”



                            http://math.albany.edu/math/pers/hammond/unixphil.html




Wednesday, April 10, 13
Number of open connections per IP




           netstat -ntu | awk '{print $5}' | 
           cut -d: -f1 | sort | uniq -c | sort -n




                              http://www.commandlinefu.com/commands/view/1767/number-of-open-connections-per-ip.




Wednesday, April 10, 13
Why don’t we just
                          code in this style?


Wednesday, April 10, 13
This seems familiar
                                again…


Wednesday, April 10, 13
Welcome to
                           Functional
                          Programming


Wednesday, April 10, 13
“Writing unit tests is reinventing
                     functional programming
                  in non-functional languages”




                          http://noss.github.io/2009/02/25/writing-unit-tests-is-reinventing-functional-programming-in-non-functional-languages.html




Wednesday, April 10, 13
What can we learn from
                          Functional Programming?




Wednesday, April 10, 13
The proper use of Types




Wednesday, April 10, 13
What does ‘null’ mean?




Wednesday, April 10, 13
What does
                          ‘true|false’ mean?



Wednesday, April 10, 13
Functions with just one
                              responsibility



Wednesday, April 10, 13
Radical separation of pure
                      code from impure code



Wednesday, April 10, 13
Let’s see an example




Wednesday, April 10, 13
Food for Thought




                          http://thinking-forth.sourceforge.net
Wednesday, April 10, 13
“Inside every well-
                          written large program
                          is a well-written small
                                 program”

                                 http://www.linfo.org/q_programming.html




Wednesday, April 10, 13
Questions?


Wednesday, April 10, 13
Thanks!
                              http://twitter.com/old_sound
                              http://github.com/videlalvaro
                          http://www.slideshare.net/old_sound


Wednesday, April 10, 13

Weitere ähnliche Inhalte

Was ist angesagt?

サーバーが完膚なきまでに死んでもMySQLのデータを失わないための表技
サーバーが完膚なきまでに死んでもMySQLのデータを失わないための表技サーバーが完膚なきまでに死んでもMySQLのデータを失わないための表技
サーバーが完膚なきまでに死んでもMySQLのデータを失わないための表技yoku0825
 
MQ入門
MQ入門MQ入門
MQ入門HIRA
 
Pacemaker+PostgreSQLレプリケーションで共有ディスクレス高信頼クラスタの構築@OSC 2013 Tokyo/Spring
Pacemaker+PostgreSQLレプリケーションで共有ディスクレス高信頼クラスタの構築@OSC 2013 Tokyo/SpringPacemaker+PostgreSQLレプリケーションで共有ディスクレス高信頼クラスタの構築@OSC 2013 Tokyo/Spring
Pacemaker+PostgreSQLレプリケーションで共有ディスクレス高信頼クラスタの構築@OSC 2013 Tokyo/SpringTakatoshi Matsuo
 
Kafka vs Pulsar @KafkaMeetup_20180316
Kafka vs Pulsar @KafkaMeetup_20180316Kafka vs Pulsar @KafkaMeetup_20180316
Kafka vs Pulsar @KafkaMeetup_20180316Nozomi Kurihara
 
Jenkinsとamazon ecsで コンテナCI
Jenkinsとamazon ecsで コンテナCIJenkinsとamazon ecsで コンテナCI
Jenkinsとamazon ecsで コンテナCIshigeyuki azuchi
 
Kafkaを使った マイクロサービス基盤 part2 +運用して起きたトラブル集
Kafkaを使った マイクロサービス基盤 part2 +運用して起きたトラブル集Kafkaを使った マイクロサービス基盤 part2 +運用して起きたトラブル集
Kafkaを使った マイクロサービス基盤 part2 +運用して起きたトラブル集matsu_chara
 
EC2のストレージどう使う? -Instance Storageを理解して高速IOを上手に活用!-
EC2のストレージどう使う? -Instance Storageを理解して高速IOを上手に活用!-EC2のストレージどう使う? -Instance Storageを理解して高速IOを上手に活用!-
EC2のストレージどう使う? -Instance Storageを理解して高速IOを上手に活用!-Yuta Imai
 
MySQLとPostgreSQLの基本的なレプリケーション設定比較
MySQLとPostgreSQLの基本的なレプリケーション設定比較MySQLとPostgreSQLの基本的なレプリケーション設定比較
MySQLとPostgreSQLの基本的なレプリケーション設定比較Shinya Sugiyama
 
【Zabbix2.0】snmpttによるトラップメッセージの編集 #Zabbix #自宅ラック勉強会
【Zabbix2.0】snmpttによるトラップメッセージの編集 #Zabbix #自宅ラック勉強会【Zabbix2.0】snmpttによるトラップメッセージの編集 #Zabbix #自宅ラック勉強会
【Zabbix2.0】snmpttによるトラップメッセージの編集 #Zabbix #自宅ラック勉強会真乙 九龍
 
イルカさんチームからゾウさんチームに教えたいMySQLレプリケーション
イルカさんチームからゾウさんチームに教えたいMySQLレプリケーションイルカさんチームからゾウさんチームに教えたいMySQLレプリケーション
イルカさんチームからゾウさんチームに教えたいMySQLレプリケーションyoku0825
 
MySQL Document Store를 활용한 NoSQL 개발
MySQL Document Store를 활용한 NoSQL 개발MySQL Document Store를 활용한 NoSQL 개발
MySQL Document Store를 활용한 NoSQL 개발Oracle Korea
 
initとプロセス再起動
initとプロセス再起動initとプロセス再起動
initとプロセス再起動Takashi Takizawa
 
PostgreSQLのパラレル化に向けた取り組み@第30回(仮名)PostgreSQL勉強会
PostgreSQLのパラレル化に向けた取り組み@第30回(仮名)PostgreSQL勉強会PostgreSQLのパラレル化に向けた取り組み@第30回(仮名)PostgreSQL勉強会
PostgreSQLのパラレル化に向けた取り組み@第30回(仮名)PostgreSQL勉強会Shigeru Hanada
 
作って(壊して?)学ぶインターネットのしくみ サイバーエージェントの実験用ASの紹介 / Introduce experimental AS in ...
作って(壊して?)学ぶインターネットのしくみ サイバーエージェントの実験用ASの紹介 / Introduce experimental AS in ...作って(壊して?)学ぶインターネットのしくみ サイバーエージェントの実験用ASの紹介 / Introduce experimental AS in ...
作って(壊して?)学ぶインターネットのしくみ サイバーエージェントの実験用ASの紹介 / Introduce experimental AS in ...whywaita
 
MySQLバックアップの基本
MySQLバックアップの基本MySQLバックアップの基本
MySQLバックアップの基本yoyamasaki
 
メールシステムのおはなし #Mailerstudy
メールシステムのおはなし #Mailerstudyメールシステムのおはなし #Mailerstudy
メールシステムのおはなし #MailerstudyYasuhiro Araki, Ph.D
 
10年効く分散ファイルシステム技術 GlusterFS & Red Hat Storage
10年効く分散ファイルシステム技術 GlusterFS & Red Hat Storage10年効く分散ファイルシステム技術 GlusterFS & Red Hat Storage
10年効く分散ファイルシステム技術 GlusterFS & Red Hat StorageEtsuji Nakai
 

Was ist angesagt? (20)

サーバーが完膚なきまでに死んでもMySQLのデータを失わないための表技
サーバーが完膚なきまでに死んでもMySQLのデータを失わないための表技サーバーが完膚なきまでに死んでもMySQLのデータを失わないための表技
サーバーが完膚なきまでに死んでもMySQLのデータを失わないための表技
 
MQ入門
MQ入門MQ入門
MQ入門
 
Pacemaker+PostgreSQLレプリケーションで共有ディスクレス高信頼クラスタの構築@OSC 2013 Tokyo/Spring
Pacemaker+PostgreSQLレプリケーションで共有ディスクレス高信頼クラスタの構築@OSC 2013 Tokyo/SpringPacemaker+PostgreSQLレプリケーションで共有ディスクレス高信頼クラスタの構築@OSC 2013 Tokyo/Spring
Pacemaker+PostgreSQLレプリケーションで共有ディスクレス高信頼クラスタの構築@OSC 2013 Tokyo/Spring
 
Kafka vs Pulsar @KafkaMeetup_20180316
Kafka vs Pulsar @KafkaMeetup_20180316Kafka vs Pulsar @KafkaMeetup_20180316
Kafka vs Pulsar @KafkaMeetup_20180316
 
Jenkinsとamazon ecsで コンテナCI
Jenkinsとamazon ecsで コンテナCIJenkinsとamazon ecsで コンテナCI
Jenkinsとamazon ecsで コンテナCI
 
Kafkaを使った マイクロサービス基盤 part2 +運用して起きたトラブル集
Kafkaを使った マイクロサービス基盤 part2 +運用して起きたトラブル集Kafkaを使った マイクロサービス基盤 part2 +運用して起きたトラブル集
Kafkaを使った マイクロサービス基盤 part2 +運用して起きたトラブル集
 
EC2のストレージどう使う? -Instance Storageを理解して高速IOを上手に活用!-
EC2のストレージどう使う? -Instance Storageを理解して高速IOを上手に活用!-EC2のストレージどう使う? -Instance Storageを理解して高速IOを上手に活用!-
EC2のストレージどう使う? -Instance Storageを理解して高速IOを上手に活用!-
 
MySQLとPostgreSQLの基本的なレプリケーション設定比較
MySQLとPostgreSQLの基本的なレプリケーション設定比較MySQLとPostgreSQLの基本的なレプリケーション設定比較
MySQLとPostgreSQLの基本的なレプリケーション設定比較
 
【Zabbix2.0】snmpttによるトラップメッセージの編集 #Zabbix #自宅ラック勉強会
【Zabbix2.0】snmpttによるトラップメッセージの編集 #Zabbix #自宅ラック勉強会【Zabbix2.0】snmpttによるトラップメッセージの編集 #Zabbix #自宅ラック勉強会
【Zabbix2.0】snmpttによるトラップメッセージの編集 #Zabbix #自宅ラック勉強会
 
イルカさんチームからゾウさんチームに教えたいMySQLレプリケーション
イルカさんチームからゾウさんチームに教えたいMySQLレプリケーションイルカさんチームからゾウさんチームに教えたいMySQLレプリケーション
イルカさんチームからゾウさんチームに教えたいMySQLレプリケーション
 
MySQL Document Store를 활용한 NoSQL 개발
MySQL Document Store를 활용한 NoSQL 개발MySQL Document Store를 활용한 NoSQL 개발
MySQL Document Store를 활용한 NoSQL 개발
 
At least onceってぶっちゃけ問題の先送りだったよね #kafkajp
At least onceってぶっちゃけ問題の先送りだったよね #kafkajpAt least onceってぶっちゃけ問題の先送りだったよね #kafkajp
At least onceってぶっちゃけ問題の先送りだったよね #kafkajp
 
initとプロセス再起動
initとプロセス再起動initとプロセス再起動
initとプロセス再起動
 
PostgreSQLのパラレル化に向けた取り組み@第30回(仮名)PostgreSQL勉強会
PostgreSQLのパラレル化に向けた取り組み@第30回(仮名)PostgreSQL勉強会PostgreSQLのパラレル化に向けた取り組み@第30回(仮名)PostgreSQL勉強会
PostgreSQLのパラレル化に向けた取り組み@第30回(仮名)PostgreSQL勉強会
 
作って(壊して?)学ぶインターネットのしくみ サイバーエージェントの実験用ASの紹介 / Introduce experimental AS in ...
作って(壊して?)学ぶインターネットのしくみ サイバーエージェントの実験用ASの紹介 / Introduce experimental AS in ...作って(壊して?)学ぶインターネットのしくみ サイバーエージェントの実験用ASの紹介 / Introduce experimental AS in ...
作って(壊して?)学ぶインターネットのしくみ サイバーエージェントの実験用ASの紹介 / Introduce experimental AS in ...
 
各種データベースの特徴とパフォーマンス比較
各種データベースの特徴とパフォーマンス比較各種データベースの特徴とパフォーマンス比較
各種データベースの特徴とパフォーマンス比較
 
MySQLバックアップの基本
MySQLバックアップの基本MySQLバックアップの基本
MySQLバックアップの基本
 
メールシステムのおはなし #Mailerstudy
メールシステムのおはなし #Mailerstudyメールシステムのおはなし #Mailerstudy
メールシステムのおはなし #Mailerstudy
 
10年効く分散ファイルシステム技術 GlusterFS & Red Hat Storage
10年効く分散ファイルシステム技術 GlusterFS & Red Hat Storage10年効く分散ファイルシステム技術 GlusterFS & Red Hat Storage
10年効く分散ファイルシステム技術 GlusterFS & Red Hat Storage
 
第31回「今アツい、分散ストレージを語ろう」(2013/11/28 on しすなま!)
第31回「今アツい、分散ストレージを語ろう」(2013/11/28 on しすなま!)第31回「今アツい、分散ストレージを語ろう」(2013/11/28 on しすなま!)
第31回「今アツい、分散ストレージを語ろう」(2013/11/28 on しすなま!)
 

Ähnlich wie Writing testable code

Intravert atx meetup_condensed
Intravert atx meetup_condensedIntravert atx meetup_condensed
Intravert atx meetup_condensedzznate
 
ChefConf2014 - Chef TDD
ChefConf2014 - Chef TDD ChefConf2014 - Chef TDD
ChefConf2014 - Chef TDD Daniel Tracy
 
Keeping your users happy with testable apps - Greg Shackles
Keeping your users happy with testable apps - Greg ShacklesKeeping your users happy with testable apps - Greg Shackles
Keeping your users happy with testable apps - Greg ShacklesXamarin
 
The State of Puppet
The State of PuppetThe State of Puppet
The State of PuppetPuppet
 
Genestack BioIT-World-2013
Genestack BioIT-World-2013Genestack BioIT-World-2013
Genestack BioIT-World-2013genestack
 
Test Driven Infrastructure Development
Test Driven Infrastructure DevelopmentTest Driven Infrastructure Development
Test Driven Infrastructure DevelopmentPuppet
 
Test driven infrastructure development
Test driven infrastructure developmentTest driven infrastructure development
Test driven infrastructure developmentTomas Doran
 
NodeJS: Writing tests -- A Beginners' Guide
NodeJS: Writing tests -- A Beginners' GuideNodeJS: Writing tests -- A Beginners' Guide
NodeJS: Writing tests -- A Beginners' GuideGrey Ang
 
Eclipse con 2012 - Devops - Luke Kanies
Eclipse con 2012 - Devops - Luke KaniesEclipse con 2012 - Devops - Luke Kanies
Eclipse con 2012 - Devops - Luke KaniesPuppet
 
Engineering culture
Engineering cultureEngineering culture
Engineering culturePamela Fox
 
Piccolo coding dojo (milano xpug 2013-04-11)
Piccolo coding dojo (milano xpug 2013-04-11)Piccolo coding dojo (milano xpug 2013-04-11)
Piccolo coding dojo (milano xpug 2013-04-11)Andrea Francia
 
Unmoderated User Testing
Unmoderated User TestingUnmoderated User Testing
Unmoderated User TestingZURB
 
Connect and Collaborate C
Connect and Collaborate CConnect and Collaborate C
Connect and Collaborate CTerri Sallee
 
Eclipse con 2012 - Frictionless operations with Puppet - Luke Kanies
Eclipse con 2012 - Frictionless operations with Puppet - Luke KaniesEclipse con 2012 - Frictionless operations with Puppet - Luke Kanies
Eclipse con 2012 - Frictionless operations with Puppet - Luke KaniesPuppet
 
Specking Interactors with PHPSpec and YOLO (DDD) at PHPConference Argentina 2013
Specking Interactors with PHPSpec and YOLO (DDD) at PHPConference Argentina 2013Specking Interactors with PHPSpec and YOLO (DDD) at PHPConference Argentina 2013
Specking Interactors with PHPSpec and YOLO (DDD) at PHPConference Argentina 2013cordoval
 
Puppet Camp Berlin 2014: Advanced Puppet Design
Puppet Camp Berlin 2014: Advanced Puppet DesignPuppet Camp Berlin 2014: Advanced Puppet Design
Puppet Camp Berlin 2014: Advanced Puppet DesignPuppet
 

Ähnlich wie Writing testable code (20)

When Tdd Goes Awry
When Tdd Goes AwryWhen Tdd Goes Awry
When Tdd Goes Awry
 
Writing the docs
Writing the docsWriting the docs
Writing the docs
 
Intravert atx meetup_condensed
Intravert atx meetup_condensedIntravert atx meetup_condensed
Intravert atx meetup_condensed
 
ChefConf2014 - Chef TDD
ChefConf2014 - Chef TDD ChefConf2014 - Chef TDD
ChefConf2014 - Chef TDD
 
Keeping your users happy with testable apps - Greg Shackles
Keeping your users happy with testable apps - Greg ShacklesKeeping your users happy with testable apps - Greg Shackles
Keeping your users happy with testable apps - Greg Shackles
 
The State of Puppet
The State of PuppetThe State of Puppet
The State of Puppet
 
Genestack BioIT-World-2013
Genestack BioIT-World-2013Genestack BioIT-World-2013
Genestack BioIT-World-2013
 
Testable Code ... In Joomla!?
Testable Code ... In Joomla!?Testable Code ... In Joomla!?
Testable Code ... In Joomla!?
 
Test Driven Infrastructure Development
Test Driven Infrastructure DevelopmentTest Driven Infrastructure Development
Test Driven Infrastructure Development
 
Test driven infrastructure development
Test driven infrastructure developmentTest driven infrastructure development
Test driven infrastructure development
 
NodeJS: Writing tests -- A Beginners' Guide
NodeJS: Writing tests -- A Beginners' GuideNodeJS: Writing tests -- A Beginners' Guide
NodeJS: Writing tests -- A Beginners' Guide
 
Eclipse con 2012 - Devops - Luke Kanies
Eclipse con 2012 - Devops - Luke KaniesEclipse con 2012 - Devops - Luke Kanies
Eclipse con 2012 - Devops - Luke Kanies
 
Engineering culture
Engineering cultureEngineering culture
Engineering culture
 
Piccolo coding dojo (milano xpug 2013-04-11)
Piccolo coding dojo (milano xpug 2013-04-11)Piccolo coding dojo (milano xpug 2013-04-11)
Piccolo coding dojo (milano xpug 2013-04-11)
 
Unmoderated User Testing
Unmoderated User TestingUnmoderated User Testing
Unmoderated User Testing
 
Connect and Collaborate C
Connect and Collaborate CConnect and Collaborate C
Connect and Collaborate C
 
Eclipse con 2012 - Frictionless operations with Puppet - Luke Kanies
Eclipse con 2012 - Frictionless operations with Puppet - Luke KaniesEclipse con 2012 - Frictionless operations with Puppet - Luke Kanies
Eclipse con 2012 - Frictionless operations with Puppet - Luke Kanies
 
Debugging Android - GDG Munich
Debugging Android - GDG MunichDebugging Android - GDG Munich
Debugging Android - GDG Munich
 
Specking Interactors with PHPSpec and YOLO (DDD) at PHPConference Argentina 2013
Specking Interactors with PHPSpec and YOLO (DDD) at PHPConference Argentina 2013Specking Interactors with PHPSpec and YOLO (DDD) at PHPConference Argentina 2013
Specking Interactors with PHPSpec and YOLO (DDD) at PHPConference Argentina 2013
 
Puppet Camp Berlin 2014: Advanced Puppet Design
Puppet Camp Berlin 2014: Advanced Puppet DesignPuppet Camp Berlin 2014: Advanced Puppet Design
Puppet Camp Berlin 2014: Advanced Puppet Design
 

Mehr von Alvaro Videla

Improvements in RabbitMQ
Improvements in RabbitMQImprovements in RabbitMQ
Improvements in RabbitMQAlvaro Videla
 
Data Migration at Scale with RabbitMQ and Spring Integration
Data Migration at Scale with RabbitMQ and Spring IntegrationData Migration at Scale with RabbitMQ and Spring Integration
Data Migration at Scale with RabbitMQ and Spring IntegrationAlvaro Videla
 
RabbitMQ Data Ingestion at Craft Conf
RabbitMQ Data Ingestion at Craft ConfRabbitMQ Data Ingestion at Craft Conf
RabbitMQ Data Ingestion at Craft ConfAlvaro Videla
 
Scaling applications with RabbitMQ at SunshinePHP
Scaling applications with RabbitMQ   at SunshinePHPScaling applications with RabbitMQ   at SunshinePHP
Scaling applications with RabbitMQ at SunshinePHPAlvaro Videla
 
Unit Test + Functional Programming = Love
Unit Test + Functional Programming = LoveUnit Test + Functional Programming = Love
Unit Test + Functional Programming = LoveAlvaro Videla
 
RabbitMQ Data Ingestion
RabbitMQ Data IngestionRabbitMQ Data Ingestion
RabbitMQ Data IngestionAlvaro Videla
 
Dissecting the rabbit: RabbitMQ Internal Architecture
Dissecting the rabbit: RabbitMQ Internal ArchitectureDissecting the rabbit: RabbitMQ Internal Architecture
Dissecting the rabbit: RabbitMQ Internal ArchitectureAlvaro Videla
 
Introduction to RabbitMQ | Meetup at Pivotal Labs
Introduction to RabbitMQ | Meetup at Pivotal LabsIntroduction to RabbitMQ | Meetup at Pivotal Labs
Introduction to RabbitMQ | Meetup at Pivotal LabsAlvaro Videla
 
Rabbitmq Boot System
Rabbitmq Boot SystemRabbitmq Boot System
Rabbitmq Boot SystemAlvaro Videla
 
Cloud Foundry Bootcamp
Cloud Foundry BootcampCloud Foundry Bootcamp
Cloud Foundry BootcampAlvaro Videla
 
Cloud Messaging With Cloud Foundry
Cloud Messaging With Cloud FoundryCloud Messaging With Cloud Foundry
Cloud Messaging With Cloud FoundryAlvaro Videla
 
Código Fácil De Testear
Código Fácil De TestearCódigo Fácil De Testear
Código Fácil De TestearAlvaro Videla
 
Desacoplando aplicaciones
Desacoplando aplicacionesDesacoplando aplicaciones
Desacoplando aplicacionesAlvaro Videla
 
Theres a rabbit on my symfony
Theres a rabbit on my symfonyTheres a rabbit on my symfony
Theres a rabbit on my symfonyAlvaro Videla
 
Scaling Web Apps With RabbitMQ - Erlang Factory Lite
Scaling Web Apps With RabbitMQ - Erlang Factory LiteScaling Web Apps With RabbitMQ - Erlang Factory Lite
Scaling Web Apps With RabbitMQ - Erlang Factory LiteAlvaro Videla
 
Integrating php withrabbitmq_zendcon
Integrating php withrabbitmq_zendconIntegrating php withrabbitmq_zendcon
Integrating php withrabbitmq_zendconAlvaro Videla
 

Mehr von Alvaro Videla (20)

Improvements in RabbitMQ
Improvements in RabbitMQImprovements in RabbitMQ
Improvements in RabbitMQ
 
Data Migration at Scale with RabbitMQ and Spring Integration
Data Migration at Scale with RabbitMQ and Spring IntegrationData Migration at Scale with RabbitMQ and Spring Integration
Data Migration at Scale with RabbitMQ and Spring Integration
 
RabbitMQ Data Ingestion at Craft Conf
RabbitMQ Data Ingestion at Craft ConfRabbitMQ Data Ingestion at Craft Conf
RabbitMQ Data Ingestion at Craft Conf
 
Scaling applications with RabbitMQ at SunshinePHP
Scaling applications with RabbitMQ   at SunshinePHPScaling applications with RabbitMQ   at SunshinePHP
Scaling applications with RabbitMQ at SunshinePHP
 
Unit Test + Functional Programming = Love
Unit Test + Functional Programming = LoveUnit Test + Functional Programming = Love
Unit Test + Functional Programming = Love
 
RabbitMQ Data Ingestion
RabbitMQ Data IngestionRabbitMQ Data Ingestion
RabbitMQ Data Ingestion
 
Dissecting the rabbit: RabbitMQ Internal Architecture
Dissecting the rabbit: RabbitMQ Internal ArchitectureDissecting the rabbit: RabbitMQ Internal Architecture
Dissecting the rabbit: RabbitMQ Internal Architecture
 
Introduction to RabbitMQ | Meetup at Pivotal Labs
Introduction to RabbitMQ | Meetup at Pivotal LabsIntroduction to RabbitMQ | Meetup at Pivotal Labs
Introduction to RabbitMQ | Meetup at Pivotal Labs
 
RabbitMQ Hands On
RabbitMQ Hands OnRabbitMQ Hands On
RabbitMQ Hands On
 
Rabbitmq Boot System
Rabbitmq Boot SystemRabbitmq Boot System
Rabbitmq Boot System
 
Cloud Foundry Bootcamp
Cloud Foundry BootcampCloud Foundry Bootcamp
Cloud Foundry Bootcamp
 
Cloud Messaging With Cloud Foundry
Cloud Messaging With Cloud FoundryCloud Messaging With Cloud Foundry
Cloud Messaging With Cloud Foundry
 
Taming the rabbit
Taming the rabbitTaming the rabbit
Taming the rabbit
 
Vertx
VertxVertx
Vertx
 
Código Fácil De Testear
Código Fácil De TestearCódigo Fácil De Testear
Código Fácil De Testear
 
Desacoplando aplicaciones
Desacoplando aplicacionesDesacoplando aplicaciones
Desacoplando aplicaciones
 
Messaging patterns
Messaging patternsMessaging patterns
Messaging patterns
 
Theres a rabbit on my symfony
Theres a rabbit on my symfonyTheres a rabbit on my symfony
Theres a rabbit on my symfony
 
Scaling Web Apps With RabbitMQ - Erlang Factory Lite
Scaling Web Apps With RabbitMQ - Erlang Factory LiteScaling Web Apps With RabbitMQ - Erlang Factory Lite
Scaling Web Apps With RabbitMQ - Erlang Factory Lite
 
Integrating php withrabbitmq_zendcon
Integrating php withrabbitmq_zendconIntegrating php withrabbitmq_zendcon
Integrating php withrabbitmq_zendcon
 

Kürzlich hochgeladen

How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 

Kürzlich hochgeladen (20)

How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 

Writing testable code

  • 1. Writing Testable Code Alvaro Videla - Cloud Foundry Wednesday, April 10, 13
  • 2. About Me • Cloud Foundry Developer Advocate • Blog: http://videlalvaro.github.com/ • Twitter: @old_sound Wednesday, April 10, 13
  • 3. About Me Co-author RabbitMQ in Action http://bit.ly/rabbitmq Wednesday, April 10, 13
  • 4. I’m not a: Wednesday, April 10, 13
  • 5. I’m not a: • Application Testing Guru Wednesday, April 10, 13
  • 6. I’m not a: • Application Testing Guru • TDD Advocate Wednesday, April 10, 13
  • 7. Why is it so hard to write tests? Wednesday, April 10, 13
  • 8. Unit Testing The goal of unit testing is to isolate each part of the program and show that the individual parts are correct http://en.wikipedia.org/wiki/Unit_testing Wednesday, April 10, 13
  • 9. Unit Testing […] unit testing by definition only tests the functionality of the units themselves. http://en.wikipedia.org/wiki/Unit_testing Wednesday, April 10, 13
  • 10. Unit Testing […] Therefore, it will not catch integration errors or broader system-level errors (such as functions performed across multiple units, or non-functional test areas such as performance) http://en.wikipedia.org/wiki/Unit_testing Wednesday, April 10, 13
  • 11. Dogma vs. Reality Wednesday, April 10, 13
  • 12. A world of Trade Offs Wednesday, April 10, 13
  • 13. What should we test? Wednesday, April 10, 13
  • 14. How much should we test? Wednesday, April 10, 13
  • 15. “I get paid for code that works, not for tests, so my philosophy is to test as little as possible to reach a given level of confidence” – Kent Beck http://stackoverflow.com/questions/153234/how-deep-are-your-unit-tests/153565#153565 Wednesday, April 10, 13
  • 16. The Hidden Secret Of TDD Wednesday, April 10, 13
  • 17. The Secret of TDD Wednesday, April 10, 13
  • 18. The Secret of TDD Wednesday, April 10, 13
  • 19. Some books by Kent Beck Wednesday, April 10, 13
  • 20. To write good tests first we need to learn how to program Wednesday, April 10, 13
  • 22. We developers are like those users we like to complain so much about Wednesday, April 10, 13
  • 23. Design evolves and matures with time Wednesday, April 10, 13
  • 24. Good Code sits in the small details Wednesday, April 10, 13
  • 26. Separate pure code from impure or stateful Wednesday, April 10, 13
  • 28. Pure Functions • Referential Transparency Wednesday, April 10, 13
  • 29. Pure Functions • Referential Transparency • Don’t modify external state Wednesday, April 10, 13
  • 30. Pure Functions • Referential Transparency • Don’t modify external state • Don’t produce side effects Wednesday, April 10, 13
  • 31. What’s wrong with this code? if($player->getScore() > 0) { $player->setSwizzle(7); } else { $player->setSwizzle( $player->getSwizzle() + 1 ); } https://dl.dropboxusercontent.com/u/7810909/docs/what-does-fp-mean/what-does-fp-mean/chunk-html/ar01s05.html Wednesday, April 10, 13
  • 32. What’s wrong with this code? $newScore = $player->getScore() > 0 ? 7 : $player->getSwizzle() + 1; $player->setSwizzle($newScore); https://dl.dropboxusercontent.com/u/7810909/docs/what-does-fp-mean/what-does-fp-mean/chunk-html/ar01s05.html Wednesday, April 10, 13
  • 33. Score calculation can be moved into its own function Wednesday, April 10, 13
  • 34. Score calculation can be tested now Wednesday, April 10, 13
  • 35. First write Pure Code Wednesday, April 10, 13
  • 36. Add impure code step by step when needed Wednesday, April 10, 13
  • 37. Write Composable Code Wednesday, April 10, 13
  • 38. Function Composition http://en.wikipedia.org/wiki/Function_(mathematics) Wednesday, April 10, 13
  • 39. Function Composition http://en.wikipedia.org/wiki/Function_(mathematics) Wednesday, April 10, 13
  • 41. “Many UNIX programs do quite trivial tasks in isolation, but, combined with other programs, become general and useful tools.” http://math.albany.edu/math/pers/hammond/unixphil.html Wednesday, April 10, 13
  • 42. Number of open connections per IP netstat -ntu | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n http://www.commandlinefu.com/commands/view/1767/number-of-open-connections-per-ip. Wednesday, April 10, 13
  • 43. Why don’t we just code in this style? Wednesday, April 10, 13
  • 44. This seems familiar again… Wednesday, April 10, 13
  • 45. Welcome to Functional Programming Wednesday, April 10, 13
  • 46. “Writing unit tests is reinventing functional programming in non-functional languages” http://noss.github.io/2009/02/25/writing-unit-tests-is-reinventing-functional-programming-in-non-functional-languages.html Wednesday, April 10, 13
  • 47. What can we learn from Functional Programming? Wednesday, April 10, 13
  • 48. The proper use of Types Wednesday, April 10, 13
  • 49. What does ‘null’ mean? Wednesday, April 10, 13
  • 50. What does ‘true|false’ mean? Wednesday, April 10, 13
  • 51. Functions with just one responsibility Wednesday, April 10, 13
  • 52. Radical separation of pure code from impure code Wednesday, April 10, 13
  • 53. Let’s see an example Wednesday, April 10, 13
  • 54. Food for Thought http://thinking-forth.sourceforge.net Wednesday, April 10, 13
  • 55. “Inside every well- written large program is a well-written small program” http://www.linfo.org/q_programming.html Wednesday, April 10, 13
  • 57. Thanks! http://twitter.com/old_sound http://github.com/videlalvaro http://www.slideshare.net/old_sound Wednesday, April 10, 13