Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống
1
/ 88 trang
THÔNG TIN TÀI LIỆU
Thông tin cơ bản
Định dạng
Số trang
88
Dung lượng
4,61 MB
Nội dung
[...]... today than before While Agile Software Development has greatly improved our quality and our ability to respond to change, we need to rethink ways to keep our code “minimally sufficient” for the requirements today, yet flexible for change Functionalprogramming helps us do just that FunctionalProgramming Is a Return to Simplicity Finally, building on the previous points, I see functional programming. .. 1 Why Functional Programming? A few years ago, when many developers started talking about functionalprogramming (FP) as the best way to approach concurrency, I decided it was time to learn more and judge for myself I expected to learn some new ideas, but I assumed I would still use object-oriented programming (OOP) as my primary approach to software development I was wrong As I learned about functional. .. enthusiasm for the art and science of software development I hope this short introduction will show you why my thinking changed Maybe your thinking will change, too Let’s begin! † I don’t mean that functionalprogramming is simple Becoming an expert in functionalprogramming requires mastery of many advanced, yet powerful concepts FunctionalProgramming Is a Return to Simplicity | 5 CHAPTER 2 What Is Functional. .. the literature on functionalprogramming reflects its mathematical roots, which can be overwhelming if you don’t have a strong math background In contrast, objectoriented programming seems more intuitive and approachable Fortunately, you can learn and use the principles of functionalprogramming without a thorough grounding in mathematics 7 The first language to incorporate functionalprogramming ideas... JVM but are being ported to the NET environment Today, many other languages are incorporating ideas from functionalprogramming The Basic Principles of FunctionalProgramming Don’t all programming languages have functions? If so, why aren’t all programming languages considered functional languages? Functional languages share a few basic principles Avoiding Mutable State The first principle is the use... types for anonymous functions: 12 | Chapter 2: What Is Functional Programming? package functions; public interface Function2 { R apply(A1 a1, A2 a2); } Unfortunately, you would need a separate interface for every function “arity” you want (arity is the number of arguments) Actually, it’s that number times two; one for the void return case and one for the non-void return case However, the effort... 1950s and is the second-oldest high-level programming language, after Fortran The ML family of programming languages started in the 1970s, including Caml, OCaml (a hybrid object -functional language), and Microsoft’s F# Perhaps the best known functional language that comes closest to functional “purity” is Haskell, which was started in the early 1990s Other recent functional languages include Clojure and... FunctionalProgramming Is a Return to Simplicity | 5 CHAPTER 2 What Is Functional Programming? Functional programming, in its “purest” sense, is rooted in how functions, variables, and values actually work in mathematics, which is different from how they typically work in most programming languages Functionalprogramming got its start before digital computers even existed Many of the theoretical underpinnings... about functional programming, I found good ideas for implementing concurrency, as I expected, but I also found that it brought new clarity to my thinking about the design of types* and functions It also allowed me to write more concise code Functionalprogramming made me rethink where module boundaries should go and how to make those modules better for reuse I found that the functionalprogramming community... good type design First, all functional languages emphasize the use of core container types, like lists, maps, trees, and sets for capturing and transforming data, which we’ll explore in Chapter 3 Here, I want to discuss two other benefits of functional thinking about types, enforcing valid values for variables and applying rigor to type design What About Nulls? In a pure functional language where values .