Five Lines of Code teaches refactoring that's focused on concrete rules and getting any method down to five lines or less! There’s no jargon or tricky automated-testing skills required, just easy guidelines and patterns illustrated by detailed code samples.
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.
Purchase of the print book includes a free eBook in PDF, Kindle, and ePub formats from Manning Publications.
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.
Table of Contents
1 Refactoring refactoring
2 Looking under the hood of refactoring
PART 1 LEARN BY REFACTORING A COMPUTER GAME
3 Shatter long function
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
8 Stay away from comments
9 Love deleting code
10 Never be afraid to add code
11 Follow the structure in the code
12 Avoid optimizations and generality
13 Make bad code look bad
14 Wrapping up
EbookLicense
End-User Warranty And License Agreement
1. Grant Of License
Manning Has Authorized The Download By You Of An UnrestrictedNumber Of Copies Of The Electronic Book (Ebook) In Any Of The AvailableFormats. Manning Grants You A Nonexclusive, Nontransferable License To Use TheEbook According To The Terms And Conditions Herein. This License AgreementPermits You To Install The Ebook On Any And All Your Devices For Your PersonalUse Only.
2. Restrictions
You Shall Not: (1) Share, Resell, Rent, Assign, Timeshare,Distribute, Or Transfer All Or Part Of The Ebook Or Any Rights GrantedHereunder To Any Other Person; (2) Duplicate The Ebook, Except For A SingleBackup Or Archival Copy; (3) Remove Any Proprietary Notices, Labels, Or MarksFrom The Ebook; (4) Transfer Or Sublicense Title To The Ebook To Any Other Party.
3. Intellectual Property Protection
The Ebook Is Owned By Manning And Is Protected By United StatesAnd International Copyright And Other Intellectual Property Laws. ManningReserves All Rights In The Ebook Not Expressly Granted Herein. This License AndYour Right To Use The Ebook Terminate Automatically If You Violate Any Part OfThis Agreement. In The Event Of Termination, You Must Remove The Original AndAny Copies Of The Ebook From All Your Devices.
4. Source Code Supplementary Material
Any Source Code Files Provided As A Supplement To The Book AreFreely Available To The Public For Download. Reuse Of The Code Is Permitted, InWhole Or In Part, Including The Creation Of Derivative Works, Provided That YouAcknowledge That You Are Using It And Identify The Source: Title, Publisher AndYear.
5. Limited Warranty
Manning Warrants That The Ebook Files, A Copy Of Which You AreAuthorized To Download, Are Free From Defects In The Operational Sense ThatThey Can Be Read By A Pdf Reader Or Epub Reader, Or Other. Except For ThisExpress Limited Warranty, Manning Makes And You Receive No Warranties, Express,Implied, Statutory Or In Any Communication With You, And Manning SpecificallyDisclaims Any Other Warranty Including The Implied Warranty Of Merchantability OrFitness Or A Particular Purpose. Manning Does Not Warrant That The Operation OfThe Ebook Will Be Uninterrupted Or Error Free. If The Ebook Was Purchased InThe United States, The Above Exclusions May Not Apply To You As Some States DoNot Allow The Exclusion Of Implied Warranties. In Addition To The AboveWarranty Rights, You May Also Have Other Rights That Vary From State To State.
6. Limitation Of Liability
In No Event Will Manning Be Liable For Any Damages, WhetherArising For Tort Or Contract, Including Loss Of Data, Lost Profits, Or OtherSpecial, Incidental, Consequential, Or Indirect Damages Arising Out Of The UseOr Inability To Use The Ebook.
7. General
This Agreement Constitutes The Entire Agreement Between You AndManning And Supersedes Any Prior Agreement Concerning The Ebook. This AgreementIs Governed By The Laws Of The State Of New York