The Grumpy Little Book Of Hack

Retired

This book is no longer available for sale.

The Grumpy Little Book Of Hack

A pocket guide for using HHVM and Hack on legacy PHP code bases

About the Book

Your co-workers simply refer to it as The App

You can hear the capital letters when they talk about it. It's an old PHP application that has been around as long as the company has. It does the job, makes good money for the company...and people are terrified to touch it or change anything. You have bravely offered to join the maintenance team because you enjoy a challenge, but the code base is intimidating and uses a version of PHP older than your older sister's daughter. She just turned 8. However, you seem to have attracted the sympathy of the systems people and some of the most senior members of the team. "If you can offer some suggestions on how we can squeeze some more performance out of this application and clean up some of the parts we know are confusing, we're behind you and on-board. Upgrading the version of PHP is possible, we just need to make sure it's the right thing to do. We believe in you!"

Wouldn't it be awesome if there were something that is pretty much a drop-in replacement for PHP and ran faster? Also, while a lot of the code in there does what it's supposed to you find yourself constantly wishing you didn't have to spend so much time reading code "inside-out" to trace what is going on. You start looking online for something that can help you. Surely there are tools that companies that run large PHP applications are using that they are happy to share.

You find it

Facebook's HHVM and Hack. It's exactly what you want and exactly what this code base needs -- a performance boost from HHVM and Hack's features to refactor your existing code to make the intent clearer. Time to send that email asking systems to create a server for you with HHVM installed, create an experimental branch in your version control system, and start making this code base easier to understand.

I'm here to help

My name is Chris Hartjes, and I have been working with PHP since 1998. When not evangelizing testing practices for PHP and doing performance art on Twitter, I am usually working with Other Peoples' Code. Over the years, I have noticed some common patterns in what might be called "bad code." It's usually running on very old versions of PHP and is wildly inconsistent in coding style and choice of solutions. Lack of consistency is, in my opinion, the number one obstacle to overcome when dealing with legacy code bases. Constantly having to figure out programming choices and the mental stress of remembering PHP's API's ("Is it needle then haystack, or haystack then needle?) can cause mental fatigue and allow refactoring efforts to fail miserably. I am always looking for ways to help the applications I work on perform better and have a code base that is consistent in it's approach to solving problems. I wrote this pocket guide to share what I've learned about how HHVM and Hack can be used to improve the quality of your PHP code base, making it more readable and applying some often-needed discipline to the development process. Hack's implementation of "gradual typing" is something I believe in very strongly and can see how it can be used to prevent weird edge-cases from happening in your code. The Grumpy Little Book Of Hack is designed to provide you with practical advice, not be an exhaustive reference guide. Solid advice, crufty code samples, and the reasoning behind the choices make for something you can use right away. Some of the topics covered include:

  • HHVM configuration
  • Extensions
  • Hack modes
  • Error handling
  • Return value typing
  • Collections

Get your legacy code base under control! HHVM and Hack offer a rare combination of extra performance and language features that help protect Future You from Present You by giving you tools to enforce typing and consistency. The Grumpy Little Book of Hack gives you everything you need to get started using Facebook's secret weapon for making PHP better.

About the Author

Chris Hartjes
Chris Hartjes

Chris Hartjes has been helping teams try and produce fewer bugs in production since 1998 with a recent focus on tools and test automation in PHP and Python.

He lives in the snowy wilds of Lucan, Ontario, Canada,

Table of Contents

  • Thanks
  • Introduction
    • Working With Legacy Applications is Hard
    • Proper Application Environments
    • What If You Can’t Refactor Everything?
    • Hack and HHVM Can Help Make Your Legacy Code Consistent
    • Type Systems
    • +1 and -1
  • Configuring HHVM
  • Getting Your Code Ready For HHVM
    • Extensions
    • Starting Tags
    • Dropping In and Out of PHP
    • XHP
    • Hackification
    • Hack Modes
    • Most Importanly, Don’t Stress Out Over Modes
  • Error Handling
  • Return Value Typing
  • Collections
    • Normal Arrays
    • Vectors
    • Map
    • Immutable Collections
    • Fluid Collections
  • Tying it All Together

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

Now, this is technically risky for us, since you'll have the book or course files either way. But we're so confident in our products and services, and in our authors and readers, that we're happy to offer a full money back guarantee for everything we sell.

You can only find out how good something is by trying it, and because of our 100% money back guarantee there's literally no risk to do so!

So, there's no reason not to click the Add to Cart button, is there?

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

In fact, authors have earnedover $13 millionwriting, publishing and selling on Leanpub.

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub