Putting it all together
#
PreambleIf you've followed the tutorial so far, you have a basic understanding fo what is terminal, a CVS, an IDE and have set up git, GitHub and VSCode. You are more than ready to link it all together and come closer to a real dev experience. What we'll do will provide you with a playground project you can use for experimentations in the future.
As of now you might never have written actual code in a file, only commands in the terminal. Let's remedy that right away.
In the next chapter we will see how to choose a programming language to start with but for now we will just code a "Hello, World!" program in some of the main programming languages out there, namely:
- Powershell
- Bash
- HTML
- Python
- Javascript
- C
- C++
- Java
If you don't want to try out some of these just skip them. There is a video for reference down below in any case.
The "Hello, World!" program
From Wikipedia :
"A 'Hello, World!' program generally is a computer program that outputs or displays the message "Hello, World!". Such a program is very simple in most programming languages, and is often used to illustrate the basic syntax of a programming language. It is often the first program written by people learning to code. It can also be used as a sanity test to make sure that computer software intended to compile or run source code is correctly installed, and that the operator understands how to use it."
Read more about it hereWe'll do that in these few steps:
- Create a GitHub repository.
- Clone it locally with a git command.
- Create a source file in a language.
- Compile, run or open the file (how we do that will depend on the language).
- Stage the file and commit.
- Repeat Step 3, 4 and 5 for each language.
- Push our commits to the remote repository on GitHub.
- Celebrate!
We will all of this via the GitHub website for Step 1 and on VSCode or a terminal for the rest.
info
The point of all this is not to learn the syntax of a particular language nor understanding what you will write.
Rather, the goal is to make apparent some the basic steps that constitutes coding, namely :
Setting up project โ Writing code โ Testing your code โ Staging/Commiting/Pushing your changes
With that in mind, here we go ๐
#
Let's do it#
Setting up the git project- On GitHub, create a new repository.
- Clone the repository locally (on your computer). If you haven't set up SSH yet, follow this tutorial.
- Open the newly created folder in VSCode and you're set for the next part.
#
Writing and executing the code#
Scripting languagesPowershell
- Prerequisites
- Code
- Execution
Windows
- None
MacOS/Linux
- Install Powershell.
Write-Output "Hello, World!"
Windows
- Open a Powershell terminal.
- Navigate to the folder containing your script.
- Execute
./my-file-name.ps1
to run it.
MacOS/Linux
- Open a terminal.
- Execute
pwsh
to start Powershell. - Navigate to the folder containing your script.
- Execute
./my-file-name.ps1
to run it.
Bash
- Prerequisites
- Code
- Execution
Windows
- Install the Windows Subsystem for Linux. Here is a tutorial.
MacOS/Linux
- None
echo 'Hello, World!'
Windows
- Open a new Linux terminal.
- Navigate to the folder containing your script.
- Execute
./my-file-name.sh
to run it.
MacOS/Linux
- Open a terminal.
- Navigate to the folder containing your script.
- Execute
./my-file-name.sh
to run it.
Python
- Prerequisites
- Code
- Execution
- Install Python from the official website.
print("Hello, world!")
- Open a terminal.
- Navigate to the folder containing your script.
- Execute
python ./my-file-name.py
to run it.
Javascript
- Prerequisites
- Code
- Execution
- Install NodeJS. Here is the official website.
console.log("Hello, World!");
- Open a terminal.
- Navigate to the folder containing your script.
- Execute
node ./my-file-name.js
to run it.
#
Markup languagesHTML
- Prerequisites
- Code
- Execution
- None.
<p>Hello, World!</p>
- Open the file with your favorite browser.
#
Compiled languagesC
- Prerequisites
- Code
- Execution
Windows
- Install a C/C++ compiler. Here is a tutorial.
MacOS
- Check if you have the clang C/C++ compiler by executing the command
clang --version
; if you see a version, you have it. - If you don't :
- Download xcode from the app store
- Run the xcode installer.
- Open up xcode go to XCode >> Preferences >> Downloads >> Command Line Tools and click install.
Linux
- Install a C/C++ compiler. Here is a tutorial.
#include <stdio.h>
int main(){ printf("Hello, World!"); return 0;}
- Open a new terminal.
- Navigate to the folder containing your source code file.
- Execute
gcc my-file-name.c -o my-executable-name
to compile the source code in an executable. Note : you should replace 'gcc' by the name of your compiler if you are using a different one (such as clang on MacOS). - Run your progam by executing
./my-executable-name
.
C++
- Prerequisites
- Code
- Execution
#include <iostream>
using namespace std;
int main(){ cout << "Hello, World!" << endl;}
- Open a new terminal.
- Navigate to the folder containing your source code file.
- Execute
g++ my-file-name.cpp -o my-executable-name
to compile the source code in an executable. Note : you should replace 'gcc' by the name of your compiler if you are using a different one (such as clang on MacOS). - Run your progam by executing
./my-executable-name
.
#
Interpreted languagesJava
- Prerequisites
- Code
- Execution
- Install the Java Development Kit from the official website.
class HelloWorld { public static void main(String args[]){ System.out.println("Hello, World!");
}}
- Open a new terminal.
- Navigate to the folder containing your source code file.
- Execute
javac my-file-name.java
to compile the source code to a Java class. - Run your Java class by executing
java my-file-name
.
#
A video for referenceHere is a video that shows all the steps. Note that I use the Code Runner extension for VSCode, so that I don't have to write my execution commands.
#
Concluding remarksWell done, now you are ready to go learn actual programming.
I hope you have noted that these languages share similarities.
That is a reason why if you know one programming language it is relatively easy to learn another (all depending on how similar they are ofc).
We'll see in the next section which language you should pick as the first one.
I would like before you move on, that whatever you choose to learn, whenever you code, remember to version your work by staging/commiting/pushing your work.
This way you will have automatisms for when you wish to collaborate and will never loose code. Here is a short article on when to commit.