Week one at AltSchool: A beginner's guide to computer Programming and more...
Annyeonghaseyo👋🏾
So, I just completed my first week of coding lessons at AltSchool, and boy do I have a lot to share! Stay with me 🚖
What's computer programming?
To start with, I learned about computer programming. This is the process of designing and writing code that a computer can understand and execute. It's like giving instructions to a machine so that it can perform a task. These instructions are written in a language that the computer can understand, such as Python, Java, or C++.
Compliers & interpreters
Now, in order for the computer to understand our instructions, we need a tool called a compiler or interpreter. A compiler is like a translator that takes our human-readable code and converts it into machine code, which is a series of 1s and 0s (also known as bits and bytes) that the computer can understand. An interpreter, on the other hand, reads our code line by line and executes it as it goes.
Bits & Bytes
Bits and bytes are the smallest units of data that a computer can understand. Bits are like tiny switches that are either on or off, while bytes are a group of 8 bits that represent a single piece of information.
Variables
We also discussed variables, which are like containers that store data. Variables can store different types of data, like numbers, words, or even entire paragraphs! Here's an example of a variable below;
# Declare a variable called "name" and assign it a string value
name = "John"
# Print a message that includes the value of the "name" variable
print("Hello, " + name + "!")
This code declares a variable called
name
and assigns it the value"John"
. It then prints a message that includes the value of thename
variable
Data types
It's important to ensure that the data you are working with is valid and can be used in the right way. This is because different types of data require different amounts of memory and have different properties. For example, a number can be an integer (a whole number) or a float (a number with decimals). It's like checking the ingredients in a recipe to make sure they're safe to eat. Examples of data types are below;
Integer: whole numbers such as 1, 2, 3, -4, -5, etc.
Floating-point: numbers with decimal points such as 3.14, 2.5, -0.5, etc.
Boolean: true or false values.
String: sequence of characters such as "hello", "world", "123", etc.
Character: single letters or symbols such as 'a', 'b', '$', etc.
Date/time: values that represent a specific point in time such as "2023-03-14" or "14:30:00".
Array/List: a collection of values of the same data type such as [1, 2, 3, 4] or ["apple", "banana", "cherry"].
Object: a collection of properties and their values such as { "name": "John", "age": 30 }.
Null: a special value indicating the absence of any data.
Undefined: a value that has not been assigned a value yet.
Data structures
We also have data structures, which are ways of organizing and storing multiple pieces of data together. It's like having a toolbox and organizing your tools in different compartments or drawers. Some examples include ;
Array: a collection of elements of the same data type that can be accessed by their index.
Linked list: a data structure that consists of nodes, where each node contains a value and a pointer to the next node in the list.
Stack: a data structure that follows the Last-In-First-Out (LIFO) principle, where elements are added and removed from the same end.
Queue: a data structure that follows the First-In-First-Out (FIFO) principle, where elements are added to the back and removed from the front.
Tree: a data structure that consists of nodes, where each node can have zero or more child nodes.
Graph: a data structure that consists of vertices (nodes) and edges (connections between nodes).
Hash table: a data structure that uses a hash function to map keys to values, allowing for constant time lookup and insertion.
Heap: a binary tree data structure where the value of each parent node is greater (or less) than its child nodes.
Set: a collection of unique elements that does not allow duplicates.
Dictionary: a data structure that stores key-value pairs, allowing for efficient lookup by key.
Control flow & recursion
Next, we have control flow, which refers to the order in which our code is executed. We use things like conditional statements (if/else) and loops (while/for) to control the flow of our code. Loops are especially useful when we need to repeat a certain action multiple times. It's like playing a song on repeat until you stop it.
Recursion is another way of repeating code, but instead of using a loop, we call the same function over and over again until we reach a certain condition.
Big O notation
When it comes to measuring the efficiency of our code, we use something called Big O notation. This helps us understand how our code performs as the size of our input grows larger. Think of it like packing for a trip. If you're packing a small bag with just a few items, it's easy and quick. But if you're packing a big suitcase with lots of clothes, shoes, and accessories, it takes more time and effort.
Similarly, if an algorithm is working with just a few items of data, it can complete its task quickly. But if it has to process a lot of data, it will take longer. Here are some examples of Big O notation:
O(1) - constant time: operations that take a fixed amount of time, regardless of the size of the input. Example: accessing an element in an array or a dictionary.
O(log n) - logarithmic time: operations that take time proportional to the logarithm of the input size. Example: binary search on a sorted array.
O(n) - linear time: operations that take time proportional to the size of the input. Example: iterating over an array or a linked list.
O(n log n) - linearithmic time: operations that take time proportional to n multiplied by the logarithm of n. Example: sorting algorithms like merge sort and quicksort.
O(n^2) - quadratic time: operations that take time proportional to the square of the input size. Example: nested loops that iterate over all pairs of elements in an array.
O(2^n) - exponential time: operations that take time that grows exponentially with the size of the input. Example: exhaustive search over all subsets of an input set.
Programming paradigms
Programming paradigms are different ways of approaching writing code, such as object-oriented and functional programming.
Functional programming is a way of writing code that focuses on using functions to perform specific tasks. It's like a recipe that tells you what ingredients to use and what steps to follow to create a specific dish.
In functional programming, functions are treated as first-class citizens, meaning that they can be assigned to variables, passed as arguments to other functions, and returned as values from functions. This allows for more flexible and modular code that can be reused in different parts of a program.
Functional programming also emphasizes immutability, meaning that data is treated as constant and never changed, but instead new data is created from existing data. This helps to prevent bugs and make code more predictable.
Object-oriented programming (OOP) on the other hand is a way of writing code that focuses on creating objects that have specific properties and behaviors. It's like making a cake. The recipe tells you what ingredients to use (properties) and what steps to follow (behaviors) to make the cake.
In OOP, objects are created from classes, which are blueprints for creating specific types of objects. For example, a class could be "car" and the objects created from that class could be different types of cars, like an SUV or a truck. Each car object would have specific properties, like color and make, and specific behaviors, like accelerating and braking.
OOP makes it easier to organize code and reuse it in different parts of a program. It also allows for better abstraction and encapsulation, meaning that code can be written in a way that hides its implementation details from other parts of the program.
An algorithm, code editor & operating systems
Algorithms are sets of instructions that tell a computer how to solve a problem, like a recipe for baking a cake.
Code editors are digital notebooks that help us write and save our code. Examples of code editors include;
Visual Studio Code: A free and open-source code editor by Microsoft that supports many programming languages and has a wide range of extensions.
Atom: Another free and open-source code editor that is highly customizable with a large number of plugins and packages.
Sublime Text: A popular code editor with a clean interface and advanced features like multiple cursors and split editing.
Notepad++: A lightweight code editor for Windows that supports many programming languages and has a customizable user interface.
Brackets: A free and open-source code editor designed for web development with features like live preview and inline editing.
Vim: A highly customizable and powerful code editor with a steep learning curve, often used by experienced programmers.
While operating systems manage all the different parts of our computer, like Windows, macOS, or Linux.
Phew! 😮💨 That was a lot to cover, but I hope I was able to explain these concepts in a relatable way. Learning about all of these things can seem overwhelming at first, but it's exciting to see how it all comes together to create amazing software and applications. I can't wait to see what I'll learn in the coming weeks!