• Complain

Joshua Backfield [Joshua Backfield] - Becoming Functional

Here you can read online Joshua Backfield [Joshua Backfield] - Becoming Functional full text of the book (entire story) in english for free. Download pdf and epub, get meaning, cover and reviews about this ebook. year: 2014, publisher: O’Reilly Media, Inc., genre: Business. Description of the work, (preface) as well as reviews are available. Best literature library LitArk.com created for fans of good reading and offers a wide selection of genres:

Romance novel Science fiction Adventure Detective Science History Home and family Prose Art Politics Computer Non-fiction Religion Business Children Humor

Choose a favorite category and find really read worthwhile books. Enjoy immersion in the world of imagination, feel the emotions of the characters or learn something new for yourself, make an fascinating discovery.

Joshua Backfield [Joshua Backfield] Becoming Functional

Becoming Functional: summary, description and annotation

We offer to read an annotation, description, summary or preface (depends on what the author of the book "Becoming Functional" wrote himself). If you haven't found the necessary information about the book — write in the comments, we will try to find it.

If you have an imperative (and probably object-oriented) programming background, this hands-on book will guide you through the alien world of functional programming. Author Joshua Backfield begins slowly by showing you how to apply the most useful implementation concepts before taking you further into functional-style concepts and practices.

Joshua Backfield [Joshua Backfield]: author's other books


Who wrote Becoming Functional? Find out the surname, the name of the author of the book and a list of all author's works by series.

Becoming Functional — read online for free the complete book (whole text) full work

Below is the text of the book, divided by pages. System saving the place of the last page read, allows you to conveniently read the book "Becoming Functional" online for free, without having to search again every time where you left off. Put a bookmark, and you can go to the page where you finished reading at any time.

Light

Font size:

Reset

Interval:

Bookmark:

Make
Chapter 1. Introduction

Our first step before we get into actual examples is to look at what defines functional programming. Specifically, we will look at the components that make up functional programming and how they relate to mathematics.

Note

Functional programming traces its roots all the way back to LISP, although the paradigm name itself wasnt truly coined until John Backus delivered his 1977 Turing Awardwinning paper Can Programming Be Liberated From the von Neumann Style? A Functional Style and Its Algebra of Programs. In his lecture, Backus discusses multiple points about applications being built as combinations of algebraic equations.

Overview of Concepts in Functional Programming

Although there is still some disagreement about what functional programming is, there are a few features that are generally agreed to be part of it:

  • First-class functions
  • Pure functions
  • Recursion
  • Immutable variables
  • Nonstrict evaluation
  • Statements
  • Pattern matching
First-Class Functions

First-class functions can either accept another function as an argument or return a function. Being able to create functions and return them or pass them to other functions becomes extremely useful in code reusability and code abstractions.

Pure Functions

Pure functions are functions that have no side effects. Side effects are actions a function may perform that are not solely contained within the function itself. When we think about side effects, we normally think about other functions, such as println or mutating a global variable. We can also see this when we pass in a variable and mutate it directly inside of that function.

Recursion

Recursion allows us to write smaller, more concise algorithms and to operate by looking only at the inputs to our functions. This means that our function is concerned only with the iteration it is on at the moment and whether it must continue.

Immutable Variables

Immutable variables , once set, cannot be changed. Although immutability seems very difficult to do, given the fact that the state must change within an application at some point, well see ways that we can accomplish it.

Nonstrict Evaluation

Nonstrict evaluations allow us to have variables that have not been computed yet. Strict evaluationsassigning a variable as soon as it is definedare what we are used to. Nonstrict means that we can have a variable that does not get assigned (computed) until the first time it is referenced.

Statements

Statements are evaluable pieces of code that have a return value. Think about if statements that have a return value of some kind. Each line of code should be considered a statement, meaning there are very few side effects within the application itself.

Pattern Matching

Pattern matching doesnt really appear in mathematics, but assists functional programming in decreasing the need for specific variables. In code we usually encapsulate a group of variables together inside of an object. Pattern matching allows us to better type-check and extract elements from an object, making for simpler and more concise statements with less need for variable definitions.

Functional Programming and Concurrency

Concurrency enables us to do processing in parallel, and we wont cover much about it here because the topic could fill its own book. Some people believe that functional programming actually solves concurrency issues, but this is not actually the case; rather, some of the concepts of functional programming help us to create more well-defined patterns to handle concurrency.

For example, techniques such as message passing help us to create more independent threads by allowing a thread to receive messages without causing another thread to block before it is received.

In addition, features such as immutability help us to define global states and allow global state transitions as a whole rather than partial state changes or major synchronizations between threads.

Conclusion

This chapter was intended as a high-level overview of the important concepts of functional programming. At this point youre probably wondering how can I actually get started using these concepts? As we go through this book, well look at how to implement these features in your code.

In each chapter, Ill introduce a concept, and then well work to refactor and implement it in our example code for the ficticious company XXY. The examples have no driver code. I assume that everyone reading this book can write simple Java main() functions to test out the code were writing. Im doing this for two reasons.

First, I really want you to write the code and test it out yourself; just reading the examples isnt going to help you understand the concepts or help you become a better functional programmer.

Second, I want to draw attention away from the driver code. Sometimes, when writing more extraneous code to actually call the code that were refactoring, we either forget to refactor the driver code or tend to write too much. Would it really be useful to create a set of driver code to create 10 or 20 Customer objects?

Each language example is compilable and runnable. The language examples will not rely on external packages. One of the things I truly dislike about some concept books or language books is that normally the author will push you to download third-party packages. In contrast, the goal of this book is to teach you how to deal with functional concepts using the core language.

Chapter 2. First-Class Functions

Although most functional programming books present immutable variables first, were going to start with first-class functions. My hope is that as you read through this chapter, you will see ways in which you could start using some of these ideas at your job tomorrow.

First-class functions are functions treated as objects themselves, meaning we can pass a function as a parameter to another function, return a function from a function, or store a function in a variable. This is one of the most useful features in functional programming, and also one of the most difficult to learn to use effectively.

Introduction to XXY

Welcome to your new company, XXY. You have been hired for your functional programming skills, which your boss would like to use in order to make the companys code more functional. XXY currently uses Java but is interested in some newer languages such as Groovy or Scala. Although you have some ideas, you have been told that the company cant afford to just throw away all of its current code and start over.

All right, its time to get down to business. You have been tasked with adding a new function to return a list of enabled customers addresses. Your boss tells you the code should be added to the Customer.java file, where ).

Example 2-1. Customer.java file contents
importjava.util.ArrayList;importjava.util.List;publicclassCustomer{staticpublicArrayList<Customer>allCustomers=newArrayList<Customer>();publicInteger
Next page
Light

Font size:

Reset

Interval:

Bookmark:

Make

Similar books «Becoming Functional»

Look at similar books to Becoming Functional. We have selected literature similar in name and meaning in the hope of providing readers with more options to find new, interesting, not yet read works.


Reviews about «Becoming Functional»

Discussion, reviews of the book Becoming Functional and just readers' own opinions. Leave your comments, write what you think about the work, its meaning or the main characters. Specify what exactly you liked and what you didn't like, and why you think so.