SlideShare une entreprise Scribd logo
1  sur  38
Télécharger pour lire hors ligne
PHP Doesn't Suck
Who are you?


                     John Hobbs

                     - Developer at What Cheer
                     - @jmhobbs
                     - https://github.com/jmhobbs
                     - http://velvetcache.org/




PHP Doesn't Suck
PHP Sucks

                   T_PAAMAYIM_NEKUDOTAYIM

                     get_class() => gettype()

       PHPE9568F34-D428-11d2-A769-00AA001ACF42

                         sort( &$array )


                        www.phpsadness.com
PHP Doesn't Suck
PHP Sucks

                                             Low Barrier To Entry
                                              Weak Community
                                              Google-Copy-Paste
                                                    NIH

      “In the end I think you will find that your homegrown
      small framework has saved you time and aggravation
      and you end up with a better product.” - Rasmus

             http://toys.lerdorf.com/archives/38-The-no-framework-PHP-MVC-framework.html

PHP Doesn't Suck
I can write
                   terrible code in
                    any language.
                                - Me

PHP Doesn't Suck
Making It Not Suck

                   Learn the Language




                    http://php.net/manual


PHP Doesn't Suck
Making It Not Suck

                        Test Your Code




                      http://www.simpletest.org/
                        http://www.phpunit.de/
                   http://qa.php.net/write-test.php


PHP Doesn't Suck
Making It Not Suck

                       NO LIVE EDITS
                             (mostly)




               CAPISTRANO WORKS FINE WITH PHP

PHP Doesn't Suck
Making It Not Suck
                      Share & Be shared




                                  Github
                   PSR-0 (http://tinyurl.com/yh6jydd)

PHP Doesn't Suck
Making It Not Suck
                         Have A Style




        http://www.mediawiki.org/wiki/Manual:Coding_conventions

PHP Doesn't Suck
Making It Not Suck
                          Try The REPL
          jmhobbs@Cordelia:~$ phpsh
          Starting php
          type 'h' or 'help' to see instructions & features
          php> echo "Oh hai!";
          Oh hai!
          php> include "test.php";

          php> whoa();
          lol, functions!1!
          php>
          jmhobbs@Cordelia:~$


                       http://www.phpsh.org/

PHP Doesn't Suck
Making It Not Suck
                         Read Code
                      (Including other languages!)




PHP Doesn't Suck
USE
        A
   FRAMEWORK
                   (Hint: Not Zend)
PHP Doesn't Suck
Use A Framework


                    - HMVC
                    - Useful helpers
                    - Super flexible
                    - Great modules system
                    - Great modules


                    http://kohanaframework.org/
PHP Doesn't Suck
Use A Framework



         namespace appcontrollers;

         class PostsController extends lithiumactionController {

              public function index() {
                  return array('foo' => 'bar', 'title' => 'Posts');
              }
         }



                                 http://lithify.me/
PHP Doesn't Suck
Use A Framework
                                    Skunk
         // Initialize
         $s = new Skunk();

         // Add a route
         $s->get(
            '/hi(/<name>)',
            function ( &$s, $name = “world” ) {
              $s->body = “Hello $name!";
            }
         );

         // Run it!
         $s->run();


                        https://github.com/jmhobbs/Skunk
PHP Doesn't Suck
So...
PHP Doesn't Suck
It's Getting Better
    5.4

      - http://www.php.net/manual/en/language.oop5.traits.php
        (Traits => Mixins)

      - http://svn.php.net/viewvc?view=revision&revision=313641
        (Short Array Syntax: [ “a” => “b” ])

      - http://news.php.net/php.internals/55293
        (SVN => git)



PHP Doesn't Suck
Discussion


                   Questions?
                   Comments?

PHP Doesn't Suck
PHP Doesn't Suck




This is a presentation about PHP.

If you are looking for a fight, leave now.
Who are you?


                           John Hobbs

                           - Developer at What Cheer
                           - @jmhobbs
                           - https://github.com/jmhobbs
                           - http://velvetcache.org/




      PHP Doesn't Suck



I'm John Hobbs.

I make fancy websites at What Cheer.

I have a twitter and a github and I blog but no one
   reads it.

If I'm known for anything on the Internet it's Beef Taco.

Just google Beef Taco and it's the top item.

I kid you not.
PHP Sucks

                        T_PAAMAYIM_NEKUDOTAYIM

                          get_class() => gettype()

            PHPE9568F34-D428-11d2-A769-00AA001ACF42

                              sort( &$array )


                             www.phpsadness.com
     PHP Doesn't Suck



PHP Sucks.

The language itself has some fundamental flaws that
 crept in early in it's life and have not been excised
 yet, mostly for compatibility issues.

Crappy error messages.
Inconsistent naming conventions.
Stupid “features”
In place array sorts.

There is a decent chunk of these, phpsadness.com is
 a good place to read and track them.

PHP has a weird history of full rewrites, but it's held
 onto backwards compatibility through a lot of them.

Zend (4/5) is a decent engine, but the old cruft is lame.
PHP Sucks

                                                   Low Barrier To Entry
                                                    Weak Community
                                                    Google-Copy-Paste
                                                          NIH

            “In the end I think you will find that your homegrown
            small framework has saved you time and aggravation
            and you end up with a better product.” - Rasmus

                   http://toys.lerdorf.com/archives/38-The-no-framework-PHP-MVC-framework.html

      PHP Doesn't Suck



Why else does PHP suck?

Well, it runs everywhere. It's billed as an easy
 language to learn, fast. And it is, if you want to write
 crappy code.

The community is, compared to Python and Ruby,
 fragmented and not sophisticated. Testing is a big
 problem here. Ever used a phpt?

Because PHP is everywhere, you can Google for
 anything and get some code. Too often people don't
 read it, they just copy-paste. So they lose a chance
 to learn and also integrate crappy code.

There also seems to be a serious not-invented-here
 syndrome in PHP. This includes Rasmus. Don't
 listen to Rasmus.
I can write
                         terrible code in
                          any language.
                                       - Me

      PHP Doesn't Suck



I can write terrible code in any language.

The point is that the quality of the code has a lot to do
 with who is writing it, and how much they
 understand.

Don't blame everything on the language.

So how can we write better PHP?
Making It Not Suck

                         Learn the Language




                          http://php.net/manual


      PHP Doesn't Suck



Learn the language.

It sounds simple, but I bet there is lots of stuff that even
   good PHP programmers don't know about PHP.

Has anyone here ever written a __clone method?

How much of the manual have you read?

Have you ever compiled an extension? Written one?
Making It Not Suck

                             Test Your Code




                           http://www.simpletest.org/
                             http://www.phpunit.de/
                        http://qa.php.net/write-test.php


     PHP Doesn't Suck



Test your code.

This is a huuuuge deal. There are good testing tools
 for PHP, use them. I like SimpleTest, but it's a
 personal choice, and an easy one.

TDD makes you think, something PHP doesn't always
 make you do.

Something else that unit testing does is force you to
 separate code. PHP is it's own template language,
 so it's super easy to mix business logic with
 presentation. Don't. Testing will help.
Making It Not Suck

                                 NO LIVE EDITS
                                       (mostly)




                         CAPISTRANO WORKS FINE WITH PHP

      PHP Doesn't Suck



No live edits. Stay off of production.

I admit, I don't use version control on some stuff. One
   off tools and pages, wordpress blogs, stuff that
   doesn't really matter.

If you are writing an app or a library, you should be
   using version control and running deployments after
   all your tests pass.

Capistrano gets along fine with PHP, and if you would
 rather you can use phing and other tools.

PHP tempts you to edit live in production. Resist.
Making It Not Suck
                            Share & Be shared




                                        Github
                         PSR-0 (http://tinyurl.com/yh6jydd)

      PHP Doesn't Suck



Share your code, and use shared code.

You don't have to come up with your own version of a
 lot of things.

But don't just blindly copy code or use any old module.

Look at the code and make a judgment call. It's okay
  to fork or rewrite if it's in bad shape, but then share it
  back to the community!

If you are writing a library, be compatible. If it's
   generic, there are naming conventions like PSR-0.

(I admit I am bad at being compatible)
Making It Not Suck
                               Have A Style




              http://www.mediawiki.org/wiki/Manual:Coding_conventions

      PHP Doesn't Suck



Have a style you stick to.

Being clear and consistent in your code is essential, no
 sloppy formatting.

Bad style is endemic of google-copy-paste code.

If you are working on someone else's project, use their
    style before you make a pull request.

It's polite, it's clean it's essential.

I use a variant of MediaWiki's conventions.
Making It Not Suck
                                Try The REPL
                jmhobbs@Cordelia:~$ phpsh
                Starting php
                type 'h' or 'help' to see instructions & features
                php> echo "Oh hai!";
                Oh hai!
                php> include "test.php";

                php> whoa();
                lol, functions!1!
                php>
                jmhobbs@Cordelia:~$


                             http://www.phpsh.org/

      PHP Doesn't Suck



Other languages have a great REPL.

PHP, not so much.

Luckily we have a good one from Facebook, written
  mostly in Python actually.

Get it and give it a shot.

When you forget argument ordering it's often easier to
 try it in the shell than to go look it up on php.net.
Making It Not Suck
                              Read Code
                           (Including other languages!)




     PHP Doesn't Suck



Actually READ the code you use.

This one is a big one. Read other people's code, the
 good and the bad.

Identify what you like and what you don't like about
  other people's code.

Try out new things you find in other peoples code.

And don't be just a PHP programmer.

Read and write some other languages, Python, Ruby,
 whatever.

I am convinced the more well read you are, in any
   language, the better you will be as a programmer.
USE
             A
        FRAMEWORK
                        (Hint: Not Zend)
     PHP Doesn't Suck



Use a framework.

A framework will make you organize your code within a
  set of conventions. Which conventions don't matter
  as much as the fact that they exist.

I recommend not Zend because it frightens me.

Learn your framework well.

Read it's core, submit patches, be involved.

Here are few examples of frameworks:
Use A Framework


                          - HMVC
                          - Useful helpers
                          - Super flexible
                          - Great modules system
                          - Great modules


                          http://kohanaframework.org/
      PHP Doesn't Suck



I'm a Kohana user.

It's not all roses though, there are no migrations either,
   which is gross.

Development moves fast, and breaks api a lot. It's
 managed with versioning though, and there is plenty
 of backporting and bug fixes.
Use A Framework



              namespace appcontrollers;

              class PostsController extends lithiumactionController {

                   public function index() {
                       return array('foo' => 'bar', 'title' => 'Posts');
                   }
              }



                                      http://lithify.me/
     PHP Doesn't Suck



Another cool one is Lithium.

It's very “leading edge” and uses namespaces like they
   are going out of style.
Use A Framework
                                         Skunk
              // Initialize
              $s = new Skunk();

              // Add a route
              $s->get(
                 '/hi(/<name>)',
                 function ( &$s, $name = “world” ) {
                   $s->body = “Hello $name!";
                 }
              );

              // Run it!
              $s->run();


                             https://github.com/jmhobbs/Skunk
     PHP Doesn't Suck



Finally I included a Sinatra and Bottle style framework
  that I wrote.

I wouldn't necessarily recommend using Skunk, but it's
  a good example a little, single file framework with an
  interesting API and feel.
So...
      PHP Doesn't Suck



So.

Those are my thoughts on how to write better PHP.

As for the language itself...
It's Getting Better
          5.4

            - http://www.php.net/manual/en/language.oop5.traits.php
              (Traits => Mixins)

            - http://svn.php.net/viewvc?view=revision&revision=313641
              (Short Array Syntax: [ “a” => “b” ])

            - http://news.php.net/php.internals/55293
              (SVN => git)



      PHP Doesn't Suck



It's getting better.

5.4 is on it's way and it's bringing some fixes for major
  pain points.
Discussion


                        Questions?
                        Comments?

     PHP Doesn't Suck



Please be gentle.

Contenu connexe

Tendances

8 Things to Do Before You Manage Your Boss
8 Things to Do Before You Manage Your Boss8 Things to Do Before You Manage Your Boss
8 Things to Do Before You Manage Your BossWiley
 
Ppt karaoke game
Ppt karaoke gamePpt karaoke game
Ppt karaoke gameTEss30
 
Epic 2 ppts
Epic 2 pptsEpic 2 ppts
Epic 2 pptsTEss30
 
PowerPoint Karaoke (Sample Presentation)
PowerPoint Karaoke (Sample Presentation)PowerPoint Karaoke (Sample Presentation)
PowerPoint Karaoke (Sample Presentation)Amber Case
 
Death By Powerpoint
Death By PowerpointDeath By Powerpoint
Death By PowerpointRyan Flynn
 
My little pony
My little ponyMy little pony
My little ponyEverlight
 
Powerpoint Karaoke - ISTE Session
Powerpoint Karaoke - ISTE SessionPowerpoint Karaoke - ISTE Session
Powerpoint Karaoke - ISTE SessionJon Corippo
 
powerpoint karaoke
powerpoint karaokepowerpoint karaoke
powerpoint karaokenein geist
 
Best of Battle Decks 2
Best of Battle Decks 2Best of Battle Decks 2
Best of Battle Decks 2Mike Monteiro
 
How I got 2.5 Million views on Slideshare (by @nickdemey - Board of Innovation)
How I got 2.5 Million views on Slideshare (by @nickdemey - Board of Innovation)How I got 2.5 Million views on Slideshare (by @nickdemey - Board of Innovation)
How I got 2.5 Million views on Slideshare (by @nickdemey - Board of Innovation)Board of Innovation
 
Top Productivity Working Hacks by Jan Rezab
Top Productivity Working Hacks by Jan RezabTop Productivity Working Hacks by Jan Rezab
Top Productivity Working Hacks by Jan RezabJan Rezab
 
10 Reasons Why Successful Leaders Are Keeping a Journal
10 Reasons Why Successful Leaders Are Keeping a Journal10 Reasons Why Successful Leaders Are Keeping a Journal
10 Reasons Why Successful Leaders Are Keeping a JournalLouis-Xavier Lavallée
 
McCann Sydney PowerPoint Karaoke 2
McCann Sydney PowerPoint Karaoke 2McCann Sydney PowerPoint Karaoke 2
McCann Sydney PowerPoint Karaoke 2Frank Lang
 

Tendances (20)

8 Things to Do Before You Manage Your Boss
8 Things to Do Before You Manage Your Boss8 Things to Do Before You Manage Your Boss
8 Things to Do Before You Manage Your Boss
 
Chicken
ChickenChicken
Chicken
 
Ppt karaoke game
Ppt karaoke gamePpt karaoke game
Ppt karaoke game
 
Epic 2 ppts
Epic 2 pptsEpic 2 ppts
Epic 2 ppts
 
PowerPoint Karaoke (Sample Presentation)
PowerPoint Karaoke (Sample Presentation)PowerPoint Karaoke (Sample Presentation)
PowerPoint Karaoke (Sample Presentation)
 
PowerPoint Karaoke
PowerPoint KaraokePowerPoint Karaoke
PowerPoint Karaoke
 
Death By Powerpoint
Death By PowerpointDeath By Powerpoint
Death By Powerpoint
 
Powerpoint Karaoke, Maputo 2015
Powerpoint Karaoke, Maputo 2015Powerpoint Karaoke, Maputo 2015
Powerpoint Karaoke, Maputo 2015
 
My little pony
My little ponyMy little pony
My little pony
 
Powerpoint Karaoke - ISTE Session
Powerpoint Karaoke - ISTE SessionPowerpoint Karaoke - ISTE Session
Powerpoint Karaoke - ISTE Session
 
powerpoint karaoke
powerpoint karaokepowerpoint karaoke
powerpoint karaoke
 
Best of Battle Decks 2
Best of Battle Decks 2Best of Battle Decks 2
Best of Battle Decks 2
 
How I got 2.5 Million views on Slideshare (by @nickdemey - Board of Innovation)
How I got 2.5 Million views on Slideshare (by @nickdemey - Board of Innovation)How I got 2.5 Million views on Slideshare (by @nickdemey - Board of Innovation)
How I got 2.5 Million views on Slideshare (by @nickdemey - Board of Innovation)
 
Top Productivity Working Hacks by Jan Rezab
Top Productivity Working Hacks by Jan RezabTop Productivity Working Hacks by Jan Rezab
Top Productivity Working Hacks by Jan Rezab
 
10 Reasons Why Successful Leaders Are Keeping a Journal
10 Reasons Why Successful Leaders Are Keeping a Journal10 Reasons Why Successful Leaders Are Keeping a Journal
10 Reasons Why Successful Leaders Are Keeping a Journal
 
Death by PowerPoint
Death by PowerPointDeath by PowerPoint
Death by PowerPoint
 
McCann Sydney PowerPoint Karaoke 2
McCann Sydney PowerPoint Karaoke 2McCann Sydney PowerPoint Karaoke 2
McCann Sydney PowerPoint Karaoke 2
 
Designing Presentations
Designing PresentationsDesigning Presentations
Designing Presentations
 
powerpoint karaoke
powerpoint karaokepowerpoint karaoke
powerpoint karaoke
 
Death by Power Point
Death by Power PointDeath by Power Point
Death by Power Point
 

En vedette

Unit testing in PHP
Unit testing in PHPUnit testing in PHP
Unit testing in PHPLee Boynton
 
Erin elchesyn the digestive system
Erin elchesyn the digestive systemErin elchesyn the digestive system
Erin elchesyn the digestive systemMrs Seo
 
Essentials of corr med presentation -understanding the legal enviroment in co...
Essentials of corr med presentation -understanding the legal enviroment in co...Essentials of corr med presentation -understanding the legal enviroment in co...
Essentials of corr med presentation -understanding the legal enviroment in co...Zoey Lovell
 
Jack murrell wright digestive system
Jack murrell wright digestive systemJack murrell wright digestive system
Jack murrell wright digestive systemMrs Seo
 
SharingEconomy: The Buzzword of the Moment
SharingEconomy: The Buzzword of the MomentSharingEconomy: The Buzzword of the Moment
SharingEconomy: The Buzzword of the MomentSimone Cicero
 
The secret order of the illuminati
The secret order of the illuminatiThe secret order of the illuminati
The secret order of the illuminatiRiaz Zalil
 
ppt on Industrial policy
ppt on Industrial policyppt on Industrial policy
ppt on Industrial policyCodelaxy Ltd.
 
A Generic Apple "Steve Jobs" style Keynote Address Presentation
A Generic Apple "Steve Jobs" style Keynote Address PresentationA Generic Apple "Steve Jobs" style Keynote Address Presentation
A Generic Apple "Steve Jobs" style Keynote Address PresentationThe App Store Chronicle
 
Illuminati presentation
Illuminati presentationIlluminati presentation
Illuminati presentation04burkem
 
Buzzword Bingo 2017
Buzzword Bingo 2017Buzzword Bingo 2017
Buzzword Bingo 2017ron mader
 
How to think like a startup v3
How to think like a startup v3How to think like a startup v3
How to think like a startup v3Loic Le Meur
 
Industrial policy.ppt
Industrial policy.pptIndustrial policy.ppt
Industrial policy.pptShikha Gupta
 
Steve Jobs Inspirational Quotes
Steve Jobs Inspirational QuotesSteve Jobs Inspirational Quotes
Steve Jobs Inspirational QuotesInsideView
 
Shall we play a game?
Shall we play a game?Shall we play a game?
Shall we play a game?Maciej Lasyk
 
The Future of Everything
The Future of EverythingThe Future of Everything
The Future of EverythingCharbel Zeaiter
 
Hype vs. Reality: The AI Explainer
Hype vs. Reality: The AI ExplainerHype vs. Reality: The AI Explainer
Hype vs. Reality: The AI ExplainerLuminary Labs
 
Designing Teams for Emerging Challenges
Designing Teams for Emerging ChallengesDesigning Teams for Emerging Challenges
Designing Teams for Emerging ChallengesAaron Irizarry
 

En vedette (20)

Unit testing in PHP
Unit testing in PHPUnit testing in PHP
Unit testing in PHP
 
Random powerpoint
Random powerpointRandom powerpoint
Random powerpoint
 
Erin elchesyn the digestive system
Erin elchesyn the digestive systemErin elchesyn the digestive system
Erin elchesyn the digestive system
 
Wwe john cena
Wwe john cenaWwe john cena
Wwe john cena
 
Essentials of corr med presentation -understanding the legal enviroment in co...
Essentials of corr med presentation -understanding the legal enviroment in co...Essentials of corr med presentation -understanding the legal enviroment in co...
Essentials of corr med presentation -understanding the legal enviroment in co...
 
Jack murrell wright digestive system
Jack murrell wright digestive systemJack murrell wright digestive system
Jack murrell wright digestive system
 
SharingEconomy: The Buzzword of the Moment
SharingEconomy: The Buzzword of the MomentSharingEconomy: The Buzzword of the Moment
SharingEconomy: The Buzzword of the Moment
 
The secret order of the illuminati
The secret order of the illuminatiThe secret order of the illuminati
The secret order of the illuminati
 
ppt on Industrial policy
ppt on Industrial policyppt on Industrial policy
ppt on Industrial policy
 
A Generic Apple "Steve Jobs" style Keynote Address Presentation
A Generic Apple "Steve Jobs" style Keynote Address PresentationA Generic Apple "Steve Jobs" style Keynote Address Presentation
A Generic Apple "Steve Jobs" style Keynote Address Presentation
 
Illuminati presentation
Illuminati presentationIlluminati presentation
Illuminati presentation
 
Buzzword Bingo 2017
Buzzword Bingo 2017Buzzword Bingo 2017
Buzzword Bingo 2017
 
How to think like a startup v3
How to think like a startup v3How to think like a startup v3
How to think like a startup v3
 
Industrial policy.ppt
Industrial policy.pptIndustrial policy.ppt
Industrial policy.ppt
 
Steve Jobs Inspirational Quotes
Steve Jobs Inspirational QuotesSteve Jobs Inspirational Quotes
Steve Jobs Inspirational Quotes
 
The Build Trap
The Build TrapThe Build Trap
The Build Trap
 
Shall we play a game?
Shall we play a game?Shall we play a game?
Shall we play a game?
 
The Future of Everything
The Future of EverythingThe Future of Everything
The Future of Everything
 
Hype vs. Reality: The AI Explainer
Hype vs. Reality: The AI ExplainerHype vs. Reality: The AI Explainer
Hype vs. Reality: The AI Explainer
 
Designing Teams for Emerging Challenges
Designing Teams for Emerging ChallengesDesigning Teams for Emerging Challenges
Designing Teams for Emerging Challenges
 

Similaire à PHP Doesn't Suck

Similaire à PHP Doesn't Suck (20)

Article 01 What Is Php
Article 01   What Is PhpArticle 01   What Is Php
Article 01 What Is Php
 
Winter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHPWinter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHP
 
Winter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHPWinter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHP
 
Fall 2011 PHP Class - Session 1
Fall 2011 PHP Class - Session 1Fall 2011 PHP Class - Session 1
Fall 2011 PHP Class - Session 1
 
Php
PhpPhp
Php
 
Upstate CSCI 450 PHP Chapters 5, 12, 13
Upstate CSCI 450 PHP Chapters 5, 12, 13Upstate CSCI 450 PHP Chapters 5, 12, 13
Upstate CSCI 450 PHP Chapters 5, 12, 13
 
01 Php Introduction
01 Php Introduction01 Php Introduction
01 Php Introduction
 
Php tutorial
Php tutorialPhp tutorial
Php tutorial
 
Php tutorial
Php tutorialPhp tutorial
Php tutorial
 
Php tutorial
Php tutorialPhp tutorial
Php tutorial
 
Php tutorial
Php tutorialPhp tutorial
Php tutorial
 
Php mysql
Php mysqlPhp mysql
Php mysql
 
Php tizag tutorial
Php tizag tutorialPhp tizag tutorial
Php tizag tutorial
 
PHP learning
PHP learningPHP learning
PHP learning
 
php_tizag_tutorial
php_tizag_tutorialphp_tizag_tutorial
php_tizag_tutorial
 
Php tizag tutorial
Php tizag tutorial Php tizag tutorial
Php tizag tutorial
 
php_tizag_tutorial
php_tizag_tutorialphp_tizag_tutorial
php_tizag_tutorial
 
Php tizag tutorial
Php tizag tutorialPhp tizag tutorial
Php tizag tutorial
 
PHP - Introduction to PHP Fundamentals
PHP -  Introduction to PHP FundamentalsPHP -  Introduction to PHP Fundamentals
PHP - Introduction to PHP Fundamentals
 
Using PHP
Using PHPUsing PHP
Using PHP
 

Dernier

ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024The Digital Insurer
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...apidays
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfOverkill Security
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 

Dernier (20)

ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 

PHP Doesn't Suck

  • 2. Who are you? John Hobbs - Developer at What Cheer - @jmhobbs - https://github.com/jmhobbs - http://velvetcache.org/ PHP Doesn't Suck
  • 3. PHP Sucks T_PAAMAYIM_NEKUDOTAYIM get_class() => gettype() PHPE9568F34-D428-11d2-A769-00AA001ACF42 sort( &$array ) www.phpsadness.com PHP Doesn't Suck
  • 4. PHP Sucks Low Barrier To Entry Weak Community Google-Copy-Paste NIH “In the end I think you will find that your homegrown small framework has saved you time and aggravation and you end up with a better product.” - Rasmus http://toys.lerdorf.com/archives/38-The-no-framework-PHP-MVC-framework.html PHP Doesn't Suck
  • 5. I can write terrible code in any language. - Me PHP Doesn't Suck
  • 6. Making It Not Suck Learn the Language http://php.net/manual PHP Doesn't Suck
  • 7. Making It Not Suck Test Your Code http://www.simpletest.org/ http://www.phpunit.de/ http://qa.php.net/write-test.php PHP Doesn't Suck
  • 8. Making It Not Suck NO LIVE EDITS (mostly) CAPISTRANO WORKS FINE WITH PHP PHP Doesn't Suck
  • 9. Making It Not Suck Share & Be shared Github PSR-0 (http://tinyurl.com/yh6jydd) PHP Doesn't Suck
  • 10. Making It Not Suck Have A Style http://www.mediawiki.org/wiki/Manual:Coding_conventions PHP Doesn't Suck
  • 11. Making It Not Suck Try The REPL jmhobbs@Cordelia:~$ phpsh Starting php type 'h' or 'help' to see instructions & features php> echo "Oh hai!"; Oh hai! php> include "test.php"; php> whoa(); lol, functions!1! php> jmhobbs@Cordelia:~$ http://www.phpsh.org/ PHP Doesn't Suck
  • 12. Making It Not Suck Read Code (Including other languages!) PHP Doesn't Suck
  • 13. USE A FRAMEWORK (Hint: Not Zend) PHP Doesn't Suck
  • 14. Use A Framework - HMVC - Useful helpers - Super flexible - Great modules system - Great modules http://kohanaframework.org/ PHP Doesn't Suck
  • 15. Use A Framework namespace appcontrollers; class PostsController extends lithiumactionController { public function index() { return array('foo' => 'bar', 'title' => 'Posts'); } } http://lithify.me/ PHP Doesn't Suck
  • 16. Use A Framework Skunk // Initialize $s = new Skunk(); // Add a route $s->get( '/hi(/<name>)', function ( &$s, $name = “world” ) { $s->body = “Hello $name!"; } ); // Run it! $s->run(); https://github.com/jmhobbs/Skunk PHP Doesn't Suck
  • 18. It's Getting Better 5.4 - http://www.php.net/manual/en/language.oop5.traits.php (Traits => Mixins) - http://svn.php.net/viewvc?view=revision&revision=313641 (Short Array Syntax: [ “a” => “b” ]) - http://news.php.net/php.internals/55293 (SVN => git) PHP Doesn't Suck
  • 19. Discussion Questions? Comments? PHP Doesn't Suck
  • 20. PHP Doesn't Suck This is a presentation about PHP. If you are looking for a fight, leave now.
  • 21. Who are you? John Hobbs - Developer at What Cheer - @jmhobbs - https://github.com/jmhobbs - http://velvetcache.org/ PHP Doesn't Suck I'm John Hobbs. I make fancy websites at What Cheer. I have a twitter and a github and I blog but no one reads it. If I'm known for anything on the Internet it's Beef Taco. Just google Beef Taco and it's the top item. I kid you not.
  • 22. PHP Sucks T_PAAMAYIM_NEKUDOTAYIM get_class() => gettype() PHPE9568F34-D428-11d2-A769-00AA001ACF42 sort( &$array ) www.phpsadness.com PHP Doesn't Suck PHP Sucks. The language itself has some fundamental flaws that crept in early in it's life and have not been excised yet, mostly for compatibility issues. Crappy error messages. Inconsistent naming conventions. Stupid “features” In place array sorts. There is a decent chunk of these, phpsadness.com is a good place to read and track them. PHP has a weird history of full rewrites, but it's held onto backwards compatibility through a lot of them. Zend (4/5) is a decent engine, but the old cruft is lame.
  • 23. PHP Sucks Low Barrier To Entry Weak Community Google-Copy-Paste NIH “In the end I think you will find that your homegrown small framework has saved you time and aggravation and you end up with a better product.” - Rasmus http://toys.lerdorf.com/archives/38-The-no-framework-PHP-MVC-framework.html PHP Doesn't Suck Why else does PHP suck? Well, it runs everywhere. It's billed as an easy language to learn, fast. And it is, if you want to write crappy code. The community is, compared to Python and Ruby, fragmented and not sophisticated. Testing is a big problem here. Ever used a phpt? Because PHP is everywhere, you can Google for anything and get some code. Too often people don't read it, they just copy-paste. So they lose a chance to learn and also integrate crappy code. There also seems to be a serious not-invented-here syndrome in PHP. This includes Rasmus. Don't listen to Rasmus.
  • 24. I can write terrible code in any language. - Me PHP Doesn't Suck I can write terrible code in any language. The point is that the quality of the code has a lot to do with who is writing it, and how much they understand. Don't blame everything on the language. So how can we write better PHP?
  • 25. Making It Not Suck Learn the Language http://php.net/manual PHP Doesn't Suck Learn the language. It sounds simple, but I bet there is lots of stuff that even good PHP programmers don't know about PHP. Has anyone here ever written a __clone method? How much of the manual have you read? Have you ever compiled an extension? Written one?
  • 26. Making It Not Suck Test Your Code http://www.simpletest.org/ http://www.phpunit.de/ http://qa.php.net/write-test.php PHP Doesn't Suck Test your code. This is a huuuuge deal. There are good testing tools for PHP, use them. I like SimpleTest, but it's a personal choice, and an easy one. TDD makes you think, something PHP doesn't always make you do. Something else that unit testing does is force you to separate code. PHP is it's own template language, so it's super easy to mix business logic with presentation. Don't. Testing will help.
  • 27. Making It Not Suck NO LIVE EDITS (mostly) CAPISTRANO WORKS FINE WITH PHP PHP Doesn't Suck No live edits. Stay off of production. I admit, I don't use version control on some stuff. One off tools and pages, wordpress blogs, stuff that doesn't really matter. If you are writing an app or a library, you should be using version control and running deployments after all your tests pass. Capistrano gets along fine with PHP, and if you would rather you can use phing and other tools. PHP tempts you to edit live in production. Resist.
  • 28. Making It Not Suck Share & Be shared Github PSR-0 (http://tinyurl.com/yh6jydd) PHP Doesn't Suck Share your code, and use shared code. You don't have to come up with your own version of a lot of things. But don't just blindly copy code or use any old module. Look at the code and make a judgment call. It's okay to fork or rewrite if it's in bad shape, but then share it back to the community! If you are writing a library, be compatible. If it's generic, there are naming conventions like PSR-0. (I admit I am bad at being compatible)
  • 29. Making It Not Suck Have A Style http://www.mediawiki.org/wiki/Manual:Coding_conventions PHP Doesn't Suck Have a style you stick to. Being clear and consistent in your code is essential, no sloppy formatting. Bad style is endemic of google-copy-paste code. If you are working on someone else's project, use their style before you make a pull request. It's polite, it's clean it's essential. I use a variant of MediaWiki's conventions.
  • 30. Making It Not Suck Try The REPL jmhobbs@Cordelia:~$ phpsh Starting php type 'h' or 'help' to see instructions & features php> echo "Oh hai!"; Oh hai! php> include "test.php"; php> whoa(); lol, functions!1! php> jmhobbs@Cordelia:~$ http://www.phpsh.org/ PHP Doesn't Suck Other languages have a great REPL. PHP, not so much. Luckily we have a good one from Facebook, written mostly in Python actually. Get it and give it a shot. When you forget argument ordering it's often easier to try it in the shell than to go look it up on php.net.
  • 31. Making It Not Suck Read Code (Including other languages!) PHP Doesn't Suck Actually READ the code you use. This one is a big one. Read other people's code, the good and the bad. Identify what you like and what you don't like about other people's code. Try out new things you find in other peoples code. And don't be just a PHP programmer. Read and write some other languages, Python, Ruby, whatever. I am convinced the more well read you are, in any language, the better you will be as a programmer.
  • 32. USE A FRAMEWORK (Hint: Not Zend) PHP Doesn't Suck Use a framework. A framework will make you organize your code within a set of conventions. Which conventions don't matter as much as the fact that they exist. I recommend not Zend because it frightens me. Learn your framework well. Read it's core, submit patches, be involved. Here are few examples of frameworks:
  • 33. Use A Framework - HMVC - Useful helpers - Super flexible - Great modules system - Great modules http://kohanaframework.org/ PHP Doesn't Suck I'm a Kohana user. It's not all roses though, there are no migrations either, which is gross. Development moves fast, and breaks api a lot. It's managed with versioning though, and there is plenty of backporting and bug fixes.
  • 34. Use A Framework namespace appcontrollers; class PostsController extends lithiumactionController { public function index() { return array('foo' => 'bar', 'title' => 'Posts'); } } http://lithify.me/ PHP Doesn't Suck Another cool one is Lithium. It's very “leading edge” and uses namespaces like they are going out of style.
  • 35. Use A Framework Skunk // Initialize $s = new Skunk(); // Add a route $s->get( '/hi(/<name>)', function ( &$s, $name = “world” ) { $s->body = “Hello $name!"; } ); // Run it! $s->run(); https://github.com/jmhobbs/Skunk PHP Doesn't Suck Finally I included a Sinatra and Bottle style framework that I wrote. I wouldn't necessarily recommend using Skunk, but it's a good example a little, single file framework with an interesting API and feel.
  • 36. So... PHP Doesn't Suck So. Those are my thoughts on how to write better PHP. As for the language itself...
  • 37. It's Getting Better 5.4 - http://www.php.net/manual/en/language.oop5.traits.php (Traits => Mixins) - http://svn.php.net/viewvc?view=revision&revision=313641 (Short Array Syntax: [ “a” => “b” ]) - http://news.php.net/php.internals/55293 (SVN => git) PHP Doesn't Suck It's getting better. 5.4 is on it's way and it's bringing some fixes for major pain points.
  • 38. Discussion Questions? Comments? PHP Doesn't Suck Please be gentle.