Beschreibung
ABAP developers, are you looking to clean up your code? Then pick up this official companion to the Clean ABAP GitHub repository. This book is brimming with best practices, straight from the experts, to help you write effective ABAP code. Start by learning when to apply each clean ABAP practice. Then, dive into detailed code examples and explanations for using classes, methods, names, variables, internal tables, and more. From writing code to troubleshooting and testing, this is your complete style guide!In this book, youll learn about:a. Clean ABAP ConceptsWhat is clean ABAP and why is it important to write clean code? Understand clean ABAP concepts with insight from the experts, including special considerations for legacy code and performance.b. Best PracticesWalk through the what, why, and how behind clean ABAP best practices. Learn to improve your code, including using classes and interfaces appropriately, handling method design and control flow, designing and running unit tests, and much more. c. Practical Examples See clean ABAP practices in action! Improve your understanding of how to write effective code. Use detailed examples for each best practice that demonstrate the difference between clean and messy code.Highlights include:1) Classes and interfaces2) Methods3) Names4) Variables and literals5) Internal tables6) Control flow7) Comments8) Formatting9) Error handling10) Unit testing11) Packages
Autorenportrait
Klaus Haeuptle is a developer, trainer, and product owner for engineering topics. During his career at SAP, he has worked as a developer on several products based on various technologies. Additionally, he facilitates communities across SAP with the intention of sharing knowledge and improving practices and tools. He has influenced testing improvements for ABAP, SAP HANA, and SAPUI5. Together with Florian Hoffmann, he wrote an internal Clean ABAP guide, which was later published externally as an open-source project and serves as the foundation for this book.
Inhalt
... Who This Book Is For ... 17
... How This Book Is Organized ... 17
... Acknowledgments ... 19
... Conclusion ... 21
1.1 ... What Is Clean ABAP? ... 23
1.2 ... How to Get Started with Clean ABAP ... 26
1.3 ... How to Handle Legacy Code ... 26
1.4 ... How to Check Code Automatically ... 28
1.5 ... How Does Clean ABAP Relate to Other Guides? ... 29
1.6 ... How to Engage with the Clean ABAP Community ... 30
1.7 ... Summary ... 31
2.1 ... Mind Legacy Code ... 33
2.2 ... Mind Performance ... 35
2.3 ... Prefer Object Orientation to Procedural Programming ... 37
2.4 ... Favor Functional Language Constructs over Procedural Language Constructs ... 43
2.5 ... Avoid Obsolete Language Elements ... 46
2.6 ... Use Design Patterns Wisely ... 48
2.7 ... Summary ... 50
3.1 ... Object Orientation ... 51
3.2 ... Scope and Visibility ... 76
3.3 ... Constructors ... 83
3.4 ... Summary ... 93
4.1 ... Object-Oriented Programming ... 95
4.2 ... Parameters ... 102
4.3 ... Method Body ... 115
4.4 ... Calling Methods ... 125
4.5 ... Summary ... 130
5.1 ... Good Naming ... 133
5.2 ... ABAP Peculiarities ... 138
5.3 ... Affixes: Prefixes, Suffixes, and Infixes ... 140
5.4 ... Dealing with Legacy Code ... 142
5.5 ... Summary ... 143
6.1 ... Variables ... 145
6.2 ... Constants ... 152
6.3 ... Strings ... 160
6.4 ... Booleans ... 161
6.5 ... Regular Expressions ... 164
6.6 ... REDUCE ... 166
6.7 ... Summary ... 168
7.1 ... Using the Right Table Category ... 171
7.2 ... Avoiding DEFAULT KEY ... 173
7.3 ... INSERT INTO TABLE and APPEND TO ... 174
7.4 ... Verifying the Existence of a Row ... 176
7.5 ... Retrieving Table Contents ... 177
7.6 ... LOOP AT WHERE and Nested IF ... 179
7.7 ... Identifying Unnecessary Table Reads ... 180
7.8 ... Block Processing of Table Rows and Single Row Operations ... 181
7.9 ... DESCRIBE TABLE and Table Function LINES ... 182
7.10 ... Summary ... 183
8.1 ... IFs ... 185
8.2 ... Nesting Depth ... 190
8.3 ... Conditions ... 190
8.4 ... CASE ... 196
8.5 ... Do 1 Times ... 200
8.6 ... Summary ... 203
9.1 ... Express Yourself in Code ... 205
9.2 ... Comment Placement and Usage ... 207
9.3 ... Comments to Avoid ... 208
9.4 ... FIXME, TODO, and XXX Comments ... 211
9.5 ... Special Comments: ABAP Doc, Pragmas, and Pseudo Comments ... 212
9.6 ... Summary ... 214
10.1 ... Consistency in Coding Style ... 216
10.2 ... Optimizing for Reading ... 216
10.3 ... The Pretty Printer ... 217
10.4 ... Number of Statements Per Line ... 218
10.5 ... Line Length ... 219
10.6 ... Condensing the Code ... 220
10.7 ... Blank Lines ... 220
10.8 ... Alignment of Assignment Statements ... 221
10.9 ... Alignment of Variable Declarations ... 222
10.10 ... Placement of Closing Brackets ... 223
10.11 ... Formatting Method Parameters ... 223
10.12 ... Summary ... 227
11.1 ... Messages ... 229
11.2 ... Return Codes ... 232
11.3 ... Exceptions ... 236
11.4 ... Raising and Catching ... 245
11.5 ... Summary ... 252
12.1 ... Test Classes ... 254
12.2 ... Test Methods ... 262
12.3 ... Class under Test ... 266
12.4 ... Naming ... 267
12.5 ... Assertions ... 269
12.6 ... Test Doubles ... 279
12.7 ... Test Seams ... 289
12.8 ... Principles ... 291
12.9 ... Summary ... 294
13.1 ... General Package Concepts ... 297
13.2 ... Package Concepts in ABAP ... 299
13.3 ... Package Design Options ... 304
13.4 ... Package Checks ... 308
13.5 ... Consequences of Poor or No Package Strategy ... 316
13.6 ... Summary ... 316
14.1 ... Common Understanding among Team Members ... 319
14.2 ... Collective Code Ownership ... 320
14.3 ... Clean Code Developer Initiative ... 322
14.4 ... Tackling the Broken Window Effect ... 323
14.5 ... Code Review and Learning ... 326
14.6 ... Clean Code Advisor ... 330
14.7 ... Learning Techniques ... 330
14.8 ... Continuous Learning in Cross-Functional Teams ... 334
14.9 ... Summary ... 337