Edit


Is computational thinking the same as “thinking like a computer”? I sure hope not, because computers are dumb and we do not want to think like them!

However, computers are very fast! They can perform a range of (rather simple) “things” very quickly! It is this quickness that makes them appear impressively smart!

Each fundamental “thing” it can do (like “add two numbers”) is called an instruction.

We call the set of instructions (surprise, surprise) an instruction set.

For us to be able to tell the computer to do something interesting, we need to speak to it using a series of instructions (from the set of instructions the computer understands) that will eventually be “executed” by that particular computer. We write code to represent those instructions.




Computational Thinking

Edit


Computational thinking is very much about having the mindset to conceptualise and break down a (large) problem into something that is solvable. It is all about the ideas, as opposed to the tools.

Computational thinking happens in our head. It is the fundamental first step to solving a problem, before we even start writing code. It’s about thinking about the problem, and how we can break it down into smaller problems that we can solve.

If it’s not clear in our head, it’s not going to be clear in our code! This is why it’s often helpful to “step away” from the computer, and think about the problem in a different way if we feel stuck.

This is why we will be learning object-oriented programming, as it helps us to think about the problem in a way that is more natural to us.

“As humans, we are used to thinking about the world in terms of objects.”




Programming

Edit


Isn’t programming and coding just the same thing?

Very often people use the terms programming and coding interchangeably. However, in this course, we would like to make a distinction between the two.

For easy problems, we can often go straight to coding.

For more complex problems, it’s impossible to get straight into coding! Where would you start!?!? It’s important to first think about modelling the problem and designing a solution in a way that is more natural to us (as humans). This makes it easier for us to eventually write the code. The code we produce will end up being easier for us to understand, build, and maintain.


Once we have an idea of how to solve the problem (thanks to our computational thinking ability), we can start working towards “a more technical” representation of those ideas.

You can think of programming as the design aspect, just before coding.

Object-oriented programming is a way that helps us design our programs in a way that allows a more natural transition from those initial ideas. Once we understand OOP, it makes it easier to eventually translate into code.


Note that it says “an idea”—not “the idea”. It’s important to note that there is no single “correct” way to solve a problem. There are often many different ways to solve a problem, and it’s up to you to decide which way to take. This is why it’s important to understand the problem well, and to think about it in a way that is more natural to you. Learning object-oriented programming will help us to think about the problem in a way that is more natural to us.




Coding

Edit


Now that we have a plan, we can start writing code!

Coding is the process of writing code that represents the solution to the problem.

The code we produce is using the language that the computer understands, allowing it to execute the instructions we have given it.


Time is money!

Edit

Computers are getting cheaper and more powerful.

The time it takes to run a program is (generally) not a big deal. However, the time it takes to write a program is a big deal!

As a professional engineer, your time is very valuable — much more than that of the computer!

We are usually willing to sacrifice “computing performance” for the sake of simplicity and elegance in our code. Any potential performance improvements you could achieve is likely to be negligible in comparison to the time you would need to spend improving it. Besides, if the program’s performance is indeed deemed an issue, you can always address it later.

For this reason, it’s important that you are productive and efficient when writing code. Using object-oriented programming can help us be more productive overall, since it allows us to more easily develop code that is easier to understand, build, and maintain.

It’s not only saving your time, but also the time of your colleagues and your future self! The easier it is for you (and others) to understand your code, the easier it is to maintain it and build on it.




The Art of Writing Software

This is a great video to appreciate what this course is about.




From Human Language to Machine Language



The Java compilation process

Watch this video before class:


Different CPUs tend to have different architectures, and as such will have a different instruction set that they can follow.

We all know that computers need 0’s and 1’s in order to do as they’re told. Luckily, we don’t need to stoop down that low to get them to do what we want!

This is where assemblers, compilers, and interpreters come in!

Assemblers

The human English language consists of 26 letters, while machine language consists of only 2 letters: 0 and 1.

The first computers were massive and expensive: the computer’s time was more important than the programmer’s time!

Programming them involved giving instructions directly to the CPU in the form of a sequence of bits (i.e., machine language), for example:

00000001001010100100000000100000

Some bits specify the instruction to perform:

opcode 000000 refers to adding

Some bits specify what registers to work with:

register 01000 = register 01001 + register 01010

Clearly this is tedious and error prone, so programs were written (i.e., assemblers) that automatically created the binary machine code above from something more human readable, that is assembly code:

add $8, $10, $9

Compilers

Assemblers are pretty straightforward to implement: each instruction easily converts to the same corresponding sequence of bits.

Writing assembly code simplified programming (compared to using machine code), but why not create a more high-level language? Something closer to human language, that would automatically create us the assembly code?

Compilers do precisely this! Their task is more complex than that of assemblers, as they need to perform many steps.

The first compilers were less efficient than experienced programmers. But as complexity of hardware increased, state-of-the-art compilers took over.

By now, the programmer’s time was more important than the computer’s time. This is especially true when it comes to software maintenance, not just construction. This is why it’s important to construct code that is easy to maintain! Hopefully you are getting to appreciate the idea of what is meant by design.

A compiler translates the complete source code into some target program (either machine code or assembly code).

The compiled target program is run at some later time when instructed by the user, providing any other necessary runtime input.

Pros:

  • Higher performance, especially for repeated instructions.
  • Less memory required (do not need the compiler to remain in memory once you have the target program).

Compiler

Interpreters

An interpreter, on the otherhand, executes the source one statement at a time.

The interpreter not only stays around, but execution of the program focuses around it.

Any necessary input is provided at the same time that the source is executed.

Pros:

  • Greater flexibility.
  • Easier debugging (direct access to source code).
  • Faster development time.

Interpreter

Java Virtual Machines

Is Java a compiled or interpreted language? Both!

The Java Compilation stage

The Java compiler (javac) compiles the Java source files (*.java filename extension) into bytecode (*.class filename extensions).

The Java Interpretation stage

The Java Virtual Machine (JVM, java) runs the bytecode, after translating it to a format that the underlying machine understands.

Java compilation process


Compilers versus Interpreters


Java Virtual Machine




Command Line

The command line is a text-based interface to the computer. It is a way to give instructions to the computer, and to see the output of those instructions. This is in contrast to the graphical user interface (GUI), which is what most people are used to.

So, why would we want to use the command line even though we have a GUI?

The command line is often:

  • Faster than the GUI, especially for repetitive tasks.
  • More powerful than the GUI, especially for complex tasks.
  • More flexible than the GUI, especially for tasks that are not supported by the GUI.
  • More consistent than the GUI, especially across different operating systems.
  • More scriptable than the GUI, especially for automating tasks.
  • More automatable than the GUI, especially for tasks that need to be done repeatedly.
  • More efficient than the GUI, especially for tasks that require a lot of resources.
  • More reliable than the GUI, especially for tasks that need to be done accurately.
  • More accessible than the GUI, especially for tasks that need to be done remotely.
  • More extensible than the GUI, especially for tasks that need to be done with other tools.
  • More customisable than the GUI, especially for tasks that need to be done in a specific way.




Command Line Basics

Watch this video for a quick overview of the command line:


This video helps explain why the command line is often better than the GUI for many tasks. Don’t worry about specific technical terms used, just try to understand the general idea and points being made:




How will we use the command line in this course?

You will see the command line be used during lectures, and this is mostly for demonstration purposes to gently introduce you to the command line, and see what its capabilities are.

Do you need to memorise all the commands demonstrated in lectures? No! You can always look up the commands you need, as you need them.

If you find the command line a little overwhelming, don’t worry! The learning goal isn’t to replicate what is demonstrated in the lectures, but to appreciate what the command line is capable of, appreciate its immense power, and to understand how it can be used to communicate with the computer.

Will you need to use the command line in this course? Yes! But only for a few specific tasks, and you will be guided through these tasks when the time comes. These include:

  • Compiling and running Java programs using the Maven wrapper:
    • ./mvnw for Unix/Mac OS or .\mvnw.cmd for Windows
  • Committing and pushing your code to GitHub using Git:
    • git for Unix/Mac OS or git for Windows
  • Sometimes, you might find it helpful to navigate directories:
    • cd for Unix/Mac OS or cd for Windows
  • Sometimes, you might find it helpful to list files and directories:
    • ls for Unix/Mac OS or dir for Windows
  • There are a few other commands that you might find helpful, but these are the main ones you will encounter, and the only ones you need to care about for now.

That’s it!

You will be guided step-by-step for the Maven wrapper and Git commands through the Hello GitHub assignment. The purpose of this assignment is to get you comfortable with using the command line for these specific tasks, as you will be doing this for the rest of your assignments, using the exact same commands and process. It will become second nature to you in no time.




Terminology often used with the command line

You might hear a few terms thrown around when it comes to the command line. Here are a few of them:

  • Terminal: This is the program that you use to interact with the command line. It’s the program that you open to type in commands. In macOS, the terminal is called Terminal. In Windows, the terminal is called Command Prompt or PowerShell. In Linux, the terminal is called Terminal.
  • Shell: This is the program that interprets the commands you type in. It’s the program that takes your commands and tells the computer what to do. There are many different shells, but the most common one is called Bash. You might hear people refer to the terminal as the shell, but they are not the same thing. The terminal is the program you use to interact with the shell. The shell is the program that interprets the commands you type in, while the terminal is the application (i.e., the thing with the window) that you use to interact with the shell.
  • Command: This is the instruction you give to the computer. It’s the thing you type into the terminal. For example, dir (in Windows) or ls (in macOS and Linux) is a command that lists the files and directories in the current directory. cd is a command that changes the current directory. git is also a command that does a lot of things, but mostly it’s used to manage your code. You will learn more about these commands as you need them.
  • Options: These are extra instructions you can give to a command. They are like the settings on a piece of equipment. They tell the command how to behave. You can use options to customise the behaviour of a command. For example, you can use the -l option with the ls command to list the files and directories in the current directory in a detailed format. You can use the -a option with the ls command to list all the files and directories in the current directory, including the hidden ones.
  • Directory: This is the same thing as a folder. It’s a place where you can store files. You can think of it as a container for files. You can have directories inside directories, and files inside directories. You can navigate between directories using the cd command. You can list the files and directories in the current directory using the ls command (in macOS and Linux) or the dir command (in Windows).
  • Path: This is the address of a file or directory. It’s like the address of a house. It tells you where the file or directory is located. You can use paths to navigate between directories, and to access files and directories. There are two types of paths: absolute paths and relative paths. An absolute path is the full address of a file or directory, starting from the root directory (/ in macOS and Linux, and C:\ in Windows). A relative path is the address of a file or directory relative to the current directory. You will learn more about paths as you need them.
  • File: This is a collection of data. It’s like a piece of paper. It can contain text, images, videos, or anything else. You can create, read, update, and delete files using the command line. You can also move, copy, and rename files using the command line.