# Creative Commons

## Summary

Works such as a photograph, a digital artwork, an essay, etc. are automatically protected by copyright. Anyone who wants to use these works have to ask the copyright owner for permission. This is not ideal for a creator who wishes to share his or her own works more openly. This is the problem that the **Creative Commons** organization aims to address with its licenses.

There are different types of CC licenses giving users different levels of openness. In essence, these licenses are legal tools to give users *permission in advance* to share and use the works. While copyrights state "all rights reserved", CC licenses state "some rights reserved". Ultimately, CC is a framework that fosters openness and changes the way we share, collaborate, remix and reuse content.

## Discussion

### What's the case for Creative Commons licensing?

Copyright law can be traced back to the sixth century, but it was only in 1710 that it became an act of Parliament (in Great Britain) through the Statute of Anne, also known as the Copyright Act 1710. This law granted creators the right to protect their works and set the terms in which their works may be used by others. Initially for books, it was later applied to translations, maps, paintings, photographs, motion pictures and computer programs.

Copyright is automatic. This becomes a problem in a connected world. It went against Internet's culture of sharing and collaboration. Creators who had no problems with others using their works, had no way to tell people about their intentions. Users who wished to reuse the open works of others had no legal framework to do so. There was therefore a need for an open license.

In the late 1990s, the GNU GPL license was available but it was tailored for software. It wasn't suited for cultural works. Moreover, for cultural works, one required a range of options to give creators the choice of licensing.

### Which popular platforms have adopted Creative Commons licensing?

Flickr, Wikipedia, YouTube and Vimeo are some popular adopters of CC licensing. Among research communities, PLOS is a big adopter. Within Springer Nature, on the bioRxiv preprint server, most articles use CC licensing. Blogging platform Medium adopted CC licensing back in 2015.

The Free Software Foundation (FSF) recommends the use of CC0 for releasing any work into public domain. The White House website uses CC licensing. In 2015, Europeana had about 8 million cultural objects using a CC license and another 9 million using Public Domain Mark.

Wikimedia commons allows the use of CC0, CC-BY and CC-BY-SA.

### Isn't the Creative Commons legal jargon intimidating for common users?

While it's true that the legal language is often difficult to understand for common users, there's an alternative version that offers a simplified explanation of the licenses. While the legal code is the actual license, its sufficient for users to read the simpler version. Called **Commons Deed**, it's the "human-readable" version of the licenses.

There's also a third layer that makes it easier for search engines and other software tools to identify works that are using CC licenses. Such information is embedded into web pages, not visible on the pages for people but can be parsed by search engines. Creative Commons website illustrates one approach to adding metadata wherever CC-licensed is reused. It uses Dublin Core to do this.

### What are the different Creative Commons licenses available for use?

There are six different CC licenses: CC BY, CC BY-SA, CC BY-NC, CC BY-ND, CC BY-NC-SA, CC BY-NC-ND.

All six licenses permit copying and publishing of the works. BY implies that **attribution** to the original author is required. Attribution is mandatory in all CC licenses. Anything marked with NC implies only **non-commercial** use is allowed. Anything marked with ND implies **no derivative** use: you cannot modify or adapt the original work. Anything marked with SA implies **share alike**, meaning that derived works must be released under the same license as the original work.

From the above understanding, we can say that CC BY is most open and CC BY-NC-ND is least open. CC BY-NC-ND is still better than a copyright since the work in its original form can be shared or reused non-commercially with attribution.

In 2014, it was seen that one-third of CC licenses in use was CC BY, 76% allowed remixing and 58% allowed commercial use.

### What's CC0? How's it different from works in public domain?

CC0 allows creators to place their work as nearly as possible into public domain.

When a copyright expires, the work comes into public domain. Creative Commons has defined a symbol to indicate this with its **Public Domain Mark (PDM)**, in addition to another symbol that indicates **CC0**. CC0 is useful when the copyright has not expired but the copyright owner willingly gives up the rights so that others can freely reuse the work. CC0 gives maximum freedom, to reuse or adapt, even commercially, without attribution.

In 2015, Flickr started allowing users to share their works under CC0 or PDM. SpaceX released its images under CC0. Europeana had 26,000 images under CC0 plus 3.6 million works under PDM.

### Are there guidelines to use and attribute works with CC licenses?

Attribution should include the original author's name, title of the work, a hyperlink that points to the page where the work was obtained, the type of license used and a link pointing to the license. For example, if the work is an image, this attribution may be place immediately below the image or as an endnote on the same page. Since version 4.0, attributions may be on a separate page that's hyperlinked from the place of reuse.

Version 2.0 clarified three conditions for linkback. Linking back must be practical; that is, licensee can't be faulted for failing to link to a dead page. Licensor must provide a valid linkback URL. This URL must point to the correct CC licensing terms and not misdirect users to unrelated sites.

Version 3.0 relaxed the title requirement but added the requirement to link back to source. It also stated that if you adapt or modify the work, this must be noted.

Here's an example attribution: "Creative Commons 10th Birthday Celebration San Francisco" by tvol is licensed under CC BY 2.0.

### Are CC licenses an alternative to copyrights?

CC licenses are not alternatives to copyrights. A work must be copyrighted in order to be licensed under CC. Only the copyright owner can place the work under a CC license, or authorize someone to do so. Creative Commons licenses expire when the underlying copyright and similar rights expire.

CC licenses are non-exclusive: the copyright owner can enter into separate agreements as well. CC licenses are non-revocable: even if the copyright owner revokes the CC license, all those already reusing the work will continue to do so under the original terms. The fact that CC licenses are irrevocable is seen by some as a limitation. It doesn't give licensors an option to change their mind later.

CC licenses don't limit rights granted through statutory exceptions, including fair use.

### What are some criticisms of Creative Commons and its licenses?

With CC licenses, even small modifications can be treated as an adaptation and the person doing it can take credit for it. However, in a 2012 lawsuit, the U.S. copyright law was applied. It considered the work as non-derivative since there were no major additions or deletions.

In 2014, Yahoo! announced plans to sell prints of photos on Flickr. Owners of copyrighted photos would get a revenue share but those who had used CC BY license would get nothing. Licensors have no protection against who or how their works will be used in the future. In a similar case, Apple Academic Press republished and sold open access research articles.

Though not limited to CC-licensed work, plagiarism is a problem. You could reuse a work based on its stated CC license, but the original work might still be under copyright. For example, a person who doesn't own the image uploads it to Flickr and licenses it as CC BY. This is in fact a copyright infringement.

There's also criticism that Creative Commons as an organization offers no protection. You're on your own if things go wrong.

### If I wish to adopt Creative Commons licensing, what resources are available?

Creative Commons website is a good place to start. The CC blog is a place to follow news and tips about CC licensing. The CC FAQ is a useful reference. To get connected with the CC community, join the CC Global Affiliate Network, one of their mailing lists or Slack channels. There's also the annual CC Global Summit for discussions, workshops and community building.

To help find works licensed under Creative Commons, there's the official CC Search. Additionally, there are plenty of other search services. Examples include Free Music Archive, Let's CC, Internet Archive, 500px Creative Commons, and Project Gutenberg.

### How is the Creative Commons organization structured?

Creative Commons is a network of staff, board, emeritus, advisory council, audit committee, and affiliates around the world.

The **Creative Commons Global Affiliate Network** includes over 500 volunteers and community members who serve as CC representatives in over 85 countries. In 2017, a new strategy was formed. The new network is built on individuals rather than teams that depend on organizations. Organizations can also be part of it as partners. The network is not a separate legal entity and is supported by CC HQ. The network comprises of local chapters, each having an elected representative and a public lead or coordinator. Governance is via the **Global Network Council** with one representation from each chapter plus three from CC HQ.

Finally, all activities are carried out within **Platforms**, or areas of work. Some of these include Arts & culture, Open access, Open data, Technology, Open science, etc.

## Milestones

1998

The Copyright Term Extension Act (CTEA) in the U.S extends copyright terms by another 20 years. This creates problems for Eric Eldred who was planning to publish works that were about to come into public domain. Together with Lawrence Lessig, a professor at Harvard Law School, they challenge the Act. They eventually lose the case in 2003.

2001

Inspired by Elred's idea to make works freely available on the Internet, Lawrence Lessig creates **Creative Commons**.

Dec
2002

The first version Creative Commons licenses is published.

May
2004

Version 2.0 of CC licenses is released. Attribution is treated as a standard practice and must link back to licensor's work. The use of CC licenses to music is clarified.

Feb
2007

Version 3.0 of CC licenses is released. This clarifies aspects of internationalization. The term **unported license** is used to refer to licenses not adapted to local jurisdictions. Compatibility structure is included so that users know what license to use based on source licenses.

Mar
2009

To enable creators to surrender the copyright and database rights to their work, and place them as nearly as possible in public domain, **CC0** is created. It's universal and can be used in any jurisdiction. It's not exactly a license but a legal tool. It's the "no rights reserved" alternative to CC licenses.

May
2009

Wikimedia Foundation votes to move all its content from GNU Free Documentation License (GFDL) to Creative Commons Attribution Share-Alike 3.0 (CC BY-SA 3.0) license. GFDL is suited for software documentation and it requires that full license text be included. Comparatively, CC BY-SA 3.0 is easier to use with only a link to the license.

Nov
2013

Version 4.0 of CC licenses is released. This offers global licenses that can be used without "porting". This effort to internationalize the licenses started in December 2011. Attribution is allowed via a link to a separate page. A licensor may request removal of attribution if so desired. Any licensing breach can be corrected within 30 days.

Oct
2014

Ported licenses are available for 60 countries. For example, India has ported CC license v2.5 as its latest; China has v3.0. With v4.0, ported licenses are largely redundant.

2017

The number of works licensed under CC has grown from 50 million in 2006 to 1.47 billion in 2017. In 2017, the CC Search tool gets 1.5 million queries and the CC website gets 50 million visitors.

Creative Commons


# CSS Grid Layout

## Summary

When displaying content on a webpage, there's often a need to layout the content in a particular way. For example, we may want the header and footer sections to span the entire width of the viewport while the main content be organized as a three-column layout. Header section itself may be divided into a fixed-width logo section to the left and a flexible-width title section to the right.

CSS Grid Layout is a standard that gives user interface designers a powerful system to implement layouts with ease. It's part of the CSS3 specification standardized by W3C.

It's meant to complement and not replace earlier systems such as CSS Flexbox.

## Discussion

### Why should I adopt CSS Grid when there's already CSS Flexbox?

Traditionally, layout was done using HTML tables. Then came CSS properties `display`, `float` and `position` that allowed us to control the layout. While these are still relevant, Flexbox came along to provide an easier way to distribute space and align content.

The limitation with Flexbox is that it does layout only in one direction. Thus, items can be laid out horizontally but not vertically at the same time. Even if the items were to wrap across multiple lines, items on each line will not be aligned to those on other lines. Via nesting, Flexbox can be used to create two-dimensional layouts but CSS Grid is easier to use.

CSS Grid is capable of aligning items both horizontally and vertically. Interestingly, items within the grid can also overlap, which neither Flexbox nor a HTML table element is capable of doing.

CSS Grid doesn't replace Flexbox. Grid items can be flex parents and vice versa.

### Which are the key building blocks of CSS Grid?

CSS Grid has the following parts:

    + **Container**: This is the element that contains the grid within it. It's defined by CSS `display: grid`.
    + **Item**: Immediate child elements of a container are grid items. Grandchildren and further nested elements are not considered as grid items.
    + **Line**: A grid is split into rows and columns using grid lines. Lines also define the container's borders. Lines are numbered, starting from 1. Thus, a grid of m rows will have m+1 horizontal lines; of n columns will have n+1 vertical lines.
    + **Track**: A grid track is a generic term for a grid row or column. It's the space between two adjacent grid lines.
    + **Cell**: This is an intersection of a row and a column. It's the smallest unit of the grid that can be referenced.
    + **Area**: This consists of one or more adjacent grid cells.

### What are the different ways of specifying width in CSS Grid?

Grid items, rows and columns can be sized **explicitly** using CSS properties `grid-template-rows` and `grid-template-columns`. For example, `grid-template-columns: 90px 50px 120px` defines three columns with exact sizes.

What if we had five items but only two columns are defined? The extra three grid items will be sized **implicitly**. If `grid-auto-flow: column`, we'll end up with five columns. If `grid-auto-flow: row`, we'll end up with three rows with the last row having only one item.

For explicit sizes we can use `px`, `em`, `%`, etc. Fractional sizes (`fr`) can also be used. Thus, `grid-template-columns: 1fr 2fr` will make two columns, with the second one twice as wide as the first. While `px` specifies **fixed** sizes, `fr` specifies **flexible** sizes. Fractional sizes are calculated based on remaining space after other length values have been processed. For example, given `grid-template-columns: 3rem 25% 1fr 2fr`, the calculation would be `1fr = ((gridwidth) - (3rem) - (25% of gridwidth)) / 3`. The value `auto` will stretch grid item to fill remaining space.

### How do I control the alignment of content in CSS Grid?

A grid item can be aligned within its cell or area using CSS property `justify-self` for horizontal alignment and `align-self` for vertical alignment. These effectively adjust margins for the items. Each of these properties can take values start, end, center, or stretch.

What if we wish to apply the same alignment to all grid items? This is done by specifying CSS properties at the container level. Use `justify-items` for horizontal alignment and `align-items` for vertical alignment. As a shortcut, there's also `place-items` that specifies alignment in both directions.

What if all the grid's tracks take up a space smaller the container? Then `justify-content` and `align-content` becomes useful not just for alignment but also for adding spaces in the right places to fill the container. These effectively adjust padding for the container. Some allowed values include normal, start, end, center, stretch, space-around, space-between, space-evenly, baseline, first baseline, and last baseline.

Alignment works for both inline and block elements.

### What are named areas and where are they useful?

We can make an item span multiple columns using `grid-column-start`, `grid-column-end`, `grid-row-start`, and `grid-row-end`. Shortcuts for these are `grid-column` and `grid-row`. For example, `grid-column: 3 / span 2` says that item will start from third column and span two columns.

**Grid areas** offer a simpler way to avoid using grid line numbers. Areas can be only rectangles. Areas are named for easy referencing. Gaps can exist between areas but not between cells within an area. Gaps themselves can be set using `grid-row-gap` and `grid-column-gap`, with `grid-gap` as a shorthand to set both. Grid gaps are also called *gutters*.

Within HTML elements, use CSS property `grid-area` to name the target area. This tells exactly in which area this content must be placed. The mapping of grid cells to grid areas is done using the `grid-template-areas` property. For a responsive design, we could use media queries to switch between different definitions of template areas without duplicating the content.

### When there's nested grids, what's the use of subgrids?

Consider the use of grids to lay out cards. With nested grids, each card has an inner grid that's used to organize card title, an image and a description. Layout of contents in the inner grid is independent of the outer grid. Moreover, one card is not aware of alignment of contents in another card. This means that if some card titles run into multiple lines, subsequent content within the inner grid will not be aligned across cards (the outer grid).

Subgrid solves this problem. A subgrid defers the definition of its rows and columns to its parent grid container. Content of the subgrid influence the sizing and alignment of its parent container.

A subgrid can be created with `{ display:grid; grid-template-columns:subgrid; grid-template-rows:subgrid; }`. It's possible to create rows-only or columns-only subgrid. Within the subgrid, we may not want extra spacing between rows. This is achieved with `row-gap:0`.

### Could you share additional technical details on CSS Grid?

It's interesting to note that grid line numbers can be negative. Value -1 refers to last line; value -2 is last but one line; and so on. Also, fractional widths can be floating point numbers.

With fractional units, available space is filled up but it still obeys the minimum size of container or the content within. Sizes are not calculated upfront. Only after content is placed into grid items, the sizes of grid tracks are calculated.

By default, grid items will be stretched to fit the grid area. Avoid using percentages in paddings or margins on grid items. Number of rows and columns can be defined using `grid-template-areas`, `grid-template-rows` and `grid-template-columns`. If there's conflict, the larger number will be used.

Don't assume you need breakpoints, for example, to reflow content with varying number of columns. Sizing with only percentages will not help you exercise the full power and flexibility of CSS Grid. CSS Grid is simple enough to be used directly. Don't look for a grid framework.

### What are some resources for beginners to learn CSS Grid?

From the many online resources to learn CSS Grid, we mention a few: A Complete Grid Guide by CSS-Tricks, Rachel Andrew's Grid by Example and Layout Lab by Jen Simmons.

An interactive CSS Grid cheatsheet from Ali Alaa is handy.

For debugging CSS Grid, there are browser add-ons that developers can use. Firefox DevTools comes with Grid Inspector to inspect the grid and show line numbers and grid area names.

Most browsers support CSS Grid, including partial support from IE11. See Can I Use to see current support.

## Milestones

1940

The Swiss formalize the use of grids as a design tool. They see grids as bringing order to a design layout.

1996

Frame-based layout via stylesheets is proposed.

Dec
2005

**CSS3 Advanced Layout Module** is proposed. By April 2009, this becomes **CSS Template Layout Module**. The idea of CSS Grid Layout closely follows from these early drafts. However, these early proposals are not adopted by browser makers.

Jul
2009

W3C publishes a working draft of **CSS Flexible Box Layout** or Flexbox. After multiple revisions, first Candidate Recommendation of Flexbox is released in September 2012.

Apr
2011

Microsoft needs a flexible layout tool for the web and native app development on Windows. With some inspiration from Silverlight, Microsoft ships IE10 with an implementation of a grid layout behind `-ms-` vendor prefix. This is followed with a W3C working draft of **CSS Grid Layout**. Thus, for the first time W3C gets a draft along with a working implementation.

Aug
2011

After many months of internal development, Twitter open sources **Bootstrap**. It's a CSS framework that enables easier creation of layouts based on a 12-column grid. CSS Grid provides a more flexible layout since designers need not start with 12 columns.

May
2017

W3C publishes **CSS Grid Layout Module Level 1** as a Candidate Recommendation. This is also the year when many major browsers start supporting CSS Grid.

Feb
2018

W3C publishes the first working draft of **CSS Grid Layout Module Level 2**. Level 2 adds subgrid capabilities and allows nested grids to participate in the sizing of parent grids. It also adds aspect-ratio-controlled gutters. In December 2019, Firefox becomes the first browser to implement subgrids and continues to be the only browser even in December 2020.

CSS Grid Layout


# Cohesion vs Coupling

## Summary

When a large software is decomposed into smaller modules, it's inevitable that these modules will interact with one another. If the boundaries of these modules have been poorly identified, then the modules will heavily depend and frequently interact with one another. In a poor design, it might also happen that classes and methods within a module perform diverse tasks and therefore don't seem to belong together.

**Cohesion** is about how well elements within a module belong together and serve a common purpose. **Coupling** is about how much one module depends or interacts with other modules. Thus, cohesion is an intra-module concern whereas coupling cuts across modules.

To manage the complexity of an application, a software designer must find the right balance of cohesion and coupling. This is relevant to object-oriented design, the design of APIs and microservices.

## Discussion

### Could you explain cohesion and coupling with an example?

Consider a software project with folders containing associated files. In one approach, folders `Entities`, `Factories`, `Repositories` and `Services` are created. This seems like a good organization but from a functional perspective there's tight coupling across folders. The boundaries don't reflect the semantics. For example, product management would involve `Product` entity, `ProductFactory`, `ProductRepository` and `ProductService` across all folders. Moreover, folders have logical cohesion but poor functional cohesion. For example, each factory deals with a different entity type and have little in common functionally.

A better way to organize would be to have folders `Orders`, `Products` and `Users`. This organization is based on purpose and functionality. This is better because any change to product management would impact only files co-located in a single folder. Code is more readable and maintainable. Teams would be more independent, each working on its own folder. Each folder could also be versioned and released independently of others.

In short, low cohesion means the module is trying to do too many things. High coupling means modules are tightly interconnected via many complex interfaces and information flows.

### How should I balance cohesion and coupling when designing software systems?

Ideally, we should aim for **high cohesion and low coupling**. Related parts of code should be in the same module. Each module should be independent of others. Modules should interact in a minimal way. In modular programming, we use the term 'module' in a general sense. In practice, a module could be any of these, at different levels of abstraction: folder, JavaScript file, C++ class, C# assembly, Java package, Python module, REST endpoint, microservice, etc.

Apply the *Single Responsibility Principle (SRP)* for high cohesion. Use well-defined interfaces and inversion of control for low coupling.

An anti-pattern is when a piece of code does all the work. This is a monolith that some call a *God Object* or a *Big Ball of Mud*. There's also code that exhibits low cohesion and high coupling, when module boundaries are poorly defined. A developer might try to solve this via decoupling. But decoupling without cohesion will make the code even more difficult to follow. Using interfaces that don't represent an abstraction is an indication of **destructive decoupling**.

### Why should I care about cohesion and coupling when my code works?

In any complex software, code is written once and maintained regularly. Those who maintain it are not necessarily those who originally wrote it. Therefore, the goal is to write code that's easy to maintain and evolve.

Cohesion makes it easier to understand code. If each module's purpose is clear, we can think at higher levels of abstraction without getting into detailed implementation of modules. For deployment, fewer modules are impacted.

Low coupling means fewer interconnections across modules. It means one module can be changed or even replaced without impacting other modules. It means modules are isolated from the implementation details of others. Low coupling aids simulation and testing.

### How are cohesion and coupling relevant to microservices?

If improperly architected, an application based on microservices might end up being a **distributed monolith**. In such an application, microservices are chatty, calling one another often. Changes to one microservice requires changes to others. Same developers work on the codebases of many microservices. Microservices share the same database or even code.

To solve these problems, one approach is to adopt **domain-driven design**. Restrict access using scoping rules. Use public APIs to encourage loose coupling. REST APIs shouldn't be tightly coupled to specific applications or services. Effectively, the idea is to get the boundaries right towards high cohesion and low coupling.

If a microservice relies on the physical address of another service, then there's tight location coupling. Service discovery tools can solve this. If a microservice needs to wait for another's response, there's temporal coupling. A message bus or event stream can solve this.

For testing, unit tests created for a microservice shouldn't impact integration or end-to-end tests. To verify interfaces across services, gRPC and Avro can help. Test coupling can be minimized by mocking APIs and dependent services.

### Which are the different types of software cohesion?

Parts of a module that collectively perform a single well-defined function is the strongest type of cohesion. There are however many other types of cohesion, some more desirable than others:

    + **Coincidental cohesion**: Parts are not related and just happen to be in the same module. Such a module is hard to understand, maintain or reuse.
    + **Logical cohesion**: Parts relate to different entities though they perform similar logical functions. For example, mouse inputs and keyboard inputs are handled in the same class.
    + **Temporal cohesion**: Parts that are executed when something happens, such as start-up or clean-up routines. Code changes may affect many modules.
    + **Procedural cohesion**: Code that's called one after another.
    + **Sequential cohesion**: Similar to procedural cohesion with the additional constraint that the execution sequence is important. For example, call `readFile()` before calling `processData()`.
    + **Communicational cohesion**: Also called information cohesion. Parts that share or operate on the same data.
    + **Functional cohesion**: The most desirable type of cohesion. Parts work together in fulfilling a single function or purpose.

### Which are the different types of software coupling?

Data and control are two types of information flow across modules. If only some data is exchanged, the amount of coupling is probably acceptable. Exchanging lots of data and control results in a high degree of coupling.

Here are a few types of coupling:

    + **Content coupling**: One module modifies local variables of another module or branches execution into another module. Violates the principle of information hiding.
    + **Control coupling**: Using control flags, one module controls the execution path in another module. Makes code hard to understand.
    + **Common coupling**: Modules access global variables. Modules are bound together via shared data structures. Leads to unexpected side effects and error propagation.
    + **Stamp coupling**: A module passes an entire data structure to another when only some data members are needed.
    + **External coupling**: When interfacing with external tools, devices or libraries, module is coupled to the external device interface, communication protocol or data format.
    + **Data coupling**: Use of parameter lists to pass data from one module to another.

### Are there quantitative measures to evaluate software cohesion and coupling?

**Relation Cohesion** (H) measures average number of internal relationships per type. Given N types and R internal relationships, `H=(R+1)/N`. A suitable range is 1.5-4.0. Higher values may indicate over-coupling internally. Another measure of cohesion is **Lack of Cohesion Of Methods (LCOM)**. LCOM has range 0-1. Zero is ideal. It's variant **LCOM Henderson-Sellers (LCOM HS)** has range 0-2. An LCOM HS value exceeding one is bad.

**Afferent coupling** (Ca) measures the number of types in other modules that depend on elements of this module. A high value implies a module with many responsibilities. **Efferent coupling** (Ce) measures the number of types from outside the module used in this module. A high value implies a module highly dependent on others. These metrics could be applied to types, fields, methods, namespaces, etc. The ratio `Ce/(Ce+Ca)` is called **Instability**, which measures a module's resilience to change. A value of 0 is ideal.

Class inheritance in OOP is a form of tight coupling. Some relevant metrics include weighted methods per class, depth of inheritance tree, number of children and count of base classes.

## Milestones

Jun
1974

Stevens et al. propose a method to reduce complexity. They call it **Structured Design** or **Composite Design**. A system can be divided and simplified into smaller pieces. This improves and speeds up the writing, debugging and modifying of code. This is because each part can be considered separately. However, identifying suitable "modules" of code is not trivial. They therefore introduce the concepts of cohesion and coupling.

Jun
1994

Chidamber and Kemerer propose six **design metrics** to evaluate object-oriented design. They evaluate and interpret them on two real-world projects that use C++ and Smalltalk. The degree of similarity among methods is a measure of class cohesion. Class complexity can be measured by the number of methods and instance variables it contains, depth of inheritance and number of immediate descendants. Methods are a of measure communication complexity among classes.

2001

Craig Larman in his book *Applying UML and Patterns: An Introduction to Object-Oriented Analysis and Design and the Unified Process (2nd edition)* calls cohesion and coupling "the yin and yang of software engineering." Bad cohesion usually results in bad coupling, and vice versa. He also notes that,

> The level of coupling alone can't be considered in isolation from other principles such as expert and high cohesion.

2003

Eric Evans publishes a book titled *Domain-Driven Design: Tackling Complexity in the Heart of Software*. He notes that as humans and designers, it's hard for us to think or reason about many concepts at a time (high coupling). We also find it hard to understand logically unrelated ideas (low cohesion). It therefore makes sense to recognize these limitations as we design software systems.

Jan
2014

Software architect/designer Kirwan explains why the mantra of "loose coupling and high cohesion" may not work in practice. He points out flaws in the paper by Stevens et al. (1994). For example, maximizing cohesion is neither a clear concept nor desirable. Too many dependencies within a module gives no structural benefit. When change happens, its effect within the module could be as bad as across modules in a tightly coupled system. Thus, it's only a matter of perspective: are we looking at classes in a package or across packages?

Cohesion vs Coupling


# Audio Feature Extraction

## Summary

Application of machine intelligence and deep learning in the subdomain of audio analysis is rapidly growing. Some examples include automatic speech recognition, digital signal processing, and audio classification, tagging and generation. Virtual assistants such as Alexa, Siri and Google Home are largely built atop models that can perform perform artificial cognition from audio data.

To train any statistical or ML model, we need to first extract useful features from an audio signal. Audio feature extraction is a necessary step in audio signal processing, which is a subfield of signal processing. It deals with the processing or manipulation of audio signals. It removes unwanted noise and balances the time-frequency ranges by converting digital and analog signals. It focuses on computational methods for altering the sounds.

This article introduces most commonly used audio features that are used as inputs to models.

## Discussion

### What is an audio signal?

An audio signal is a representation of sound. It encodes all the necessary information required to reproduce sound. Audio signals come in two basic types: analog and digital.

Analog refers to audio recorded using methods that replicate the original sound waves. Examples include vinyl records and cassette tapes. Digital audio is recorded by taking samples of the original sound wave at a specified rate, called *sampling rate*. CDs and MP3 files are examples of digital formats.

In the real world, conversions between digital and analog waveforms are common and necessary. ADC (Analog-to-Digital Converter) and the DAC (Digital-to-Analog Converter) are part of audio signal processing and they achieve these conversions.

### What are the common audio features useful for modeling?

Audio features are description of sound or an audio signal that can basically be fed into statistical or ML models to build intelligent audio systems. Audio applications that use such features include audio classification, speech recognition, automatic music tagging, audio segmentation and source separation, audio fingerprinting, audio denoising, music information retrieval, and more.

Different features capture different aspects of sound. Generally audio features are categorised with regards to the following aspects:

    + **Level of Abstraction**: High-level, mid-level and low-level features of musical signals.
    + **Temporal Scope**: Time-domain features that could be instantaneous, segment-level and global.
    + **Musical Aspect**: Acoustic properties that include beat, rhythm, timbre (colour of sound), pitch, harmony, melody, etc.
    + **Signal Domain**: Features in the time domain, frequency domain or both.
    + **ML Approach**: Hand-picked features for traditional ML modeling or automatic feature extraction for deep learning modeling.

### How do we categorize audio features at various levels of abstraction?

These broad categories cover mainly musical signals rather than audio in general:

    + **High-level**: These are the abstract features that are understood and enjoyed by humans. These include instrumentation, key, chords, melody, harmony, rhythm, genre, mood, etc.
    + **Mid-level**: These are features we can perceive. These include pitch, beat-related descriptors, note onsets, fluctuation patterns, MFCCs, etc. We may say that these are aggregation of low-level features.
    + **Low-level**: These are statistical features that are extracted from the audio. These make sense to the machine, but not to humans. Examples include amplitude envelope, energy, spectral centroid, spectral flux, zero-crossing rate, etc.

### Could you briefly explain the temporal scope for audio features?

This type of categorisation applies to audio in general, that is, both musical and non-musical:

    + **Instantaneous**: As the name suggests, these features give us instantaneous information about the audio signal. These consider tiny chunks of the audio signal, in the range of milliseconds. The minimum temporal resolution that humans are capable of appreciating is around 10ms.
    + **Segment-level**: These features can be calculated from segments of the audio signal in the range of seconds.
    + **Global**: These are aggregate features that provide information and describe the whole sound.

### Could you explain on the signal domain features for audio?

Signal domain features consist of the most important or rather descriptive features for audio in general:

    + **Time domain**: These are extracted from waveforms of the raw audio. Zero crossing rate, amplitude envelope, and RMS energy are examples.
    + **Frequency domain**: These focus on the frequency components of the audio signal. Signals are generally converted from the time domain to the frequency domain using the *Fourier Transform*. Band energy ratio, spectral centroid, and spectral flux are examples.
    + **Time-frequency representation**: These features combine both the time and frequency components of the audio signal. The time-frequency representation is obtained by applying the Short-Time Fourier Transform (STFT) on the time domain waveform. Spectrogram, mel-spectrogram, and constant-Q transform are examples.

### Could you describe some time-domain audio features?

**Amplitude Envelope** of a signal consists of the maximum amplitudes value among all samples in each frame. This feature gives a rough idea of loudness. It is however, sensitive to outliers. This feature has been extensively used for onset detection and music genre classification.

**Root Mean Square Energy** is based on all samples in a frame. It acts as an indicator of loudness, since higher the energy, louder the sound. It is however less sensitive to outliers as compared to the Amplitude Envelope. This feature has been useful in audio segmentation and music genre classification tasks.

**Zero-Crossing Rate** is simply the number of times a waveform crosses the horizontal time axis. This feature has been primarily used in recognition of percussive vs pitched sounds, monophonic pitch estimation, voice/unvoiced decision for speech signals, etc.

### What are the audio features under the ML approach?

**Traditional Machine Learning** approach considers all or most of the features from both time and frequency domain as inputs into the model. Features need to be hand-picked based on its effect on model performance. Some widely used features include Amplitude Envelope, Zero-Crossing Rate (ZCR), Root Mean Square (RMS) Energy, Spectral Centroid, Band Energy Ratio, and Spectral Bandwidth.

**Deep Learning** approach considers unstructured audio representations such as the spectrogram or MFCCs. It extracts the patterns on its own. By late 2010s, this became the preferred approach since feature extraction is automatic. It's also supported by the abundance of data and computation power.

Commonly used features or representations that are directly fed into neural network architectures are spectrograms, mel-spectrograms, and Mel-Frequency Cepstral Coefficients (MFCCs).

### What are spectrograms?

A spectrogram is a visual depiction of the spectrum of frequencies of an audio signal as it varies with time. Hence it includes both time and frequency aspects of the signal. It is obtained by applying the Short-Time Fourier Transform (STFT) on the signal. In the simplest of terms, the STFT of a signal is calculated by applying the Fast Fourier Transform (FFT) locally on small time segments of the signal.

### What is a mel-spectrogram?

Apparently, we humans perceive sound logarithmically. We are better at detecting differences in lower frequencies than higher frequencies. For example, we can easily tell the difference between 500 and 1000 Hz, but we will hardly be able to tell a difference between 10,000 and 10,500 Hz, even though the distance between the two pairs is the same. Hence, the **mel scale** was introduced. It is a logarithmic scale based on the principle that equal distances on the scale have the same *perceptual* distance.

Conversion from frequency (f) to mel scale (m) is given by

$$ m=2595 \cdot log(1+\frac{f}{500}) $$

A mel-spectrogram is a therefore a spectrogram where the frequencies are converted to the mel scale.

### What are MFCCs?

The information of the rate of change in spectral bands of a signal is given by its cepstrum.  A cepstrum is basically a spectrum of the log of the spectrum of the time signal. The resulting spectrum is neither in the frequency domain nor in the time domain and hence, it was named the **quefrency** (an anagram of the word *frequency*) domain. The Mel-Frequency Cepstral Coefficients (MFCCs) are nothing but the coefficients that make up the mel-frequency cepstrum.

The cepstrum conveys the different values that construct the formants (a characteristic component of the quality of a speech sound) and timbre of a sound. MFCCs thus are useful for deep learning models.

### What is Band Energy Ratio?

The Band Energy Ratio (BER) provides the relation between the lower and higher frequency bands. It can be thought of as the measure of how dominant low frequencies are. This feature has been extensively used in music/speech discrimination, music classification etc.

### Could you explain the Spectral Centroid and Spectral Bandwidth features?

The Spectral Centroid provides the center of gravity of the magnitude spectrum. In other words, it gives the frequency band where most of the energy is concentrated. It maps into a very prominent timbral feature called "brightness of sound" (energetic, open, dull). Mathematically, the spectral centroid is the weighted mean of the frequency bins.

The spectral bandwidth or spectral spread is derived from the spectral centroid. It is the spectral range of interest around the centroid, that is, the variance from the spectral centroid. It has a direct correlation with the perceived timbre. The bandwidth is directly proportional to the energy spread across frequency bands. Mathematically, it is the weighted mean of the distances of frequency bands from the Spectral Centroid.

### Which libraries provide the essential tools for audio data processing?

Librosa and TorchAudio (Pytorch) are two Python packages that used for audio data pre-processing.

## Milestones

1928

Creation of the **Nyquist-Shannon sampling theorem**. Harry Nyquist shows that up to 2B independent pulse samples could be sent through a system of bandwidth B.

1951

The Kay Electric Co. produces the first commercially available machine for audio spectrographic analysis, which they market under the trademark *Sona-Graph*. The graphs produced by a Sona-Graph come to be called **Sonagrams**. For decades, all spectrograms are called Sonagrams.

1957

Max Mathews becomes the first person to **synthesize audio** from a computer, giving birth to computer music.

1963

The concept of the **cepstrum** is introduced by B. P. Bogert, M. J. Healy, and J. W. Tukey . After publication of the FFT in 1965, the cepstrum is redefined so as to be reversible to the log spectrum. Shortly afterwards, Oppenheim and Schafer define the **complex cepstrum**, which is reversible to the time domain.

1965

The **Fast Fourier Transform (FFT)** algorithm is developed by Cooley and Tukey. It reduces the computational complexity of Discrete Fourier Transform (DFT) significantly from \(O(N^2)\) to \(O(N \cdot log\_{2}N)\).

1988

Lewis and Todd propose the use of **neural networks** for automatic music composition. Lewis uses a multi-layer perceptron for his algorithmic approach to composition called "creation by refinement". On the other hand, Todd uses a Jordan auto-regressive neural network (RNN) to generate music sequentially — a principle that stays relevant in decades to come.

2002

Marolt et al. use a **multi-layer perceptron** operating on top of spectrograms for the task of note onset detection. This is the first time that someone processes music in a format that is not symbolic. This starts a new research era: learning a mapping system (or function) able to solve a task directly from raw audio, as opposed to solving it using engineered features (like spectrograms) or from symbolic music representations (like MIDI scores).

2009

Following Hinton's approach based on pre-training deep neural networks with deep belief networks, Lee et al. build the first deep **convolutional neural network** for music genre classification. This is the foundational work that establishes the basis for a generation of deep learning researchers designing better models to recognize high-level (semantic) concepts from music spectrograms.

2014

Dieleman and Schrauwen build the first **end-to-end music classifier**. They explore the idea of directly processing waveforms for the task of music audio tagging. They achieve some degree of success, though spectrogram-based models are still superior to waveform-based ones.

2016

Deepmind introduces *WaveNet*, a deep generative model of raw audio waveforms. It is able to generate relatively realistic-sounding human-like voices by directly modeling waveforms using a neural network method trained with recordings of real speech.

Apr
2020

OpenAI introduces *Jukebox*, a model that generates music with singing in the raw audio domain. They use VQ-VAE and the power of transformers to show that the combined model at scale can generate high-fidelity and diverse songs with coherence lasting multiple minutes.

Audio Feature Extraction


# Data Loss Prevention

## Summary

Collection, management and use of data has become important to many organizations. In some cases, data is central to their products and services. Some of this data could be sensitive information about partners or customers. In other cases, data-driven decisions give organizations a competitive edge. Losing this data can therefore impact business operations and even threaten survival.

Data loss prevention (DLP) is about being proactive in protecting data. It's about implementing processes and best practices, about adopting the right tools and technologies to prevent data loss. A well-defined organization-wide DLP approach is likely to work better than ad hoc approaches within individual departments.

DLP generally involves protecting data in use, data in motion and data at rest. Protection can be categorized into endpoint, network or storage DLP. Given different types of data and many touchpoints, an effective strategy is to combine different DLP techniques.

## Discussion

### What types of data matter for DLP?

Important data that need protection include intellectual property (source code, design documents, etc.), corporate data (legal, financial, employee data, etc.), and customer data (name, address, credit card numbers, etc.). Data can either be structured (well organized and easy to process) or unstructured (more qualitative and harder to process).

Broadly, data comes in three states, all of which need to be protected:

    + **Data in Use**: Data while it's being used by an application or an endpoint.
    + **Data in Motion**: Data while it's being transferred over a network.
    + **Data at Rest**: Data while it's stored on a file server within an enterprise network, in a storage service in the cloud or in a portable storage device.

### What are the common causes of data losses?

**Accidental deletion** of files or even parts of a file are data losses, particularly when backups are not available. File system updates are common everyday operations. Hence, accidental deletion is a real risk. Such a loss can happen due to wrong user operation, bugs in automation scripts or system misconfiguration.

Data is commonly stored on hard drives. Data loss from **hard drive failures** is a real possibility. Failures could be due to mechanical fault, overheating, mishandling, liquid damage, etc. Physical damage to equipment can also occur to due fires, explosions, or natural disasters.

A sudden system shutdown due to a **power outage** can damage hard drives. Data could be unrecoverable even after power is restored. In general, if systems are shutdown improperly or power supply is unstable, there's a chance of data loss.

**Viruses or malware** can result in attackers stealing, deleting or corrupting data. Entry point for these are usually third-party application links, external hard drives, pen drives, and memory cards. Another external threat is physically stealing a device that contains data.

### What are the types of data loss prevention?

Data loss prevention solutions are primarily classified based on type and source of data:

    + **Endpoint DLP**: Organizations have a variety of endpoints, from portable devices (pen drives, cell phones, hard drives) to fixed devices (servers, workstations, printers). Endpoint DLP solutions are installed on such devices. For example, endpoint DLP can log or prevent file copying or sharing.
    + **Network DLP**: Applicable to all networked devices and to all network-accessible data. For example, when a user attempts to email sensitive information on a corporate network, network DLP could encrypt or block the data. Network DLP is common in enterprises that handle high volumes of data.
    + **Cloud DLP**: May be considered a subset of Network DLP. Applicable to enterprises that use cloud services.
    + **Storage DLP**: The focus is on the access and sharing of data while it's in storage. Alerts are triggered when data is not stored securely. Storage DLP is common for data warehouses and data lakes.

### What are some specific DLP techniques?

Broadly, techniques cover prevention, detection, response and analysis. A comprehensive DLP solution should address all aspects of data security: storage and transmission; encryption and key management; authentication and authorization; real-time monitoring of both network traffic and endpoint activity; threat detection and alerting; data backup and recovery plan; up-to-date policies; regulatory compliance; on-premise or cloud security.

Even when storage systems are secured against intrusion, logical protection controls must be in place. This includes encrypting, masking, and anonymizing data before it goes into storage. This gives additional protection against exposure or misuse should data be stolen.

Encryption can be applied for both data at rest and in motion. Cryptographic hashing can be used to anonymize personally identifiable information data. Data fingerprinting can be used to identify and track data. Content can be analyzed via rules-based expressions, database fingerprinting, partial document matching, full document matching (using file hash), domain identification, and statistical analysis.

For better user awareness, we could add visible metadata to headers or footers, or watermarks. These are visible reminders to users not to share sensitive data.

### What do you mean by security policies and rules in DLP?

Policies determine how sensitive is a piece of data and what operations are allowed on that data. Policies may define who can access it, if it can copied internally or externally, if it should be encrypted, if it can be attached in an email, who to notify for unauthorized access, and so on. Rules are mechanisms that implement policies.

Data classification is critical to enforcing these policies. Data categories or classes may include Top Secret, Confidential and Public; or alternatively, Public, Private or Restricted. Or they could be aligned to standards such as GDPR or HIPAA.

Creating effective policies involves a few steps. Start by asking what types of data are available, where they're stored, who can access them and who's accessing them. Start with classifying different types of data and how important is each one to the business. Assess risk factors and vulnerabilities. Data that's not relevant to the business can be deleted, thus optimizing DLP implementation. Document the policies in detail. This helps implementation and compliance. Enforce the policies across the organization. Collect metrics to know how well DLP is working. Automate workflows.

### What metrics can help in assessing maturity of a DLP solution?

Data classification is typically done by a trained software model that comes with a certain performance. Sometimes the model may fail to identify sensitive data. This is the problem of **true negatives**. This is a critical failure since a lenient policy would be applied and the sensitive data could get stolen or lost. The other problem is one of **false positives** whereby non-sensitive data is classified as sensitive and a strict security policy is unnecessarily applied to it. This reduces usability and productivity.

Policies can have **exceptions**. For example, a user may be given temporary access to a document. Many exceptions can mean that the policy probably needs to be refined.

A high **number of unmanaged devices** is not ideal for an enterprise. This metric should be kept low. Laptops, smartphones, and removable storage devices are endpoints. If these are outside the control of the IT department, enforcing DLP policies will not be possible.

If an issue is detected, we wish to fix it quickly. **Alert response time** is a metric to motivate workflow optimizations.

### What are best practices for implementing a strong DLP?

Implementing DLP is not a one-time effort. "Setting and forgetting" is a recipe for failure. Review and adapt policies, approaches, tools and technologies as the business evolves. When new to DLP, implement in phases based on priorities. Define the primary objective for implementing DLP. Align DLP with existing security architecture.

Apply DLP at every stage of a data's lifecycle, be it collection, storage, analysis, update, migration, deletion or archival. Create easy-to-follow security rules. Rules should not be too restrictive that they affect productivity. While relying on tools, don't forget to train people.

An organization must have a centralized DLP program, which also makes it easier to update DLP strategy and policies. Avoid ad hoc DLP approaches at different departments.

DLP solutions should comply with industry regulations such as GDPR, HIPAA (healthcare information), SOX, and PCI DSS (credit card data).

### What's the approach to data classification in DLP?

Effective DLP can happen only when data is correctly classified, be it structured or unstructured data. Define and execute policies as relevant to each data type. Adopt or create a classification system that can be easily customized. Preconfigured classification methods can be a starting point.

Automatic classification will be more consistent and reliable than asking users to classify their data. There are many approaches to data classification. It can be as simple as applying regular expressions or heuristics. For example, a 16-digit string can imply credit card information.

A more sophisticated approach is to train and deploy machine learning models. Models could be trained to recognize sensitive information, inside information, public information, personally identifiable information (PII), financial data, regulated data, intellectual property, and more.

One way to aid data classification is to insert metadata at the point of creating or saving the data. Metadata could include file format, author, date of creation/update, confidentiality level, etc. Metadata also speeds up search and classification.

### Could you describe some DLP products?

Symantec, McAfee, Web-sense, SecureTrust, Check Point, Digital Guardian, SolarWinds, CoSoSys, CrowdStrike, Trustifi and ManageEngine offer DLP products and solutions.

Lepide Data Security Platform and McAfee DLP are example solutions that can analyze metadata and data to discover and classify data.  Netwrix has a data classification product that includes features such as reusable index for better performance, flexible taxonomy manager that enables companies easily self-manage their data, transparency that informs users why a document was classified in a particular way, and remediation workflows to redact content, quarantine files, or revoke permissions.

Examples of DLP implemented in the cloud are Google's Cloud DLP, Nightfall and Acronis. Cloud DLP can scan/discover/classify data, mask sensitive data, and statistically measure re-identification risks. Nightfall automates classification, monitoring, alerting and redaction. In general, cloud DLP solutions integrate via APIs to various other systems (Slack, Google Drive, Jira, etc.) and hence prevent data loss via these systems.

Cloudflare One and API Shield are tools that implement DLP for data on Cloudflare.

### What are the limitations of data loss prevention?

There are ways to bypass DLP techniques. Malicious actors on the inside can send encrypted files that DLP tools can't scan or classify. DLP tools may be unable to handle large files. Users can also take screenshots and embed them into documents. Data can be obfuscated by simply setting the font to Wingdings.

DLP rules need to actively monitored and maintained. Data classification is rarely perfect. False positives and false negatives are a problem.

With cloud-based DLP solutions, sensitive data is processed in the cloud, which is at odds with enterprises not willing to send such data outside their networks.

## Milestones

1980

In the early 1980s, the **first computer viruses** are created. Created as curiosities, these later are evolved for malicious purposes. At a keynote speech for the *Chaos Computer Club*, German computer engineer Berger encourages others to explore such viruses.

1986

A virus called *Brain* is created by two Pakistani brothers. It infects the boot sector of storage media formatted with the DOS File Allocation Table (FAT) file system. It's creators claim that the virus is intended to be mostly harmless, simply displaying a copyright message about the pirated software and changing the name of the floppy drive. However, many people report that the virus has wiped their data or made their drives slow and unresponsive.

2014

Hackers steal credit card data of more than 50 million customers of Home Depot. Home Depot incurs a loss of $260 million. This is just one example to highlight the high cost of data loss and the need for DLP. On the whole, very high-profile data breaches are discovered all through the 2010s: Target (2013), Yahoo (2013), U.S. Voter database (2015), AdultFriendFinder (2016), etc.

2015

During this decade, as more of enterprise data starts moving to the cloud, so does the need and adoption of **cloud-based DLP** solutions. Performance requirements also demand that DLP be done in the cloud. DLP that initially started with compliance focus transitions during the 2010s towards threat detection, privacy and protected of personal data. It's been said that,

> The best uses for DLP today live under a triple umbrella of security, privacy, and compliance.

2016

The U.S. government releases the *Data Security Policy Principles Framework for the Precision Medicine Initiative (PMI)* that was launched by President Obama in early 2015. This sets guidelines and expectations to protect sensitive patient data.

2020

The National Institute of Standards and Technology (NIST) releases version 1.0 of the *NIST Privacy Framework: A Tool for Improving Privacy through Enterprise Risk Management*. It offers enterprises guidelines towards protecting personal data. The document also links the Privacy Framework to NIST's Cybersecurity Framework.

Data Loss Prevention


# Supervised vs Unsupervised Learning

## Summary

Machine Learning is the art and science of training machines with data without explicitly programming them. The Machine Learning algorithms can be classified into Supervised and Unsupervised Learning algorithms.

In Supervised Learning, the model is presented with input and desired output. The model learns from this data and is then presented with new data to make predictions i.e. either classify them or predict numeric values.

In contrast, the Unsupervised models work on their own to analyze the data provided to them and find underlying patterns and relationships between the input/output variables without any prior training of data.

The main difference between both is that a Supervised model learns from the data by making predictions iteratively and adjusting for the correct answer thereby making it more reliable than an Unsupervised model which has no idea what the values for the output might be.

## Discussion

### Explain the working behind both the algorithms.

**Supervised Learning** involves a training set that has labeled data and the goal is to find a mapping function that maps the inputs to desired outputs.

For example, the model is given a dataset say, fruits, it gathers all the information like shape, size, taste, and name of the fruit and learns about each type of data. Once the model gets trained, it is presented with a new fruit (test data), using the training data, the model will predict the name of the fruit by analyzing all the information learned previously.

Unlike Supervised Learning, **Unsupervised Learning** exhibits self-organization. The algorithm is provided with unlabeled and unclassified data and is expected to find hidden features from the data. It involves the grouping of data based on similarities, patterns, or differences without any guidance.

For example, the model is fed with unlabeled data of cats and dogs. The model divides the data into two different clusters without knowing their labels. Now, when it is presented with a cat's image (test data), based on the knowledge gathered, it will put it into the cat's cluster.

### Explain Supervised and Unsupervised Learning with real-life examples.

We can take a real-life example of a baby and a family dog. She recognizes her family dog. When she is introduced to a new dog, she identifies it as a dog because it has the same features (4 legs, 2 ears, 2 eyes) as her dog. This is *Unsupervised Learning*. If it would have been *Supervised Learning*, a family member would have told her that it's a dog.

Supervised Learning use cases include:

    + Classifying whether an email is Spam or not
    + Predicting house prices
    + Predicting weather conditions
    + Predicting whether a Customer is happy with the service or notUnsupervised Learning use cases include:

    + Finding correlations in customer data
    + Classifying people based on interest
    + Grouping customers by their purchase behavior
    + Reducing the complexity of a problem

### What types of problems are solved using Supervised and Unsupervised Learning Algorithms?

Supervised Learning can be broadly classified into Classification and Regression problems.

    + **Classification** problems use algorithms to allot the data into categories such as true-false or some specific categories like apple-oranges etc. Classification of an email as Spam or not is an example. Support Vector Machine and Decision Tree, etc are some classification algorithms.
    + **Regression** problems use algorithms to predict some numerical value or find a relation between input and output variables. Weather Forecasting is a regression example. Linear Regression is a regression algorithm.Unsupervised Learning can be categorized into Clustering, Association and Dimensionality Reduction .

    + **Clustering** involves grouping the data into clusters based on similarities or differences. Market Segmentation is a clustering example. K-Means Clustering is one of the clustering algorithms.
    + **Association** determines the set of items that occur together in the dataset. A real-life example is Market Basket Analysis. Apriori, Eclat, F-P Growth are some association algorithms.
    + **Dimensionality Reduction** refers to reduce the dimension of a dataset so that they can be easily processed by supervised algorithms. There are two steps involved i.e. feature selection and feature extraction.

### What are the Advantages and Disadvantages of using Supervised Learning over Unsupervised Learning?

The results produced by Supervised models tend to be more accurate and reliable than those produced by Unsupervised models since the data of supervised is well known and labeled.

Supervised Learning can get more specific about the data and output which is not possible in the case of Unsupervised Learning as it's the job of the model to group the data and find the hidden patterns.

The results of supervised model can be ascertained as there is prior knowledge about the classes invovled. Contrarily, unsupervised output cannot be ascertained.

Supervised Learning model is considered a little complex as compared to Unsupervised model as the Supervised model might require a lot of computation time to train and the labels for input/output variables require expertise. This is why unsupervised techniques are preferred.

Supervised algorithms are not suitable for handling complex tasks which Unsupervised algorithms handle perfectly. For example, if the test data is a little different from training data, the supervised algorithm will yield incorrect results.

### How is Supervised Learning different from Unsupervised Learning?

Some key differences are as follows:

    + **Goals**: The goal of Supervised Learning is to train the model with labeled data so that it predicts correct output when given test data whereas the goal of Unsupervised Learning is to process large chunks of data to find out interesting insights, patterns, and correlations present in the data.
    + **Output Feedback**: Supervised Learning has a direct feedback mechanism as the machine is trained with labeled data whereas there's no feedback mechanism involved in the case of Unsupervised Learning as the model is unaware of output.
    + **Complexity**: Unsupervised models are more complex as they need large data to produce outputs/ insights as compared to Supervised models.
    + **Applications**: Supervised algorithms are great for Spam Detection, Weather Forecasting, Price Predictions, etc. On the other hand, Unsupervised algorithms work well for Anomaly Detection, Recommendation Engines, and Medical Imaging, etc.

### How to decide whether to use Supervised or Unsupervised Learning for a particular task?

To decide on which Machine Learning model to choose, one needs to answer the following questions:

    + **Input Data**: Is the data labeled or unlabeled? For Supervised algorithms to work, entire data needs to be labeled and Unsupervised algorithms work best with unlabeled data.
    + **Goals**: The problem to be solved is defined or not? Supervised algorithms can work only if the problem is well-defined but Unsupervised algorithms will be able to find hidden patterns and insights from the data and generate new problems.
    + **Algorithms**: Does the dimensionality of your data coincide with that of existing algorithms? Will the algorithm support the amount of data you have?So, Supervised Learning gives quite accurate results but fails to perform on large data. Contrarily, Unsupervised algorithms can handle large data but can yield inaccurate results.

### What to do when the data has both labeled and unlabeled data items?

When the data has both labeled and unlabeled data items, **Semi-Supervised Learning** can be preferred. Semi-Supervised Learning integrates both Supervised and Unsupervised approaches. It was introduced to counter the expensive costs of acquiring labeled data. So, this model is trained on a large chunk of unlabeled data combined with a small chunk of labeled data.

Semi-Supervised Learning uses Unsupervised Learning approach to cluster similar data and then trains the model on different batches of data labeling the unlabeled data. These labels are called *Pseudo Labels*. The model is now trained on the combination of pseudo labeled and labeled data which leads to improvement in the model's accuracy.

Semi-Supervised Learning can ideal for the medical field wherein the doctor's efforts combined with that of the machine can lead to better accuracy. For example, a *Radiologist* can manually label some CT scans for tumors which can increase the machine's accuracy of predicting the right patients who need medical attention.

### What is self-supervised learning and how it related to supervised and unsupervised learning?

**Self Supervised Learning** is based on artificial neural network. It obtains supervisory signals from data itself predicting the hidden part of input from unhidden part of input. First, it recognises the pseudo labels and then uses supervised and unsupervised learning for further task.

Self-Supervised Learning is considered as autonomous form of *Supervised Learning* where there is no need of labeled input/outputs. It is like an extension to *Unsupervised Learning* but does not involve grouping or clustering. Alike *Semi-Supervised Learning*, it depends on manually labeled data. However, it does not require any prior labeled data as *Semi-Supervised Learning* does.

Self-Supervised Learning automates the process of labeling the data minimizing the cost of obtaining labeled data for *Supervised Learning*. Self-Supervised Learning applications include speech recognition, voice recognition, face detection, 3-d rotations etc.

Real Life examples include:

    + Wav2vec, a Facebook algorithm used to perform speech recognition.
    + BERT, Bidirectional Encoder Representations from Transformers, a Google algorithm used to understand the context of search queries better.

## Milestones

1943

First mathematical model of neural networks presented in the scientific paper "A logical calculus of the ideas immanent in nervous activity" by Walter Pitts and Warren McCulloch.

1949

The book "The Organization of Behavior" by Donald Hebb is published. This book has theories on relationship of neural networks and brain activity.

1950

Alan Turing creates the “Turing Test” to determine if a computer had human-like intelligence. For passing this test, a computer should be able to make a human believe that it is another human.

1952

Arthur Samuel, from IBM, made the first computer program on the game of checkers. IBM tried to improve it by iteratively making winning strategies. This led to development of alpha-beta pruning and minimax algorithm.

1957

Frank Rosenblatt combines Donald Hebb's model of brain cell with Arthur Samuel's theory of machine learning to create a perceptron. It successfully stimulated the thought processes of the human brain. This is where today’s neural networks originate from.

1967

Marcello Pelillo created the K-Nearest Neighbor algorithm (**Supervised Learning**)which is used for classification and regression in machine learning. This could give the solution to traveling salesmen problem (start from a random city and visit all cities in shortest possible distance).

1990

This year saw the transformation of Machine Learning from a knowledge-driven approach to a data-driven approach. Researchers created programs for computers that could analyze large amounts of data and draw conclusions from the results. (**Unsupervised learning**)

1995

Random Forest Algorithm got introduced in a paper published by Tin Kam Ho. This algorithm creates and merges multiple AI decisions into a "forest". When relying on multiple different decision trees, the model significantly improves in its accuracy and decision-making.

2009

The book “Introduction to Semi-Supervised Learning” was published in 2009 and was written by Xiaojin Zhu and Andrew Goldberg.

Supervised vs Unsupervised Learning


# Code Comments

## Summary

Code is typically written once but read by many. Current or future team members will read the code. In an open source project, many more folks including end users may read the code. Therefore, code readability is important. Sometimes when the code alone doesn't provide context or clarify intent, the developer may write extra descriptions. These descriptions are called **code comments**.

Code comments enhance readability. They facilitate code reviews, refactoring, and maintenance. Moreover, code comments are ignored by compilers and interpreters when producing the final executable. Thus, they incur no runtime performance overhead. However, too many or unnecessary comments can reduce readability.

All modern languages support code comments. Different languages have different syntaxes. Comments can be single-line or multi-line.

## Discussion

### What are the purposes for which code comments make sense?

Code comments are used for various purposes:

    + **Description**: Used for describing the logic behind the code, not the code itself. Used for describing the algorithm or explaining why it was chosen. Even flowcharts in ASCII could be included.
    + **Licensing**: Licensing or copyright information are written as comments.
    + **Metadata**: Could include author and date of the first version, name and contact of current maintainer. Could include external references to provide context, such as, a published paper or a StackOverflow answer.
    + **Pending Work**: Comments tagged with `FIXME` or `TODO` indicate pending work. Editors/IDEs often recognize them.
    + **Debugging**: Developers comment out redundant code or code causing problems. These comments are ideally deleted once the problem is found.
    + **Directives**: Directives meant for editors and interpreters. For example, UNIX scripts use `#!` to know what interpreter must be used. Python uses `# -*- coding: UTF-8 -*-` to inform the encoding used for the source file.
    + **Documentation**: For documenting interfaces and to assist editors/IDEs. Tools exist to automatically create documentation from these comments. Some developers treat these as documentation, not comments.

### What are some anti-patterns when writing code comments?

Writing lots of comments explaining every single detail of what the code does is an anti-pattern. Too many comments clutter the source file and reduce readability. Moreover, such comments are also hard to maintain as the code evolves.

Using comments to keep a historical record of how the code has evolved is an anti-pattern. This is best done by your version control system. Old code that's no longer used should not be commented. It's cleaner to delete the code. If required, we can always get it from the version control system.

Magic comments are those that give editors and interpreters directives. These may be important for the correct working of the software. Mixing such comments with regular comments can be problematic. Someone may delete the magic comments by mistake.

### Aren't comments an indication of bad code?

Some developers believe that comments are not necessary if the code is clean. Comments don't fix bad code. It's been said that,

> Don't document bad code – rewrite it.

From this perspective, there are ways to refactor bad code and get rid of unnecessary comments:

    + **Naming**: A variable `i` could be renamed to `numGoals`, which clarifies intention. Do this for variables, methods and classes.
    + **Structure**: If a code fragment can't be understood without comments, try to change the code structure. Design patterns help in this regard.
    + **Sub-expressions**: Where there's a complex expression, split it into multiple sub-expressions.
    + **New Method**: A comment that explains a block of code can be removed by extracting that code into its own method. The method's name should clarify intent.
    + **Assertion**: A variable may be expected to obey some constraint. Don't state this in a comment. Instead, use an assertion.When all the above are employed and code is refactored, only a few comments may remain. Mostly likely, these explain why the code is written in a certain way or describe complex algorithms that couldn't be simplified.

### Could you share some tips for writing code comments?

Avoid commenting what's already obvious in the code. Comments should explain at a higher level of abstraction. In other words, "why" comments are good, "how" comments are bad.

Organize code into blocks, each block performing a single task. A comment could precede each block. This makes it easier for others to follow the flow at a high level. In fact, some developers write these comments first before writing the code.

Get to the point. Avoid jokes, poetry and verbosity. Be polite in your comments. Write comments in a consistent style. Write them for other developers, although some write them for non-programmers. If you write `TODO` comments, remember to take action on these later. Update comments when updating code.

Some developers argue that multi-line nested comments are a bad idea. They can lead to *run-away comments* that create bugs.

Take inspiration from guidelines defined by others. For example, Google Style Guides are available for many languages and most of these include guidelines for comments. There are also guidelines for documenting APIs.

### What are some patterns for writing code comments?

Experienced developers most likely know when and how to write good code comments. Chris Travers has attempted to formalize these practices by giving them names:

    + **Documentation Comment Pattern**: For documenting interfaces and not for explaining the code itself.
    + **Section Heading Comment Pattern**: Comments are used to separate sections of code, such as public vs private methods. Helpful to organize code and find things quickly later.
    + **Footnote Comment Pattern**: Comments that describe why a particular approach was adopted. Short and informative. Generally used when such information can't be deduced from the code.
    + **Warning Comment Pattern**: Comments that warn developers of some special needs, such as calling a function as a superuser. Warnings may be about security or design flaws. Comments may include `TODO` or `FIXME` annotations.
    + **Signed Comment Pattern**: Useful in a team. Comments are accompanied by initials of the developer. Makes it easy to know who to approach for discussions.
    + **Woven Code Pattern**: Code and documentation are go together. Document first and then code to that documentation.

### Which are the syntax types for code comments?

Comment syntaxes vary across languages but basically there are two types:

    + **Inline Comment**: Used for a single-line comment, marked by a start comment token till the end of the line.
    + **Block Comment**: Used for a multi-line comment, marked by a pair of start-end comment tokens. In some languages, block comments can be nested, that is, a block comment within another block comment is permitted.A language may support one or both types of syntaxes. Some languages such as ALGOL, Mathematica, OCaml, Simula, and Smalltalk don't have a single-line comment syntax but the token pair for block comments may be used within the same line. Some languages such as R, Python, FORTRAN, Erlang and Visual Basic don't have block comments. Though Python has `""" … """`, these are meant for documentation, not comments.

PHP is an example that supports multiple syntaxes for inline comments (`#` and `//`).

### What's the syntax for adding comments to source code?

Without being exhaustive, we list some start tokens used for inline comments:

    + **`#`**: UNIX/Linux shells, Cobra, Perl, Python, Ruby, Seed7, Windows PowerShell, PHP, R, Make, Maple, Elixir, Nim
    + `//`: ActionScript, C, C++, C#, D, F#, Go, Java, JavaScript, Kotlin, Objective-C, PHP, Rust, Scala, SASS, Swift, Xojo
    + `--`: Euphoria, Haskell, SQL, Ada, AppleScript, Eiffel, Lua, VHDL, SGML, PureScript
    + `%`: TeX, Prolog, MATLAB, Erlang, S-Lang, Visual Prolog
    + `;`: Assembly x86, Lisp, Common Lisp, Clojure, Scheme
    + `REM`: BASIC, Batch filesWe list some start-end token pairs for block comments:

    + `/* … */`: ActionScript, C, C++, C#, D, Go, Java, JavaScript, Kotlin, Objective-C, PHP, PL/I, Prolog, Rexx, Rust, Scala, SAS, SASS, SQL, Swift, Visual Prolog, CSS
    + `(* … *)`: Delphi, ML, Mathematica, Object Pascal, Pascal, Seed7, Applescript, OCaml, Standard ML, Maple, Newspeak, F#
    + `#| … |#`: Lisp, Scheme, Racket
    + `=begin … =end`: Ruby

### Can data have comments attached to them?

Indeed, data can have comments too. Like code comments, these can be descriptions, metadata, references, etc. For example, static web content is served commonly in HTML. HTML (and XML) documents can have comments within `<!-- … -->` that are not displayed by web browsers.

It's common for computer systems to use **configuration files**. Typical formats are Microsoft Windows INI, XML, JSON and YAML. Except for JSON, all others allow for comments. Although JSON doesn't support comments by syntax, developers have found a way to add comments from a semantic standpoint by following certain naming conventions. For example, `"_comment1": "this is my comment"` is a comment although JSON parsers will treat is as data. The reason JSON doesn't have a comment syntax is that developers were adding parsing directives in them, thereby making it less interoperable.

Comments in configuration files probably make sense just as comments in code. In a quote that's attributed to James Gosling, it's been said that,

> Every configuration file becomes a programming language, so you might as well think that way.

## Milestones

1957

Designed at IBM, FORTRAN is released as a programming language along with a compiler. FORTRAN allows comments, thereby making the code accessible to non-programmers. A comment is a **full-line comment** marked by letter *C* at position 1 till the end of the line. COBOL and BASIC that follow soon after also support comments from a fixed position. The use of fixed position simplified compiler design. We should note that since the early 1950s assemblers have supported comments starting at any position, including **trailing comments**.

1960

ALGOL is defined by a committee as a "second-generation" language. It supports **block comments**. Pascal takes inspiration from ALGOL and is released in 1970. It also supports block comments.

1970

Through the 1970s, structured programming becomes more popular. The same can be said of object-oriented programming in the 1980s. Programs evolve to higher levels of abstraction. Programs become more organized. Computer systems have more memory and so variable names could be longer and more descriptive. Hungarian notation is less favoured. These developments imply a lesser need to write comments.

1981

In one of the earliest experiments, Woodfield et al. find that code comments **improve readability**. Tenny (1985) shows that comments improve the understanding of the Banker's Algorithm. Further experiments through the 1980s and early 1990s confirm these findings and highlight the importance of code comments in maintaining large software projects.

Oct
2007

Fluri et al. report results of a study on how code and its comments evolve. Based on three open source projects, they find that new code is barely accompanied by comments. Class and method declarations are commented more often than method calls. About 97% of comment changes are done in the same version as the code changes. Their research method associates code with comments based on proximity and a token-based string similarity measure.

2010

Since writing comments is extra work for developers, it's common to encounter code that's inadequately commented. During the period 2010-2014, tools emerge to **automatically generate code comments**. These use techniques from Information Retrieval (IR). From the mid-2010s, neural networks are more often employed for this problem.

2011

Haouari et al. present one of the first taxonomies for code comments. They identify four high-level categories.

2013

Steidl et al. identify seven high-level categories of comments. Their main aim is to understand developers' commenting habits. They find that commenting out code has negative impact on code readability. Section comments such as `// ---- Getter and Setter Methods ---` improve readability. Method comments help callers understand the system design and how to call those methods.

Feb
2019

Code comments sometimes include links to licenses, software homepages, and specifications. Hata et al. analyze 9.6 million links and find that about 10% are outdated. The point is that links in comments are fragile and need regular maintenance.

Apr
2019

Pascarella et al. manually classify 40,000 lines of code comments from 14 open source Java projects. Their goal is to empirically determine the types of comments developers are writing. In the process, they develop a **taxonomy of code comments**. They also develop machine learning features and algorithms to automate the classification.

Code Comments


# Django

## Summary

Django is a free open source web framework written in Python. Like any web framework, it simplifies the development of web applications. It's tagline refers to Django as "the web framework for perfectionists with deadlines". Django Software Foundation, which is a non-profit organization, maintains Django.

The following claims are made about Django: ridiculously fast, fully loaded, reassuringly secure, exceedingly scalable and incredibly versatile. Django's default installation can be extended with third-party packages, such as from Django Packages.

While meant primarily for fullstack web apps (often database driven), Django can be used to provide backend services for mobile apps via REST API calls, to build real-time apps or even a content management system.

## Discussion

### What does it mean to say that Django is "fully loaded"?

Django's default installation comes with capabilities common for typical web applications. This includes user authentication, content administration, database ORM, database schema migrations, URL routing, RSS feeds, a templating engine, forms, a caching framework, CSRF protection, and many more. Variously called as "fully loaded", "full stack", "out of the box" or "batteries included", they all mean the same thing: default installation contains lots of features that we need not download and install individually.

This does not imply that developers are restricted to using only what Django ships. Django is flexible enough to allow developers to use their preferred alternatives. For example, developers can use their own templating engine or ORM.

### What are the advantages of Django?

Advantages include the following:

    + Django is based on Python, which is a popular language that's easy to learn and powerful. Python works on any platform and is also open source.
    + Django's official documentation is comprehensive and includes easy to follow tutorials.
    + Django has an active community that contribute via open packages, tutorials, books and code snippets.
    + Because Django takes the "batteries included" approach, downloading it and getting started is quick and easy.
    + With Django's built-in admin interface, it's easy to organize model fields or process data.
    + Django adapts the well-known MVC architecture and therefore code can be written with clean abstractions.
    + Django community makes regular stable releases, some of which are Long Term Support (LTS) releases that get three years of support.

### What's the architecture used by Django?

Django uses what is called MTV Architecture: Model-Template-View. This is equivalent to the more well-known MVC architecture: Model-View-Controller. The traditional controller's job is done by the framework itself and hence the MTV nomenclature does not emphasize it.

The components of MTV architecture as are follows:

    + **Model** - Data access layer. This deals with access, validation and relationships among data. Models are Python classes that mediate between Django ORM and the database tables.
    + **Template** - Presentation layer. This deals with how data is displayed to the client.
    + **View** - Business logic layer. This is a bridge between models and templates. A view accesses model data and redirects it to a template for presentation. Unlike the definition of a view in traditional MVC architecture, a Django view describes which data you see, not how you see it. It's about processing, not presentation.

### What are the different backend databases supported?

Django officially supports PostgreSQL, MySQL, SQLite and Oracle Database Server. In addition, third-party vendors provide support to interface their databases to Django. These include SAP SQL Anywhere, IBM DB2, Microsoft SQL Server, Firebird and ODBC. A branch of Django development called Django-nonrel is already supports a couple of non-relational databases, MongoDB and Google App Engine. However, support for many more NoSQL are listed on the NoSqlSupport Wiki page.

All these databases need to provide a driver in Python. Psycopg is a popular one for PostgreSQL. MySQLdb is a driver for MySQL but it does not support Python 3. Its equivalent driver for Python 3 is mysqlclient. All these drivers conform to Python DB API.

PostgreSQL is preferred by the Django community. A Django app can connect to multiple databases.

### What are some popular large-scale websites using Django?

Django has been used in the following sites: Disqus, Bitbucket, Instagram, Mozilla Firefox, Pinterest, NASA, The Washington Post and Eventbrite. Pinterest later migrated to Flask due to their need for database sharding.

 DjangoSites is a site that tracks websites that are built using Django. As of October 2017, more than 5000 sites are listed.

### How does Django compare against other web frameworks?

As of July 2017, Django was the sixth most popular web framework. When considering only Python-based frameworks, it was in the top position. When looking at stars and forks on GitHub, Django, Flask and Tornado come up on top.

Among the Python-based frameworks are the following:

    + **Non-full-stack** - Flask, Bottle, CherryPy, Pyramid
    + **Full-stack** - Django, Tornado, TurboGears, web2pyIt's been said that Flask is a microframework suited for small apps with simple requirements. For larger apps, Pyramid or Django may be more suitable. Pyramid allows developers to put together the right tools for their app and hence offers more flexibility than the "batteries included" approach of Django. For example, Django ORM comes out of the box but Flask and Pyramid let developers choose any ORM of their choice. With Tornado, developers can do asynchronous programming.

### Is Django recommended for a Python beginner?

Flask is probably easiest to learn for beginners. Django has some learning curve but this effort will be worthwhile in the long run when building complex apps. Developers have commented that Web.py and Bottle are suitable for beginners.

It's important to know Python well before starting on any web framework. For example, it's been mentioned that trying to learn Python via Django is not the right approach.

### Can you share some performance results of Django?

Performance of Django in terms of throughput is seen to be above average, while Bottle and Pyramid appear to lead the pack. We should keep in mind that performance metrics are many (speed, memory consumption, etc.) and may involve tradeoffs.

A direct comparison between Django and Ruby on Rails done in January 2017 shows that on average Python is slower than Ruby by 0.7%. Benchmark tests on three different hardware show that CPPSP and Go are highly performant. Django does poorly in these tests.

It's been claimed that Django sites have handled peak traffic of 50K hits per second. Discus has used an HTTP caching layer called Varnish to scale to 45K hits per second. They make the point that the bottleneck in their app is due to slow database queries or network latency rather than the web framework.

### Can Django be used for mobile apps, REST APIs or microservices?

Django cannot be used for developing native mobile apps. However, backend services for a mobile app can be developed with Django. Django REST framework can be used to build RESTful APIs for both web and mobile (native or hybrid) apps.

### Is Django suited for real-time services and asynchronous apps?

There are frameworks such as Meteor (Node.js) and Derby (JavaScript) that have been designed for real-time services and event-driven model. Within the world of Python, there are frameworks that support real-time needs of modern apps.

Django was not designed for real time. However, with suitable add-on packages such as Django Channels, it can be used for real-time apps. A curated list of Python asynchronous frameworks and libraries is also being maintained on GitHub. This includes Tornado, gevent, asyncio and Twisted. Celery addresses real-time requirements and has provision to integrate with Django.

### What is the best way to test a Django-based web app?

Django relies on `unittest` module of Python for testing but developers can choose to use other testing frameworks of their choice. Django offers a test client that allows us to programmatically sends requests and validate responses. It's recommended that testing should involve a combination of Django test clients and "in-browser" testing frameworks such as Selenium.

### What is WSGI in the context of deploying a Django web app?

WSGI stands for Web Server Gateway Interface and is standardized as PEP 3333. It sits as a high-level interface between Python-based web applications and web servers. This improves portability of apps across different web servers that support WSGI. Because of WSGI, a particular choice of a Python web framework need not limit the deployment to only servers that support that framework.

Django development environment comes with a lightweight server but for production such a server is not suitable. Django is a web framework that needs a separate web server. This is unlike some frameworks such as CherryPy that has a built-in WSGI server.

Django documentation describes the steps to deploy the same app across different web servers: Apache with mod\_wsgi, Gunicorn or uWSGI. When deploying to the cloud, cloud providers usually share the deployment steps. For example, Nginx could be the frontend web server that interfaces with uWSGI application server, which in turn invokes the Django application.

## Milestones

2003

Web programmers Adrian Holovaty and Simon Willison begin using Python to build web apps for Lawrence Journal-World newspaper. Django has its roots here. This also implies that Django was from the outset focused on solving real-world problems.

Jul
2005

Django is released to the public. The framework is named Django after jazz guitarist Django Reinhardt.

Dec
2005

First Django app launched at The Washington Post.

Mar
2011

Django 1.3 starts support for class-based views.

Feb
2013

Support for Python 3 is added.

Apr
2017

Django 1.11 is released. It's the final major release to have support for Python 2. This will be supported till April 2020.

Dec
2017

Django 2.0 is released with only Python 3.4+ support.

Django