ebook img

Seven web frameworks in seven weeks adventures in better web apps PDF

296 Pages·2014·6.198 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Seven web frameworks in seven weeks adventures in better web apps

Early Praise for Seven Web Frameworks in Seven Weeks The title implies a breadth-first analysis of some fairly disparate technologies, but there is a surprising amount of depth here, more than enough to emphasize the essential qualities of each one. If you’re a polyglot, or aspire to be, this book is a very large ball of awesome. ➤ Jim Crossley Immutant core team member; principal software engineer, Red Hat Objective and clear. More than an introduction, it’s a head start! Just as wide and as deep as any modern developer would like. I definitely recommend it. ➤ Pablo Aguiar Software engineering consultant This book is great fun. The authors guide you quickly through each framework, in each case giving you a fast but clear, coherent, and surprisingly detailed taste that includes major features, design philosophy, implementation, and testing, plus hints for further investigation. Two JavaScript frameworks, one Ruby, one Haskell, two Clojure, and one Erlang. If you like web programming, you’re going to enjoy this book. ➤ Giles Bowkett Experienced developer and well-known blogger I thoroughly enjoyed reading the book. In fact, the Yesod chapter even gave me fresh ideas on how to expose non-Haskellers to the strengths of a strong type system. ➤ Michael Snoyman Creator of Yesod; lead software engineer, FP Complete Seven Web Frameworks in Seven Weeks Adventures in Better Web Apps Jack Moffitt Fred Daoud The Pragmatic Bookshelf Dallas, Texas • Raleigh, North Carolina Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and The Pragmatic Programmers, LLC was aware of a trademark claim, the designations have been printed in initial capital letters or in all capitals. The Pragmatic Starter Kit, The Pragmatic Programmer, Pragmatic Programming, Pragmatic Bookshelf, PragProg and the linking g device are trade- marks of The Pragmatic Programmers, LLC. Every precaution was taken in the preparation of this book. However, the publisher assumes no responsibility for errors or omissions, or for damages that may result from the use of information (including program listings) contained herein. Our Pragmatic courses, workshops, and other products can help you and your team create better software and have more fun. For more information, as well as the latest Pragmatic titles, please visit us at http://pragprog.com. The team that produced this book includes: Bruce A. Tate (series editor) Jacquelyn Carter (editor) Potomac Indexing, LLC (indexer) Molly McBeath (copyeditor) David J Kelly (typesetter) Janet Furlow (producer) Juliet Benda (rights) Ellie Callahan (support) Copyright © 2014 The Pragmatic Programmers, LLC. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form, or by any means, electronic, mechanical, photocopying, recording, or otherwise, without the prior consent of the publisher. Printed in the United States of America. ISBN-13: 978-1-93778-563-5 Encoded using the finest acid-free high-entropy binary digits. Book version: P1.0—January 2014 Contents Foreword . . . . . . . . . . . . . vii Acknowledgments . . . . . . . . . . . ix Preface . . . . . . . . . . . . . . xi 1. Sinatra . . . . . . . . . . . . . . 1 A Simple Domain-Specific Language 1 Day 1: Building a Bookmarking Application 2 Day 2: Creating Views 11 Day 3: Adding Features 22 Wrapping Up 32 2. CanJS . . . . . . . . . . . . . . 35 What Makes CanJS Unique? 35 Day 1: Building Objects and Synchronizing Changes 37 Day 2: Creating Controllers 48 Day 3: Working with Models 57 Wrapping Up 71 3. AngularJS . . . . . . . . . . . . . 73 The Big Picture 73 Day 1: Using Dependency Injection 75 Day 2: Creating Controllers and Views 90 Day 3: Building Filters and Routes 101 Wrapping Up 112 4. Ring . . . . . . . . . . . . . . 115 Introducing Ring 115 Day 1: Basic Towers 116 Day 2: Patterns of Bricks 133 Contents • vi Day 3: Other Ways to Build 142 Wrapping Up 151 5. Webmachine . . . . . . . . . . . . 155 Introducing Webmachine 155 Day 1: HTTP Request as State Machine 157 Day 2: Building Apps 168 Day 3: Illuminating HTTP’s Dark Corners 182 Wrapping Up 194 6. Yesod . . . . . . . . . . . . . . 197 Introducing Yesod 197 Day 1: Data You Can’t Get Wrong 198 Day 2: Views, Forms, and Auth 208 Day 3: Rumbling Along 219 Wrapping Up 231 7. Immutant . . . . . . . . . . . . . 233 Introducing Immutant 233 Day 1: Beyond the Web Basics 235 Day 2: Building Data Pipelines 245 Day 3: Polyglot Apps 256 Wrapping Up 267 8. Wrap-Up . . . . . . . . . . . . . 269 Key Ideas 269 Happy Exploring 273 A1. Bibliography . . . . . . . . . . . . 275 Index . . . . . . . . . . . . . . 277 Foreword In 2003, I took my family to Durango, Colorado, where we rode on the Durango & Silverton train. The narrow gauges of the railroad once served well against the narrow red sandstone cliffs, where every inch of space was at a premium. These days, the train is a relic of the past, rendered obsolete by cars and planes that are safer and more efficient. Time marches on. Today, too, we witness revolution. Single-core computers are dead or dying. True, their multicore descendants are technical marvels. They also represent a tremendous technical challenge. The languages we used to depend on do not work as well as they once did. As a result, we are seeing a new generation of languages emerge. So far, no one has been kind enough to declare a winner. Against this backdrop in 2010, I wrote Seven Languages in Seven Weeks. In truth, I didn’t expect it to sell many copies. After all, it was a book about languages in a Java world; a book about programming paradigms in a time where everything was object oriented. Still, programmers sensed the danger of our stagnating skills and embraced the concept that learning programming languages for the sake of learning them can make you smarter and better able to cope with change. The book was a resounding success. Three years later, there’s still no clear leader, though functional programming is starting to gain traction. We’re finding that the multicore wafer tossed into our virtual pond years ago has created waves that are increasing in size and velocity. We need more than inheritance to organize our code. We need robust frameworks on the client to handle the robust development that is happening there. And we need true concurrent frameworks to take full advantage of their concurrent languages. It’s just not enough to lay wider tracks over the narrow tracks we used last year. In this book, Fred and Jack will show you the leading edge of people who are reinventing the way web development should be done. You’ll see a traditional object-oriented framework called Sinatra. You’ll move on to the client side, report erratum • discuss Foreword • viii where exciting things are happening with JavaScript. You’ll take a tour of CanJS and AngularJS to see how to do full, rich client-side development. Next, you’ll swing back to the server side to see what’s happening in functional languages. You’ll encounter two Clojure frameworks in the minimalist Ring and the robust Immutant. You’ll see a state machine–based design in Erlang called WebMachine. If those aren’t enough to blow your mind, you’ll find the incredibly powerful Haskell framework called Yesod. The “Seven in Seven” books are designed to expand your mind. I am extremely proud to bring you this next installment, Seven Web Frameworks in Seven Weeks. It’s my sincerest hope that this book will take you beyond whatever tracks are holding you back. Best regards, Bruce Tate CTO, icanmakeitbetter.com report erratum • discuss Acknowledgments We would like to thank the team at the Pragmatic Bookshelf for making this book possible. Thanks especially to Jackie Carter, our editor, for all of her expertise and tireless efforts to make this book better and for bringing it to the finish line. Thanks also to Bruce Tate—we are both fans of his book, and we are honored to follow in his footsteps. Thank you, Andy Hunt and Dave Thomas, for creating such a great environment in which to write about the technical subjects that we all find fascinating. Thanks to the technical reviewers who contributed their expert advice on each framework: Konstantin Haase (Sinatra), David Luecke (CanJS), Miško Hevery (AngularJS), James Reeves (Ring), Justin Sheehy (Webmachine), Michael Snoyman (Yesod), Jim Crossley and Toby Crawley (Immutant) and to the reviewers who offered their comments and suggestions for various chapters of the book: Kimberly Hagen, Kevin Wiley, Pablo Aguiar, Mick Thompson, Christopher Zorn, Nathaniel Schutta, and Aaron Bedra. We would not have such innovative frameworks to write about were it not for their creators: Blake Mizerany, Justin Meyer, Miško Hevery, Adam Abrons, Justin Sheehy, Andy Gross, Mark McGranaghan, James Reeves, Jim Crossley, Toby Crawley, Michael Snoyman, and their respective teams and contributors. Thanks also to the readers who contributed to the beta-book process on the errata page; you have helped make this book better. From Jack: I’d like to thank my wife, Kim, for encouraging me to write another book, being a sounding board for my ideas, and spending time reviewing the book. Thanks also to my two children—Beatrix and Jasper— who provided many happy distractions. I’d also like to thank Sean Johnson, who introduced me to Bruce, which got the whole project started. From Fred: Thanks to my wife, Nadia, for being such a beautiful person in every way. Life is everything with you. Thanks to Lily and Ruby for adding so much fun and excitement to our family! report erratum • discuss

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.