Clean ABAP
  1. 351 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

About this book

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, you'll learn about: a. Clean ABAP Concepts
What 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 Practices
Walk 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 interfaces
2) Methods
3) Names
4) Variables and literals
5) Internal tables
6) Control flow
7) Comments
8) Formatting
9) Error handling
10) Unit testing
11) Packages

Frequently asked questions

Yes, you can cancel anytime from the Subscription tab in your account settings on the Perlego website. Your subscription will stay active until the end of your current billing period. Learn how to cancel your subscription.
At the moment all of our mobile-responsive ePub books are available to download via the app. Most of our PDFs are also available to download and we're working on making the final remaining ones downloadable now. Learn more here.
Perlego offers two plans: Essential and Complete
  • Essential is ideal for learners and professionals who enjoy exploring a wide range of subjects. Access the Essential Library with 800,000+ trusted titles and best-sellers across business, personal growth, and the humanities. Includes unlimited reading time and Standard Read Aloud voice.
  • Complete: Perfect for advanced learners and researchers needing full, unrestricted access. Unlock 1.4M+ books across hundreds of subjects, including academic and specialized titles. The Complete Plan also includes advanced features like Premium Read Aloud and Research Assistant.
Both plans are available with monthly, semester, or annual billing cycles.
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 1000+ topics, we’ve got you covered! Learn more here.
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more here.
Yes! You can use the Perlego app on both iOS or Android devices to read anytime, anywhere — even offline. Perfect for commutes or when you’re on the go.
Please note we cannot support devices running on iOS 13 and Android 7 or earlier. Learn more about using the app.
Yes, you can access Clean ABAP by Klaus Haeuptle,Florian Hoffmann,Rodrigo Jordão,Michel Martin,Anagha Ravinarayan,Kai Westerholz in PDF and/or ePUB format, as well as other popular books in Computer Science & Computer Science General. We have over one million books available in our catalogue for you to explore.

Information

1 Introduction

Writing cleaner code is an easy way to boost the quality and maintainability of your code. You can start doing it anywhere and anytime, with any kind of code and project. The price? Practice, discipline, and patience.
In this chapter, we’ll start our discussion of clean ABAP by defining and describing the importance of code readability in Section 1.1. Then, in Section 1.2, we’ll show you how to get started with clean ABAP. Since you’ll likely inherit and interact with legacy code, in Section 1.3, we’ll describe some basic clean code principles, like the Boy Scout Rule and clean islands. In Section 1.4, you’ll learn how to check code automatically. To round out this introduction, we’ll compare clean ABAP with other coding guides in Section 1.5, and finally, we’ll describe how you can interact with the clean ABAP community in Section 1.6.

1.1 What Is Clean ABAP?

Clean ABAP adopts the principles described in Robert C. Martin’s book, Clean Code, specifically for the ABAP programming language. It expands on selected topics to advance the notion further.
While Martin’s original publication applies to all programming languages, its examples mostly deal with Java. Thus, adopting these principles and code in languages with other properties, such as ABAP, can be quite challenging.
The goal of clean ABAP is to close this gap by providing examples that can be readily consumed by ABAP coders, offering guidelines that point out where ABAPers might need to deviate, and relating clean code topics to other guides for the ABAP language.
In the following sections, we’ll explore a fundamental value of clean ABAP: readability. We’ll also take a look at the story behind clean ABAP.

1.1.1 What Is Readability?

Thankfully, programmers who write good code have always been around, but it was Martin who, in 2008, gave wide attention to the notion that code should not only be correct and efficient, but also readable.
The definition is simple: Code is readable if it can be understood easily and quickly.
For example, a “dirty” statement like t = 42. is hard and time-consuming for the reader to understand. The reader must find out that “t” stands for “timeout,” that the number is a duration in seconds, and that 42 is the default timeout for all operations in this context.
The equivalent clean statement timeout_in_seconds = DEFAULT_TIMEOUT., in comparison, gives all these details readily away at first glance—the code is much more readable.
So, why should we care about readability? Past literature on software mostly dealt with the correctness and resource efficiency of programming languages.
For example, Donald E. Knuth’s The Art of Computer Programming gave us thousands of pages that compare the processing times and memory consumption of algorithms to help you pick the optimal algorithms for your purposes.
Martin made the point that, if resource efficiency was the only aspect that counted, we should all be writing code in first-generation programming languages, like assembler, which are by their very nature languages that enable maximum control over all resources and thus have the greatest potential for optimization.
The reason we don’t use a language like assembler is that those languages are extremely hard to understand. They deal with the lowest level of detail you can possibly have on a computer, such as registers, adders, and interrupts. Seeing the bigger picture in this sea of details is particularly challenging.
As human beings, we tend to think in higher levels of abstractions, such as functions, objects, and interfaces—the reason we invented second-, third-, and fourth-generation programming languages, like ABAP, in the first place.
If understandability is what these languages add, then following Martin’s argument, why is code that we write in these abstract languages so hard to understand?
The point we want to emphasize is that programming languages may enable you to write readable code, but that readability doesn’t emerge on its own in some magical way. You must actively learn how to write clean code, just like traditional authors must learn how to write good English prose.
This leads us to what we gain with readability. We read code a lot more than we write code. We may reread our own code many times over when debugging it or extending it with new features. We also read other developers’ code all the time, in reviews, in support tickets, and when connecting to new components. As a result, every minute we invest in simplifying our code usually pays off several times over on the reading side.
The advantages of readability go way beyond time savings. Readable code is easier to verify and therefore harder to get wrong. You’ll not only be able to debug readable code more quickly, but you’ll have fewer bugs right from the beginning.
Also, the software’s design becomes clearer with smaller individual components. As a consequence, attaching new features is easier because more places exist where new features can be plugged in easily, and many more components can be swapped out with little extra effort.

1.1.2 What’s the Story behind Clean ABAP?

In 2010, three development Scrum teams from the SAP governance, risk, and compliance department, including Florian Hoffmann, started coding the new solution SAP Fraud Management in ABAP. To meet the quarterly release cycle in Scrum mode, we started by attending a training—given by Klaus Haeuptle—that was mostly influenced by clean code.
Although we reached many of our targets in the following years, we found that teams still sported quite distinct ideas about what good ABAP code was supposed to look like. Code reviews sometimes degraded into subjective quarrels over harmless details like whitespace formatting.
In February 2018, we started collecting our best practices for clean ABAP code to learn from each other, create an objective grounding for our code reviews, and onboard new developers more easily. We started with a Wiki page, then moved to an internal GitHub repository as the content grew.
Over the course of 2018, Klaus Haeuptle started an engineering ecosystem, a loose community of hundreds of software developers who wanted to share agile expertise.
In November 2018...

Table of contents

  1. Dear Reader
  2. Notes on Usage
  3. Table of Contents
  4.   Preface
  5. 1   Introduction
  6. 2   The ABAP Language
  7. 3   Classes and Interfaces
  8. 4   Methods
  9. 5   Names
  10. 6   Variables and Literals
  11. 7   Internal Tables
  12. 8   Control Flow
  13. 9   Comments
  14. 10   Formatting
  15. 11   Error Handling
  16. 12   Unit Testing
  17. 13   Packages
  18. 14   How to Implement Clean ABAP
  19. A   The Authors
  20. Index
  21. Service Pages
  22. Legal Notes