Django Views 🐉, Linux notes 🐧, Design of C++ 👨🏻‍💻

By Prajwal Haniya

Techletter #83 | July 27, 2024

class-based views and generic views

Class-based views (CBVs) and generic views in Django are powerful tools that allow developers to create views using object-oriented programming principles. They provide a more structured and reusable way to handle HTTP requests compared to traditional function-based views.

Class-based views:

A simple example of a class-based view:

from django.http import HttpResponse
from django.views import View

class MyView(View):
    def get(self, request):
        return HttpResponse("Hello, world!")

urls.py

from django.urls import path
from .views import MyView

urlpatterns = [
    path('hello/', MyView.as_view()),
]

Generic views:

Generic views are a subset of class-based views that provide pre-built views for common tasks, such as creating, retrieving, updating, and deleting objects (CRUD operations). They simplify the process of building views by abstracting common patterns into reusable components.

Types of Generic Views

  1. CreateView: Used for creating new objects.
  2. RetrieveView: Displays a single object or a list of objects.
  3. UpdateView: Handles updating existing objects.
  4. DeleteView: Manages the deletion of objects.
  5. ListView: Displays a list of multiple objects.
  6. DetailView: Shows detailed information about a single object
from django.views.generic import ListView
from .models import MyModel

class MyModelListView(ListView):
    model = MyModel
    template_name = 'myapp/mymodel_list.html'

urls.py

from django.urls import path
from .views import MyModelListView

urlpatterns = [
    path('mymodels/', MyModelListView.as_view()),
]

Linux Notes

The real power of linux comes from it’s command line interface called shell.

What is a distro?

Linux is extremely configurable and includes thousands of programs. As a result, different varieties of Linux have arisen to serve different needs and tastes. They all share certain core components but may look different and include different programs and files. Each variety is called a distro (short for “distri‐ bution”). Popular distros include Ubuntu Linux, Red Hat Enterprise Linux, Slackware, and Mint among others.

What’s a command?

A Linux command typically consists of a program name fol‐ lowed by options and arguments, typed within a shell, like this:

wc -l myfile

The program name (wc, short for “word count”) refers to a program somewhere on disk that the shell will locate and run.

Options, which usually begin with a dash, affect the behavior of the program. In the preceding command, the -l option tells wc to count lines and not words. The argument myfile specifies the file that wc should read and process.


The design of c++

The design of C++ has focused on programming techniques dealing with fundamental notions such as memory, mutability, abstraction, resource management, expression of algorithms, error handling, and modularity.

The Design and Evolution of C++ book [Stroustrup,1994] (known as D&E) outlines the ideas and design aims of C++ in greater detail, but two principles should be noted:

The C++ language features most directly support four programming styles:

I am adding C++ to my language of interest.