Refactoring JavaScript
Turning Bad Code Into Good Code
Paperback Engels 2017 1e druk 9781491964927Samenvatting
How often do you hear people say things like this? "Our JavaScript is a mess, but we’re thinking about using [framework of the month]."
Like it or not, JavaScript is not going away. No matter what framework or ”compiles-to-js” language or library you use, bugs and performance concerns will always be an issue if the underlying quality of your JavaScript is poor. Rewrites, including porting to the framework of the month, are terribly expensive and unpredictable. The bugs won’t magically go away, and can happily reproduce themselves in a new context. To complicate things further, features will get dropped, at least temporarily.
The other popular method of fixing your JS is playing “JavaScript Jenga,” where each developer slowly and carefully takes their best guess at how the out-of-control system can be altered to allow for new features, hoping that this doesn’t bring the whole stack of blocks down. This book provides clear guidance on how best to avoid these pathological approaches to writing JavaScript:
- Recognize you have a problem with your JavaScript quality.
- Forgive the code you have now, and the developers who made it.
- Learn repeatable, memorable, and time-saving refactoring techniques.
- Apply these techniques as you work, fixing things along the way.
- Internalize these techniques, and avoid writing as much problematic code to begin with.
Bad code doesn’t have to stay that way. And making it better doesn’t have to be intimidating or unreasonably expensive.
Specificaties
Lezersrecensies
Inhoudsopgave
1. What Is Refactoring?
How Can You Guarantee Behavior Doesn’t Change?
What Is the Point of Refactoring if Behavior Doesn’t Change?
What Is and Isn’t Refactoring
Wrapping Up
2. Which JavaScript Are You Using?
Versions and Specifications
Platforms and Implementations
Precompiled Languages
Frameworks
Libraries
What JavaScript Do You Need?
What JavaScript Are We Using?
Wrapping Up
3. Testing
The Many Whys of Testing
The Many Ways of Testing
Tools and Processes
Wrapping Up
4. Testing in Action
New Code from Scratch
New Code from Scratch with TDD
Untested Code and Characterization Tests
Debugging and Regression Tests
Wrapping Up
5. Basic Refactoring Goals
Function Bulk
Inputs
Outputs
Side Effects
Context Part 1: The Implicit Input
Context Part 2: Privacy
Wrapping Up
6. Refactoring Simple Structures
The Code
Our Strategy for Confidence
Renaming Things
Useless Code
Variables
Strings
Working with Arrays: Loops, forEach, map
Wrapping Up
7. Refactoring Functions and Objects
The Code (Improved)
Array and Object Alternatives
Testing What We Have
Extracting Functions
Streamlining the API with One Global Object
Wrapping Up
8. Refactoring Within a Hierarchy
About “CRUD Apps” and Frameworks
Let’s Build a Hierarchy
Let’s Wreck Our Hierarchy
Inheritance and Architecture
Has-A Relationships
Inheritance Antipatterns
Wrapping Up
9. Refactoring to OOP Patterns
Template Method
Strategy
State
null Object
Wrapper (Decorator and Adapter)
Facade
Wrapping Up
10. Asynchronous Refactoring
Why Async?
Fixing the Pyramid of Doom
Callbacks and Testing
Promises
Wrapping Up
11. Functional Refactoring
The Restrictions and Benefits of Functional Programming
The Basics
Advanced Basics
Burritos
Learning and Using Burritos
Moving from OOP to FP
Wrapping Up
12. Conclusion
Appendix A: Further Reading and Resources
Index
Rubrieken
- advisering
- algemeen management
- coaching en trainen
- communicatie en media
- economie
- financieel management
- inkoop en logistiek
- internet en social media
- it-management / ict
- juridisch
- leiderschap
- marketing
- mens en maatschappij
- non-profit
- ondernemen
- organisatiekunde
- personal finance
- personeelsmanagement
- persoonlijke effectiviteit
- projectmanagement
- psychologie
- reclame en verkoop
- strategisch management
- verandermanagement
- werk en loopbaan