Today, the coding environment is changing at an incredibly fast pace. With the advancement of AI technology, the way we write code has fundamentally changed. AI models like ChatGPT and Copilot can quickly generate clean code, creating a world that is completely different from the era where humans wrote every line of code from start to finish.
This change poses an important question for developers:
"In an era where AI writes code for us, is there really a need for developers to deeply understand the internal workings of the code?"
I want to answer this question without hesitation: "Yes".
Why Should We Understand Deeply? – The Engineer's Responsibility and Collaboration with AI
1. Risk Management and Responsibility
While copying and pasting AI-generated code might help complete projects quickly, it carries significant long-term risks.
-
Unknown Errors: The code suggested by AI may appear fine on the surface but can cause unexpected bugs in certain situations.
-
Scalability Issues: As the project grows, using code without understanding its internal logic can become a hindrance.
Ultimately, it is the developer who must solve all these problems. As a developer, you must understand how the tools and code you use work and be able to diagnose and resolve errors quickly when they arise.
2. Growth as a True ‘Engineer’
Even in the era of AI, or rather, because it is the era of AI, it is necessary to deeply understand code.
-
Effective Communication: When asking AI questions, being able to specifically explain where the issues are will yield better answers.
-
Proactive Design: The ability to decide how to combine frameworks or libraries and what structure to create is still up to humans.
-
Improved Technical Insight: Understanding internal workings leads to structural and creative ideas like, “This framework works this way, so I can extend this feature like this.”
This understanding is especially important in web frameworks like Django. The various features provided within Django, especially class-based views (CBV), offer great convenience and scalability, but if you only have a vague idea of their internal structure, you could face significant difficulties as your project grows.
Reasons for Transitioning from FBV to CBV
Simplicity of FBV (Function-Based View)
Most beginners in Django start their journey with FBV (Function-Based View).
-
Intuitive: The structure of receiving
request
and returningresponse
is easy to understand. -
Quick Prototyping: It is easy to assemble the screen with short code, making initial development fast.
However, as projects grow and the number of URLs and views to manage increases, managing code with only FBVs becomes complex, and repetitive logic starts to appear in various places. This becomes quite a burden in terms of maintenance and scalability.
Reusability and Scalability of CBV (Class-Based View)
CBVs apply the philosophy of object-oriented programming (OOP) to Django view logic.
-
Reusability: It is easy to create inheritance structures or extend by separating view logic into methods.
-
Clear Structure: Different methods are automatically invoked based on requests (GET, POST, etc.), leading to well-organized code.
-
Maintenance Ease: You can place common functionality in the parent class and only override what is necessary for each screen (or view).
For instance, suppose you need to create several list pages of the same shape. In FBV, you would write the same (or similar) code repeatedly, while in CBV, by inheriting from a basic class like ListView, you can apply it much more simply by just changing the model or template name. This is the true strength of CBVs.
Reasons Why Mastering CBV is Beneficial
-
Greatly enhances code readability and maintainability.
-
Even if the project scale expands, common functionalities can be easily modularized and extended.
-
You can quickly set up CRUD using the various CBV classes (ListView, DetailView, CreateView, UpdateView, DeleteView, etc.) that Django provides.
-
Enables more proactive collaboration for developers. AI-generated code can also be finely controlled regarding which CBV to inherit from and how.
Goals of the CBV Exploration Series
In this blog series, we will explore various CBVs in Django one by one. We will specifically discuss in which situations each CBV is most effective and how to customize them for use.
Through this process, we aim to achieve the following outcomes:
-
Understanding of Code Functionality: Not just copying and pasting AI-generated code, but developing the ability to explain “why it should be written this way” on your own.
-
Knowledge of the Roles and Usage of CBVs: By understanding the characteristics of various CBVs provided by Django, you will be able to pick the right view for each situation, saying, “
FormView
is suitable for this situation.” -
Efficient and Proactive Collaboration with AI: If you gain insights like “which part should be modified” from the code suggested by AI, you can efficiently guide AI and maximize productivity.
Preview of Future Topics
-
Understanding Django's Basic View Class
- We will learn about the structure of the
View
class and how Django calls it during the request-response cycle.
- We will learn about the structure of the
-
Handling Forms Easily with FormView
-
We will look at how to utilize
FormView
for handling user inputs (forms). -
You can learn patterns for form validation, error message handling, and redirecting on success.
-
-
Utilization of ListView and DetailView
-
We will cover how to efficiently structure the
ListView
andDetailView
for list pages and detail pages. -
Along with real project examples, tips for dealing with template context data will be shared.
-
-
Simplifying CRUD with CreateView, UpdateView, and DeleteView
-
We will examine view classes that almost automate CRUD (Create, Read, Update, Delete) operations.
-
This will help those wondering, “Should I write my own model form or use the capabilities of CBVs?”
-
-
Efficient Template Rendering with TemplateView
-
We will explore how to utilize
TemplateView
for simple page rendering. -
We will provide tips on how to structure the layout in situations where rapid HTML template rendering is necessary.
-
Conclusion: The Journey Ahead
As we discuss in this series, you will explore the rich world of CBVs provided by Django. If you have only used FBVs until now, you will gain a new perspective by discovering how CBVs work! For those who already have experience with CBVs, you can consider deeper usage methods and extension strategies together.
In the age of AI, what developers should focus on is not just writing code, but understanding how the code works and the ability to design better structures. Django's CBVs are a very appropriate subject for learning and practicing this.
In the next post, we will start with Django's basic View
class to examine its foundational structure. Let's learn step by step and become “real engineers” who write more robust and scalable code.
Recommended Resources
Future ‘CBV Exploration Series’ Preview
-
Part 2: “Understanding the Operation Principle and Lifecycle of Django's Basic View Class”
-
Part 3: “FormView: Cleanly Handling Forms”
-
Part 4: “ListView & DetailView: Implementing Data Lists and Detail Views”
-
... (to be continued)
Thank you for reading through the post! We hope you look forward to the upcoming series, and feel free to leave any questions or thoughts in the comments!
“Even in an era of AI-generated code, our engineering sense and insights will shine brighter than ever.”
There are no comments.