Skip to content

Latest commit

 

History

History
215 lines (148 loc) · 11.7 KB

1.md

File metadata and controls

215 lines (148 loc) · 11.7 KB

Introduction

What is programming?

Telling a computer to do something. Complex tasks are explained to the computer in a step-by-step manner. These steps are called an algorithm. When performed from start to finish they are said to be executed.

An analogy is preparing a meal. A recipe is a programme. The cook is the computer.

Programmes accept input and return output. For example a search engine can take a text query as input and produce a list of search results as output.

A recipe takes food ingredients as input, and outputs a delicious meal based on them. Different ingredients result in a different meal, despite following the same steps.

Programmes can call other programmes as a form of abstractions. By referencing a complex series of operations as a programme, we hide the implementation details.

A recipe may call for greasing a pan, leaving the exact method up to the cook: using butter, olive oil, or cooking spray.

Since each programme is an encapsulation of a task, we can quickly create more and more complex programmes through composition. Each step up

For example a recipe contains a series of complex steps, but is itself only a single step in the organisation of a fancy dinner, which in turn is only a single step in a birthday party.

Programmes can also call themselves, which is called recursion. For example a recipe to make yoghurt may require an existing yoghurt starter to grow the new culture.

To ensure the programme was written correctly, automated tests are written. These expect certain behaviour from the programme and warn the programmer if any deviation is found. In the cooking analogy this could be a simple taste test.

The different coding languages and how they fit

Increasing Complexity

Computers are fundamentally mechanical machines with lots of programmable switches. Early computers were massive because they used bulky components. Their programmes were primitive because there were simply not many components involved.

Switches can be open or closed, two states, which is why computers are called binary. Each switch is a bit. A byte is 8 bits and a megabyte is 8 million bits.

Modern computers contain many orders of magnitude more switches, thanks to tiny transistors. Today billions of transistors can fit in a chip the size of a fingernail. The rate of increasing density of these transistors has been observed to grow exponentially, roughly doubling every 2 years, and is called Moore's Law.

To harness the power of such complex machines, equally complex programmes are created through abstractions and encapsulation, enabling functionality unimaginable just decades ago.

Low Level Languages

Programming languages are considered low level when they deal with concepts closer to the metal. For example activating specific instructions within a processor or allocating and releasing memory space for data.

Low level languages are designed for high-performance computing but come at a cost of programming complexity. Sometimes they are used for performance-critical sections of an application where implementations can be tuned for specific processors or platforms.

Assembly:

mov [02h], 'H'
mov [04h], 'e'
mov [06h], 'l'
mov [08h], 'l'
mov [0ah], 'o'
mov [0ch], ','
mov [0eh], 'W'
mov [10h], 'o'
mov [12h], 'r'
mov [14h], 'l'
mov [16h], 'd'
mov [18h], '!'

; color all characters:
mov cx, 12  ; number of characters.
mov di, 03h ; start from byte after 'h'

c:  mov [di], 11101100b   ; light red(1100) on yellow(1110)
    add di, 2 ; skip over next ascii code in vga memory.
    loop c

High Level Languages

High level languages are designed to make it easier to programme complex applications. They introduce primitives to work with complex data more easily. For example text, lists, dates. This is in contrast to dealing directly with arbitrary bits and bytes.

The concept of a higher level language is relative. To a C++ programmer the JavaScript language is high level. But to an Assembly programmer the C++ language is high level.=

JavaScript:

console.log('Hello, World!')

Domain Specific Languages

Niche use-cases sometimes call for new languages that lend themselves even more to very specific tasks, at the cost of not being generally suitable to most other tasks.

For example generating HTML for user interfaces in web applications can be tedious in JavaScript, so web developers often use templating languages instead.

JavaScript:

function createPhoto(url, description) {
  const photo = document.createElement('img')
  photo.src = url
  photo.alt = description
  return photo
}

Handlebars:

<img src="{{url}}" alt="{{description}}">

Back end vs Front end

Client-Server Model

On the web, the most common flow of information is called the client-server model.

The client device runs a web browser, or user agent. The user agent does not share information with other user agents. It only sends requests for content, called resources, to a web server.

The web server sends a response to the request. Conversely, the web server does not send requests to user agents.

Front End Programming

Programmes that are executed by a user agent are called the front end.

Web browsers support open standards like HTML, CSS, SVG, and JavaScript. Programming front end applications typically means writing programmes in those languages.

Front end programming focuses on design and usability. Complex front end programmes consist of many different user interfaces, let the user work with large volumes of data, or contain rich visual effects and animations.

Challenges in front end engineering are the ability to write programmes that work in different web browsers, work smoothly on all sorts of devices with high or low power, large or small screens, and automatically testing code for bugs.

Transpilation

There are many languages that can be automatically translated, or transpiled, into JavaScript. This allows the use of different programming languages while still executing JavaScript code in the web browser.

Coffee Script:

square = (x) -> x * x

JavaScript:

square = function(x) {
  return x * x;
};

Back End Programming

A web server is a machine running 24/7 and serves resources for a particular web site to all clients.

The concerns for back end programmers are very different from front end programming. There is a high emphasis on performance, reliability, and security.

Performance

To handle large numbers of concurrent requests, web servers are scaled either horizontally, by adding more processors or servers to share the workload, or vertically, by using faster computers and more efficient programmes.

Some programming languages and frameworks make this easier to achieve than others. For example Go is a language very well-suited at horizontal scaling because of its concurrency support. Node.js, a JavaScript engine for back end programming, is designed for high performance, asynchronous programming. Languages like C or C++ allow more efficient code, but are unsuitable for most web applications due to their low level primitives.

Reliability

When a front end application has an error, only one user is affected. But the back end going down could be catastrophic for all users.

Back end programming typically involves building redundant systems. When one programme crashes, another takes over. This can be extended to entire web servers, data centres, or even geographic areas.

Redundancy is also key to ensuring data survives disastrous hardware failure. Copies of data is kept on multiple servers, in several places around the world.

Security

Building secure programmes means using trusted libraries and frameworks. These are often full of mathematics and information theory. Young programming languages may come with immature libraries or frameworks that have not yet stood the test of time.

Overview of HTML, CSS and JavaScript

HTML: Content & Semantics

See: https://github.com/cbas/webdev-breakdown#html

CSS: Design & Layout

See: https://github.com/cbas/webdev-breakdown#css

JavaScript: Behaviour & Logic

See: https://github.com/cbas/webdev-breakdown#javascript

Overview of databases and key coding languages

Databases store data for high performance searching and retrieval.

Relational vs NoSQL

Storing relational data means breaking down data models into relationships between entities.

Popular relational databases are PostgreSQL and MySQL.

For example a classroom has a subject and many students. Students have a name.

In a relational database these would be stored as tables with a row per entry and columns for properties. The classroom table is small and would contain an entry for each class. The students table would contain a row per student, and columns for their name and which class they are in.

In a NoSQL database a. array of classrooms would be stored as an object that contains an array of students, each of which has a name property.

Popular NoSQL databases are MongdoDB and CouchDB.

The difference between these approaches is subject of much controversy. Relational databases are extremely mature, well tested, and proven to scale. Some benefits of NoSQL are that they are easy to understand, and designed for common problems faced by web applications.

JSON

Data is exchanged between clients and servers in a common format modelled after JavaScript's object notation syntax. JSON supports data types like text strings, integer numbers, floating point numbers, lists or arrays, and key value pairs or objects.

{
  "classroom": {
    "hours": 10,
    "score": 7.6,
    "students": [
      { "name": "Alice" },
      { "name": "Bob" },
      { "name": "Eve" }
    ]
  }
}

APIs

Back ends in the past would serve HTML responses to web browsers. Frameworks like PHP and Ruby on Rails were designed for this.

Since the advent of native mobile apps, back ends have focused on serving only the data as JSON. This saves on bandwidth, which makes back ends more scalable and reusable across different front end apps. Since front ends only transfer the minimun amount of JSON data, they respond more quickly and consume less power.

In the RESTful approach, data is accessed in the Create-Read-Update-Delete (CRUD) pattern using HTTP methods like GET, POST, PUT, and DELETE.

Languages: PHP, Ruby, Java, .Net, Node.js, etc.

The choice of language depends on a wide range of factors, not just technical differences between languages.

Each project has its own requirements. Each team has its own strengths.

When choosing a platform or language, choose what works for you, not someone else.

Chicken & Egg

The utility of languages lies partly in the code that has been written in them. For example Haskell is a beautiful, elegant language but you'd struggle to write a mobile game in it.

Who's Who?

  • PHP is wildly popular due to frameworks like WordPress and Magento. It is well suited for web applications and Facebook proves that PHP can scale.
  • Ruby is often used with the Rails framework to build web applications. It is great at quckly knocking out a prototype app but less suited at large scale apps.
  • Java lends itself well to larger teams thanks to a mature ecosystem of engineers and tools. It's also the default choice for Android development, though other options exist.
  • .Net is used for Windows apps and sometimes web app backends. Its connection to Microsoft is controversial since vendor lock-in is a concern.
  • Node.js is great for real time backend apps, asynchronous operations, handling large numbers of users, or building simple RESTful JSON APIs.
  • ObjectiveC & Swift are the default choices for iOS development. As with Android, it is possible to write front end web applications and wrap them for iOS.