万本电子书0元读

万本电子书0元读

顶部广告

Hands-On Functional Programming in Rust电子书

售       价:¥

8人正在读 | 0人评论 9.8

作       者:Andrew Johnson

出  版  社:Packt Publishing

出版时间:2018-05-31

字       数:33.0万

所属分类: 进口书 > 外文原版书 > 电脑/网络

温馨提示:数字商品不支持退换货,不提供源文件,不支持导出打印

为你推荐

  • 读书简介
  • 目录
  • 累计评论(0条)
  • 读书简介
  • 目录
  • 累计评论(0条)
Explore the support Rust offers for creating functional applications in Rust. Learn about various design patterns, implementing concurrency, metaprogramming, and so on in the process About This Book ? Learn generics, organization, and design patterns in functional programming ? Modularize your applications and make them highly reusable and testable using functional design patterns ? Get familiar with complex concepts such as metaprogramming, concurrency, and immutability Who This Book Is For This book is for Rust developers who are comfortable with the language and now want to improve their coding abilities by learning advanced functional techniques to enhance their skillset and create robust and testable apps. What You Will Learn ? How Rust supports the use of basic functional programming principles ? Use functional programming to handle concurrency with elegance ? Read and interpret complex type signatures for types and functions ? Implement powerful abstractions using meta programming in Rust ? Create quality code formulaically using Rust's functional design patterns ? Master Rust's complex ownership mechanisms particularly for mutability In Detail Functional programming allows developers to divide programs into smaller, reusable components that ease the creation, testing, and maintenance of software as a whole. Combined with the power of Rust, you can develop robust and scalable applications that fulfill modern day software requirements. This book will help you discover all the Rust features that can be used to build software in a functional way. We begin with a brief comparison of the functional and object-oriented approach to different problems and patterns. We then quickly look at the patterns of control flow, data the abstractions of these unique to functional programming. The next part covers how to create functional apps in Rust; mutability and ownership, which are exclusive to Rust, are also discussed. Pure functions are examined next and you'll master closures, their various types, and currying. We also look at implementing concurrency through functional design principles and metaprogramming using macros. Finally, we look at best practices for debugging and optimization. By the end of the book, you will be familiar with the functional approach of programming and will be able to use these techniques on a daily basis. Style and approach Step-by-step guide covering advanced concepts and building functional applications in Rust
目录展开

Title Page

Copyright and Credits

Hands-On Functional Programming in Rust

Packt Upsell

Why subscribe?

PacktPub.com

Contributors

About the author

About the reviewer

Packt is searching for authors like you

Preface

Who this book is for

What this book covers

To get the most out of this book

Download the example code files

Conventions used

Get in touch

Reviews

Functional Programming – a Comparison

Technical requirements

Reducing code weight and complexity

Making generics more generic

Functions as values

Iterators

Compact legible expressions

Strict abstraction means safe abstraction

Scoped data binding

Algebraic datatypes

Mixing object-oriented programming and functional programming

Improving project architecture

File hierarchy, modules, and namespace design

Functional design patterns

Metaprogramming

Summary

Questions

Further reading

Functional Control Flow

Technical requirements

Designing the program

Gathering project requirements

Architecting a code map from requirements

Creating a Rust project

Writing stubs for each program requirement

Implementing program logic

Filling in the blanks

Parsing input and storing as building description and floor requests

Updating location, velocity, and acceleration

If the next floor request in the queue is satisfied, then remove it from the queue

Adjusting motor control to process the next floor request

Printing real-time statistics

Printing summary

Breaking down long segments into components

Searching for abstractions

Writing tests

Unit testing

Integration testing

Summary

Questions

Functional Data Structures

Technical requirements

Adjusting to changing the scope of the project

Gathering new project requirements

Architecting a change map from requirements

Translating expectations into requirements

Translating requirements into a change map

Mapping requirements directly to code

Writing the physics simulator

Writing the motor controller

Writing the executable to run a simulation

Writing the executable to analyze a simulation

Running simulations and analyzing data

Summary

Questions

Generics and Polymorphism

Technical requirements

Staying productive during downtime

Learning about generics

Investigating generics

Investigating parametric polymorphism

Investigating generalized algebraic datatypes

Investigating parametric lifetimes

Defining lifetimes on ground types

Defining lifetimes on generic types

Defining lifetimes on traits

Defining lifetime subtyping

Investigating parametric types

Applying parameterization concepts

Parameterizing data

Parameterizing functions and trait objects

Parametric traits and implementations

Summary

Questions

Code Organization and Application Architecture

Technical requirements

Shipping a product without sacrificing quality

Reorganizing the project

Planning content of files by type

Organizing the motor_controllers.rs module

Organizing the buildings.rs module

Planning content of files by purpose

Organizing the motion_controllers.rs module

Organizing the trip_planning.rs module

Organizing the elevator_drivers.rs module

Planning content of files by layer

Organizing the physics.rs module

Organizing the data_recorder.rs module

Planning the content of files by convenience

Organizing the simulate_trip.rs executable

Organizing the analyze_trip.rs executable

Organizing the operate_elevator.rs executable

Mapping code changes and additions

Developing code by type

Writing the motor_controllers.rs module

Writing the buildings.rs module

Developing code by purpose

Writing the motion_controllers.rs module

Writing the trip_planning.rs module

Writing the elevator_drivers.rs module

Developing code by layer

Writing the physics.rs module

Writing the data_recorders.rs module

Developing code by convenience

Writing the simulate_trip.rs executable

Writing the analyze_trip.rs executable

Writing the operate_elevator.rs executable

Reflecting on the project structure

Summary

Questions

Mutability, Ownership, and Pure Functions

Technical requirements

Recognizing anti-patterns of ownership

Inspecting the microcontroller drivers

Inspecting the type and trait definitions

Defining the OverrideCode enum

Defining the ErrorCode enum

Defining the AuthorizedSession struct and deconstructor

Authorizing sessions

Checking errors and resetting state

Privileged commands

Normal commands

Querying library and session state

Inspecting the foreign library tests

Issuing override codes

Accessing status information and sessions

Deactivating active sessions

Issuing normal commands

Issuing privileged commands

Denying unauthorized commands

Inspecting the Rust tests

Rust authorization with sessions

Rust sharing session reference

Privileged commands

Unprivileged commands

Denying access to privileged commands

Learning the rules of ownership

When the owner goes out of scope, the value will be dropped

Using immutable data

Fixing the hard-to-reproduce bug

Preventing hard-to-reproduce bugs

Using pure functions

Summary

Questions

Design Patterns

Technical requirements

Using the functor pattern

Using the monad pattern

Using the combinator pattern

Parser combinators

Using the lazy evaluation pattern

Summary

Questions

Implementing Concurrency

Technical requirements

Using subprocess concurrency

Understanding nix fork concurrency

Using thread concurrency

Understanding Send and Sync traits

Using functional design for concurrency

Summary

Questions

Performance, Debugging, and Metaprogramming

Technical requirements

Writing faster code

Compiling with release mode

Doing less work

Optimizing the code that needs it – profiling

For a code rarely executed, performance is not affected

Multiples of small numbers are also small numbers

Measuring first, to optimize it

Putting the fridge next to the computer

Capping the Big O

Constanting no growth

Logarithmic growth

Polynomial growth

Exponential growth

Referencing data is faster

Preventing bugs with defensive coding

Using Option and Result instead of panic!

Using typesafe interfaces instead of stringly typed interfaces

Using the heartbeat pattern for long running processes

Validating input and output

Finding and fixing bugs

Metaprogramming

Summary

Questions

Assessments

Functional Programming – a Comparison

Functional Control Flow

Functional Data Structures

Generics and Polymorphism

Code Organization and Application Architecture

Mutability, Ownership, and Pure Functions

Design Patterns

Implementing Concurrency

Performance, Debugging, and Metaprogramming

Other Books You May Enjoy

Leave a review - let other readers know what you think

累计评论(0条) 0个书友正在讨论这本书 发表评论

发表评论

发表评论,分享你的想法吧!

买过这本书的人还买过

读了这本书的人还在读

回顶部