Computing fundamentals

What is software development?

Is it Engineering?

Engineering is the application of scientific, economic, social, and practical knowledge in order to invent, design, build, maintain, research, and improve structures, machines, devices, systems, materials and processes.

Is it a science?

Software development is an art

  • The word art literally means skill
  • Software developers skills improves with practice and experience
  • There are different styles and tastes of programming
  • Aesthetics are important
  • Every programmer has her own tricks
  • There is no deterministic solution to a problem
  • Programming involves creativity

Programming Languages

Programming languages by abstraction level

c#

We can classify programming languages according to the level of abstraction of the commands we can give to the machine's hardware

Programming languages by paradigm

We can classify programming languages according to the level of abstraction of the commands we can give to the machine's hardware

Imperative programming

 telling the "machine" how to do something, and as a result what you want to happen will happen.

var numbers = [1,2,3,4,5]
var doubled = []

for(var i = 0; i < numbers.length; i++) {
  var newNumber = numbers[i] * 2
  doubled.push(newNumber)
}
console.log(doubled) //=> [2,4,6,8,10]

Declarative programming

telling the "machine" what you would like to happen, and let the computer figure out how to do it.

var numbers = [1,2,3,4,5]
 
var doubled = numbers.map(function(n) {
  return n * 2
})
console.log(doubled) //=> [2,4,6,8,10]

Declarative programming

SELECT * from dogs
INNER JOIN owners
WHERE dogs.owner_id = owners.id
//dogs = [{name: 'Fido', owner_id: 1}, {...}, ... ]
//owners = [{id: 1, name: 'Bob'}, {...}, ...]

var dogsWithOwners = []
var dog, owner

for(var di=0; di < dogs.length; di++) {
  dog = dogs[di]

  for(var oi=0; oi < owners.length; oi++) {
    owner = owners[oi]
    if (owner && dog.owner_id == owner.id) {
      dogsWithOwners.push({
        dog: dog,
        owner: owner
      })
    }
  }}
}

Application lifecycle management

Structure of a program

Structure of a program

  • Data type definitions
  • Comments
  • Pre-processor directives
  • Sentences
#include <stdio.h>

void main()
{
    /* Starting program execution */
    int a, b, c = 5;
    a = 3 * c;
    b = 32 / 4;
    c = a − b;
    printf("Valor resultante: %d\n", c);
}
  • Declaration of functions
  • Constants
  • Variables

Variables

  • Abstract object where a value can be stored
  • It can be consulted or modified during program execution
  • Allocates memory space for storing the possible values

Constants

  • Its value can be consulted, but not modified

Arithmetic Operators

int numero = 1;

// Unary operators
numero++; // 2
numero--; // 1
-numero; // -1

// Binary operators
numero + 3; // 2
numero % 2 // 0
numero - 1; // -1
numero * -5; // 5
numero / 5; // 1

// Join expressions
(numero * 10) + 2; // 12
((numero++) + 1) / 2; // 7

Conditional Operators

int uno = 1;
int dos = 2;

uno < dos; // true
uno > dos; // false
uno > 1; // false
uno >= 1; // true
uno <= 1; // true
uno == 1; // true
uno != dos // true 

Logical operators

  • && and also
  • || or else
  • ! negate

Operators priority

Fundamentals of coding

Conditionals

Conditionals

Executing a group of sentences or another, depending on the result of evaluating a conditional expression

if

int numero = 10;

if(numero == 10)
{
    Console.WriteLine("Número es igual a 10");
}

if-else

int numero = 9;

if(numero == 10)
{
    Console.WriteLine("Número es mayor que 10");
}
else
{
    Console.WriteLine("Número no es igual a 10");
}

if-else-if

int numero = 9;

if(numero == 10)
{
    Console.WriteLine("Número es mayor que 10");
}
else if(numero == 9)
{
    Console.WriteLine("Número es igual a 9");
}
else
{
    Console.WriteLine("Número no es igual a 10 ni tampoco a 9");
}

switch

int numero = 9;

switch(numero)
{
    case 10:
        Console.WriteLine("Número es igual a 10");
        break;
    case 9:
        Console.WriteLine("Número es igual a 9");
        break;
    default:
        Console.WriteLine("Número no es igual a 10 ni tampoco a 9");
        break;
}

switch

int numero = 9;

switch(numero)
{
    case 10:
    case 9:
        Console.WriteLine("Número es igual a 9 o a 10");
        break;
    default:
        Console.WriteLine("Número no es igual a 10 ni tampoco a 9");
        break;
}

conditional operator "?"

int numero = 9;

bool esNueve = numero == 9 ? true : false;

if(esNueve)
{
    Console.WriteLine("Número es igual a 9");
}

joining conditions

int numero = 9;

if(numero == 9 && numero == 10)
{
    Console.WriteLine("OK");
}

if(numero == 9 & numero == 10)
{
    Console.WriteLine("OK");
}

if(numero == 9 || numero == 10)
{
    Console.WriteLine("OK");
}

if(numero == 9 | numero == 10)
{
    Console.WriteLine("OK");
}

Exercise 1

Write a program that reads three integer numbers and writes in console the maximum and minimum values.

Exercise 2

Given two sides of a rectangle, calculate the area and perimeter and print them in console

Exercise 3

Given a number of seconds, print in console how many days, hours, minutes and seconds correspond

Iterators

while

while(condition)
{
    // group of sentences
}

do-while

do
{
    // group of sentences
}
while(condition);

for

for(initial_sentence; break_condition; incr/decr) {
    // group of sentences
}

breaking iterators

do {
    
    if (num < 0) {
    {  
        Console.WriteLine("The number can't be negative");
        break;
        /* leaves the iteration. */
    }
    if (num > 100) {
        Console.WriteLine("The number is too big");
        continue;
        /* Don't execute the rest of sentences and breaks the iteration */
    }
    ...
} while (num != 0 );

Exercise 1

Text

Write a program to calculate the sum of every multiples of 5 between two given numbers

Functions

Functions

A function is a reusable block of code that performs one specific task.

also known as methods, procedures or routines

Functions are black boxes

Functions are black boxes

int Square(int x) {
    return x * x;
}
  • May be parameterized or not
  • May return a result or not 
  • If you expect a result, it's a function. If don't, it's a command.
void printInConsole(string message){
    console.log("MESSAGE: " + message);
}

...

printInConsole("Hello World!");

...

$ MESSAGE: Hello World!

DRY: Do not repeat yourself

if (value > 5) {
    console.log("value is greater than 5");
}

if (value > 6) {
    console.log("value is greater than 6");
}

if (value > 7) {
    console.log("value is greater than 7");
}

if (value > 8) {
    console.log("value is greater than 8");
}

DRY: Do not repeat yourself

void valueIsGreaterThan(value, comparator) {
    if(value > comparator) {
        console.log("Value is greater than " + comparator);
    }
}

...

valueIsGreaterThan(10, 5);
valueIsGreaterThan(10, 6);
valueIsGreaterThan(10, 7);
valueIsGreaterThan(10, 8);
valueIsGreaterThan(10, 9);

Single Responsibility Principle

A software entity should never have more than one reason to change. 

OOP: Object Oriented Programming

Computing fundamentals

By Daniel de la Cruz Calvo

Computing fundamentals

Work in progress: Computer fundamentals lessons for people who want to start learning programming.

  • 824