AI-Assisted Coding
The Practical Guide for Software Development
Book Information
- Publisher: SAP PRESS
- Authors: Michael Kofler, Bernd Öggl, Sebastian Springer
- Year: 2025
- Edition: 1
- Pages: 395
- Languages: English
Description
Generative AI is transforming software development. Stay on the cutting edge with this guide to AI pair programming! Learn how to make the most of modern tools like ChatGPT and GitHub Copilot to improve your coding. Automate refactoring, debugging, and other tedious tasks, and use techniques such as prompt engineering and retrieval-augmented generation to get the code you need. Follow practical examples that show how you can program faster, more efficiently, and with fewer errors with the help of AI.
- Optimize your daily development tasks with AI
- Work with tools like GitHub Copilot, ChatGPT, and OpenHands to generate code, refactor programs, and debug scripts
- Explore AI options for database design, unit testing, documentation, administration, and more
Key Highlights
- Structured programming with AI
- Debugging
- Unit testing
- Refactoring
- Automatic document creation
- Database development and design
- Scripting and administration
- Local large language models (LLMs)
- Retrieval-augmented generation (RAG)
- ChatGPT and GitHub Copilot
- OpenHands
- OpenAI API
You'll learn about
- Hype versus Reality:
Learn from expert developers to understand the possibilities (and pitfalls) of AI tools. With the help of practical code examples, see how to use AI helpers correctly to their full potential.
- Assistants for All Tasks:
This guide gives you an up-to-date overview of all aspects of AI-assisted coding: GitHub Copilot autocompletions, project bootstrapping with OpenHands, debugging and refactoring, application development, and more.
- In the Cloud or Local?:
Use OpenAI’s API to integrate AI models directly into your own scripts and automations—or use local large language models (LLMs) to work independently of cloud services.
Table of Contents
- Preface
- Local Execution of Language Models
- Coding with AI Support for Advanced Users
- AI Makes Mistakes and Hallucinates
- The Three Stages of Using AI
- There’s No Getting around AI Tools
- Part I Coding with AI Support
- 1 Introduction
- 1.1 Coding via Chat
- 1.1.1 Password Generator
- 1.1.2 Python: Searching and Replacing Dates
- 1.1.3 SQL: Analysis of a Table
- 1.1.4 PHP: Bearer Token Authentication
- 1.1.5 Porting a Bash Script for PowerShell
- 1.1.6 Paid ChatGPT Offers
- 1.1.7 Anthropic Claude
- 1.2 The Art of Prompting
- 1.2.1 Prompt Frameworks
- 1.2.2 A Question of Context
- 1.2.3 Custom GPTs
- 1.2.4 Comparing Custom GPTs, Fine-Tuning, and Retrieval-Augmented Generation
- 1.3 Code Wizards
- 1.3.1 Installing GitHub Copilot
- 1.3.2 First Steps with Visual Studio Code and GitHub Copilot
- 1.3.3 Switching between Code Suggestions
- 1.3.4 Tips and Tricks
- 1.3.5 Chat Mode with Additional Keywords
- 1.3.6 Chat Examples
- 1.3.7 Alternatives to the Chat Sidebar
- 1.3.8 Other Functions
- 1.3.9 Security and Data Protection
- 1.3.10 Trouble in Remote Mode
- 1.4 Chat or Wizard?
- 1.5 Basic Principles of Large Language Models
- 1.5.1 From the Human Brain to Neural Networks
- 1.5.2 Machine Learning through Backpropagation
- 1.5.3 Large Language Models
- 1.5.4 The Transformer Model
- 1.5.5 Generative Pretrained Transformer (GPT)
- 1.5.6 Training: From Training Material to Language Model
- 1.5.7 Large Language Model Application: From Prompt to Response
- 1.5.8 The Limits of Linguistic “Intelligence”
- 1.5.9 The Size of the Context Window
- 1.5.10 The Fill-in-the-Middle Approach
- 2 Pair Programming
- 2.1 Structuring Code into Functions
- 2.1.1 Defining Functions Yourself
- 2.1.2 Defining Functions and Parameters
- 2.1.3 Detailed Questions about Functions and Parameters
- 2.1.4 Code Optimization
- 2.1.5 Code Reuse
- 2.1.6 Splitting Code across Multiple Files
- 2.2 Example: IBAN Validation
- 2.2.1 Start
- 2.2.2 Checking the IBAN Length
- 2.2.3 Troubleshooting
- 2.2.4 Test
- 2.2.5 Removing Spaces from the IBAN
- 2.2.6 Checksum Test
- 2.2.7 Trouble with the Test Data
- 2.2.8 Code Optimization
- 2.3 Object-Oriented Programming
- 2.3.1 Example: User Account Class
- 2.3.2 Output of the Object
- 2.3.3 JSON Export and Constructor
- 2.3.4 Example: Bank Account
- 2.3.5 Example: Sorting Photos Based on EXIF Data
- 2.3.6 Example: Dealing with Singletons
- 2.4 Example: Quiz
- 2.4.1 Class Design
- 2.4.2 Implementing the Question Class
- 2.4.3 A Pool of Questions for Testing
- 2.4.4 Methods for the Question Class
- 2.4.5 UML Diagram
- 2.4.6 AI Bot or Code Wizard?
- 2.5 Example: Solving Sudoku
- 2.5.1 Class Setup
- 2.5.2 Detaching Individual Fields in Rows
- 2.5.3 Solving Individual Fields in Columns and in Blocks
- 2.5.4 Test Code and Issues with the Test Data
- 2.5.5 Brainstorming
- 2.5.6 Storing Solution Candidates per Field
- 2.5.7 Filling in Fields Where Only One Solution Number Is Possible
- 2.5.8 Personal Conclusion
- 2.5.9 Alternative Procedure
- 2.5.10 Prompting Correctly
- 3 Debugging
- 3.1 Web Applications
- 3.1.1 CSS Fixes
- 3.1.2 iCal Download in the Browser
- 3.1.3 Backend Frontend without a Proxy Server
- 3.1.4 JavaScript Fetch with the Wrong Content Type
- 3.1.5 JamGPT
- 3.2 App Development
- 3.2.1 Flutter and Null Safety Values
- 3.2.2 Layouts in Flutter
- 3.3 Developing on Raspberry Pi
- 3.3.1 Step-by-Step Debugging on a Raspberry Pi
- 3.3.2 Help for Creating Log Entries
- 3.4 Visual Studio and Visual Studio Code
- 3.4.1 Missing Python Modules in VS Code
- 3.4.2 Visual Studio Exception Debugging
- 3.5 Conclusion
- 4 Refactoring
- 4.1 Introduction to Refactoring
- 4.1.1 Objectives of Refactoring
- 4.2 Refactoring Using AI Tools
- 4.2.1 Recognizing the Need for Refactoring
- 4.3 Best Practices
- 4.3.1 Only the Internal Structure May Be Changed
- 4.3.2 Small-Step Approach
- 4.3.3 Test-Driven Refactoring
- 4.3.4 Defining Clear Goals
- 4.4 Conclusion
- 5 Testing Software
- 5.1 Generating Test Data
- 5.2 AI-Supported Test Automation
- 5.2.1 Creating AI-Supported Unit Tests
- 5.3 Test-Driven Development with AI
- 5.3.1 Implementing the First Test
- 5.3.2 The Second Test
- 5.3.3 The Third Test
- 5.3.4 Generating Test Data
- 5.4 Using Dependencies
- 5.5 Optimizing Tests
- 5.5.1 Optimizing Test Code
- 5.5.2 Writing Missing Tests
- 5.6 End-to-End Tests
- 5.6.1 Generating an End-to-End Test
- 5.6.2 Creating a Page Object
- 5.7 Conclusion
- 6 Documenting Software
- 6.1 Challenges with Documentation
- 6.2 Inline Documentation
- 6.2.1 Sample Inline Documentation
- 6.3 Function and Class Documentation
- 6.3.1 Benefits and Drawbacks of Function and Class Documentation
- 6.3.2 Sample Function and Class Documentation
- 6.4 API Documentation
- 6.4.1 Sample API Documentation
- 6.5 Outdated Documentation
- 6.6 Conclusion
- 7 Databases
- 7.1 Database Design
- 7.1.1 Example: Database for an Online Store
- 7.1.2 Database Management System Selection
- 7.1.3 Example: Cloud Shopping List
- 7.1.4 Changing the Database Schema
- 7.2 SQL Commands
- 7.2.1 Date Calculation
- 7.2.2 Troubleshooting
- 7.2.3 WordPress Image Search
- 7.2.4 Complex Query with Subquery or Self Join
- 7.2.5 Formatting an SQL Command
- 7.3 Administration
- 7.3.1 PostgreSQL: User Administration
- 7.3.2 SQL Server: Automated Backup
- 7.3.3 Determining the Schema of a Database
- 7.3.4 MariaDB Tuning
- 7.4 Client Programming
- 8 Scripting and System Administration
- 8.1 Scripting
- 8.1.1 Bash: Loop Over a Text File
- 8.1.2 PowerShell: Sorting Photos
- 8.1.3 Python: SQLite Application
- 8.1.4 Bash Troubleshooting
- 8.1.5 Python: Recursive Search for Files
- 8.1.6 Other Prompt Examples
- 8.2 Example: Converting a Python Script to PHP Code
- 8.3 Regular Expressions
- 8.3.1 Searching and Replacing Dates
- 8.3.2 File Search Using grep
- 8.4 System Administration
- 8.4.1 SSH Authentication by Key
- 8.4.2 Docker Setup
- 8.4.3 Proxy Server
- 8.4.4 Fixing Network Issues in a Virtual Machine with a Web Server
- 8.4.5 Linux Server Setup
- 8.4.6 Additional Prompts
- 8.5 Example: “wget” Script Plus “tmpfs” Configuration
- 8.5.1 Developing a “wget” Script
- 8.5.2 Linux Server Configuration with “tmpfs”
- 8.5.3 Conclusion
- 8.6 Calling GitHub Copilot and ChatGPT in the Terminal
- 8.6.1 GitHub Command-Line Interface (“gh”)
- 8.6.2 Shell-GPT (“sgpt”)
- 8.6.3 Using Language Models in the Terminal (“llm”)
- Part II Local Language Models and Advanced AI Tools
- 9 Executing Language Models Locally
- 9.1 Spoiled for Choice of Large Language Model
- 9.1.1 Which Models Solve Which Problems?
- 9.1.2 Hardware Requirements
- 9.1.3 Alternatives to the Local Execution of Models
- 9.2 GPT4All
- 9.2.1 Installation and Use
- 9.2.2 Chat with Your Files
- 9.2.3 Conclusion
- 9.3 Ollama
- 9.3.1 Benefits of Ollama
- 9.3.2 General Structure of Ollama
- 9.3.3 Local Installation and Execution
- 9.3.4 Running Ollama in a Docker Container
- 9.4 Open WebUI for Ollama
- 9.4.1 Installing Open WebUI
- 9.4.2 Using Custom Documents in Open WebUI
- 9.4.3 Custom Workspace Models
- 9.5 Continue
- 9.5.1 Installation
- 9.5.2 Usage
- 9.6 Ollama API
- 9.6.1 Ollama REST API
- 9.6.2 Libraries for Accessing the Ollama API
- 9.7 Tabby
- 9.7.1 Installing the Tabby Server and the Plug-In
- 9.7.2 Usage
- 9.8 Conclusion
- 10 Automated Code Processing
- 10.1 OpenAI API
- 10.1.1 Setting Up an API Account
- 10.1.2 Hello, World!
- 10.1.3 Formulating the Prompt
- 10.1.4 Chat System
- 10.1.5 Processing the Response
- 10.1.6 Uploading and Downloading Files
- 10.1.7 Uploads for Special Applications
- 10.1.8 Playground
- 10.2 Ollama API
- 10.3 Groq API
- 10.4 Example: Automated Commenting of Code
- 10.4.1 Real-Life Experience
- 10.4.2 Extracting Code from the Response
- 10.4.3 Genuine Errors
- 10.4.4 Trouble with Large Code Files
- 10.4.5 Translating Existing Comments
- 10.4.6 Conclusion
- 10.5 Example: From Python 2 to Python 3
- 10.5.1 Real-Life Experience
- 11 Level 3 Tools: OpenHands and Aider
- 11.1 OpenHands
- 11.1.1 Installation
- 11.1.2 The Web Interface
- 11.2 Using OpenHands
- 11.2.1 Not Too Much at Once!
- 11.2.2 Conclusion
- 11.3 Aider
- 11.3.1 Installation
- 11.3.2 Start
- 11.3.3 Aider Commands
- 11.3.4 Multiline Prompts
- 11.3.5 Coding Rules and Conventions
- 11.3.6 Aider in the Web Browser
- 11.4 Using Aider
- 11.4.1 Example 1: Sorting Photos
- 11.4.2 Example 2: Web Scraping
- 11.4.3 Example 3: Implementing Changes in a Large Project
- 11.4.4 More Prompting Examples and Video Tips
- 12 Retrieval-Augmented Generation and Text-to-SQL
- 12.1 RAG Quick Start
- 12.2 The Viel-Falter (Many Butterflies) Project
- 12.3 Loading Documents
- 12.3.1 SimpleDirectoryReader and SimpleWebPageReader
- 12.4 Creating an Index
- 12.4.1 The Embedding Model
- 12.5 Vector Store Databases
- 12.6 RAG Queries
- 12.6.1 Source Code
- 12.6.2 Conclusion
- 12.7 Text-to-SQL
- 12.7.1 Database Export from MongoDB to SQLite
- 12.7.2 Text-to-SQL with LlamaIndex
- 12.7.3 Sample Queries
- 12.7.4 Conclusion
- 13 Risks and Outlook
- 13.1 Issues and Limitations of Using AI Tools
- 13.1.1 Old, Cumbersome Code
- 13.1.2 The Question of Maintainability
- 13.1.3 Privacy
- 13.1.4 A New Kind of Dependency
- 13.1.5 Learning to Program in the Age of AI
- 13.2 Exemplary AI Failure
- 13.2.1 Outdated Information
- 13.2.2 Hallucinations
- 13.2.3 Logic Errors
- 13.2.4 Security Issues
- 13.2.5 Less Than Ideal Solutions
- 13.3 Ethical Issues
- 13.3.1 The Origin of AI Knowledge
- 13.3.2 Jobless IT Experts
- 13.3.3 Unlimited Energy Consumption
- 13.4 Conclusions and Outlook
- 13.4.1 Better Results with More Prior Knowledge and Experience
- 13.4.2 Cloud or Local AI?
- 13.4.3 Quality Enhancement through Training with AI-Generated Code
- 13.4.4 The Coming Few Years
- 13.4.5 Conclusion
Disclaimer
SAP, other SAP products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of SAP SE (or an SAP affiliate company) in Germany and other countries. Our Company is not affiliated to SAP SE or any of its affiliated companies including but not limited to: Sybase, Business Objects, Hybris, Ariba and SuccessFactors. All other names, brands, logos, etc. are registered trade or service marks of their respective owners.