AI-Assisted Programming Better Planning, Coding, Testing, and Deployment (Tom Taulli) (Z-Library)

Author: Tom Taulli

技术

Get practical advice on how to leverage AI development tools for all stages of code creation, including requirements, planning, design, coding, debugging, testing, and documentation. With this book, beginners and experienced developers alike will learn how to use a wide range of tools, from general-purpose LLMs (ChatGPT, Gemini, and Claude) to code-specific systems (GitHub Copilot, Tabnine, Cursor, and Amazon CodeWhisperer). You'll also learn about more specialized generative AI tools for tasks such as text-to-image creation. Author Tom Taulli provides a methodology for modular programming that aligns effectively with the way prompts create AI-generated code. This guide also describes the best ways of using general purpose LLMs to learn a programming language, explain code, or convert code from one language to another.

📄 File Format: PDF
💾 File Size: 11.2 MB
90
Views
4
Downloads
0.00
Total Donations

📄 Text Preview (First 20 pages)

ℹ️

Registered users can read the full content for free

Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.

📄 Page 1
(This page has no text content)
📄 Page 2
PROGR AMMING L ANGUAGES AI-Assisted Programming linkedin.com/company/oreilly-media youtube.com/oreillymedia Get practical advice on how to leverage AI development tools for all stages of code creation, including requirements, planning, design, coding, debugging, and testing. With this book, beginners and experienced developers alike will learn how to use a wide range of tools, from general-purpose LLMs (ChatGPT, Gemini, and Claude) to code-specific systems (GitHub Copilot, Tabnine, Cursor, and Amazon CodeWhisperer). You’ll also learn about more specialized generative AI tools for tasks such as text-to-image creation. Author Tom Taulli provides a methodology for modular programming that aligns effectively with the way prompts create AI-generated code. This guide also describes the best ways of using general-purpose LLMs to learn a programming language, explain code, or convert code from one language to another. This book examines: • The core capabilities of AI-based development tools • Pros, cons, and use cases of popular systems, including GitHub Copilot • Ways to use ChatGPT, Gemini, Claude, and other generic LLMs for coding • Using AI development tools for the software development lifecycle, including requirements, planning, coding, debugging, and testing • Prompt engineering for development • Using AI-assisted programming for tedious tasks like creating regular expressions • How to use AI-based low-code and no-code tools Tom Taulli is an author, advisor, and investor who’s penned numerous books, including Artificial Intelligence Basics. He also contributes to publications such as AIBusiness.com, Inc.com, Barrons.com, eSecurity Planet, and Kiplingers.com, and has developed educational courses for O’Reilly and Pluralsight, focusing on areas such as generative AI, databases, and Python. 9 7 8 1 0 9 8 1 6 4 5 6 0 6 9 9 9 9 US $69.99 CAN $87.99 ISBN: 978-1-098-16456-0 “When we added vector search to Cassandra in six weeks, Copilot and ChatGPT were key to meeting our deadline, but most developers have yet to take advantage of AI tools like these. Tom’s book is a great way to get started and will save you hours of trial and error.” —Jonathan Ellis Cofounder and CTO of DataStax
📄 Page 3
Praise for AI-Assisted Programming When we added vector search to Cassandra in six weeks, Copilot and ChatGPT were key to meeting our deadline, but most developers have yet to take advantage of AI tools like these. Tom’s book is a great way to get started and will save you hours of trial and error. —Jonathan Ellis, cofounder and CTO of DataStax AI-Assisted Programming is an excellent resource that showcases Tom’s expertise and equips readers for the current evolution of software development, empowering everyone to code. —Justin Dorfman, Open Source Community Manager at Sourcegraph AI is rapidly changing how developers build software. From code editors to terminal and more, AI assistance is becoming pervasive. AI-Assisted Programming should be the first read for any developer trying to get the most from AI in their daily workflows. —Zach Lloyd, CEO and cofounder of Warp Tom Taulli’s book is a well-structured journey into how AI tools like ChatGPT can change the game for developers—both early in their careers and for seasoned experts. It shares applicable insights on the ups and downs of AI-powered coding, much like my own journey from marketing and business to shipping features in production for our app. Great for programmers looking to leverage AI as part of their toolbox. —Titus Capilnean, cofounder at Private Market Labs AI has changed the game for development. Every programmer will need to know how to work with tools like GitHub Copilot. Tom’s book shows how. —Muddu Sudhakar, CEO and cofounder of Aisera
📄 Page 4
Tom Taulli AI-Assisted Programming Better Planning, Coding, Testing, and Deployment Boston Farnham Sebastopol TokyoBeijing
📄 Page 5
978-1-098-16456-0 [LSI] AI-Assisted Programming by Tom Taulli Copyright © 2024 Tom Taulli. All rights reserved. Printed in the United States of America. Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472. O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles (https://oreilly.com). For more information, contact our corporate/institu‐ tional sales department: 800-998-9938 or corporate@oreilly.com. Acquisitions Editor: Brian Guerin Development Editor: Shira Evans Production Editor: Kristen Brown Copyeditor: Paula L. Fleming Proofreader: Emily Wydeven Indexer: Potomac Indexing, LLC Interior Designer: David Futato Cover Designer: Karen Montgomery Illustrator: Kate Dullea April 2024: First Edition Revision History for the First Edition 2024-04-10: First Release See https://oreilly.com/catalog/errata.csp?isbn=9781098164560 for release details. The O’Reilly logo is a registered trademark of O’Reilly Media, Inc. AI-Assisted Programming, the cover image, and related trade dress are trademarks of O’Reilly Media, Inc. The views expressed in this work are those of the author and do not represent the publisher’s views. While the publisher and the author have used good faith efforts to ensure that the information and instructions contained in this work are accurate, the publisher and the author disclaim all responsibility for errors or omissions, including without limitation responsibility for damages resulting from the use of or reliance on this work. Use of the information and instructions contained in this work is at your own risk. If any code samples or other technology this work contains or describes is subject to open source licenses or the intellectual property rights of others, it is your responsibility to ensure that your use thereof complies with such licenses and/or rights.
📄 Page 6
Table of Contents Foreword. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xi Preface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xiii 1. New World for Developers. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 Evolution and Revolution 2 Generative AI 5 The Benefits 6 Minimizing Search 6 Your Advisor 8 IDE Integration 9 Reflecting Your Codebase 10 Code Integrity 11 AI-Powered Documentation Generator 11 Modernization 12 Drawbacks 15 Hallucinations 15 Intellectual Property 15 Privacy 16 Security 17 Training Data 17 Bias 18 A New Way for Developers 18 Career 19 10x Developer? 19 Skills of the Developer 20 Conclusion 20 v
📄 Page 7
2. How AI Coding Technology Works. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 Key Features 21 Code Suggestions and Context-Aware Completions Versus Smart Code Completion 22 Compilers Versus AI-Assisted Programming Tools 23 Levels of Capability 24 Generative AI and Large Language Models (LLMs) 26 Evolution 26 The Transformer Model 27 OpenAI Playground 30 Evaluating LLMs 35 Types of LLMs 38 Evaluation of AI-Assisted Programming Tools 40 Conclusion 41 3. Prompt Engineering. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 Art and Science 44 Challenges 44 The Prompt 45 Context 46 Instructions 46 Summarization 47 Text Classification 48 Recommendation 48 Translation 49 Input of Content 50 Format 50 Best Practices 51 Be Specific 51 Acronyms and Technical Terms 52 Zero- and Few-Shot Learning 53 Leading Words 54 Chain of Thought (CoT) Prompting 54 Leading Questions 55 Ask for Examples and Analogies 55 Reducing Hallucinations 56 Security and Privacy 57 Autonomous AI Agents 58 Conclusion 60 4. GitHub Copilot. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61 GitHub Copilot 61 vi | Table of Contents
📄 Page 8
Pricing and Versions 62 Use Case: Programming Hardware 63 Use Case: Shopify 64 Use Case: Accenture 65 Security 65 Getting Started 66 Codespaces and Visual Studio Code 67 Suggestions 69 Comments 72 Chat 72 Inline Chat 77 Open Tabs 79 Command-Line Interface 80 Copilot Partner Program 81 Conclusion 82 5. Other AI-Assisted Programming Tools. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83 Amazon’s CodeWhisperer 83 Google’s Duet AI for Developers 85 Tabnine 87 Replit 88 CodeGPT 91 Cody 91 CodeWP 93 Warp 94 Bito AI 96 Cursor 97 Code Llama 98 Other Open Source Models 99 StableCode 99 AlphaCode 100 PolyCoder 100 CodeT5 101 Enterprise Software Companies 101 Conclusion 102 6. ChatGPT and Other General-Purpose LLMs. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103 ChatGPT 103 GPT-4 104 Navigating ChatGPT 105 Mobile App 108 Custom Instructions 109 Table of Contents | vii
📄 Page 9
Browse with Bing 109 Tedious Tasks 113 Regular Expressions 114 Starter Code 115 GitHub README 115 Cross-Browser Compatibility 116 Bash Commands 117 GitHub Actions 117 Plugins 118 The Codecademy Plugin 119 The AskYourDatabase Plugin 120 Recombinant AI Plugin 121 GPTs 121 Gemini 123 Applications 125 Gemini for Coding 126 Claude 128 Conclusion 130 7. Ideas, Planning, and Requirements. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131 Brainstorming 131 Market Research 133 Market Trends 135 Total Addressable Market 136 Competition 137 Requirements 139 Product Requirements Document 140 Software Requirements Specification 141 Interviews 142 Whiteboarding 143 Tone 144 Approaches to Project Planning 145 Test-Driven Development (TDD) 147 Planning Web Design 149 Conclusion 152 8. Coding. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153 Reality Check 153 Judgment Calls 155 Learning 156 Comments 157 Modular Programming 158 viii | Table of Contents
📄 Page 10
Starting a Project 159 Autofill 160 Refactoring 162 Ninja Code 162 Extract Method 163 Decomposing Conditionals 164 Renaming 164 Dead Code 165 Functions 166 Object-Oriented Programing 167 Frameworks and Libraries 168 Data 169 Frontend Development 171 CSS 172 Creating Graphics 172 AI Tools 173 APIs 176 Conclusion 177 9. Debugging, Testing, and Deployment. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179 Debugging 179 Documentation 180 Code Review 182 Unit Tests 183 Pull Requests 186 Deployment 187 User Feedback 189 The Launch 190 Conclusion 191 10. Takeaways. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193 The Learning Curve Is Steep 193 There Are Major Benefits 194 But There Are Drawbacks 194 Prompt Engineering Is an Art and Science 195 Beyond Programming 195 AI Won’t Take Your Job 196 Conclusion 196 Index. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197 Table of Contents | ix
📄 Page 11
(This page has no text content)
📄 Page 12
Foreword When I graduated from UCLA in the early 1990s, I thought I would be a professor. But when IBM hired me, I quickly fell in love with the technology industry. There was no turning back. I would go on to work at other companies like VMware, Pivotal, EMC, and SGI. Then I founded several startups. My latest is Aisera, which builds generative AI solu‐ tions for enterprises. Our platform helps with customer service, employee experience, enterprise search, IT service desk, and AIOps. Throughout my career, I’ve seen many innovations, such as the emergence of the internet, cloud computing, mobile devices, and deep learning. Yet there was one area of technology that saw little progress: software development. As a founder, this was certainly a big frustration. There would often be certain things we wanted to do but could not because of the bottlenecks with our engineering teams. But with AI-assisted programming, the game has changed in a big way. It has made Aisera more agile and nimble. It’s been a force multiplier that has helped propel our growth. Now, when I consider hiring a developer, I want to know how they leverage AI. How are they using this powerful technology to handle tedious processes and code faster? Bottom line: I believe that understanding AI-assisted programming tools is a critical skillset. According to Microsoft CEO Satya Nadella, they are “becoming standard issue for any developer…” But understanding AI-assisted programming requires a different approach. It’s not like typical development. You need to understand how to use generative AI systems. This is where Tom’s book comes in. He has written a playbook for any developer who wants to become proficient with AI-assisted programming. He’s covered the key top‐ ics and has provided many useful examples. He also has done this in a fun manner, making the topic approachable. xi
📄 Page 13
No doubt, it’s an exciting time to be a developer. There are many opportunities for career growth. And one of the best moves you can make is learning AI-assisted programming. — Muddu Sudhakar CEO and cofounder of Aisera xii | Foreword
📄 Page 14
Preface I started coding back in the early ’80s. My first rig was an Atari 400—not exactly a powerhouse with its membrane keyboard, just 8K of RAM, and programs that loaded from cassettes. I learned the BASIC language and created simple games and utility apps. I was totally into it. Naturally, over time I upgraded to beefier machines. Along the way, I got my hands dirty with languages like Pascal, C, and C++. But the IDEs didn’t change much, except for syntax highlighting and debugging features. Everything changed dramatically with the arrival of GitHub Copilot and ChatGPT. Trying out these tools felt like the moment I first held an iPhone—absolutely game-changing. In natural language, I asked ChatGPT to write code. Or in VS Code, I would type a fragment of a function, and GitHub Copilot would generate a code block. Often it was like hitting the bull’s-eye. Oh, and then I used ChatGPT to turn images into code. Yet the real power was that these tools could handle many of the tedious tasks for developers. Who’s into wrestling with regex statements or piecing together bash com‐ mands or GitHub actions? Not me, for sure. But these AI programming tools? They eat that stuff for breakfast. Turns out, these AI tools are handy for more than just coding. I began using ChatGPT for brainstorming app ideas, drafting requirements, and even knocking out unit tests. It didn’t take long for me to be convinced that AI-assisted programming would be one of those must-have skills for programmers. So yes, I saw a big need to write this book. I put together an outline and pitched it to O’Reilly. The folks there instantly saw the potential. xiii
📄 Page 15
Writing the book has been lots of fun, and I’ve learned a lot. I’ve also interviewed many smart developers who have provided me with great ideas and tips. But AI-assisted programming is quickly evolving. This is why this book has a com‐ panion GitHub repository. Here, I’ll make updates to the book and include other important developments in this exciting field. So thank you for picking up this book. I hope you find it not only informative but also a valuable guide in your journey. What’s Covered Here’s a brief look at each chapter: • Chapter 1, “New World for Developers”: This chapter kicks off with a look into how generative AI is changing the game for coders. It talks about how these AI tools are helping developers think more about the big picture and less about the nitty-gritty of coding. The chapter also takes a stroll through the history of pro‐ gramming languages. There are also details about the advanced AI technologies like GPT-4. • Chapter 2, “How AI Coding Technology Works”: The chapter starts off by explaining generative AI and why transformer models and large language models are big deals in the programming world. To top it off, there’s a walkthrough of OpenAI’s Playground, showing how you can play around with these AI models and tweak them to suit your coding needs. • Chapter 3, “Prompt Engineering”: The information here is critical to using AI- assisted programming tools. This chapter is packed with practical tips, like deal‐ ing with wordy or confusing prompts and deterring AI from making stuff up. Plus, it breaks down the key parts of a prompt and shows you how to use them effectively. • Chapter 4, “GitHub Copilot”: This chapter is a walkthrough of this powerful tool. There’s a look at the core features like creating code with comments, Chat, and using an AI-powered command-line interface. There is also coverage of custom‐ izing the system for proprietary codebases. • Chapter 5, “Other AI-Assisted Programming Tools”: This chapter details the other top AI-assisted programming tools like Amazon CodeWhisperer, Google’s Duet AI, and Replit to name just a few. • Chapter 6, “ChatGPT and Other General-Purpose LLMs”: This covers how to use these tools for tasks like handling regular expressions, starter code, and GitHub Actions. xiv | Preface
📄 Page 16
• Chapter 7, “Ideas, Planning, and Requirements”: The focus here is on using chat‐ bots to kick off software projects. This involves topics like brainstorming, market research, requirements documents, and test-driven development. • Chapter 8, “Coding”: This chapter goes through common scenarios for develop‐ ment, whether working with APIs, using modular programming, or refactoring. There’s also a look at handling functions and object-oriented programming. • Chapter 9, “Debugging, Testing, and Deployment”: This chapter is about the less glamorous parts of development. It covers topics like fixing bugs, using AI- assisted programming tools for code reviews, making unit tests, and describing pull requests. • Chapter 10, “Takeaways”: This is a wrap-up of the book, emphasizing the main points. How This Book Is Different Software developers thrive on certainty. When you give a program certain input, you always get the same output. For ages, this pure deterministic logic was the heart and soul of software. But when you use AI-assisted programming tools, things get a bit topsy-turvy. Get‐ ting results is like rolling dice since everything works on probabilities. When you prompt an AI tool to whip up some code, and even use the same prompt over multi‐ ple tries, you might get different results each time. Sure, it’s a bit of a head-scratcher at first, but once you get the hang of it, it’s totally worth it. That’s why there is a chapter on prompt engineering that will help with this new approach to programming. Who Should Read This Book This book is for any developer, whether you’re just starting out or you’ve been in the game for many years. Conventions Used in This Book The following typographical conventions are used in this book: Italic Indicates new terms, URLs, email addresses, filenames, and file extensions. Constant width Used for program listings, as well as within paragraphs to refer to program ele‐ ments such as variable or function names, databases, data types, environment variables, statements, and keywords. Preface | xv
📄 Page 17
Constant width bold Shows commands or other text that should be typed literally by the user. Constant width italic Shows text that should be replaced with user-supplied values or by values deter‐ mined by context. This element signifies a general note. Using Code Examples Supplemental material (code examples, exercises, etc.) is available for download at https://github.com/ttaulli/AI-Assisted-Programming-Book. If you have a technical question or a problem using the code examples, please send email to support@oreilly.com. This book is here to help you get your job done. In general, if example code is offered with this book, you may use it in your programs and documentation. You do not need to contact us for permission unless you’re reproducing a significant portion of the code. For example, writing a program that uses several chunks of code from this book does not require permission. Selling or distributing examples from O’Reilly books does require permission. Answering a question by citing this book and quoting example code does not require permission. Incorporating a significant amount of example code from this book into your product’s documentation does require permission. We appreciate, but generally do not require, attribution. An attribution usually includes the title, author, publisher, and ISBN. For example: “AI-Assisted Program‐ ming by Tom Taulli (O’Reilly). Copyright 2024 Tom Taulli, 978-1-098-16456-0.” If you feel your use of code examples falls outside fair use or the permission given above, feel free to contact us at permissions@oreilly.com. O’Reilly Online Learning For more than 40 years, O’Reilly Media has provided technol‐ ogy and business training, knowledge, and insight to help companies succeed. xvi | Preface
📄 Page 18
Our unique network of experts and innovators share their knowledge and expertise through books, articles, and our online learning platform. O’Reilly’s online learning platform gives you on-demand access to live training courses, in-depth learning paths, interactive coding environments, and a vast collection of text and video from O’Reilly and 200+ other publishers. For more information, visit https://oreilly.com. How to Contact Us Please address comments and questions concerning this book to the publisher: O’Reilly Media, Inc. 1005 Gravenstein Highway North Sebastopol, CA 95472 800-889-8969 (in the United States or Canada) 707-827-7019 (international or local) 707-829-0104 (fax) support@oreilly.com https://www.oreilly.com/about/contact.html We have a web page for this book, where we list errata, examples, and any additional information. You can access this page at https://oreil.ly/AI-assisted-programming. For news and information about our books and courses, visit https://oreilly.com. Find us on LinkedIn: https://linkedin.com/company/oreilly-media Watch us on YouTube: https://youtube.com/oreillymedia Acknowledgments I want to thank the folks at O’Reilly who believed in this book and worked hard to make it a reality: Nicole Butterfield, Shira Evans, and Brian Guerin. I also had the benefit of outstanding tech reviewers. They include Roja Boina, Abraham Borg, Sarah Kim, Ebubechukwu (Nnenna) Oguaju-Dike, and Gaurav Deshmukh. Preface | xvii
📄 Page 19
(This page has no text content)
📄 Page 20
CHAPTER 1 New World for Developers While juggling dense neural network architectures and pixel-wrangling computer vision at Stanford from 2011 to 2016, Andrej Karpathy also moonlighted at Google. Over there, he tinkered around and whipped up a feature-learning system for You‐ Tube videos. Then he decided to become a founding member of OpenAI and later the senior director of AI at Tesla, where he led a team to create the Autopilot system. It’s safe to say he’s one the world’s top coders. He is also a skilled wordsmith with a massive Twitter—or X—following of nearly 800,000 followers. When ChatGPT cata‐ pulted onto the scene, he tweeted: The hottest new programming language is English. He wasn’t kidding. This wasn’t just a poetic ode to coding but a nod to a future where typing out natural language prompts could conjure up computer code in seemingly any language. It’s like having a bilingual genie in your computer, ready to transcribe your English wishes into code commands. Then there came a tweet that echoed the sentiments of many developers: Copilot has dramatically accelerated my coding, it’s hard to imagine going back to “manual coding”. Still learning to use it but it already writes ~80% of my code, ~80% accuracy. I don’t even really code, I prompt. & edit. Karpathy was tipping his hat to Microsoft’s GitHub Copilot, a fresh brew of AI- assisted programming. But it wouldn’t be long until many other tools sprouted up. The pace of innovation was breathtaking. Now, for all the coders out there, the landscape might look like a dense jungle. What’s this brave new world of AI tools? Where do they dazzle, and where do they fizzle? And how do you wade through all this to become a savvy AI-assisted programmer? 1
The above is a preview of the first 20 pages. Register to read the complete e-book.

💝 Support Author

0.00
Total Amount (¥)
0
Donation Count

Login to support the author

Login Now
Back to List