Book description
In Five Lines of Code you will learn:- The signs of bad code
- Improving code safely, even when you don’t understand it
- Balancing optimization and code generality
- Proper compiler practices
- The Extract method, Introducing Strategy pattern, and many other refactoring patterns
- Writing stable code that enables change-by-addition
- Writing code that needs no comments
- Real-world practices for great refactoring
Improving existing code—refactoring—is one of the most common tasks you’ll face as a programmer. Five Lines of Code teaches you clear and actionable refactoring rules that you can apply without relying on intuitive judgements such as “code smells.” Following the author’s expert perspective—that refactoring and code smells can be learned by following a concrete set of principles—you’ll learn when to refactor your code, what patterns to apply to what problem, and the code characteristics that indicate it’s time for a rework.
About the Technology
Every codebase includes mistakes and inefficiencies that you need to find and fix. Refactor the right way, and your code becomes elegant, easy to read, and easy to maintain. In this book, you’ll learn a unique approach to refactoring that implements any method in five lines or fewer. You’ll also discover a secret most senior devs know: sometimes it’s quicker to hammer out code and fix it later!
About the Book
Five Lines of Code is a fresh look at refactoring for developers of all skill levels. In it, you’ll master author Christian Clausen’s innovative approach, learning concrete rules to get any method down to five lines—or less! You’ll learn when to refactor, specific refactoring patterns that apply to most common problems, and characteristics of code that should be deleted altogether.
What's Inside
- The signs of bad code
- Improving code safely, even when you don’t understand it
- Balancing optimization and code generality
- Proper compiler practices
About the Reader
For developers of all skill levels. Examples use easy-to-read Typescript, in the same style as Java and C#.
About the Author
Christian Clausen works as a Technical Agile Coach, teaching teams how to refactor code.
Quotes
Down to earth, focused, and right on point. It will challenge you without intimidating you and without insulting your intelligence.
- Robert C. Martin
A delightful and fun introduction to one of the most overlooked parts of programming—refactoring.
- Charles Lam, EVN AG
Gave me new insights on how to keep my code readable and maintainable. I highly recommend it.
- John Norcott, Webstaurantstore
These techniques are simple but powerful, and the exercises makes it easy to learn them. They can be used in any language I know!
- Christian Hasselbalch Thoudahl, BEC Financial Technologies
Publisher resources
Table of contents
- inside front cover
- Five Lines of Code
- Copyright
- dedication
- brief contents
- contents
- front matter
- 1 Refactoring refactoring
- 2 Looking under the hood of refactoring
- Part 1. Learn by refactoring a computer game
- 3 Shatter long functions
- 4 Make type codes work
- 5 Fuse similar code together
- 6 Defend the data
- Part 2. Taking what you have learned into the real world
-
7 Collaborate with the compiler
-
7.1 Getting to know the compiler
- 7.1.1 Weakness: The halting problem limits compile-time knowledge
- 7.1.2 Strength: Reachability ensures that methods return
- 7.1.3 Strength: Definite assignment prevents accessing uninitialized variables
- 7.1.4 Strength: Access control helps encapsulate data
- 7.1.5 Strength: Type checking proves properties
- 7.1.6 Weakness: Dereferencing null crashes our application
- 7.1.7 Weakness: Arithmetic errors cause overflows or crashes
- 7.1.8 Weakness: Out-of-bounds errors crash our application
- 7.1.9 Weakness: Infinite loops stall our application
- 7.1.10 Weakness: Deadlocks and race conditions cause unintended behavior
- 7.2 Using the compiler
- 7.3 Trusting the compiler
- 7.4 Trusting the compiler exclusively
- Summary
-
7.1 Getting to know the compiler
- 8 Stay away from comments
-
9 Love deleting code
- 9.1 Deleting code may be the next frontier
- 9.2 Deleting code to get rid of incidental complexity
- 9.3 Categorizing code based on intimacy
- 9.4 Deleting code in a legacy system
- 9.5 Deleting code from a frozen project
- 9.6 Deleting branches in version control
- 9.7 Deleting code documentation
- 9.8 Deleting testing code
- 9.9 Deleting configuration code
- 9.10 Deleting code to get rid of libraries
- 9.11 Deleting code from working features
- Summary
-
10 Never be afraid to add code
- 10.1 Accepting uncertainty: Enter the danger
- 10.2 Using spikes to overcome the fear of building the wrong thing
- 10.3 Overcoming the fear of waste or risk with a fixed ratio
- 10.4 Overcoming the fear of imperfection by embracing gradual improvement
- 10.5 How copy and paste effects change velocity
- 10.6 Modification by addition through extensibility
- 10.7 Modification by addition enables backward compatibility
- 10.8 Modification by addition through feature toggles
- 10.9 Modification by addition through branch by abstraction
- Summary
-
11 Follow the structure in the code
- 11.1 Categorizing structure based on scope and origin
- 11.2 Three ways that code mirrors behavior
- 11.3 Adding code to expose structure
- 11.4 Observing instead of predicting, and using empirical techniques
- 11.5 Gaining safety without understanding the code
- 11.6 Identifying unexploited structures
- Summary
- 12 Avoid optimizations and generality
-
13 Make bad code look bad
- 13.1 Signaling process issues with bad code
- 13.2 Segregating into pristine and legacy code
- 13.3 Approaches to defining bad code
- 13.4 Rules for safely vandalizing code
-
13.5 Methods for safely vandalizing code
- 13.5.1 Using enums
- 13.5.2 Using ints and strings as type codes
- 13.5.3 Putting magic numbers in the code
- 13.5.4 Adding comments to the code
- 13.5.5 Putting whitespace in the code
- 13.5.6 Grouping things based on naming
- 13.5.7 Adding context to names
- 13.5.8 Creating long methods
- 13.5.9 Giving methods many parameters
- 13.5.10 Using getters and setters
- Summary
- 14 Wrapping up
- Appendix A. Installing the tools for part 1
- index
- inside back cover
Product information
- Title: Five Lines of Code
- Author(s):
- Release date: October 2021
- Publisher(s): Manning Publications
- ISBN: 9781617298318
You might also like
book
The Art of Clean Code
Most software developers waste thousands of hours working with overly complex code. The eight core principles …
book
Good Code, Bad Code
Practical techniques for writing code that is robust, reliable, and easy for team members to understand …
article
Write Clean Code from Scratch
This collection is designed to equip developers with practical strategies and techniques for writing high-quality, maintainable …
book
Programming C# 10
C# is undeniably one of the most versatile programming languages available to engineers today. With this …