Programming with Types
Summary

Programming with Types teaches you to design safe, resilient, correct software that’s easy to maintain and understand by taking advantage of the power of strong type systems. Designed to provide practical, instantly useful techniques for working developers, this clearly written tutorial introduces you to using type systems to support everyday programming tasks.

Purchase of the print book includes a free eBook in PDF, Kindle, and ePub formats from Manning Publications.

About the technology

Common bugs often result from mismatched data types. By precisely naming and controlling which data are allowable in a calculation, a strong type system can eliminate whole classes of errors and ensure data integrity throughout an application. As a developer, skillfully using types in your everyday practice leads to better code and saves time tracking down tricky data-related errors.

About the book

Programming with Types teaches type-based techniques for writing software that’s safe, correct, easy to maintain, and practically self-documenting. Designed for working developers, this clearly written tutorial sticks with the practical benefits of type systems for everyday programming tasks. Following real-world examples coded in TypeScript, you’ll build your skills from primitive types up to more-advanced concepts like functors and monads.

What's inside

Building data structures with primitive types, arrays, and references
How types affect functions, inheritance, and composition
Object-oriented programming with types
Applying generics and higher-kinded types

About the reader

You’ll need experience with a mainstream programming language like TypeScript, Java, JavaScript, C#, or C++.

About the author

Vlad Riscutia is a principal software engineer at Microsoft. He has headed up several major software projects and mentors up-and-coming software engineers.
1131815096
Programming with Types
Summary

Programming with Types teaches you to design safe, resilient, correct software that’s easy to maintain and understand by taking advantage of the power of strong type systems. Designed to provide practical, instantly useful techniques for working developers, this clearly written tutorial introduces you to using type systems to support everyday programming tasks.

Purchase of the print book includes a free eBook in PDF, Kindle, and ePub formats from Manning Publications.

About the technology

Common bugs often result from mismatched data types. By precisely naming and controlling which data are allowable in a calculation, a strong type system can eliminate whole classes of errors and ensure data integrity throughout an application. As a developer, skillfully using types in your everyday practice leads to better code and saves time tracking down tricky data-related errors.

About the book

Programming with Types teaches type-based techniques for writing software that’s safe, correct, easy to maintain, and practically self-documenting. Designed for working developers, this clearly written tutorial sticks with the practical benefits of type systems for everyday programming tasks. Following real-world examples coded in TypeScript, you’ll build your skills from primitive types up to more-advanced concepts like functors and monads.

What's inside

Building data structures with primitive types, arrays, and references
How types affect functions, inheritance, and composition
Object-oriented programming with types
Applying generics and higher-kinded types

About the reader

You’ll need experience with a mainstream programming language like TypeScript, Java, JavaScript, C#, or C++.

About the author

Vlad Riscutia is a principal software engineer at Microsoft. He has headed up several major software projects and mentors up-and-coming software engineers.
49.99 In Stock
Programming with Types

Programming with Types

by Vlad Riscutia
Programming with Types

Programming with Types

by Vlad Riscutia

Paperback(1st Edition)

$49.99 
  • SHIP THIS ITEM
    In stock. Ships in 1-2 days.
  • PICK UP IN STORE

    Your local store may have stock of this item.

Related collections and offers


Overview

Summary

Programming with Types teaches you to design safe, resilient, correct software that’s easy to maintain and understand by taking advantage of the power of strong type systems. Designed to provide practical, instantly useful techniques for working developers, this clearly written tutorial introduces you to using type systems to support everyday programming tasks.

Purchase of the print book includes a free eBook in PDF, Kindle, and ePub formats from Manning Publications.

About the technology

Common bugs often result from mismatched data types. By precisely naming and controlling which data are allowable in a calculation, a strong type system can eliminate whole classes of errors and ensure data integrity throughout an application. As a developer, skillfully using types in your everyday practice leads to better code and saves time tracking down tricky data-related errors.

About the book

Programming with Types teaches type-based techniques for writing software that’s safe, correct, easy to maintain, and practically self-documenting. Designed for working developers, this clearly written tutorial sticks with the practical benefits of type systems for everyday programming tasks. Following real-world examples coded in TypeScript, you’ll build your skills from primitive types up to more-advanced concepts like functors and monads.

What's inside

Building data structures with primitive types, arrays, and references
How types affect functions, inheritance, and composition
Object-oriented programming with types
Applying generics and higher-kinded types

About the reader

You’ll need experience with a mainstream programming language like TypeScript, Java, JavaScript, C#, or C++.

About the author

Vlad Riscutia is a principal software engineer at Microsoft. He has headed up several major software projects and mentors up-and-coming software engineers.

Product Details

ISBN-13: 9781617296413
Publisher: Manning
Publication date: 12/07/2019
Edition description: 1st Edition
Pages: 325
Product dimensions: 7.30(w) x 9.10(h) x 0.80(d)

About the Author

Vlad Riscutia is a software architect at Microsoft.

Table of Contents

Preface xi

Acknowledgments xiii

About this book xiv

About the cover illustration xvii

1 Introduction to typing 1

1.1 Whom this book is for 2

1.2 Why types exist 2

Os and Is 3

What are types and type systems? 4

1.3 Benefits of type systems 5

Correctness 6

Immutability 7

Encapsulation 9

Composability 10

Readability 12

1.4 Types of type systems 13

Dynamic and static typing 13

Weak and strong typing 15

Type inference 16

1.5 In this book 17

2 Basic types 19

2.1 Designing functions that don't return values 20

The empty type 20

The unit type 22

Exercises 23

2.2 Boolean logic and short circuits 23

Boolean expressions 24

Short circuit evaluation 24

Exercise 26

2.3 Common pitfalls of numerical types 26

Integer types and overflow 27

Floating-point types and rounding 30

Arbitrarily large numbers 33

Exercises 33

2.4 Encoding text 34

Breaking text 34

Encodings 35

Encoding libraries 36

Exercises 38

2.5 Building data structures with arrays and references 38

Fixed-size arrays 39

References 40

Efficient lists 40

Binary trees 43

Associative arrays 45

Implementation trade-offs 46

Exercise 47

3 Composition 49

3.1 Compound types 50

Tuples 50

Assigning meaning 52

Maintaining invariants 53

Exercise 56

3.2 Expressing either-or with types 56

Enumerations 57

Optional types 58

Result or error 61

Variants 65

Exercises 68

3.3 The visitor pattern 69

A naïve implementation 69

Using the visitor pattern 70

Visiting a variant 73

Exercise 75

3.4 Algebraic data types 75

Product types 75

Sum types 76

Exercises 76

4 Type safety 79

4.1 Avoiding primitive obsession to prevent misinterpretation 80

The Mars Climate Orbiter 81

The primitive obsession antipattern 83

Exercise 83

4.2 Enforcing constraints 84

Enforcing constraints with the constructor 84

Enforcing constraints with a factory 85

Exercise 86

4.3 Adding type information 86

Type casting 86

Tracking types outside the type system 87

Common type casts 90

Exercises 93

4.4 Hiding and restoring type information 93

Heterogenous collections 94

Serialization 96

Exercises 100

5 Function types 102

5.1 A simple strategy pattern 103

A functional strategy 104

Typing functions 106

Strategy implementations 106

First-class functions 107

Exercises 107

5.2 A state machine without switch statements 108

Early Programming with Types 108

State machines 110

State machine implementation recap 116

Exercises 117

5.3 Avoiding expensive computation with lazy values 117

Lambdas 118

Exercise 120

5.4 Using map, filter, and reduce 120

Map() 120

Filter() 122

Reduce() 124

Library support 128

Exercises 128

5.5 Functional programming 128

6 Advanced applications of function types 131

6.1 A simple decorator pattern 132

A functional decorator 133

Decorator implementations 135

Closures 135

Exercises 137

6.2 Implementing a counter 137

An object-oriented counter 137

A functional counter 138

A resumable counter 139

Counter implementations recap 140

Exercises 140

6.3 Executing long-running operations asynchronously 141

Synchronous execution 141

Asynchronous execution: callbacks 142

Asynchronous execution models 143

Asynchronous functions recap 146

Exercises 147

6.4 Simplifying asynchronous code 147

Chaining promises 149

Creating promises 150

More about promises 152

Async/await 156

Clean asynchronous code recap 157

Exercises 158

7 Subtyping 161

7.1 Distinguishing between similar types in TypeScript 162

Structural and nominal subtyping pros and cons 164

Simulating nominal subtyping in TypeScript 165

Exercises 166

7.2 Assigning anything to, assigning to anything 167

Safe deserialization 167

Values for error cases 171

Top and bottom types recap 174

Exercises 174

7.3 Allowed substitutions 174

Subtyping and sum types 175

Subtyping and collections 177

Subtyping and function return types 179

Subtyping and function argument types 180

Variance recap 184

Exercises 184

8 Elements of object-oriented programming 187

8.1 Defining contracts with interfaces 188

Exercises 191

8.2 Inheriting data and behavior 191

The is-a rule of thumb 191

Modeling a hierarchy 192

Parameterizing behavior of expressions 193

Exercises 194

8.3 Composing data and behavior 195

The has-a rule of thumb 196

Composite classes 196

Implementing the adapter pattern 198

Exercises 200

8.4 Extending data and behavior 200

Extending behavior with composition 202

Extending behavior with mix-ins 203

Mix-in in TypeScript 204

Exercise 206

8.5 Alternatives to purely object-oriented code 206

Sum types 206

Functional programming 209

Generic programming 210

9 Generic data structures 213

9.1 Decoupling concerns 214

A reusable identity function 216

The optional type 217

Generic types 218

Exercises 219

9.2 Generic data layout 219

Generic data structures 220

What is a data structure? 220

Exercises 221

9.3 Traversing any data structure 221

Using iterators 223

Streamlining iteration code 227

Iterators recap 232

Exercises 233

9.4 Streaming data 233

Processing pipelines 234

Exercises 236

10 Generic algorithms and iterators 239

10.1 Better map(), filter(), reduce() 240

Map() 240

Filter() 241

Reduce() 242

Filter()/reduce()

Pipeline 242

Exercises 243

10.2 Common algorithms 243

Algorithms instead of loops 244

Implementing a fluent pipeline 245

Exercises 248

10.3 Constraining type parameters 248

Generic data structures with type constraints 249

Generic algorithms with type constraints 251

Exercise 252

10.4 Efficient reverse and other algorithms using iterators 253

Iterator building blocks 254

A useful find() 259

An efficient reverse() 262

Efficient element retrieval 265

Iterator recap 267

Exercises 268

10.5 Adaptive algorithms 268

Exercise 270

11 Higher kinded types and beyond 275

11.1 An even more general map 276

Processing results or propagating errors 279

Mix-ana-match function application 281

Functors and higher kinded types 282

Functors for functions 285

Exercise 287

11.2 Monads 287

Result or error 287

Difference between map() and bind() 291

The monad pattern 293

The continuation monad 294

The list monad 295

Other monads 298

Exercise 298

11.3 Where to next? 298

Functional programming 298

Generic programming 299

Higher kinded types and category theory 299

Dependent types 299

Linear types 300

Appendix A TypeScript installation and source code 303

Appendix B TypeScript cheat sheet 305

Index 309

From the B&N Reads Blog

Customer Reviews