Stage 4: Allow Comments

Chapter 1: Networks

Networks

While not of absolute importance to this course, an understanding of networks is key to understanding the greater impact of the Internet and the manner in which it functions. Simply put, a network is a group of three or more entities that can communicate using a channel, even while not directly connected to each other.

Assembling a Network

In order to assemble a functional network, be that a computer network, a smoke signal network, or something similar, three elements are needed. First, a way to encode and interpret messages sent and received (in terms of bits) is needed, followed by a way to route these messages. Finally, rules for deciding who gets to use the resources first and for what must be made to organize the flow of data.

Measuring a Network

A network is measured in terms of two important concepts, latency and bandwidth. Novice programmers often tend to confuse the two, though they refer to two important but distinct concepts. Latency is defined as the time it takes for a message to get from a source to a receiver, while bandwidth is the amount of information transmitted for every unit of time, be that in terms of megabits per second or some other measurement.

Chapter 2: Make the Internet Work for You

URLs

URLs, or Uniform Resource Locators, are the addresses of the Internet, corresponding to a specific webpage or web resource. They are generally composed of three main parts, the protocol, the host, and the path. The protocol is generally 'http' or 'https' and deals in terms of get and post requests, the host refers to the name of the website in question, and the path states the name of the desired file.

HTTP

HTTP, HyperText Transfer Protocol, is used in the protocol part of a URL to handle get or post requests sent forth from the browser regarding a specific file or page. Request lines containing a method (get or post), path, and version ID comprise part of an HTTP request, followed by a number of informational name/value pairs called headers. Servers respond in terms of status lines, composed of version ids, status codes, and reason phrases, either indicating the request was successful or whether the server was unable to execute the request.

Servers

In simple terms, servers store information and are responsible for responding reliably to HTTP requests, be those get or post requests. Servers generally respond in two manners, static and dynamic responses. Static responses are, as the name implies, static files like images or prerendered HTML files that are simply returned to the browser. Dynamic responses however, build a response in real time based on the request through the use of web applications.

Chapter 3: Forms

What are Forms?

Forms are a way for users to input data to a server. They can take a number of forms, from dropdown boxes to blank input boxes to option buttons, though they all serve the same essential function of supplying a server with the required information. They have many uses, from blogs to comments sections on news websites to social media postings.

Types of Forms

As stated previously, forms may take many forms. Three commonly used variations are blank input boxes, buttons, and dropdown menus. Buttons come in all forms, from radio buttons to checkboxes, and may be arranged in a mutually exclusive manner or in such a way to allow the user to select all applicable options.

Validation

One danger of user-inputed data is the problem of unwanted spam or malicious content that could potential cause server-side problems if not properly verified. Unless server requests are properly validated by the server, users may add malware to the server, crippling the ability of the server to properly handle requests, in effect 'crashing' it.

Chapter 4: Modulus and Dictionaries

Modulus

Like other mathematic operators, such as the add, minus, divide, and multiply operators, modulus is frequently employed in Python. The modulus operator, taking the form of the percent sign on a standard keyboard, returns the remainder of division between two integer operands.

Dictionaries

Like lists and tuples, dictionaries are a way to categorize, store, and call for information in a program. Unlike the other two, however, dictionaries are arranged in terms of key/value pairs, wherein a key is used to refer to a specific listed value. Thus, calling for a value using the square brackets requires notating the specific assigned key of that value inside the brackets. Dictionaries may be nested inside each other, just as is the case with lists and tuples.

Dictionaries vs Lists

Perhaps the most important distinction between lists and dictionaries concerns the matter of order. Lists print their values in order, while dictionaries are unordered, and print values in a random pattern unless a key is specified. Also, dictionaries are significantly faster at returning values than lists when provided a key.

Chapter 5: Methods

Get and Post

Get and Post are two commonly used methods employed by browsers and servers to interact with each other. Get is used to fetch documents and files from a server, while Post is used to update data stored on the server. Get includes parameters within the URL, while Post puts these parameters in the body. While Get methods have maximum lengths, Posts do not, though unlike Gets, they cannot cache data.

Problems with Get

It is very dangerous to use Get requests to alter the server data. Post requests are permitted to change server data, but using Get requests to do the same is not only unreliable, it also comes with the risk of deleting or disfiguring stored data, particularly links. It is far less risky to use forms rather than links, as forms submit data using Post requests.

When to Use Each

As stated previously, Get requests are best for fetching documents and files, be those images, HTML documents, or other static file types. However, when the user intends to change server data, such as his password or his username on a social network, it is important to use Post requests, which change the server data.

Chapter 6: Validation

What is Validation

Validation is the act of verifying user-input data and checking that what is received is correct and harmless. Servers, if not properly protected from spammers and hackers, can receive malicious data input from unverified Post requests, and validation allows the server to deny harmful data if certain conditions are not met. Validation is import for all websites that employ some sort of dynamic content.

Validation in Action

If a user makes a Get request, receiving a form from a server, and submits malicious data in a Post request that does not fit the predetermined conditions for acceptance, the server may reset the form and force the user to submit correctly rather than subject itself to potentially dangerous code. In effect, validation is a form of server security that assively scans incoming data against a ruleset to ascertain potential dangers.

String Substitution and HTML Escaping

Two useful tools for coders are string substitution and HTML escaping. String substitution, as the name implies, allows coders to simplify code by using a single base string of code into which multiple variables are plugged, in effect reducing the amount of redundant code in a program. HTML escaping replaces certain characters with other characters to prohibit malicious users from potentially 'breaking' forms and input boxes.

Chapter 7: HTML Templates

What is a Template?

Defined simply, HTML templates are libraries that build strings, specifically strings of HTML. Template languages, like Jinja, are incredibly useful in that they allow coders to increase and enhance readability by separating HTML and Python into separate files. Through the use of a single base HTML template, content can be generated on the fly simply by filling in the appropriate fields.

Inheritance

Much like CSS, or classes in Python, the concept of inheritance also applies to HTML templating languages. Through the use of the 'block' statement in Jinja, coders can specify certain parts of an HTML template for use on all pages, such as a title or a header/footer, making all other pages inherit from that page.

Templating Tips

Any aspiring programmers seeking to harness the power of templating languages should be familiar with a number of tips. First, it is important to remember to auto-escape variables, ensuring that malicious or hapless users are unable to crash the program. Second, it is necessary to minimize the code in the HTML templates to limit confusion. Likewise, the inverse is true as well, that HTML should be limited in the code itself.

Chapter 8: Databases

Databases

Databases are large, structured programs that store and retrieve desired data per user request. Databases are significantly more useful than hand-querying data, as they reduce the likelihood of errors and are less tedious. Databases are generally connected to web servers, and operate in terms of data tables that store data in a comprehensive fashion.

SQL

SQL, or Structured Query Language, is a popular database language invented the 1970s that asks questions of data submitted to a database server. It enjoys continued popularity in the current era and serves as a basis for many different types of database languages, like MySQL and SqLite.

Types of Database

There are many database languages that see frequent use by coders, both SQL-based and non SQL-based in nature. Database languages may be relational, and based off of SQL, like MySQL, SqLite, and Oracle, or not based off SQL, like NoSQL languages Mongo and Couch. Others exist as well, including Dynamo, used by Internet giant Amazon, or the Google App Engine language, which shares similarities with SQL.