The Grumpy Little Book Of Hack
Last updated on 2015-03-20
About the Book
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
- Hack modes
- Error handling
- Return value typing
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.
- 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
- Starting Tags
- Dropping In and Out of PHP
- Hack Modes
- Most Importanly, Don’t Stress Out Over Modes
- Error Handling
- Return Value Typing
- Normal Arrays
- Immutable Collections
- Fluid Collections
- Tying it All Together
The Leanpub 45-day 100% Happiness Guarantee
Within 45 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.
See full terms
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), EPUB (for phones and tablets) and MOBI (for 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.