Grant Proposal: Modern Object Oriented Programming in Perl
Sun, 11-May-2014 by
Makoto Nozaki
edit post
_We have received the following grant application. Please leave feedback in the comments field by May 22nd, 2014._
# Modern Object Oriented Programming in Perl
- Name:
Toby Inkster
- Amount Requested:
USD 4,000
## Synopsis
The proposal is to write a book on Modern OO programming techniques using Moose, Moo, and (where applicable) Class::Tiny. This would be written in a similar style to chromatic's _Modern Perl_ book, following the same test-driven approach to development, but covering modern Perl OO programming tools, techniques, and patterns in greater depth.
The primary target audience would be people who are already familiar with programming in Perl, but want to learn about modern object-oriented programming techniques, using Moose and Moo. A secondary target audience would be non-Perl programmers wishing to learn about object-oriented concepts which might not be available in the programming languages they are familiar with (e.g. many OO programming languages do not support the concept of roles) and expose themselves to ideas that might make them better OO programmers overall.
The starting point for the book would be [C# Programming](http://en.wikibooks.org/wiki/C_Sharp_Programming), a book available on the Wikibooks website under the Creative Commons Attibution-ShareAlike licence, and the completed project would thus be made available under the same licence.
## Benefits to the Perl Community
The project will aim to make Moose and Moo more understandable to Perl programmers, and also aim to make programmers outside the Perl programming community look at Perl afresh and understand that it may have something to offer them.
Because Moose shares similarities with both Steven Little's proposed metaobject protocol for the Perl 5 core, and with Perl 6's object model, it is hoped that the book will provide a foundation for future books or tutorials on these.
## Deliverables
- A book in at least 16 chapters, each of a similar length and depth to those in the C# book covering the following topics (the list of topics mostly being derived from the C# book):
- Introduction
An introduction to the book, and references to other books for establishing foundation knowledge upon which this book will build. It would introduce the concept of metaprogramming, but not explain in much depth how to do it.
- Namespaces
Giving your code its own space to live in.
- Classes and Methods
The blueprints for objects that describe how they should work.
- Objects
Cornerstones of any object-oriented programming language, objects are the tools you use to perform work.
- Encapsulation and accessor levels
Explains protection of object states by encapsulation, or the bundling of an object's data and functionality. (This would be quite substantially rewritten.)
- Lazily built attributes
(A new chapter demonstrating programming patterns based on lazily-built attributes.)
- Type constraints and coercions
(C# is a typed language, so Perl would need a completely different treatment. This chapter would be written from scratch.)
- Roles
(These are not covered by the C# book, so this chapter would be written from scratch, but I may be able to re-use some material from the C# chapter on abstract classes.)
- Interfaces
Define a template, on which to base sub-classes. (This would require significant rewriting from C#, and would discuss using roles as a way to formalize common interfaces.)
- Delegation and callbacks
Learn about delegation and callbacks. (This is likely to also involve significant rewriting from the C# chapter on delegation and events. This may cover dependency injection, or dependency injection may be split out into a separate chapter.)
- Traits
(This would be a new chapter written from scratch about the run-time application of roles to objects and classes.)
- Inheritance
Re-using existing code to improve or specialize the functionality of an object.
- Exceptions
Responding to errors that can occur. (This would cover defining exception classes, and throwing and catching exceptions. It would also list some common exceptions thrown from within Moose, and give examples of catching them.)
- Object Lifetime
Learn about the lifetime of objects, where they are allocated and learn about garbage collection.
- Design Patterns
Learn commonly used design methodologies to simplify and/or improve your development framework.
- Metaprogramming Techniques
(A new from-scratch chapter introducing the Moose MOP, and discussing some limited ways of metaprogramming Moo - e.g. wrapping the \`has\` keyword.)
The book would be made available in pod as a CPAN distribution, and in HTML on the author's website. The source materials for the book would be mirrored on both GitHub.com and Bitbucket.org.
The CPAN distribution would also include executable scripts for key examples from the book.
- A `Task::*` module would be uploaded to CPAN for one-step installation of all the modules covered by the book, and all the modules necessary to execute the example scripts provided.
- If porting the C# examples to Perl brings to light any deficiencies in [Moose](https://metacpan.org/pod/Moose) or [Moo](https://metacpan.org/pod/Moo), whereby there are key OO ideas from C# that cannot be replicated in these frameworks, these will be discussed with the maintainers of those projects, and the best way to proceed will be decided. This may lead to improvements to [Moose](https://metacpan.org/pod/Moose) or [Moo](https://metacpan.org/pod/Moo), or the release of new `MooseX::*` or `MooX::*` extension modules.
## Project Details
The proposed title of the book, _Modern Object Oriented Programming in Perl_ is a working title and subject to change. The chapter list may be rearranged slightly in the final version, with some chapters perhaps being merged, and others possibly split if they seem too lengthy.
The code samples will primarily use [Moose](https://metacpan.org/pod/Moose) and [Moo](https://metacpan.org/pod/Moo). When possible, sample code will be provided for both frameworks, so that they can be compared side-by-side. For some advanced topics, Moo may not offer sufficient facilities, so only a Moose example would be provided. For some very basic topics, [Class::Tiny](https://metacpan.org/pod/Class::Tiny) and/or [Role::Tiny](https://metacpan.org/pod/Role::Tiny) code samples would also be provided. (The reason for this choice is that Role::Tiny is the basis for Moo's role system, and that there are tentative plans to enable some level of integration between Moo and Class::Tiny.)
The book may mention, but will not cover in any level of detail other Perl object-oriented frameworks such as [Mouse](https://metacpan.org/pod/Mouse), [Moops](https://metacpan.org/pod/Moops), p5-mop, or [Class::Accessor](https://metacpan.org/pod/Class::Accessor). The book will not cover ""do-it-yourself"" techniques for writing constructors an accessors, except perhaps for comparison to demonstrate the superior approach of using an OO framework.
Overall the book would encourage correctness, robustness, encapsulation, and non-repetitive design rather than writing especially memory-efficient or fast code, but optimization techniques may be touched on, and the compromises involved may be discussed.
The chapter on type constraints and coercions will cover Moose's and Moo's built-in type constraint systems, but will concentrate on [Type::Tiny](https://metacpan.org/pod/Type::Tiny), a standalone type constraint framework which supports both Moose and Moo. (Disclaimer: I am the developer of Type::Tiny.)
The chapter on exceptions will use [Try::Tiny](https://metacpan.org/pod/Try::Tiny) and [Throwable](https://metacpan.org/pod/Throwable).
The chapter on encapsulation will make use of [Lexical::Accessor](https://metacpan.org/pod/Lexical::Accessor). (Disclaimer: I am also the developer of Lexical::Accessor.)
## Inch-stones
The progress of the project as a whole can be measured by the completion of each chapter. Chapters will not necessarily be completed in the order which they are intended to appear in the book. (The introduction is in fact, likely to be the final chapter written.)
Naturally until the whole book is complete, even a chapter which is ""complete"" will be subject to revisions -- it is not frozen in stone.
## Project Schedule
My estimate is that each chapter will require two to three days of solid work on average. (Chapters which mostly replicate the original C# book will take less; chapters which require substantial original work, somewhat more.) Additionally, I estimate roughly a week will be needed to stitch the completed chapters together into a cohesive whole.
I plan to dedicate roughly two days a week to the project, over the course of about four months. The planned start for the project is September 2014, with a planned completion date in January or February 2015.
## Completeness Criteria
All the chapters will be available in pod, on CPAN, under a free licence.
(Which is not to say that I'll abandon it thereafter. If errors or omissions are pointed out after the end of the grant, or if new versions of [Moose](https://metacpan.org/pod/Moose) or [Moo](https://metacpan.org/pod/Moo) are released which make the book incorrect, I intend to continue updating the book for the foreseeable future.)
## Bio
I am a freelance developer based in the UK who uses Perl as his preferred programming language, though also develops actively in PHP and Javascript, and dabbles occasionally in other programming languages. I am the author of over 200 CPAN distributions, including many extensions to [Moose](https://metacpan.org/pod/Moose) and [Moo](https://metacpan.org/pod/Moo).
I am the primary developer of [Type::Tiny](https://metacpan.org/pod/Type::Tiny) and [Moops](https://metacpan.org/pod/Moops), each of which are frameworks designed to integrate with both Moo and Moose, which has taught me a great deal about the differences and similarities between them. Type::Tiny and Moops were each included in the top 10 best distributions created in 2013, [according to ratings on MetaCPAN](http://niceperl.blogspot.co.uk/2014/01/best-perl-distributions-created-at-2013.html). Type::Tiny now has over 100 other CPAN distributions listing it as a direct dependency.
I have contributed, albeit often in minor ways, to many of the modules that I propose to cover in the book. I am listed as a contributor to [Moo](https://metacpan.org/pod/Moo), [Role::Tiny](https://metacpan.org/pod/Role::Tiny), and [Class::Tiny](https://metacpan.org/pod/Class::Tiny), according to their respective documentation; to [Throwable](https://metacpan.org/pod/Throwable), according to its change log; and to p5-mop-redux, according to GitHub.
I have written an article on the O'Reilly Programming Blog comparing Moose roles with similar approaches for horizontal code reuse in other programming languages. See [http://programming.oreilly.com/2014/01/horizontal-reuse-an-alternative-to-inheritance.html](http://programming.oreilly.com/2014/01/horizontal-reuse-an-alternative-to-inheritance.html).
Raised in both Australia and the UK, I speak English natively.
Comments (13)
I like the concept but I have a few concerns about this proposal.
First, the submitter doesn't have much writing experience other than a single article to point to. Typically, book proposals are submitted with at least one sample chapter. I think that would be appropriate for this grant proposal too.
Second, and perhaps more concerning, is that there is no mention of how editing and tech review will be done for this book. My experience as a book author tells me that both of these things are crucial for creating a solid end product.
I imagine tech reviewing could be obtained by simply asking people in the community to read the book and contribute changes via git, and wouldn't require additional funds. However, getting someone to act as an editor might take actual money.
Hi,
i think this is a really cool idea and it would help many people understanding and getting into Moo(se).
I really like Toby's code on CPAN. I like the fact that you can contact him easily. And he's really responsive.
When the qualitiy of this book is as good as his code I really say "Yes" to this grant.
I really hope that the book will focus on the Perl (scripting language) specifics of OO patterns. I propose to add an cookbook homepage with recipes which can be added over time.
Thumbs up!
Best regards
A. Mock
I think Toby Inkster's work on Perl is marvellous, and definitely support this grant.
Thank you to everybody for the comments so far.
Addressing some of Dave Rolsky's concerns:
I don't have very many more "articley" things I can point to. I do occasionally blog about Perl-related topics, such as here and here, though blogging is a somewhat different style of writing than you'd expect in a book.
Many of my CPAN releases include extensive documentation, and sometimes mini-tutorials. Examples include Type::Tiny::Manual::Libraries, Kavorka::Manual::MultiSubs, and Set::Equivalence. Another good example is Moops::Manual::Objects101 which is somewhat relevant as it is a port of an object-oriented programming tutorial in another programming language (in this case, Visual Basic) to Perl; in some ways a miniature version of what I hope to produce if given this grant.
Regarding technical review, as per my open source code, I would be writing all this "in the open", with a repository on GitHub (and mirrored on Bitbucket.org). Feedback on any aspect of the writing as it progressed would be not only welcomed, but actively encouraged. I'd also frequently upload "checkpoints" to the CPAN as developer releases (i.e. containing underscores in the version number) to ensure as wide as possible an audience for the work in progress.
There are a couple of people that I would have loved to ask to edit the book, but I couldn't really expect them to donate their time without any recompense. I was conscious of keeping the amount requested as low as feasible, so didn't want to add the cost of hiring an editor to it. I will note that the Attribution-ShareAlike License would allow for edited versions to be produced afterwards.
Addressing one of Andreas Mock's points:
A "cookbook" does indeed sound like a very good idea. It could take the form of a multi-author blog, or a wiki. I think that is certainly something to bear in mind for publishing the HTML version of the book.
Because I've been asked about it on IRC, here are a list of general principles I hope to encourage through the book:
They won't be given their own chapters, not because they're too unimportant, but because they're too important. The concepts will be introduced early on, in the chapters about classes, objects, and encapsulation, and the principles will be followed in all the later chapters.
I endorse this vigorously. Vigorously, I say! Also seriously.
If you write it, I will guarantee you two sales -- one to me, personally, and one to my lending library.
B
I'd like to see this funded.
Toby, do you plan to try and do a print edition as well, in the style of Modern Perl?
This sounds like a good idea. I would prefer more text spent on Moose than Moo since it is the main beast of the Perl OOP.
I would also be interested in a good section on Design Patterns. Although a topic on its own, I have been debating whether or not to buy a book on design patterns for awhile now. Most books that talk about design patterns are for Ruby/C++/Java, ect. I would love to have the topic covered but with Perl.
Metaprogramming Techniques sounds like a good section to read as well.
Toby asked my opinion on drafts of this proposal and revised them per my suggestions. The Perl community has long needed a book on this subject. I have confidence in both the author and his outline--he will deliver something of great value to Perl.
Though the price might seem steep to some, my professional opinion as a writer and an editor is that the requested grant amount is a bargain for both the work required and the value of the finished product.
To elaborate on my first comment. Overall, I'm more for the proposal than against it, regardless of my original concerns. I think having this book out there would be valuable for the community and this is not that much money for the creation of a book.
Thank you to everybody for their comments. I believe the official feedback period is now over, but I'm still happy to hear people's ideas - either here if the comments remain open, or by e-mail.