Better Perl Practices

J
Jay ShirleySoftware Developer at Infinity Interactive
Better Programming
      Practices
             
  When Best isn’t good enough
Better Programming Practices




                        About Me
         • Jay Shirley, jshirley@gmail.com
         • On IRC (a lot), irc.perl.org as ‘jshirley’
         • IT Director, National Auto Sport
         • Co-Founder of www.coldhardcode.com
         • Opinionated
Better Programming Practices




                               Better

         • Useful techniques for better applications
         • Best is for Knuth, we build applications
Better Programming Practices




                               Why?

         • We all complain
         • Sometimes we whine
         • JFDI
Better Programming Practices




     Step 1: You’re Wrong

         • Hopefully just the first time
         • Better to be wrong and learn, than to
             never learn.
Better Programming Practices




                  Step 2: Learn

         • Accept you will not be right the first time
         • Still give a lot of thought
         • Make your second attempt stick
Better Programming Practices




            Step 3: Be Happy

         • Don’t be perfect
         • Perfect your technique
         • Be Happy (Or at least your boss will be)
Better Programming Practices




                               Design

         • Goals!
         • Understand your role
           • Don’t over-extend
           • Don’t let others, either.
Better Programming Practices




                               Testing

         • Is not a goal
           • Don’t design tests, design API then test
         • Coverage is not a valuable metric of
             completeness or progression
Better Programming Practices




                     Refactoring

         • This is inevitable
         • Make it count
         • Learn!
Better Programming Practices




            It’s about the API

         • Make it simple on yourself
         • Expose flaws in tests
         • Impress your boss
Better Programming Practices




              These are good

         • We can all agree: Design, Test, Refactor
         • But we never do them.
         • Habits!
Better Programming Practices




        Establishing Habits

         • Make mole hills out of mountains
         • Make it easier to do the right thing
         • Make it harder to do the wrong thing
Better Programming Practices




           How to get habits

         • Make things easier as time goes on
         • Make things better as time goes on
         • Make people happier as time goes on
         • It’s about the future
Better Programming Practices




           Habits in Practice

         • The Hows:
           • How to (test|design|refactor)
Better Programming Practices




                     How to test
         • Schema classes
           • SQLite
           • Unit Tests
         • Applications
           • Test::Class, Test::FITesque
           • Workflow Tests
Better Programming Practices




               How not to test


         • ok(1, ‘it works’);
Better Programming Practices




                               Testing

            • Lots of Good Tools:
              • Test::Class
              • Email::Send::Test
              • Test::WWW::Mechanize
Better Programming Practices




                How to design

         • First, get something working
           • Syntax Sketch
           • Establish individual goals (methods)
         •
Better Programming Practices




                     Not Unique

         • You are probably not the first to solve the
             problem
         • Find similar functionality
Better Programming Practices




                           Iterative

         • Simmer & Reduce
         • That is your secret sauce
         • Software is fluid, not stone
Better Programming Practices




              Clever Japanese


         •
Better Programming Practices




             Web != Desktop

         • You control the environment
         • You control the deployment
         • Slow? Scalability! Add another server.
         • Apple would kill to have this
Better Programming Practices




         Better Applications

         • Your software is only as good as its tools
         • Don’t reinvent wheels
Better Perl Practices




                        Better Perl
Better Programming Practices




                 Simple Syntax

           my $foo = $request->params->{foo};
           my $bar = $request->params->{bar};
Better Programming Practices




             good code, type

           my $data = $request->params;
           my $foo = $data->{foo};
           my $bar = $data->{bar};
Better Programming Practices




             Type Less is not

           my $s=($api?$api->params:$request-
           >params)||$request->params;
           ${“__PACKAGE__::$_”}=($s->{$_})
            for keys%$s;
Better Programming Practices




            warnings & strict

           use warnings;
           use strict;
Better Programming Practices




             good code, type

           my $data = {map{$_=>$request-
           >params->{$_}}@keys
           my $foo = $data->{foo};
           my $bar = $data->{bar};
Better Programming Practices




                      Test::Class

         • This is the best test package
         • Don’t take my word for it, chromatic and
             Ovid have written a ton on it at http://
             modernperlbooks.com/
Better Perl Practices




              I failed 3 times
Better Programming Practices




                               Why?

         • Package based testing
           • Wrap each package in a Test:: package
           • More flexible than .t files (code reuse)
         • Better configuration for testing
Better Programming Practices




                   Base Classes

         • Common Functionality
         • Easy to change
         • Awesome in Perl
Better Programming Practices




             Find Dierences
Better Programming Practices




          Do More with Less

         • Make code better
         • Write less
         • Next step: use Moose;
Better Programming Practices




                      Moose 101

         • This is not a Moose talk
         • Perl API to Perl OO
         • Keep it Simple
Better Programming Practices




         Use what you need

         • Too many OO-API modules on CPAN
         • Moose does most of it
         • Don’t need it all, just ‘use Mouse;’
Better Programming Practices




                      Use Config

         • Configure everything you can think of
         • You’ll figure out how to do it easily
         • The more you do it, the easier it is
         • (MooseX::SimpleConfig)
Better Programming Practices




       Favorite Recipe Ever
           with 'MooseX::SimpleConfig';
           with 'MooseX::Getopt';
           has +configfile = (
                default =
                  (
                    grep { defined $_ and -f $_ }
                    @places_to_look
                   )[0]||””
           );
Better Programming Practices




                         To Recap

         • Write less code (Base classes)
         • Test where it matters
         • Use Moose (Write less code)
           • Config!
Better Programming Practices




                               Moose


         • Yay, we have time for this!
Better Programming Practices




                      Class::MOP

         • CLOS for Perl 5.
         • 20 year old Lisp technology.
         • Moose is syntactic sugar.
Better Programming Practices




        Moose = Better API

         • Better Accessors
         • Lazy Builders
         • Less Code
         • More Tests
Better Programming Practices




          Not Invented Here
         • Moose is better than what you would
             write
            • It is written by many people
            • It has a huge test suite
         • You can do more with Moose
Better Programming Practices




                               Slow?
         • Moose is not slow
         • Moose is slower
         • Mostly Startup
           • Linear Scalability (constant time)
           • Use more hardware
Better Programming Practices




                     Incremental

         • Add where needed
         • Refactor when the time is right
         • “Progressive Enhancement”
Better Programming Practices




                       Immediate

         • Type Checking
           • (Yes, it still is Perl)
         • ‘ArrayRef[MyObject]’ works in Moose
Better Programming Practices




          A Word of Caution

         • Everything will look like a Role
         • That’s normal
         • Resist the temptation, then build a role.
1 of 49

Recommended

Encouraging Agile Discipline by
Encouraging Agile DisciplineEncouraging Agile Discipline
Encouraging Agile DisciplinePatchSpace Ltd
594 views66 slides
Good programming practices updated by
Good programming practices updatedGood programming practices updated
Good programming practices updatedAgha Dostain
679 views16 slides
Coding standards for java by
Coding standards for javaCoding standards for java
Coding standards for javamaheshm1206
9.1K views20 slides
C# conventions & good practices by
C# conventions & good practicesC# conventions & good practices
C# conventions & good practicesTan Tran
15.9K views19 slides
Adobe Photoshop Basics - Session 1 by
Adobe Photoshop Basics - Session 1Adobe Photoshop Basics - Session 1
Adobe Photoshop Basics - Session 1xneptune
39.7K views15 slides
Coding Best Practices by
Coding Best PracticesCoding Best Practices
Coding Best Practicesmh_azad
6.6K views24 slides

More Related Content

Similar to Better Perl Practices

Mlw by
MlwMlw
Mlwoscon2007
392 views34 slides
Scripting Recipes for Testers by
Scripting Recipes for TestersScripting Recipes for Testers
Scripting Recipes for TestersAdam Goucher
821 views45 slides
Test Driven Development With YUI Test (Ajax Experience 2008) by
Test Driven Development With YUI Test (Ajax Experience 2008)Test Driven Development With YUI Test (Ajax Experience 2008)
Test Driven Development With YUI Test (Ajax Experience 2008)Nicholas Zakas
31.1K views73 slides
PHX Session #3 - "It Works on My Machine!" Closing the Loop Between Developme... by
PHX Session #3 - "It Works on My Machine!" Closing the Loop Between Developme...PHX Session #3 - "It Works on My Machine!" Closing the Loop Between Developme...
PHX Session #3 - "It Works on My Machine!" Closing the Loop Between Developme...Steve Lange
600 views21 slides
Week7 by
Week7Week7
Week7Rich Price
139 views11 slides
Dynamic Languages In The Enterprise (4developers march 2009) by
Dynamic Languages In The Enterprise (4developers march 2009)Dynamic Languages In The Enterprise (4developers march 2009)
Dynamic Languages In The Enterprise (4developers march 2009)Ivo Jansch
1.2K views49 slides

Similar to Better Perl Practices(20)

Scripting Recipes for Testers by Adam Goucher
Scripting Recipes for TestersScripting Recipes for Testers
Scripting Recipes for Testers
Adam Goucher821 views
Test Driven Development With YUI Test (Ajax Experience 2008) by Nicholas Zakas
Test Driven Development With YUI Test (Ajax Experience 2008)Test Driven Development With YUI Test (Ajax Experience 2008)
Test Driven Development With YUI Test (Ajax Experience 2008)
Nicholas Zakas31.1K views
PHX Session #3 - "It Works on My Machine!" Closing the Loop Between Developme... by Steve Lange
PHX Session #3 - "It Works on My Machine!" Closing the Loop Between Developme...PHX Session #3 - "It Works on My Machine!" Closing the Loop Between Developme...
PHX Session #3 - "It Works on My Machine!" Closing the Loop Between Developme...
Steve Lange600 views
Dynamic Languages In The Enterprise (4developers march 2009) by Ivo Jansch
Dynamic Languages In The Enterprise (4developers march 2009)Dynamic Languages In The Enterprise (4developers march 2009)
Dynamic Languages In The Enterprise (4developers march 2009)
Ivo Jansch1.2K views
Session #3: "It Works on My Machine!" Closing the Loop Between Development & ... by Steve Lange
Session #3: "It Works on My Machine!" Closing the Loop Between Development & ...Session #3: "It Works on My Machine!" Closing the Loop Between Development & ...
Session #3: "It Works on My Machine!" Closing the Loop Between Development & ...
Steve Lange765 views
Unit Test Your Database by David Wheeler
Unit Test Your DatabaseUnit Test Your Database
Unit Test Your Database
David Wheeler6.5K views
Selected Sessions from RailsConf 2007 by Jerry Richardson
Selected Sessions from RailsConf 2007Selected Sessions from RailsConf 2007
Selected Sessions from RailsConf 2007
Jerry Richardson508 views
How the JDeveloper team test JDeveloper at UKOUG'08 by kingsfleet
How the JDeveloper team test JDeveloper at UKOUG'08How the JDeveloper team test JDeveloper at UKOUG'08
How the JDeveloper team test JDeveloper at UKOUG'08
kingsfleet1.6K views
Enterprise PHP Development - ZendCon 2008 by Ivo Jansch
Enterprise PHP Development - ZendCon 2008Enterprise PHP Development - ZendCon 2008
Enterprise PHP Development - ZendCon 2008
Ivo Jansch1.5K views
Enterprise PHP (php|works 2008) by Ivo Jansch
Enterprise PHP (php|works 2008)Enterprise PHP (php|works 2008)
Enterprise PHP (php|works 2008)
Ivo Jansch8.6K views
When To Use Ruby On Rails by dosire
When To Use Ruby On RailsWhen To Use Ruby On Rails
When To Use Ruby On Rails
dosire29K views
Rails Is From Mars Ruby Is From Venus Presentation 1 by railsconf
Rails Is From Mars  Ruby Is From Venus Presentation 1Rails Is From Mars  Ruby Is From Venus Presentation 1
Rails Is From Mars Ruby Is From Venus Presentation 1
railsconf935 views

Recently uploaded

Evolving the Network Automation Journey from Python to Platforms by
Evolving the Network Automation Journey from Python to PlatformsEvolving the Network Automation Journey from Python to Platforms
Evolving the Network Automation Journey from Python to PlatformsNetwork Automation Forum
12 views21 slides
Design Driven Network Assurance by
Design Driven Network AssuranceDesign Driven Network Assurance
Design Driven Network AssuranceNetwork Automation Forum
15 views42 slides
Zero to Automated in Under a Year by
Zero to Automated in Under a YearZero to Automated in Under a Year
Zero to Automated in Under a YearNetwork Automation Forum
12 views23 slides
Data Integrity for Banking and Financial Services by
Data Integrity for Banking and Financial ServicesData Integrity for Banking and Financial Services
Data Integrity for Banking and Financial ServicesPrecisely
12 views26 slides
Vertical User Stories by
Vertical User StoriesVertical User Stories
Vertical User StoriesMoisés Armani Ramírez
12 views16 slides

Recently uploaded(20)

Data Integrity for Banking and Financial Services by Precisely
Data Integrity for Banking and Financial ServicesData Integrity for Banking and Financial Services
Data Integrity for Banking and Financial Services
Precisely12 views
SAP Automation Using Bar Code and FIORI.pdf by Virendra Rai, PMP
SAP Automation Using Bar Code and FIORI.pdfSAP Automation Using Bar Code and FIORI.pdf
SAP Automation Using Bar Code and FIORI.pdf
AMAZON PRODUCT RESEARCH.pdf by JerikkLaureta
AMAZON PRODUCT RESEARCH.pdfAMAZON PRODUCT RESEARCH.pdf
AMAZON PRODUCT RESEARCH.pdf
JerikkLaureta19 views
handbook for web 3 adoption.pdf by Liveplex
handbook for web 3 adoption.pdfhandbook for web 3 adoption.pdf
handbook for web 3 adoption.pdf
Liveplex22 views
ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ... by Jasper Oosterveld
ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ...ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ...
ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ...
PharoJS - Zürich Smalltalk Group Meetup November 2023 by Noury Bouraqadi
PharoJS - Zürich Smalltalk Group Meetup November 2023PharoJS - Zürich Smalltalk Group Meetup November 2023
PharoJS - Zürich Smalltalk Group Meetup November 2023
Noury Bouraqadi126 views
Piloting & Scaling Successfully With Microsoft Viva by Richard Harbridge
Piloting & Scaling Successfully With Microsoft VivaPiloting & Scaling Successfully With Microsoft Viva
Piloting & Scaling Successfully With Microsoft Viva
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N... by James Anderson
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...
James Anderson66 views
Business Analyst Series 2023 - Week 3 Session 5 by DianaGray10
Business Analyst Series 2023 -  Week 3 Session 5Business Analyst Series 2023 -  Week 3 Session 5
Business Analyst Series 2023 - Week 3 Session 5
DianaGray10237 views
Special_edition_innovator_2023.pdf by WillDavies22
Special_edition_innovator_2023.pdfSpecial_edition_innovator_2023.pdf
Special_edition_innovator_2023.pdf
WillDavies2217 views

Better Perl Practices

Editor's Notes

  1. Best is theoretical, it is something that cannot truly be reached because you can’t ever really know. It is an impossible goal, so lets just be better. We can build applications better, we know this because we can look at how other people do things.
  2. Even people who do things better than others can still be better. I know this because I’ve known people with very good practices still complain about shortcomings. Whether it is lacking test coverage, QA, staging, there is usually something missing and sometimes the complaints turn to whine. Well, we’re developers. We fix problems, right? So just fix it.
  3. When you look backwards, there are a lot of moments where you can point out flaws. Either your own or others, but this is very important. When you do this, you can learn and try to think of ways to do things better. Better yet, look at what other people have done. This is where the Perl Community (p5 porters, CPAN) really shines, they have all these tools built for you. Let them make the mistakes, and you learn.
  4. After acknowledging your failures, the next step is to analyze your next attempt at a problem. This is where studying other people works, but you have to get rid of the Not Invented Here attitude.
  5. Dropping all that, accepting your own limitations and doing better will make you happy. It will make you happy because you’re not trying to pick up a mountain. You’re simply enhancing something you’ve always done. If you start jogging, you don’t run a marathon. Start running a half kilometer at a time and work your way up. Perfect your technique, tempo, strategies. This all falls into 3 concepts of what constitutes “Software Development”.
  6. The first, very easy and very vague. The best way to enhance your strategy is to do an initial look at design. Design is 100% about goals. Defining your goals in your design step means your implementation will be complete, and hopefully robust. Another aspect of design is figuring out your role in the project. If you’re not a frontend guy, don’t venture into that territory. It’s hard to let go of some control, but you really can’t do it all. Design what falls in your realm, set those goals, and let other do the same.
  7. Testing is equally important, but testing happens iteratively and as time goes on your code progresses in maturity; your tests will increase in quality and coverage. A test without a design isn’t going to do much more than tell you what you already know. Another point is to not get fixated on code coverage., At least during iterative development phases, it is better to work on testing your API and not focus on code coverage. The reason is simple, in the beginning of a project a percentage of the code initially written will not be there at the end. This is refactoring.
  8. Yes, you will have to refactor code. This is why you have to accept your flaws, because your code is flawed. The first invention of any solution isn’t the right one, but that’s ok because software development doesn’t have manufacturing costs associated with it. Enjoy deleting lots of code, do it often, just make sure you use something you can commit to frequently, preferably in branches (like git or svk).
  9. By building a solid and comprehensive API that is both simple to use, and makes sense, you’ll increase productivity and reduce bugs (less code rewriting) -- both things will make your boss much happier.
  10. In the charged world of Ruby vs Python vs Perl, or vi vs emacs, it is nice to have something to agree on. I hope we all can agree on these principles here. It’s very hard to say “No, you never refactor code.” or “Testing isn’t good!” It’s also very hard to do any of this in your own projects, and even harder to make them habits. That’s really the big problem here, since all of these points have been talked to death. So, habits.
  11. A lot of the burden falls on whoever maintains the development environment. For inspiration, look at the CPAN world. When a module goes to CPAN, you have Smokers (CPAN Testers) and a variety of other tools (such as Kwalitee) that help you write better code. These are -voluntary- tools built by others that you can use for your stuff. Email yourself statistics. Nag yourself, and you’ll want to do better. Setup a smoker, setup email reports and even kwalitee. Use custom perl critic specs. The CPAN world has better supportive tools than most software companies. At your company: change this! You can. Use CPAN as an inspiration, setup a smoker and a custom CPAN repository for your companies packages.
  12. You are the master of your own destiny, and when you establish a habit it becomes easy to drop if there isn’t an eventual reward if it is harder to maintain the habits otherwise. Having tools that help you keep them, such as Smokers and custom CPAN paths, aren’t enough. The real eventual reward for good development practices is doing your job in less time. That means you can write more fun code, or just read RSS feeds. At the very least, you can justify a raise easier.
  13. So, in practice, setup tools that nag you (Smokers, CPAN overlays, etc). Use iterative testing strategies to get better APIs, then ultimately write less code and do more. This is very general, though, and each environment is different. The hardest step is really the testing, and that’s because people either fixate on coverage metrics or some other detail.
  14. To make it easier, understand what your goal is. Testing is very different based on what you are testing. Schema classes are based on unit testing, figuring out what works and what doesn’t. What relationships need work, what is missing from your API (that is what your schema class really is) When you test an application, like a web application, you are testing workflow. The difference here is that your unit tests prove the underlying things work. Workflow tests make sure things like email verification works. [Catalyst Example]
  15. Tests are not to prove it works. Tests are to prove it doesn’t break, and that your API does what it should. The difference is in coverage, for the first step cover your API. After that work on complete code coverage Tests do not require more time to finish your project, unless you release really buggy software. I’ll buy a beer to anybody who can prove otherwise, unless you work for the Internet Explorer team.
  16. The next phase of testing after API testing and then basic coverage tests is going to be your acceptance tests. I like to think of these mostly as workflow tests make sure things like email verification works, so people can sign up. At this step, it is about aligning to specifications, the design goals and end-user acceptance (also good to count number of “clicks” and test for that) If the test is hard to write, it is hard for the user to use. Except you only have to write the test once.
  17. So, testing is really about incrementing the scope of what you look at. And first focusing on the API. The API is what you design, so testing and design go hand in hand. The first step of design is a rough idea of what you are after. Think of clay modeling, you don’t start with a finalized product, you shape it from rough forms. Software is, fortunately, nothing like that -- we can throw away and replace without looking at the full form. So, think about what you want. Come up with a nice API for it, and then start filling in the methods will practical code. If a method sucks, get rid of it. Your tests will help you while you flesh this out to figure out what you want. Something I usually do is write out an “Ideal syntax sketch” that just pretends all my API functions work. Often times this turns into my first API test.
  18. Now, after you get a rough idea of how your API should look you can think about backend implementations. This is far too similar to computer science courses where you code the methods giving the example, for this, I’m sorry. But it is a good way to do things. Fortunately, you can cheat. This is where you find CPAN modules that do the work, or some other algorithm on Google. CPAN is better, because you can steal the tests, too.
  19. So when you have your methods built in, your tests cover the API and you can handle (via unit tests) all the individual points of a project it is time to put everything together and build a real application. In terms of cooking, lower the heat and start simmering. This is the boring work, everything is done and you’re assembling it. Hopefully, every project gets more boring since you can rely on code reuse from previous projects. By having everything in tested methods, you’ll know what things can and cannot do. Also, if a method needs to be changed you can do that. With the API tests, nothing will break, unless your test is broken. It’s fluid, easily changed and very, very robust.
  20. The other thing, is that a lot of computer science ideas come from an age where desktops were the real applications, and web applications were simply scripts. I’m guessing that all but a few here are working on web applications that rival very large desktop applications. Good thing, because often times we don’t know how good we have it. We control everything. We know what hardware, and however much we want to complain about how certain browsers make our lives difficult, imagine trying to support a desktop application on unknown hardware, with a lot of other variables. I’ve done it. It’s terrible. Web applications are easier, even considering how hard Microsoft makes it. So, stop thinking about software in terms of a desktop application. We control everything, and even Microsoft provides free virtual PC images of all versions of IE. Release early, release often, don’t fear change because you have the tests to make it safe.
  21. So, the key to a solid application is to remember your environment, don’t overstep your goals, test as you go and finally, use the tools available. Definitely smoke servers and sandbox development environments. These tools will help you so much. And, please, don’t reinvent wheels. CPAN has most things out there, and the hardest part is finding out the right module, since there are usually 5. Getting involved in the community helps, but looking at the unit tests of the modules is a really good litmus test for how good a module is, and how attentive an author is to the packages.
  22. To move into Perl specific areas, lets go over what makes better Perl. Applying my previous concepts, a bit part of that is looking at what is out on CPAN now and making the best usage of it. For now, lets break this into two categories. The first is testing.
  23. A lot of times you see code that is highly repetitive, like fetching parameters out of a request or something. Even if this code is simple, if you find yourself typing the same chain of commands it isn’t very good.
  24. So, simplify it. Store a reference. You can spend the couple of bytes for the scalar reference to the hash. It saves you typing, and cleans up code.
  25. Just because your creating shorthand syntax, doesn’t mean it should turn into Golf. It’s the exact opposite, really. You’re typing less by creating more variables and then saving yourself a lot of trouble later. Don’t use stupid obscure code like this. Even if you can write it, you shouldn’t.
  26. That code example would die with strict turned on, as it should. Always code with warnings and strict turned on. If you don’t, you don’t know what your code is doing. People seem to have forgotten that back when C was the highest level language, you had to initialize all your variables or you got random data in them. Don’t introduce entropy into your programs, use strict to keep things sane.
  27. Then, if you get another source of input, you only have to change one type. This is a contrived example, but I’ve had similar things come up in practice. Being able to normalize your data into a very easy to query structure will save you in the long run. The key there is easy to query, you don’t have to obfuscate things.
  28. And for testing, use Test::Class if you don’t already have a testing system you know and love. Ovid has written a lot on using Test::Class at modernperlbooks.com, it is easy to follow and very very useful.
  29. I completed 3 different projects, with the intention of using Test::Class and better testing policies. I failed miserably up until the end of the final project. This involved me talking to people at length, and finally figuring out the “right way”. The big thing is that you do have to change the way you write your code slightly, but more importantly really change the way you think about your tests. They’re not encapsulated as tiny bite sized morsels, because then you end up with no good way to share your code between tests. Test::Class helps this, by applying some structure and a development pattern. It takes a few times to learn how to do it right. Ovid and Chromatic probably forgot that, but it’s ok to fail -- just take a moment after you fail to figure out why.
  30. With the learning curve on doing these tests right, it may not be obvious why you should use it. There are a lot of benefits, and it really is worth it. You won’t have the problem of copy and pasting code from one .t file to another. Test packages make more sense, you can mix and match them. You can extend them, and override them. Your tests will come together quicker, better and generally be friendlier.
  31. Base classes are also somewhat related to Test::Class. You save your test data in an upstream class. Base classes are a very simple concept, and Perl supports multiple inheritance (in that a package can have two or more parent classes). So, you can easily get away with writing less code and doing more by using base classes. It does take different ways of thinking about the code you write though.
  32. Building base classes is, in some ways, a puzzle game. If you like this sort of thing, you’ll have fun. If not, it is yak shaving. Either way, it is better to do it. One thing is really thinking about the real differences.
  33. Base classes are great, but it will take a bit of practice to get used to building good classes. In my RESTful Catalyst applications, I have many packages that consist of nothing more than configuration blocks and an inheritance line. The base class is very complex, works with configuration, but it covers all the use cases I have and to use it I just inherit from it, and muck with config. It is very, very fast to develop with. I also can get away with rigorous testing of just the base class and feel confident it works. When I introduce new functionality, I start first with my existing tests and work from there, since the new stuff tends to be very complicated it is better to have a scratch pad.
  34. I’m a big fan of Moose, but this isn’t a Moose talk. This is about writing better code, and I believe that Moose does that (and more). Just as a simple introduction, Moose is syntactic sugar over Class::MOP. Class::MOP is an API into Perl’s OO capabilities. Effectively, it is just a layer on top of what Perl gives you that does fantastic things to your code. I’m not going to go into all the fantastic things, because then it would be a Moose talk.
  35. Instead, I’m going to talk about what you need to write better Perl code. A big problem is that if you think of Moose (or any OO-API package that is on CPAN) as nothing more than accessor generators and mutators, you’re doing it wrong. Moose handles much more. Introspection, reflection, method modifiers, mutable classes, immutable classes. It has an API into the meta definitions. But that’s a lot, and you may not need it. If you don’t, there is a minimal set of features that is called ‘Mouse’. You can use that, and speed things up and still write better code.
  36. One thing that Moose makes really easy is configuration. This is done through the idea of ‘Roles’. Roles are a very complex subject that requires a Moose talk, and this isn’t a Moose talk, so I’m just going to say that Roles are a way of mixing in functionality. The main difference can be thought of as “A class IS A” and “A role DOES”. It’s an action. Configuration is an action, and there is a fantastic role on CPAN that makes it all happen.
  37. I configure most things in my application, and one thing is that I tend to have config files in different locations. Sometimes I like to override things by having a “appname_local” configuration file that gets loaded if it exists, but that I instruct git or svn to ignore. This lets me do that, by just populating a list of locations to look for a file. While it doesn’t merge multiple files (which would be awesome), it is the next best thing right now. So here you can have multiple paths for configuration, and then they set the accessors you have generated. So go read up on the pod for MooseX::SimpleConfig and start using it, it’s on CPAN.