A Complete Beginner’s Guide To Hacking: Running Code

This post is part of the series A Complete Beginner’s Guide To Hacking

Compilers are “computer programs (or set of programs) that transforms source code written in a programming language into another computer language”.  You learned earlier that that there are different levels of languages and ultimately the hardware interacts with the binary code – well the compiler is basically the software that translates your code that people can easily read and edit to the code the computer can read and run. Not all languages need a compiler, and sometimes you will sometimes find that you actually already have the compiler installed on your computer and so it will run without you even noticing. Check what you need for the language you are working in!


Some programs have ‘fixed’ finite running time, for example a scientific Python script that has a fixed input will run until it has calculated the output and then it will finish. For these you can generally compile and then execute (start) the program and wait for the static output.

On the other hand some programs will need to be running continouously such as a website that needs to be constantly updating with live inputs. If you are running a continuous program like this it is called hosting and the live inputs and outputs will have to be associated with ports.

Ports and Addresses

Ports are not physical hardware objects, but they are the name for what exists in software within operating systems to let things in and out. All ports can be identified by a unique 16-bit number or port number which contains two pieces of information – the IP address and the protocol type.

Every device that can connect to the internet has a unique address or identity number known as it’s Internet Protocol or IP address that gives information about it. You can find out your computer’s really easily by googling “define: IP address” and Google will tell you. Port numbers obviously include this because it uniquely identifies which device the port is being hosted on.

The other piece of information is the protocol type, which tells you what exactly it is you are passing in and out of a port – there are a range of numbers, the most commonly used from 0 to 1023, that are allocated to mean different things. For example, 80 means the HyperText Transfer Protocol (HTTP) – i.e. something for the World Wide Web, and 20 is for the File Transfer Protocol to sends files from one computer to another.

Most of the time you don’t see the port numbers involved with processes as instead the internet tends to use Unique Resource Locators (URLs) which identify all the numbers involved and retrieve them for you so as to make it more secure and easier to use. The URLs you are probably familiar with are website addresses – http://www.example.com for example.

If you want to run a program on your computer that only you can see the outputs of (for example when testing a prototype website) then you can do what’s known as local hosting. This is when you you use the special IP address (or ::1 these days) and the protocol type for a local port number (often 8080) which will output to a place only visible to your computer.

If you want to run a program with live inputs and outputs then can you tell your program to listen or output at the specific port(s) needed either by specifying the port number in your code.  For example, if you are listening for inputs from a connected sensor device then you could specify its relevant port number, or you could use URLs on the web to get information from a website like Twitter or BBC News (see web APIs later for the easiest way of doing this).


You will generally find that your personal computer isn’t the best way to run an internet connected application. This is because it has probably not been designed for that purpose. As long as you are running your program you will be limiting the computer’s capacity to do other things at the same time, slowing it all down. And of course you have to leave your computer running all the time you want the program running and most ordinary computers overheat after a while. And there are several security issues involved with connections to the internet.

Therefore, most of the time people use computers that have been designed to just doing the task of hosting alone and these (and the software they run to allow them to do just this) are called servers.

Servers are often stacked up together in a rack so they can add up to more room for running more applications. There are of course services that allow you to pay for time and space on other people’s dedicated server racks, and there are some that let you use them for free too! Github and Heroku are both good examples of services that provide an easy way for you to host your application on the the world wide web for free by uploading your code to be hosted on their servers.

So now you can actually run your code!

A Note On Debugging

So when you finally get your code up and running you will need to be aware of debugging. This is the very general term for identifying and fixing the problems in your code. You will probably have been doing this whilst writing it – looking for typos for example, but most will happen after you try and run your program and discover that it doesn’t work properly. There are loads of tools out there designed to try and help you dofigure out what’s wrong. Your text editor and/or shell will probably try and suggest what and where it thinks something has gone wrong but be wary as it is often not correct about this.

Bugs can be classified into two groups – those that stop the code from actually running, often invalid syntax (these bugs are what the automated debuggers are looking for), and bugs that let the code run but it just doesn’t do what it’s supposed to. Most of the time you will be looking for a combination of these.

NEXT: Working Together


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s