Discover millions of ebooks, audiobooks, and so much more with a free trial

Only $11.99/month after trial. Cancel anytime.

Five Lines of Code: How and when to refactor
Five Lines of Code: How and when to refactor
Five Lines of Code: How and when to refactor
Ebook702 pages7 hours

Five Lines of Code: How and when to refactor

Rating: 0 out of 5 stars

()

Read preview

About this ebook

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.

Foreword by Robert C. Martin.

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
LanguageEnglish
PublisherManning
Release dateNov 9, 2021
ISBN9781638356370
Five Lines of Code: How and when to refactor

Related to Five Lines of Code

Related ebooks

Programming For You

View More

Related articles

Reviews for Five Lines of Code

Rating: 0 out of 5 stars
0 ratings

0 ratings0 reviews

What did you think?

Tap to rate

Review must be at least 10 words

    Book preview

    Five Lines of Code - Christian Clausen

    2abook_preview_excerpt.html}Isƶ_"J(EIEOڽ iR~wsot_;d"BiS d晧nwM[W{W6.ɂ~hu7w;seNERۅI۪v2Yul QُśãIxݽ;{764^bʶy%i&qmʶ6Iu];{ CqrqrqEr<]6eUC3&V2kkZ10mnyLLsV+ilsq.8?)MզC*[WvuUm#yVtM#µY.O^:9|yߧ缳w'+Kڦ1OFvEە&K[ZVHmx ǯh7ON^/856 K4 nhr2eY]s\MӺ&MZ8o_<99?9=yyf@ mfhiKk::B :Κ4O*&@ dFմݡxpwdu¥MKJoӮuWPre؆p|^en.޼~x󟓳Ë7(.xLLZeN"}-!T=" <={499={y|zpdvmKZd3n\ry|]u;bМWNx Iw6f/^H ^cMlS ZD !n ;'Ȯ 7g'ՇaϒW?'+dmܾ aQ$|`Ă,pS~UuqkݏBDmvv$5#lrg{<"146H d0zͿλzm(c42 r|bva o <8͜~ɬ_m%WpTW5YbU ̀^C>ږ k4P#A+HŠ) _˂cqlH0>m1c] )"@uKHѫ !FPntI̕ɾp&w5)-2_!L}`=/dy/Fqѯ48_W@vL/z0߯ѯ&D2FtŻH;OgGxٽe5`o?qD_Ow l($ ͬȬkV:~ ;n?QWn0O"]5̃5|,vz{=,Ӄp1 [ln?N!@<ݎL+,eg Si]VmU}wyp];ׄ-HO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