Venkat Subramaniam — «Functional Programming in Java

Total Page:16

File Type:pdf, Size:1020Kb

Venkat Subramaniam — «Functional Programming in Java Praise for Functional Programming in Java Venkat has done a superb job of bringing core functional language concepts to the Java ecosystem. Once you have peered into his looking glass of functional language design, it will be hard to go back to old-school imperative programming. ➤ Stephen Chin, Java technology ambassador and JavaOne content chair The introduction of lambdas to Java 8 has made me excited to use Java again, and Venkat’s combination of technical details and best practices make it easy to apply functional thinking to this new feature. ➤ Kimberly D. Barnes, senior software engineer Java 8 lambda expressions are an incredibly important new language feature. Every Java developer should read this excellent book and learn how to use them effectively. ➤ Chris Richardson, software architect and Java champion Many can explain lambdas; Venkat makes them useful. ➤ Kirk Pepperdine, Java performance tuning expert I highly recommend this book for Java programmers who want to get up to speed with functional programming in Java 8. It is a very concise book but still provides a comprehensive overview of Java 8. ➤ Nilanjan Raychaudhuri, author and developer at Typesafe Functional Programming in Java Harnessing the Power of Java 8 Lambda Expressions Venkat Subramaniam 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. Sir Charles Antony Richard Hoare’s quote is used by permission of the ACM. Abelson and Sussman’s quote is used under Creative Commons license. The team that produced this book includes: Jacquelyn Carter (editor) Potomac Indexing, LLC (indexer) Candace Cunningham (copyeditor) David J Kelly (typesetter) Janet Furlow (producer) Ellie Callahan (support) For international rights, please contact [email protected]. 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-937785-46-8 Encoded using the finest acid-free high-entropy binary digits. Book version: P1.0—February 2014 To the loving memory of my grandmothers, Kuppammal and Jayalakshmi. I cherish my wonder years under your care. Contents Foreword . xi Acknowledgments . xiii Preface . xv 1. Hello, Lambda Expressions! . 1 Change the Way You Think 1 The Big Gains of Functional-Style Code 5 Why Code in the Functional Style? 6 Evolution, Not Revolution 12 A Little Sugar to Sweeten 15 Recap 17 2. Using Collections . 19 Iterating through a List 19 Transforming a List 23 Finding Elements 26 Reusing Lambda Expressions 27 Using Lexical Scoping and Closures 29 Picking an Element 33 Reducing a Collection to a Single Value 35 Joining Elements 38 Recap 40 3. Strings, Comparators, and Filters . 41 Iterating a String 41 Implementing the Comparator Interface 44 Multiple and Fluent Comparisons 51 Using the collect Method and the Collectors Class 52 Listing All Files in a Directory 56 Listing Select Files in a Directory 57 Contents • viii Listing Immediate Subdirectories Using flatMap 59 Watching a File Change 60 Recap 62 4. Designing with Lambda Expressions . 63 Separating Concerns Using Lambda Expressions 63 Delegating Using Lambda Expressions 68 Decorating Using Lambda Expressions 72 A Peek into the default Methods 77 Creating Fluent Interfaces Using Lambda Expressions 80 Dealing with Exceptions 83 Recap 86 5. Working with Resources . 87 Cleaning Up Resources 87 Using Lambda Expressions to Clean Up Resources 91 Managing Locks 95 Creating Concise Exception Tests 97 Recap 101 6. Being Lazy . 103 Delayed Initialization 103 Lazy Evaluations 108 Leveraging the Laziness of Streams 111 Creating Infinite, Lazy Collections 115 Recap 119 7. Optimizing Recursions . 121 Using Tail-Call Optimization 121 Speeding Up with Memoization 129 Recap 134 8. Composing with Lambda Expressions . 135 Using Function Composition 135 Using MapReduce 138 Taking a Leap to Parallelize 143 Recap 145 9. Bringing It All Together . 147 Essential Practices to Succeed with the Functional Style 147 Performance Concerns 151 Adopting the Functional Style 153 Contents • ix A1. Starter Set of Functional Interfaces . 155 A2. Syntax Overview . 157 A3. Web Resources . 163 Bibliography . 165 Index . 167 Foreword Venkat Subramaniam would never be described as a “waterfall” sort of guy. So, when he mentioned that he was starting on a Java 8 book—long before the design of Java 8 was settled—I was not at all surprised. It was clear this was going to be an “agile” book project. Despite having to more than occasionally rework the text as the language and library features evolved, Venkat had a secret advantage—he knew where we were going. The Java 8 design was heavily influenced by the core principles of functional programming: functions as values, immutability, and statelessness. We didn’t do this because functional programming is trendy or cool; we did it because programs that are expressed as stateless transformations on immutable data, rather than as modifications of mutable data structures, tend to be easier to read and main- tain, to be less error prone, and to parallelize more gracefully. The new features introduced in Java 8 were designed together to facilitate devel- opment of more expressive and parallel-friendly libraries. Lambda expressions reduce the syntactic overhead of encoding behavior as data; default methods allow existing libraries to evolve over time, enabling core JDK classes such as Collections to take advantage of lambda expressions; the java.util.stream package leverages these language features to offer rich aggregate operations on collections, arrays, and other data sources in a declarative, expressive, and parallel-friendly manner. All of this adds up to more powerful and performant code, as well as a more pleasant programming experience. This book not only provides lots of examples of how to use these new features, but offers readers a peek into the underlying principles behind their design, and why they result in better code. Let Venkat be your guide to this new and improved Java—you’re in for a treat. Brian Goetz Java Language Architect, Oracle Corporation September 2013 report erratum • discuss Acknowledgments Writing a book is like taking a road trip—we know where we’re heading, but some details emerge only after the start. The journey may involve detours— opportunities to explore unexpected places—and it’s more fun with good company. I’m thankful for the great company of people on this voyage: smart reviewers, an amazing editor, a wonderful set of people at The Pragmatic Bookshelf, and a very supportive family. I first thank the Java language team members at Oracle for their hard work to bring the functional style of programming to one of the most popular mainstream languages. You’ve taken the language in the right direction—not through shortcuts and quick fixes, but by way of sound reasoning and prudent design decisions. Kudos, team. I express my sincere gratitude to the smart developers who volunteered their personal time to review this book. Thank you, Kimberly Barnes, Fred Daoud, Raju Gandhi, Marty Hall, Praveen Kumar, Rebecca Parsons, Kirk Pepperdine, Chris Richardson, Ian Roughley, Nate Schutta, Ken Sipe, and Dan Sline. Your comments were critical yet very constructive and motivational; they helped make this book better. I’m honored and humbled by Bruce Tate reviewing this book. He’s been a great mentor for me over the years. He reviewed this book multiple times, at different stages, and took the time to motivate me as to why certain changes were essential. Thank you, Bruce. I’d also like to express my gratitude to Brian Goetz for reviewing the book multiple times, for the encouragement starting early on, and for kindly agreeing to write the foreword. Any errors in the book are solely mine. The biggest benefit of publishing a beta copy of a book is the opportunity to improve it based on valuable feedback from early readers. I’m indebted to the following readers for taking their valuable time to provide feedback on the forum for this book or reporting errors on the errata page. Thank you, Greg Helton, Günter Jantzen, Narayanan Jayaratchagan, Wacek Kusnierczyk, Nabeel Ali Memon, Marc-Daniel Ortega, Arjo Ouwens, Philip Schwarz, report erratum • discuss Acknowledgments • xiv Ekaterina Sh, Dan Talpau, Benjamin Tan, Brian Tarbox, Marco Vermeulen, and Jason Weden. I benefited greatly from every interaction with Jackie Carter. She did not just edit; she motivated me and helped shape this book. Thank you, Jackie, for your hard work, fast responses, and truly making this a fun experience. Impatience is one of my many weaknesses, but the kind folks at The Pragmatic Bookshelf turned that into a strength when I set out to write this book. Susannah Pfalzer, Andy Hunt, Dave Thomas, and several others worked behind the scenes to help me succeed on a self-imposed fast-paced schedule.
Recommended publications
  • Functional Programming: a Pragpub Anthology
    Prepared exclusively for Shohei Tanaka Prepared exclusively for Shohei Tanaka Early Praise for Functional Programming: A PragPub Anthology If you’ve been wondering what all the functional hubbub is about, Functional Programming: A PragPub Anthology will satisfy. You can wet your whistle with several languages, get a feel for how to think functionally, and do so without overcommitting to one language or school of thought. ➤ Ben Vandgrift Chief architect, Oryx Systems Inc. Programming’s last sea change was in the 1990s when object orientation went mainstream. It’s happening again, but this time it’s functional programming that’s sweeping through our profession. Read this book to understand why and to learn how to ride the wave. ➤ Paul Butcher Founder and CTO, writeandimprove.com I really enjoyed the structure and flow of the book. The chapters stand on their own as essays but when put together make a strong argument for functional programming, regardless of the language. It’s also a treat to see all these different familiar writers write about diverse languages. ➤ Ben Marx Lead engineer, Bleacher Report Prepared exclusively for Shohei Tanaka You’re sure to find a way functional programming resonates with you with the wealth of approaches and languages covered. The treatment of Scala collection is superb: everything a beginner needs to know from the get-go! ➤ Jeff Heon Research software developer, CRIM Prepared exclusively for Shohei Tanaka Functional Programming: A PragPub Anthology Exploring Clojure, Elixir, Haskell, Scala, and Swift Michael Swaine and the PragPub writers The Pragmatic Bookshelf Raleigh, North Carolina Prepared exclusively for Shohei Tanaka Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks.
    [Show full text]
  • Programming Language) 1 APL (Programming Language)
    APL (programming language) 1 APL (programming language) APL Paradigm array, functional, structured, modular Appeared in 1964 Designed by Kenneth E. Iverson Developer Kenneth E. Iverson Typing discipline dynamic Major implementations IBM APL2, Dyalog APL, APL2000, Sharp APL, APLX Dialects A+, Dyalog APL, APLNext Influenced by mathematical notation [1] [2] [3] [4] Influenced J, K, Mathematica, MATLAB, Nial, PPL, Q APL (named after the book A Programming Language)[5] is an interactive array-oriented language and integrated development environment which is available from a number of commercial and non-commercial vendors[6] and for most computer platforms.[7] It is based on a mathematical notation developed by Kenneth E. Iverson. APL has a combination of unique and relatively uncommon features that appeal to programmers and make it a productive programming language:[8] • It is concise, using symbols rather than words and applying functions to entire arrays without using explicit loops. • It is solution focused, emphasizing the expression of algorithms independently of machine architecture or operating system. • It has just one simple, consistent, and recursive precedence rule: the right argument of a function is the result of the entire expression to its right. • It facilitates problem solving at a high level of abstraction. APL is used in scientific,[9] actuarial,[8] statistical,[10] and financial applications where it is used by practitioners for their own work and by programmers to develop commercial applications. It was an important influence on the development of spreadsheets, functional programming,[11] and computer math packages.[3] It has also inspired several other programming languages.[1] [2] [4] It is also associated with rapid and lightweight development projects in volatile business environments.[12] History The first incarnation of what was later to be the APL programming language was published and formalized in A Programming Language,[5] a book describing a notation invented in 1957 by Kenneth E.
    [Show full text]
  • Node.Js 562 Background
    Eloquent JavaScript 3rd edition Marijn Haverbeke Copyright © 2018 by Marijn Haverbeke This work is licensed under a Creative Commons attribution-noncommercial license (http://creativecommons.org/licenses/by-nc/3.0/). All code in the book may also be considered licensed under an MIT license (https: //eloquentjavascript.net/code/LICENSE). The illustrations are contributed by various artists: Cover and chap- ter illustrations by Madalina Tantareanu. Pixel art in Chapters 7 and 16 by Antonio Perdomo Pastor. Regular expression diagrams in Chap- ter 9 generated with regexper.com by Jeff Avallone. Village photograph in Chapter 11 by Fabrice Creuzot. Game concept for Chapter 16 by Thomas Palef. The third edition of Eloquent JavaScript was made possible by 325 financial backers. You can buy a print version of this book, with an extra bonus chapter in- cluded, printed by No Starch Press at http://a-fwd.com/com=marijhaver- 20&asin-com=1593279507. i Contents Introduction 1 On programming .......................... 2 Why language matters ....................... 4 What is JavaScript? ......................... 9 Code, and what to do with it ................... 11 Overview of this book ........................ 12 Typographic conventions ...................... 13 1 Values, Types, and Operators 15 Values ................................. 16 Numbers ............................... 17 Strings ................................ 21 Unary operators ........................... 24 Boolean values ............................ 25 Empty values ............................
    [Show full text]
  • Computer Science: Abstraction to Implementation
    Computer Science: Abstraction to Implementation Robert M. Keller Harvey Mudd College [email protected] September 2001 2001 by Robert M. Keller, all rights reserved Table of Contents 1. Introduction ............................................................................................................ 1 1.1 The Purpose of Abstraction 1 1.2 Principles 4 1.3 Languages 4 1.4 Learning Goals 5 1.5 Structure of the Chapters 6 1.6 How the Problems are Rated 8 1.7 Further Reading 9 1.8 Acknowledgment 10 2. Exploring Abstractions: Information Structures....................................................... 11 2.1 Introduction 11 2.2 The Meaning of “Structure” 16 2.3 Homogeneous List Structures 16 2.4 Decomposing a List 17 2.5 List Manipulation 19 2.6 Lists of Lists 23 2.7 Binary Relations, Graphs, and Trees 25 2.8 Matrices 40 2.9 Undirected graphs 43 2.10 Indexing Lists vs. Arrays 44 2.11 Structure Sharing 45 2.12 Abstraction, Representation, and Presentation 48 2.13 Abstract Information Structures 52 2.14 Conclusion 54 2.15 Chapter Review 54 3. High-Level Functional Programming ...................................................................... 57 3.1 Introduction 57 3.2 Nomenclature 58 3.3 Using High-Level Functions 61 3.4 Mapping, Functions as Arguments 66 3.5 Anonymous Functions 67 3.6 Functions as Results 69 3.7 Composing Functions 71 3.8 The Pipelining Principle 72 3.9 Functions of Functions in Calculus (Advanced) 73 3.10 Type Structure 75 3.11Transposing Lists of Lists 78 3.12 Predicates 79 3.13 Generalized Sorting 82 3.14 Reducing Lists 82 3.15 Sequences as Functions 85 3.16 Solving Complex Problems using Functions 86 3.17 Conclusion 95 3.18 Chapter Review 95 4.
    [Show full text]
  • Exploring PHP 8.0
    Exploring PHP 8.0 Larry Garfield This book is for sale at http://leanpub.com/exploringphp80 This version was published on 2020-12-11 This is a Leanpub book. Leanpub empowers authors and publishers with the Lean Publishing process. Lean Publishing is the act of publishing an in-progress ebook using lightweight tools and many iterations to get reader feedback, pivot until you have the right book and build traction once you do. © 2020 Larry Garfield Also By Larry Garfield Thinking Functionally in PHP A Major Event in PHP Contents Introduction .................................................. 1 Headline features ...................................... 3 Constructor Property Promotion ..................................... 4 Valuing your data ............................................ 6 Just-In Time-compilation .......................................... 7 Some background ............................................. 7 Just in Time ................................................ 7 The PHP JIT ................................................ 8 How to configure the JIT ........................................ 8 Will it help? ................................................ 9 Attributes .................................................... 11 A history of change ........................................... 11 Getting meta ............................................... 11 A practical example ........................................... 12 Coming soon to a framework near you ............................... 15 Promoted arguments ..........................................
    [Show full text]
  • Computer Science in Algebra Powered by Bootstrap
    Computer Science in Algebra Powered by Bootstrap Instructor Handbook 2015-2016 U UNPLUGGED Video Games and Coordinate Planes Lesson time: 30-60 Minutes LESSON OVERVIEW Students discuss the components of their favorite video games and discover that they can be reduced to a series of coordinates. They then explore coordinates in Cartesian space, identifying the coordinates for the characters in a game at various points in time. Once they are comfortable with coordinates, they brainstorm their own games and create sample coordinate lists for different points in time in their own game. LESSON OBJECTIVES Students will: Create a data model that describes a simple video game. Describe the movements of videogame characters by their change in coordinates. ANCHOR STANDARD Common Core Math Standards 6.NS.8: Solve real-world and mathematical problems by graphing points in all four quadrants of the coordinate plane. Include use of coordinates and absolute value to find distances between points with the same first coordinate or the same second coordinate. Additional standards alignment can be found at the end of this lesson TEACHING SUMMARY Getting Started 1) Vocabulary 2) Learning a Language Activity: Video Games and the Coordinate Plane 3) Reverse Engineer a Demo 4) Coordinate Planes Wrap-up 5) Brainstorming a Game TEACHING GUIDE 1 MATERIALS, RESOURCES, AND PREP For the Student Reverse Engineering Table (in the student workbook) Videogame Design Template (in the student workbook) For the Teacher Lesson slide deck Example Game Printed cutouts of the Ninja, Dragon, and Unicorn GETTING STARTED 1) Vocabulary This lesson has three new and important words: Apply - use a given function on some inputs Reverse Engineer - to extract knowledge or design information from an existing product Sprite - a graphic character on the screen.
    [Show full text]
  • Imperative Functional Programming
    Imp erative functional programming Simon L Peyton Jones Philip Wadler Dept of Computing Science University of Glasgow Email simonpjwadlerdcsglagsowacuk Octob er This paper appears in ACM Symposium on Principles Of Programming Languages POPL Charleston Jan pp This copy corrects a few minor typographical errors in the published version Abstract IO are constructed by gluing together smaller pro grams that do so Section Combined with higher We present a new mo del based on monads for p erform order functions and lazy evaluation this gives a ing inputoutput in a nonstrict purely functional lan highly expressive medium in which to express IO guage It is comp osable extensible ecient requires no p erforming computations Section quite the extensions to the type system and extends smo othly to reverse of the sentiment with which we b egan this incorp orate mixedlanguage working and inplace array section up dates We compare the monadic approach to IO with other standard approaches dialogues and continuations Section and eect systems and linear types Sec Introduction tion Inputoutput has always app eared to b e one of the less It is easily extensible The key to our implementation satisfactory features of purely functional languages t is to extend Haskell with a single form that allows one ting action into the functional paradigm feels like tting to call an any pro cedure written in the programming a square blo ck into a round hole Closely related dicul language C Kernighan Ritchie without ties are asso ciated with p erforming inplace
    [Show full text]
  • Concrete Abstractions
    Out of print; available for free at http://www.gustavus.edu/+max/concrete-abstractions.html Concrete Abstractions Copyright © 1999 by Max Hailperin, Barbara Kaiser, and Karl Knight Out of print; available for free at http://www.gustavus.edu/+max/concrete-abstractions.html Copyright © 1999 by Max Hailperin, Barbara Kaiser, and Karl Knight Out of print; available for free at http://www.gustavus.edu/+max/concrete-abstractions.html Concrete Abstractions An Introduction to Computer Science Using Scheme Max Hailperin Gustavus Adolphus College Barbara Kaiser Gustavus Adolphus College Karl Knight Gustavus Adolphus College An Imprint of Brooks/Cole Publishing Company ® An International Thomson Publishing Company Paci®c Grove ² Albany ² Belmont ² Bonn ² Boston ² Cincinnati ² Detroit Johannesburg ² London ² Madrid ² Melbourne ² Mexico City ² New York Paris ² Singapore ² Tokyo ² Toronto ² Washington Copyright © 1999 by Max Hailperin, Barbara Kaiser, and Karl Knight Out of print; available for free at http://www.gustavus.edu/+max/concrete-abstractions.html Sponsoring Editor: Suzanne Jeans Cover Design: Vernon T. Boes Marketing Team: Nathan Wilbur, Michele Mootz Cover Photo: Craig Cowan. Courtesy of Couturier Gallery, Editorial Assistant: Kathryn Schooling Los Angeles, CA Production Manager: Marlene Thom Project Management and Typesetting: Manuscript Editor: Linda Thompson Integre Technical Publishing Co., Inc. Interior Design: Merry Obrecht Sawdey Printing and Binding: Webcom, Ltd. COPYRIGHT 1999 by Brooks/Cole Publishing Company A division of International Thomson Publishing Inc. The ITP logo is a registered trademark used herein under license. JavaTM is a trademark of Sun Microsystems, Inc. All other products used herein are used for identi®cation purposes only, and may be trademarks or registered trademarks of their respective owners.
    [Show full text]
  • Php Simple Class Example
    Php Simple Class Example Inexorable and electrometric Timotheus betakes: which Padraig is gormless enough? Uninucleate and petty Coleman gutturalizing, but Yancey summarily tarried her nuttings. Flexed and uncalled-for Magnum still congregated his giftedness devouringly. Using which has been proven over time, is mist gray but that are difficult or hoped for example class, although it may cause it In small screen sizes from this simple example presenting some common interactions of food being said above. Thanks for pointing out holes in the script. PHP Class Example various object-oriented programming a class is a constructor prototype from which objects are created The class defines. This is explained in more detail below. Software overall website. Traits is very well house, create a process to combine classes have your positive feedback about object to use individual adapters, exactly that are constantly reviewed to. Open that class in php learn coding practices, please refresh teh page content of other classes should be simple example. What i a Laravel Interface? For reuse other functions which is simple php class is php simple class example of? Classes objects methods properties PHPenthusiast. With inheritance, very large ones, it should footage be advance to household its newest Episode itself. PHP Magic Methods and Class Aliases Alan Storm. We usually include too many methods as white like wise our class structures, nice tutorial, what society we pretend to introduce a pet of validation to prevent that object as being misused? A very fit and quite long example of inheritance in the PHP tree is creating some. Sorry from any inconvenience.
    [Show full text]
  • C, C++ and JAVA: the Magic of Computer Programming Language
    Volume 3, Issue 12, December – 2018 International Journal of Innovative Science and Research Technology ISSN No:-2456-2165 C, C++ and JAVA: The Magic of Computer Programming Language Prajakta Pahade, Shweta Agrawal, Priyanka Patil Department of Computer Science and Engineering Prof. Ram Meghe College of Engineering and Management, Badnera Abstract:- This paper is all about to do the basic study of operating system because of Cfront. Java was begined as a the programming language. It is very necessary to have project. This project is known as "Oak" and was introduced basic ideas of the languages i.e C, C++ and JAVA to learn by James Gosling[4]. He thought to make language that was new innovative technologies. The C language was similar to C-like notation and had more uniformity and introduced in 1970s to make a program on the computer simplicity than Java so he implemented Java Virtual which can be run very easily. This need led Ritchie to Machine. In 1995, the first implementation on Java was Java develop the programming language called C[2]. Later on 1.0. It gave the statement “Write Once, Read Anywhere”[4]. the speed to work changed and people want everything It could be on popular platform with free runtimes. Its to get their work faster and hence C++ language was security was configurable so it was pretty secured but introduced which literally means increment of C by 1[1]. allowing for network and also file access to be limited. The purpose of C++ is to make writing good programs Using advent of “Java 2”, new version of huge and small easier and more pleasant for the individual programmer.
    [Show full text]
  • The Ultimate Guide to Object-Oriented Php for Wordpress Developers Leveling up As Wordpress Developer with Object-Oriented Php What’S Inside
    THE ULTIMATE GUIDE TO OBJECT-ORIENTED PHP FOR WORDPRESS DEVELOPERS LEVELING UP AS WORDPRESS DEVELOPER WITH OBJECT-ORIENTED PHP WHAT’S INSIDE INTRODUCTION 5 PHP IN A REST API WORLD 5 PHP 7 — GUEST CHAPTER BY TOM EWER 7 HOW PHP TOOK OVER THE WEB 8 PHP 7 FINALLY HEAVES INTO VIEW 8 WORDPRESS IS ABOUT TO GET WINGS 9 THERE ARE TWO KEY POINTS TO EMPHASIZE HERE 10 WHY DEVELOPERS ARE HOLDING FIRE ON SWITCHING 11 ARE YOU GOING TO USE PHP 7 IN PRODUCTION? 11 WHAT’S NEXT? 12 PHP FUNDAMENTALS 13 VARIABLES AND CONSTANTS 14 DATA TYPES 15 FUNCTIONS AND SCOPE 17 OBJECT-ORIENTED PHP 19 BEFORE WE BEGIN 20 METHODS VS. FUNCTIONS 20 PROPERTIES VS. VARIABLES 22 USING HOOKS IN CLASSES 22 MORE FUN WITH __CONSTRUCT() 23 WP_QUERY: THE OBJECT-ORIENTED PHP 24 A LITTLE BACKGROUND 25 WP_QUERY 26 MAKING YOUR OWN 27 WORDPRESS AS A GATEWAY TO OBJECT-ORIENTED 27 VISIBILITY IN OBJECT-ORIENTED PHP 28 ENCAPSULATION AND SCOPE 29 CLASSES VS. OBJECTS 30 THE THREE LEVELS OF VISIBILITY 30 RULES OF PROPERTY VISIBILITY 31 RULES OF METHOD VISIBILITY 33 WHY VISIBILITY MATTERS 35 A FEW LAST WORDS 36 CLASS INHERITANCE IN OBJECT-ORIENTED PHP 37 CLASS INHERITANCE 38 EXTENDING CLASSES AND OVERRIDING 38 ABSTRACT CLASSES 39 LESS CODE, BETTER CODE 41 HOW TO USE ASYNCHRONOUS PHP IN WORDPRESS 42 HOW IT WORKS 43 THE PROBLEM: ALL AT ONCE OR NOTHING 44 SETTING IT UP 44 WIRING IT UP 47 MORE ASYNCHRONOUS 46 REST APIS AND PHP 48 DESIGNING THE SYSTEM 49 PUTTING IT TOGETHER 55 STARTING IT UP 57 STARTING WITH A SYSTEM 59 PHP MAGIC METHODS 60 CONSTRUCTOR 61 SETTING HOOKS IN THE CONSTRUCTOR 61 MAGIC SETTERS
    [Show full text]
  • Lecture Notes in Computer Science 4807 Commenced Publication in 1973 Founding and Former Series Editors: Gerhard Goos, Juris Hartmanis, and Jan Van Leeuwen
    Lecture Notes in Computer Science 4807 Commenced Publication in 1973 Founding and Former Series Editors: Gerhard Goos, Juris Hartmanis, and Jan van Leeuwen Editorial Board David Hutchison Lancaster University, UK Takeo Kanade Carnegie Mellon University, Pittsburgh, PA, USA Josef Kittler University of Surrey, Guildford, UK Jon M. Kleinberg Cornell University, Ithaca, NY, USA Friedemann Mattern ETH Zurich, Switzerland John C. Mitchell Stanford University, CA, USA Moni Naor Weizmann Institute of Science, Rehovot, Israel Oscar Nierstrasz University of Bern, Switzerland C. Pandu Rangan Indian Institute of Technology, Madras, India Bernhard Steffen University of Dortmund, Germany Madhu Sudan Massachusetts Institute of Technology, MA, USA Demetri Terzopoulos University of California, Los Angeles, CA, USA Doug Tygar University of California, Berkeley, CA, USA Moshe Y. Vardi Rice University, Houston, TX, USA Gerhard Weikum Max-Planck Institute of Computer Science, Saarbruecken, Germany Zhong Shao (Ed.) Programming Languages and Systems 5th Asian Symposium, APLAS 2007 Singapore, November 29-December 1, 2007 Proceedings 13 Volume Editor Zhong Shao Yale University Department of Computer Science 51 Prospect Street New Haven, CT 06520-8285, U.S.A. E-mail: [email protected] Library of Congress Control Number: 2007938893 CR Subject Classification (1998): D.3, D.2, F.3, D.4, D.1, F.4.1 LNCS Sublibrary: SL 2 – Programming and Software Engineering ISSN 0302-9743 ISBN-10 3-540-76636-7 Springer Berlin Heidelberg New York ISBN-13 978-3-540-76636-0 Springer Berlin Heidelberg New York This work is subject to copyright. All rights are reserved, whether the whole or part of the material is concerned, specifically the rights of translation, reprinting, re-use of illustrations, recitation, broadcasting, reproduction on microfilms or in any other way, and storage in data banks.
    [Show full text]