0% found this document useful (0 votes)
38 views

modern-python-programming-using-chatgpt-shivakumar-gopalakrishnan

Uploaded by

pranshu126545
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views

modern-python-programming-using-chatgpt-shivakumar-gopalakrishnan

Uploaded by

pranshu126545
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 31

 i

Modern Python
Programming using
ChatGPT
10x your software development skills with Python

Shivakumar Gopalakrishnan

www.bpbonline.com
ii 
First Edition 2025

Copyright © BPB Publications, India

ISBN: 978-93-65894-318

All Rights Reserved. No part of this publication may be reproduced, distributed or transmitted in
any form or by any means or stored in a database or retrieval system, without the prior written
permission of the publisher with the exception to the program listings which may be entered,
stored and executed in a computer system, but they can not be reproduced by the means of
publication, photocopy, recording, or by any electronic and mechanical means.

LIMITS OF LIABILITY AND DISCLAIMER OF WARRANTY


The information contained in this book is true to correct and the best of author’s and publisher’s
knowledge. The author has made every effort to ensure the accuracy of these publications, but
publisher cannot be held responsible for any loss or damage arising from any information in
this book.

All trademarks referred to in the book are acknowledged as properties of their respective
owners but BPB Publications cannot guarantee the accuracy of this information.

www.bpbonline.com
 iii

Dedicated to
Ronald Tschalär - the original ChatGPT.
I miss you everyday dear friend.
Not a day goes by without me thinking about you.
iv 

About the Author

Shivakumar Gopalakrishnan has 25 years of experience in Software Development,


DevOps, SRE, and Platform Engineering. He has worked in wide-ranging industries,
from a healthcare enterprise to a consumer-facing web-scale company. He founded a
startup, was a key architect within a Fortune 1000 company, and was a manager/engineer
in a Fortune 100 company. He has also given multiple presentations at DevOps/SRE
conferences.

He is currently a Principal Architect at BD.


 v

About the Reviewer

Rabi Jay has over 15 years of experience driving digital transformation with a unique
blend of technical depth and business acumen. His background as a Java and SAP ABAP
developer provides insights into the enterprise systems LLMs often need to integrate with.
As a leader in Deloitte’s Digital / Cloud Native practice, he has gained cross-industry
experience applying AI solutions, positioning him to identify where LLMs offer the
greatest potential for business impact.

He is passionate about making complex technology accessible, leading him to author


books on SAP NetWeaver Portal Technology and "Enterprise AI in the Cloud," along with
regular contributions to industry publications. His role as a technical reviewer for "Large
Language Model Based Solutions", and “Modern Python Programming using ChatGPT”
and as Vice President at HCL America, focused on digital transformation, demonstrate
his active engagement in the LLM field. Additionally, he runs a LinkedIn newsletter
("Enterprise AI Transformation") and a free LinkedIn course (“Generative AI for Business
Innovation”).
vi 

Acknowledgement

This book would not have been possible without the unconditional love and support of
my parents, family, friends, and colleagues.

Special thanks to Ramesh Gopalakrishnan my ex LinkedIn colleague who reviewed the


chapters and provided great input.

I first encountered Ramesh Iyer during my tenure at LinkedIn. He was introduced to me


as one of the leading engineers in the fields of software infrastructure and cloud workflow
orchestration. I was impressed to learn about his pro-bono machine learning workshop.
More importantly Ramesh is generous with his time and knowledge in mentoring and
helping out others with his vast knowledge and experience in coding and automation.
This technical expertise and his talent for teaching that I witnessed during my tenure at
LinkedIn, made me seek him out as the technical reviewer for this book. We had many
engaging discussions about the foundational elements of cloud workflow orchestration
and the potential of LLMs like ChatGPT to significantly speed up the development of
these components. True to my impression, he is the quintessential engineer's engineer.
I have always held Ramesh’s insights in high regard and am grateful for the valuable
feedback he provided, which I believe will be greatly appreciated by the readers of this
book.

Also, thank you to Rabi Jay for being the technical reviewer.

I would also like to thank BD for allowing me to pursue my passion for making lucrative
technology jobs accessible to everyone.
 vii

Preface

In the rapidly evolving landscape of software development, staying ahead of the curve is
crucial. As the world embraces automation and artificial intelligence, ChatGPT emerges
as a groundbreaking tool poised to revolutionize not just coding, but the entire software
development lifecycle (SDLC). Imagine having an intelligent assistant that not only
understands your development needs but also helps you design, implement, test, deploy,
and optimize your projects in real-time. This is not a distant future—it's here now, and it's
transforming the way we approach software development.

Welcome to "Modern Python Programming using ChatGPT," your definitive guide to


harnessing the power of artificial intelligence to reduce friction and waste across the entire
SDLC. Whether you are a seasoned developer or just starting your coding journey, this
book is designed to be your indispensable companion in navigating the complexities of
modern programming with unparalleled efficiency and creativity.

Why should you buy this book?

● Bring back the joy of sofware development: Tired of being asked for status updates,
timelines, JIRA/Confluence, roadmaps? Save the 70% of your time spent on waste
and friction. Focus on work that brings you joy.

● Comprehensive coverage of the SDLC: This book takes you through every stage
of the SDLC, from requirements gathering and design to implementation, testing,
deployment, and maintenance. Each chapter provides in-depth insights and
practical applications of ChatGPT to streamline and enhance each phase of the
SDLC.

● Address real-world developer challenges: Based on my extensive experience


working with both large enterprises and small startups, this book addresses
the real-world impediments that developers face daily. Learn how to overcome
common productivity blockers with practical, actionable solutions that leverage
the power of ChatGPT.

● Expert insights: To bring you the most comprehensive and up-to-date information,
I have interviewed dozens of top experts in the field. Their insights and experiences
enrich this book, providing you with diverse perspectives and proven strategies
for success.
viii 
● Unlock unmatched productivity: Discover how ChatGPT can automate repetitive
tasks, generate high-quality code snippets, and provide instant debugging tips,
freeing you up to focus on what truly matters—building innovative solutions.

● Master cutting-edge techniques: Stay ahead of the technology curve with


comprehensive coverage of the latest trends and best practices in Python
development. Learn how to integrate ChatGPT seamlessly into your workflow
and watch your productivity soar.

● Enhance code quality: Leverage ChatGPT's advanced capabilities to ensure your


code adheres to industry standards and best practices. From SOLID principles to
automated testing, this book equips you with the tools to write clean, maintainable,
and robust code.

● Real-world applications: Each chapter is packed with practical examples and


hands-on exercises that demonstrate how ChatGPT can be applied to real-world
scenarios. Gain the confidence to tackle complex projects and deliver high-quality
software.

● Future-proof your career: Equip yourself with the skills needed to thrive in
the future of software development. Learn how to stay current with emerging
technologies, cultivate a growth mindset, and navigate the evolving landscape of
AI and automation.

● Comprehensive and accessible: This book is crafted to be a comprehensive yet


accessible resource. It covers everything from the basics of setting up ChatGPT
to advanced techniques in deployment, performance optimization, and ethical
considerations.

Join the revolution in Python programming and elevate your skills to new heights.
"Modern Python Programming using ChatGPT" is not just a book; it is your gateway to
the future of software development. Do not miss out on the opportunity to transform your
development process and achieve unprecedented levels of productivity and innovation.
Turn the page and start a journey that will redefine your approach to software development.
Your future self will thank you.
Get ready to revolutionize your software development journey. Grab your copy now and
step into the future of Python programming with ChatGPT!
This book is divided into 14 chapters. They cover the fundamentals of ChatGPT, its
applications in Python development, best practices, and advanced techniques. The details
are listed below:
 ix

Chapter 1: ChatGPT and Its Capabilities - This chapter introduces ChatGPT, explaining
its foundational technology and how it can be utilized in various applications. It covers
the basic capabilities of ChatGPT, including its ability to understand and generate human-
like text, its strengths in conversation and content generation, and its potential uses in
software development and other fields.

Chapter 2: Benefits of Using ChatGPT in Python Development - This chapter explores


the advantages of incorporating ChatGPT into Python development. It highlights how
ChatGPT can assist in automating tasks, generating code snippets, providing debugging
tips, and improving overall productivity and efficiency for developers.

Chapter 3: Setting up ChatGPT for Python Development - This chapter guides readers
through the process of setting up ChatGPT for use in Python development. It covers the
necessary installations, configurations, and integrations required to effectively utilize
ChatGPT within a Python development environment.

Chapter 4: Requirements Gathering - This chapter discusses the role of ChatGPT in the
requirements gathering phase of software development. It explains how ChatGPT can help
in understanding client needs, documenting requirements, and generating comprehensive
requirement specifications.

Chapter 5: Design and Architecture - This chapter explains the design and architecture
phase, showing how ChatGPT can assist in creating software design documents,
architectural diagrams, and providing design recommendations based on best practices.

Chapter 6: Implementing a Software Product - This chapter covers the implementation


phase, detailing how ChatGPT can aid in writing code, suggesting libraries and frameworks,
and providing real-time coding assistance to streamline the development process.

Chapter 7: Pull Review and Commit Messages - This chapter explains how ChatGPT
can enhance the code review process by generating detailed pull request descriptions
and commit messages. It emphasizes the importance of clear communication and
documentation in version control systems.

Chapter 8: Using ChatGPT for Coding with SOLID Principles - This chapter illustrates
how ChatGPT can help developers adhere to SOLID principles in object-oriented
programming. It provides examples of how ChatGPT can suggest code refactoring and
design improvements to ensure maintainable and scalable code.

Chapter 9: Software Testing with ChatGPT in Python - This chapter focuses on the testing
phase, demonstrating how ChatGPT can assist in writing test cases, generating test data,
and automating the testing process to ensure code quality and reliability.
x 
Chapter 10: Deployment with ChatGPT - This chapter discusses the deployment phase,
showing how ChatGPT can help automate deployment scripts, configure environments,
and manage the release process to ensure smooth and error-free software deployment.

Chapter 11: Performance and Observability - This chapter covers the aspects of
performance optimization and observability. It explains how ChatGPT can assist in
identifying performance bottlenecks, suggesting optimizations, and setting up monitoring
tools to maintain software performance and reliability.

Chapter 12: Revolutionary Impact of ChatGPT - This chapter explores the transformative
impact of ChatGPT on software development practices. It discusses how ChatGPT can
revolutionize collaboration, communication, quality, security, and continuous learning
among developers. It also highlights the ethical considerations and challenges posed by
the integration of ChatGPT in development.

Chapter 13: Limitations, Pitfalls and Dangers of ChatGPT - This chapter addresses the
limitations and potential risks associated with using ChatGPT. It discusses the importance
of recognizing inaccuracies, ensuring responsible and ethical use, and protecting against
potential harms such as data breaches and security vulnerabilities.

Chapter 14: Preparing for the Future with ChatGPT - This chapter focuses on future-
proofing software development skills with ChatGPT. It provides guidance on keeping up
with trends, developing a growth mindset, networking, showcasing achievements, and
exploring new career opportunities. It emphasizes the importance of continuous learning
and adaptation in the evolving field of software development.
 xi

Code Bundle and Coloured Images

Please follow the link to download the


Code Bundle and the Coloured Images of the book:

https://rebrand.ly/qgn4un2
The code bundle for the book is also hosted on GitHub at
https://github.com/bpbpublications/Modern-Python-Programming-using-ChatGPT.
In case there’s an update to the code, it will be updated on the existing GitHub repository.

We have code bundles from our rich catalogue of books and videos available at
https://github.com/bpbpublications. Check them out!

Errata
We take immense pride in our work at BPB Publications and follow best practices to
ensure the accuracy of our content to provide with an indulging reading experience to our
subscribers. Our readers are our mirrors, and we use their inputs to reflect and improve
upon human errors, if any, that may have occurred during the publishing processes
involved. To let us maintain the quality and help us reach out to any readers who might be
having difficulties due to any unforeseen errors, please write to us at :
[email protected]

Your support, suggestions and feedbacks are highly appreciated by the BPB Publications’
Family.

Did you know that BPB offers eBook versions of every book published, with PDF
and ePub files available? You can upgrade to the eBook version at www.bpbonline.
com and as a print book customer, you are entitled to a discount on the eBook copy.
Get in touch with us at :
[email protected] for more details.

At www.bpbonline.com, you can also read a collection of free technical articles,


sign up for a range of free newsletters, and receive exclusive discounts and offers
on BPB books and eBooks.
xii 

Piracy
If you come across any illegal copies of our works in any form on the internet,
we would be grateful if you would provide us with the location address or
website name. Please contact us at [email protected] with a link to
the material.

If you are interested in becoming an author


If there is a topic that you have expertise in, and you are interested in either
writing or contributing to a book, please visit www.bpbonline.com. We have
worked with thousands of developers and tech professionals, just like you, to
help them share their insights with the global tech community. You can make
a general application, apply for a specific hot topic that we are recruiting an
author for, or submit your own idea.

Reviews
Please leave a review. Once you have read and used this book, why not leave
a review on the site that you purchased it from? Potential readers can then see
and use your unbiased opinion to make purchase decisions. We at BPB can
understand what you think about our products, and our authors can see your
feedback on their book. Thank you!

For more information about BPB, please visit www.bpbonline.com.

Join our book's Discord space


Join the book's Discord Workspace for Latest updates, Offers, Tech happenings around the
world, New Release and Sessions with the Authors:
https://discord.bpbonline.com
 xiii

Table of Contents

1. ChatGPT and Its Capabilities............................................................................................... 1


Introduction........................................................................................................................ 1
Structure.............................................................................................................................. 1
Objectives........................................................................................................................... 2
Frequently asked questions about ChatGPT................................................................. 2
Will it get me fired......................................................................................................... 2
What is the best description of ChatGPT...................................................................... 2
How reliable is ChatGPT.............................................................................................. 2
How secure is ChatGPT................................................................................................ 3
How ethical is ChatGPT............................................................................................... 3
How inclusive is ChatGPT........................................................................................ 3
Introduction to the book................................................................................................... 3
What is this book about................................................................................................. 4
Who is this book for....................................................................................................... 4
What are the prerequisites for this book........................................................................ 4
How is this book organized............................................................................................ 4
What is ChatGPT............................................................................................................... 6
A brief overview of ChatGPT and its features............................................................... 7
Comparing ChatGPT with other AI chatbots............................................................... 7
How to access and use ChatGPT.................................................................................. 8
Advanced: How does ChatGPT work.......................................................................... 10
Technology and architecture of ChatGPT................................................................... 10
Main components and techniques of ChatGPT.......................................................... 10
Strengths and limitations of ChatGPT....................................................................... 11
Strengths.............................................................................................................. 11
Limitations........................................................................................................... 12
ChatGPT specifically for Python developers.............................................................. 12
Benefits and challenges................................................................................................ 12
Benefits................................................................................................................. 13
xiv 
Challenges............................................................................................................. 13
How ChatGPT fits into SDLC.................................................................................... 14
Examples of ChatGPT conversations........................................................................... 16
ChatGPT at every stage of SDLC............................................................................... 16
Prompt engineering..................................................................................................... 22
Constructing a prompt......................................................................................... 23
Optimizing your prompt...................................................................................... 24
Useful hacks with ChatGPT........................................................................................ 26
Preventing hallucinations.................................................................................... 26
Giving ChatGPT room to think........................................................................... 27
Asking ChatGPT to think step-by-step................................................................ 27
Prompt chaining................................................................................................... 28
Checking ChatGPT's comprehension................................................................... 29
Asking ChatGPT for rewrites.............................................................................. 29
Conclusion........................................................................................................................ 30
Next steps......................................................................................................................... 30
Points to remember......................................................................................................... 31
Exercises and challenges................................................................................................ 31

2. Benefits of Using ChatGPT in Python Development.................................................... 33


Introduction...................................................................................................................... 33
Structure............................................................................................................................ 33
Objectives......................................................................................................................... 34
Making Python development easier with ChatGPT.................................................. 34
Choosing right libraries.................................................................................................. 35
Asking questions......................................................................................................... 36
Getting recommendations........................................................................................... 36
Comparing libraries and frameworks.......................................................................... 37
Write idiomatic and clean Python code....................................................................... 37
Following the Zen of Python with ChatGPT.............................................................. 38
Refactoring code with ChatGPT................................................................................. 39
Writing readable code.................................................................................................. 40
Follow the PEP 8 style guide......................................................................................... 41
 xv

Checking code style with ChatGPT............................................................................. 42


Formatting code with ChatGPT.................................................................................. 42
Naming conventions with ChatGPT.......................................................................... 43
Type hints and annotations in Python......................................................................... 44
Why use Type hints and annotations.......................................................................... 44
How to use type hints and annotations....................................................................... 45
Use ChatGPT to add Type hints and annotations...................................................... 46
Write docstrings and comments.................................................................................... 48
Why write docstrings and comments.......................................................................... 48
How to write docstrings and comments...................................................................... 49
ChatGPT to generate docstrings................................................................................. 50
Find right Python data structures and algorithms..................................................... 50
What are data structures and algorithms.................................................................... 51
How to use data structures and algorithms................................................................ 51
Use ChatGPT to choose the right data structures and algorithms............................. 52
Generate Python code snippets and pseudocode....................................................... 53
What are code snippets and pseudocode...................................................................... 53
How to generate code snippets and pseudocode.......................................................... 54
Use ChatGPT to choose the right code snippets.......................................................... 55
Enhance security in Python code.................................................................................. 55
Why enhance security in Python code........................................................................ 56
How to enhance security in Python code.................................................................... 56
Use ChatGPT to enhance security.............................................................................. 59
Conclusion........................................................................................................................ 59
Next steps......................................................................................................................... 60
Points to remember......................................................................................................... 60

3. Setting up ChatGPT for Python Development............................................................... 61


Introduction...................................................................................................................... 61
Structure............................................................................................................................ 61
Objectives......................................................................................................................... 61
Customize ChatGPT....................................................................................................... 62
ChatGPT custom instructions.................................................................................... 62
xvi 
Setup custom instructions.......................................................................................... 63
Setting up.................................................................................................................... 66
Example 1: Tailored Python code snippets........................................................... 66
Example 2: Specific Python library usage............................................................ 66
Example 3: Coding style and formatting............................................................. 67
Example 4: Error handling in Python.................................................................. 67
Conclusion........................................................................................................................ 67
Next steps......................................................................................................................... 68
Points to remember......................................................................................................... 68

4. Requirements Gathering..................................................................................................... 69
Introduction...................................................................................................................... 69
Structure............................................................................................................................ 69
Objectives......................................................................................................................... 70
Product mindset.............................................................................................................. 70
Example: Customer discovery..................................................................................... 71
Example: Conducting interviews................................................................................ 71
Growth mindset........................................................................................................... 72
Example: Growth mindset.................................................................................... 73
Example: SMART goals....................................................................................... 73
Exercise: Set SMART goals.................................................................................. 74
Being inclusive................................................................................................................. 74
Use ChatGPT to empathize......................................................................................... 74
Example: Generate personas....................................................................................... 74
Exercise: Generate empathy maps............................................................................... 77
OKRs for the success....................................................................................................... 78
Example: Using ChatGPT to generate OKRs............................................................. 78
Exercise: Generate OKRs............................................................................................ 79
What are software requirements?................................................................................. 79
Example: USB T-Shirt launcher requirements.................................................... 80
Exercise: Write requirements............................................................................... 81
Types of software requirements................................................................................... 81
Example: Types of software requirements............................................................ 81
 xvii

Exercise: Classify software requirements............................................................. 82


Eliciting requirements..................................................................................................... 83
Example: Eliciting requirements................................................................................. 83
Exercise: Questions for requirements.......................................................................... 85
Analyzing requirements................................................................................................. 85
Generate requirements................................................................................................... 85
Example: User stories.................................................................................................. 85
Exercise: Generate non-functional requirements........................................................ 86
Validating and verifying requirements........................................................................ 87
Review requirements................................................................................................... 87
Example: Review user stories............................................................................... 87
Documenting requirements........................................................................................... 88
Using ChatGPT to generate SRS................................................................................ 88
Example: SRS introduction section...................................................................... 89
Exercise: Generate SRS........................................................................................ 91
Dealing with requirement challenges........................................................................... 92
Prioritize requirements................................................................................................ 92
Example: Prioritizing requirements..................................................................... 92
Conclusion........................................................................................................................ 94
Next steps......................................................................................................................... 95
Points to remember......................................................................................................... 95

5. Design and Architecture...................................................................................................... 97


Introduction...................................................................................................................... 97
Structure............................................................................................................................ 97
Objectives......................................................................................................................... 98
Principles and patterns................................................................................................... 98
Design principles......................................................................................................... 98
Cohesion............................................................................................................... 98
Coupling............................................................................................................. 100
Abstraction......................................................................................................... 101
Modularity......................................................................................................... 102
Encapsulation..................................................................................................... 103
xviii 
Inheritance.......................................................................................................... 104
Polymorphism..................................................................................................... 105
Example: Applying design principles....................................................................... 106
Direct vs indirect diagram generation............................................................... 107
Exercise: Identify design principles........................................................................... 108
Design patterns......................................................................................................... 108
Creational patterns............................................................................................. 110
Structural patterns..............................................................................................111
Behavioral patterns............................................................................................. 112
Example: Design patterns application............................................................... 113
Exercise: Identify design patterns...................................................................... 117
Designing and architecting a software project.......................................................... 117
Designing using ChatGPT....................................................................................... 117
Understand the requirements............................................................................. 118
Generate a high-level plan.................................................................................. 118
Refining the plan or structure............................................................................ 119
Design example......................................................................................................... 119
Understand......................................................................................................... 119
Generate high level plan..................................................................................... 123
Refine.................................................................................................................. 124
Design communication................................................................................................. 127
Generating templates................................................................................................ 128
Example: Design document....................................................................................... 128
T-Shirt Launcher design document........................................................................... 128
Design and architecture quality.................................................................................. 129
Generating reports or charts..................................................................................... 130
Example: Measuring cohesion................................................................................... 131
Exercise: Rate a design document............................................................................. 131
Conclusion...................................................................................................................... 131
Next steps....................................................................................................................... 132
 xix

6. Implementing a Software Product................................................................................... 133


Introduction.................................................................................................................... 133
Structure.......................................................................................................................... 134
Objectives....................................................................................................................... 134
What is implementation............................................................................................... 134
Writing code with ChatGPT........................................................................................ 135
Example: Code initialization..................................................................................... 135
Optimizing code with ChatGPT ................................................................................. 137
Example: Code optimization..................................................................................... 137
Debugging code with ChatGPT.................................................................................. 138
Example: Code debugging......................................................................................... 138
Common Python errors............................................................................................. 139
Syntax errors...................................................................................................... 139
Runtime errors................................................................................................... 140
Semantic errors................................................................................................... 140
Module-related errors......................................................................................... 141
Example: Implementing the USB T-Shirt project...................................................... 143
Requirement: Camera movement logic...................................................................... 143
Understand the problem............................................................................................ 144
USB T-Shirt launcher description...................................................................... 144
Pseudo implementation............................................................................................. 147
Prompt for ChatGPT................................................................................................. 148
Code provided by ChatGPT....................................................................................... 149
Benefits...................................................................................................................... 153
Implementation against OKRs evaluation................................................................ 153
Key result 1: ChatGPT in software development...................................................... 154
Key result 2: Practice exercises for readers............................................................... 154
Key result 3: Code quality and best practices............................................................ 154
Key initiatives........................................................................................................... 155
OKR review summary............................................................................................... 155
Conclusion...................................................................................................................... 156
Next steps....................................................................................................................... 156
xx 
7. Pull Review and Commit Messages................................................................................ 157
Introduction.................................................................................................................... 157
Structure.......................................................................................................................... 158
Objectives....................................................................................................................... 158
PR and commit messages............................................................................................. 158
Benefits of PR............................................................................................................ 160
PR challenges............................................................................................................ 160
ChatGPT for PRs............................................................................................................ 161
Prompt....................................................................................................................... 161
Reviewing with ChatGPT............................................................................................ 164
Review messages........................................................................................................... 164
Providing feedback..................................................................................................... 165
ChatGPT for Pull Review best practices.................................................................... 166
Prompt template for PR review................................................................................. 168
Example PR review comments........................................................................... 169
PRs key results............................................................................................................... 173
Example: Measuring PRs quality............................................................................. 173
Exercise: Enforcing the PRs quality.......................................................................... 173
Exercise: Establish PR gate for T-Shirt Launcher Project........................................ 174
Conclusion...................................................................................................................... 176
Next steps....................................................................................................................... 176

8. Using ChatGPT for Coding with SOLID Principles.................................................... 177


Introduction.................................................................................................................... 177
Structure.......................................................................................................................... 177
Objectives....................................................................................................................... 178
Introduction to SOLID principles............................................................................... 178
Importance of SOLID principles............................................................................... 179
Using ChatGPT to apply SOLID principles.............................................................. 182
Single Responsibility Principle (SRP)...................................................................... 183
Open/Closed Principle (OCP)................................................................................... 184
Liskov Substitution Principle (LSP)......................................................................... 185
Interface Segregation Principle (ISP)....................................................................... 186
 xxi

Dependency Inversion Principle (DIP).................................................................... 188


ChatGPT for fixing SOLID violations......................................................................... 190
Example: USB T-Shirt Launcher class...................................................................... 190
Key results...................................................................................................................... 193
Example: Measuring key result................................................................................. 194
Exercise...................................................................................................................... 195
Task 1: Establish baseline metrics....................................................................... 195
Task 2: Implement SOLID refactoring............................................................... 196
Task 3: Measure the post-refactoring impact...................................................... 196
Task 4: Reflect on your process........................................................................... 196
Deliverable.......................................................................................................... 196
Conclusion...................................................................................................................... 197
Next steps....................................................................................................................... 197

9. Software Testing with ChatGPT in Python................................................................... 199


Introduction.................................................................................................................... 199
Structure.......................................................................................................................... 199
Objectives....................................................................................................................... 200
Introduction to testing.................................................................................................. 200
ChatGPT for testing.................................................................................................. 202
Unit testing..................................................................................................................... 203
Unit test for simple function..................................................................................... 203
Unit test case scenario............................................................................................... 204
Integration testing......................................................................................................... 206
Simulating errors and exceptions in integration tests.............................................. 207
Example.............................................................................................................. 207
Sample ChatGPT output........................................................................................... 210
System testing................................................................................................................ 212
System test case scenario........................................................................................... 212
Acceptance testing......................................................................................................... 214
Example: Acceptance testing..................................................................................... 215
Conclusion...................................................................................................................... 219
xxii 
Next steps....................................................................................................................... 219
Points to remember....................................................................................................... 219

10. Deployment with ChatGPT.............................................................................................. 221


Introduction.................................................................................................................... 221
Structure.......................................................................................................................... 222
Objectives....................................................................................................................... 222
Types and stages of deployment................................................................................. 222
Development stage.................................................................................................... 223
Testing stage.............................................................................................................. 223
Staging stage............................................................................................................. 223
Production stage........................................................................................................ 224
Best practices............................................................................................................. 224
Deployment strategies with ChatGPT....................................................................... 225
Blue-green deployment.............................................................................................. 225
Canary deployment................................................................................................... 225
Rolling deployment................................................................................................... 225
Comparative analysis of deployment strategies........................................................ 226
Deployment with ChatGPT......................................................................................... 226
USB T-Shirt launcher Local deployment.................................................................. 227
Example: Deployment to build................................................................................... 228
Build environment deployment.......................................................................... 228
Deployment automation with ChatGPT.................................................................... 232
Benefits of deployment automation........................................................................... 233
Faster and easier deployment............................................................................. 233
Higher quality and performance........................................................................ 233
Better collaboration and communication........................................................... 233
Tools and frameworks for automation....................................................................... 233
Ansible................................................................................................................ 233
Terraform............................................................................................................ 234
GitHub Actions.................................................................................................. 234
Azure DevOps.................................................................................................... 234
Helm................................................................................................................... 234
 xxiii

Comparative analysis of deployment automation tools...................................... 235


ChatGPT's role in automation........................................................................... 235
Automated production deployment........................................................................... 236
Deployment troubleshooting with ChatGPT............................................................ 241
Common issues or errors........................................................................................... 242
Troubleshooting............................................................................................................. 243
Logging...................................................................................................................... 243
Monitoring................................................................................................................ 243
Debugging and testing.............................................................................................. 244
Example: Troubleshooting USB T-Shirt deployment................................................ 244
Conclusion...................................................................................................................... 247
Next steps....................................................................................................................... 247

11. Performance and Observability....................................................................................... 249


Introduction.................................................................................................................... 249
Structure.......................................................................................................................... 249
Objectives....................................................................................................................... 250
Introduction to Observability...................................................................................... 250
Types of Observability............................................................................................... 250
Suggested tools and frameworks............................................................................... 251
Example: Understand Observability......................................................................... 251
Exercise: Observability requirements........................................................................ 252
Logging........................................................................................................................... 252
Logging by specification........................................................................................ 252
Logging using Specific Format................................................................................. 253
Logging best practices............................................................................................... 254
Metrics............................................................................................................................. 254
Tracing............................................................................................................................. 255
Alerts............................................................................................................................... 257
Common challenges in achieving effective Observability......................................... 259
Example: Observability in T-Shirt project.................................................................. 259
Adding Observability code........................................................................................ 260
Observability in Grafana Cloud................................................................................ 262
xxiv 
OKR evaluation......................................................................................................... 269
Objectives........................................................................................................... 269
Self-evaluation for Objectives............................................................................. 269
Key results / metrics .......................................................................................... 269
Evaluation for key results/metrics...................................................................... 269
Conclusion...................................................................................................................... 269
Next steps....................................................................................................................... 270

12. Revolutionary Impact of ChatGPT.................................................................................. 271


Introduction.................................................................................................................... 271
Structure.......................................................................................................................... 271
Objectives....................................................................................................................... 272
Revolutionary impact of ChatGPT............................................................................. 272
ChatGPT agents............................................................................................................. 272
Enhance collaboration and communication.............................................................. 275
Improve quality, security and reliability.................................................................... 276
Foster culture of continuous learning........................................................................ 278
Opportunities and challenges..................................................................................... 284
Conclusion...................................................................................................................... 285
Next steps....................................................................................................................... 286
Points to remember....................................................................................................... 286

13. Limitations, Pitfalls and Dangers of ChatGPT............................................................. 287


Introduction.................................................................................................................... 287
Structure.......................................................................................................................... 287
Objectives....................................................................................................................... 288
Limitations of ChatGPT................................................................................................ 288
Recognize inaccuracies................................................................................................. 289
Responsible and ethical use......................................................................................... 289
Protect yourself.............................................................................................................. 290
Abuse of GAI............................................................................................................. 290
Best practices to protect yourself............................................................................... 290
 xxv

Conclusion...................................................................................................................... 291
Next steps....................................................................................................................... 292

14. Preparing for the Future with ChatGPT......................................................................... 293


Introduction.................................................................................................................... 293
Structure.......................................................................................................................... 293
Objectives....................................................................................................................... 294
Preparing for the future using ChatGPT................................................................... 294
Keeping up with trends................................................................................................ 294
Exercise: Use ChatGPT for research......................................................................... 295
Developing a growth mindset..................................................................................... 295
Learning path example.............................................................................................. 296
Example..................................................................................................................... 296
Network effect............................................................................................................... 300
Showcase yourself......................................................................................................... 301
Example..................................................................................................................... 302
Pursue new paths.......................................................................................................... 303
Interview or presentation prep.................................................................................... 304
Presentation prep example........................................................................................ 304
Interview preparation example.................................................................................. 305
Additional resources..................................................................................................... 307
Conclusion...................................................................................................................... 307
Next steps....................................................................................................................... 308

Index...............................................................................................................................309-316
xxvi 
ChatGPT and Its Capabilities  1

Chapter 1
ChatGPT and
Its Capabilities

Introduction
In this chapter, you will learn about ChatGPT, an AI chatbot that can interact in a
conversational way, and its capabilities in Python development. You will discover
ChatGPT, how it works, and what it can do for Python developers in the entire Software
Development Life Cycle (SDLC). You will also see some examples of ChatGPT
conversations and outputs in each stage of the SDLC and learn how to evaluate and use
them in your projects. This chapter will help you understand the basics and benefits of
using ChatGPT in Python development. This chapter prepares you for the next chapters,
where we will deep dive into each phase of SDLC and apply ChatGPT.

Structure
• Frequently asked questions about ChatGPT
• Introduction to the book
• What is ChatGPT
• Advanced: How does ChatGPT work
• What can ChatGPT do for Python developers in the entire SDLC?
• Examples of ChatGPT prompts and outputs useful in the entire SDLC
• Guide to prompt engineering
2  Modern Python Programming using ChatGPT

Objectives
After completing this chapter, you will have gained an understanding of ChatGPT and
how it can be utilized for Python development across the SDLC. This includes learning
what ChatGPT is, how it functions, and its strengths and limitations. You will be able to
interact with ChatGPT through simple prompts and questions to generate useful outputs.
Most importantly, you will learn best practices for leveraging ChatGPT at each phase of the
Python SDLC - from establishing Objective Key Results (OKRs), requirements gathering
to coding, testing, and maintenance. Evaluating and thoughtfully applying ChatGPT's
outputs will enable you to enhance productivity and accelerate development workflows.
With a comprehensive overview of ChatGPT's Python development capabilities, you will
be equipped to determine where it can best support your projects.

Frequently asked questions about ChatGPT


Before we dive into the details of ChatGPT and its capabilities in Python development, let
us address some of the common questions and concerns you might have about ChatGPT.

Will it get me fired


No, ChatGPT will not get you fired. ChatGPT is not a replacement for human developers
but a tool that can help you improve your development skills and productivity. ChatGPT
is not perfect, and it cannot do everything that a human developer can do. It can only
generate texts based on the input and context you provide, and it does not understand the
logic, functionality, or quality of the code it generates. You still need to use your judgment,
creativity, and expertise to evaluate, modify, and use ChatGPT's outputs. ChatGPT is not
a threat to your job but a friend who can assist you with your tasks.

What is the best description of ChatGPT


ChatGPT is an overeager all-knowing intern that aims to please. With genuinely good
intentions it desperately tries to answer your question even if it must make things up.
Without good human expert guidance, the answers cannot be used directly in real world
applications.

How reliable is ChatGPT


ChatGPT is a powerful and advanced AI chatbot that is not infallible. ChatGPT can
sometimes generate inaccurate, irrelevant, inconsistent, or nonsensical texts. ChatGPT
can also make grammar, spelling, punctuation, or formatting mistakes. ChatGPT does not
have any knowledge of the real world, and it cannot verify or validate the information
that it generates. Therefore, you should always check and verify ChatGPT's outputs
before using them in your projects. You should also use other sources of information and
documentation to supplement and complement ChatGPT's outputs.
ChatGPT and Its Capabilities  3

How secure is ChatGPT


ChatGPT is a secure and trustworthy AI chatbot, but it is not immune to malicious attacks
or misuse. ChatGPT uses encryption and authentication to protect your data and privacy.
ChatGPT does not store or share any of your inputs or outputs with anyone else. However,
ChatGPT can also be hacked or manipulated by hackers or malicious users who can
access your OpenAI account or your Python environment. Therefore, you should always
use strong passwords and security measures to protect your OpenAI account and your
Python environment. You should also avoid using ChatGPT for sensitive or confidential
information or projects. You should obtain permission from your company before using
ChatGPT for writing your company software.

How ethical is ChatGPT


ChatGPT is an ethical and responsible AI chatbot, but it is not aware of the moral or social
implications of its outputs. ChatGPT does not have any intention or agenda to harm or
offend anyone or anything. ChatGPT only generates texts based on the input and context
that you provide, and it does not have any control over how you use or interpret its outputs.
However, ChatGPT can also generate texts that are inappropriate, offensive, harmful, or
illegal in some situations or contexts. Therefore, you should always use ChatGPT with
caution and respect for others and yourself. You should also follow the ethical principles
and guidelines of Python development and AI usage.

How inclusive is ChatGPT


ChatGPT is an inclusive and respectful AI chatbot, but it is not free of inherent bias or
prejudice. ChatGPT can sometimes generate texts that are insensitive, discriminatory, or
offensive to some groups or individuals based on their gender, race, ethnicity, religion,
caste, sexual orientation, disability, etc. ChatGPT does not have any intention or agenda to
harm or exclude anyone or anything. ChatGPT only generates texts based on the input and
context that you provide and the data that it has been trained on. However, the data that
ChatGPT has been trained on may contain biases or stereotypes that reflect the historical
and cultural realities of the internet. Therefore, you should always use ChatGPT with
caution and empathy for others and yourself. You should also report any inappropriate or
harmful outputs that ChatGPT provides to OpenAI so that they can improve the quality
and diversity of ChatGPT.

Introduction to the book


In this book, you will learn how to use ChatGPT, an AI chatbot that can interact in a
conversational way, to enhance your Python development skills and productivity.
ChatGPT is based on Generative Pre-trained Transformer (GPT) / Large Language
Model (LLM), a powerful language model that can generate natural language texts from
4  Modern Python Programming using ChatGPT

any given input. ChatGPT can help you with various aspects of Python development,
such as establishing OKRs, requirements gathering, design, implementation, testing,
deployment, communication and feedback. ChatGPT can also generate various types of
content, such as code, documentation, tests, etc., based on the input and context.

What is this book about


This book is about how to use ChatGPT to enhance your Python development skills and
productivity. The book takes a fun project (USB T-Shirt Launcher) and illustrates step by
step how its development is accelerated using ChatGPT.

Who is this book for


This book is for Python developers who want to use ChatGPT to improve their
development workflow and quality. The readers should have basic knowledge of Python
programming and software development concepts. The readers should have access to a
Python environment and optionally an OpenAI account to use ChatGPT. The readers do
not need to have prior experience with ChatGPT or other AI models, as the book will cover
the basics and best practices of using ChatGPT in Python development.

What are the prerequisites for this book


The prerequisites for this book are:
• A working knowledge of Python programming and software development
concepts
• A Python environment
• Preferable but not required: An OpenAI account with access to the OpenAI API
• Curiosity and willingness to learn and experiment with ChatGPT

How is this book organized


This book is organized into the following chapters:
• Chapter 1: ChatGPT and Its Capabilities
Introduces the integral role of ChatGPT in Python development, demonstrating
its application across the software development life cycle (SDLC). Highlights
include functionality, operation, and application stages, alongside reliability,
security, and ethical considerations. Guide to prompt engineering.
• Chapter 2: Benefits of Using ChatGPT in Python Development
Explores the integration of ChatGPT into Python workflows to enhance library/
framework selection, code writing, legacy code management, and code security,
streamlining development processes.
ChatGPT and Its Capabilities  5

• Chapter 3: Setting up ChatGPT for Python Development


Provides a guide on enhancing development efficiency with ChatGPT, emphasizing
the use of the free version and custom instructions for personalized interaction
and effective prompt crafting.
• Chapter 4: Requirements Gathering
Focuses on defining, analyzing, validating, and documenting software project
needs with ChatGPT, including elicitation techniques and actionable insights for
OKRs, and requirements gathering.
• Chapter 5: Design and Architecture
Discusses the use of ChatGPT in planning and structuring software projects to
meet functional and non-functional requirements, with a focus on scalability,
maintainability, and reusability.
• Chapter 6: Implementing a Software Product
Details writing, testing, debugging, and deploying code with ChatGPT's assistance,
highlighting code generation, optimization, and performance improvements for
project success.
• Chapter 7: Pull Review and Commit Messages
Outlines the crafting and reviewing of pull requests and commit messages using
ChatGPT, emphasizing clarity, conciseness, and consistency in documentation for
development teams.
• Chapter 8: Using ChatGPT for Coding with SOLID Principles
Aims to enhance code quality and maintainability by applying SOLID principles
with ChatGPT, identifying code smells, and refactoring to adhere to object-oriented
design principles.
• Chapter 9: Software Testing with ChatGPT in Python
Demonstrates how ChatGPT aids in software testing, including unit, integration,
system, and acceptance testing, to improve test coverage, quality, and efficiency.
• Chapter 10: Deployment with ChatGPT
Guides on deploying Python code with ChatGPT across different environments,
detailing strategies and automation for streamlined processes and troubleshooting
deployment issues.
• Chapter 11: Performance and Observability
Highlights the use of ChatGPT for integrating with observability platforms like
Grafana Cloud for Python projects' performance and reliability monitoring.

You might also like