-
-
- Intro text:
- Hello and welcome, this is the first and introductionary video of my Nim for Beginners tutorials series in which i will teach you how to write your own programs in Nim programming language.
- Intro text:
-
-
-
- First of what is programming, and what is a programming language ?
- Programming is to communicate with a computer by writting code in a programming language that then gets compiled/translated by a compiler into machine code, a binary system of 1s and 0s that the computer can understand. A programming language is just like a natural language, English in this case which i am using to communicate with you, it has it's own rules how to form words from letters and from words sentences and from those meaning, etc. A programming language is just that, a set of rules and commands, in computer jargon a syntax, with which we write our programs. Each programming language has it's own syntax, strengths and weakness.
- Nim's strengths:
- Nim differentiates from other programming languages by combining speed, portability and elegance.
- It's speed allows for writting of operating systems like the one you are using right now aswell as games and game engines.
- It's portability allows for writting of code on any of the major platforms like Windows, MacOS and Linux, whilst being able to produce code that runs on any of them, as well as the Web.
- And lastly Nim is elegant which means that it's syntax is very much like writting english words, making it very easy to learn, write and read.
- Nim also has a plethora of other powerful features like multiple optional garbage collectors, metaprogramming etc, of which i will not go into detail here, you can read more in depth about Nim trough the links in the description.
- First of what is programming, and what is a programming language ?
-
-
-
- Now let's look at Nim's simplest program and how it works:
- echo "Hello, World!"
-
- That is a standard Hello World program used by every programming language to showcase one's syntax.
- Very short and simple right ? The "echo" command is used for outputing strings/text that we write on computers. The second part "Hello, World!" is "echo" command's argument/parameter, what we want to diplay onto the console, the console being the default way of outputing information and making non graphical programs. That's all it takes for the simplest program in Nim, a command and it's argument/value.
- Now let's look at Nim's simplest program and how it works:
-
-
-
- Okay, so if you like what you have seen so far, let's move on towards setting up Nim on your computer and start programming. If you are a experienced programmer already and still want to know more about Nim first, check the links in the video's description for Nim's frontpage and features page that contain a more in depth overview of Nim.
-
-
-
- Setting up Nim and your first program Hello World
-
Ok part 1 let's download Nim from this page: https://nim-lang.org/install.html
Now download the correct version for you operating system, and follow the instructions provided there. I will show you how it's done on Windows by first clicking on the Windows icon. There you will click on the second link in yellow "Download x86_64 zip" for both 32 bit and 64 bit versions of Windows. Once the download is complete, extract Nim's folder to your chosen location and open it. In Nim's folder you will find a file called "finish.exe", run it. Once you do that it will open up a console, checking if you have MinGW C compiler installed on your computer, type "y" and press enter, do the same for everything it asks you about including adding \.nimble\bin to your PATH environment variable etc. Once you do everything it will automatically close, with that Nim is ready to be used. We will test that now, by opening our notepad, or notepad++ if you have it. Type in echo "Hello World!" and then under File, Save As, then select "Save as type" under your name as All Files (*.*) then type HelloWorld.nim above for the File name and save. (Do not use spaces in your nim file names, as Nim has a bit of a problem with that currently).
Now we need to compile that file, so let's open up Nim's terminal by typing Nim in the start menu's search and a terminal/console will open up. If Nim is not found, then you have not yet installed Nim correctly, just must run finish.exe in Nim's folder and typing Y then enter till it exists.
Now i want you to right click on HelloWorld.nim wherever you have saved it, you will then see it's "Location", copy that location "C:\Users\Kiloneie\Desktop" is my location. Now type cd(short for change directory) into Nim's terminal, then paste your location and press enter. It should output your location in a new line if you did everything as instructed, if not retrace your steps. Now type "Nim c -r HelloWorld.nim" and your program should start compiling, once it's done it will output Hello World!, if you got it this far, you have now created your very own first program in Nim! But wait, will we really be writting our programs in a notepad ? No, we will not, this was just a quick test that everything is working correctly, we must now do one more step by installing Visual Studio Code(A cross platform open source heavily extensible Code Editor by Microsoft, yes they actually do some Open Source nowadays). So let's type into google Visual Studio Code or just typing in the url: "https://code.visualstudio.com/" There you will see a button Download for Windows, theres another button right next to it on the right, by clicking that it shows you download for macOS, Windows x64(which we will be using) and Linux x64. Click on Download for Windows button(by default it's a 64 bit version). Your download should now be starting, if not the page it redirects you has "direct download link" on the top to retry. Find that file, trough whichever browser you are using or download location(show default download location)
Follow the steps of the installer like i do, will be adding a shortcut to the desktop, and "Register Code as an editor for supported file types" so that Nim(and other languages) will always open up in Visual Studio Code, and install. Once it completes click on Finish with the "Launch Visual Studio Code box ticked for yes), this should now run Visual Studio Code for you. Now under "File" select "Open File…", now navigate or paste your file's location, type Hello, it should show you HelloWorld.nim and "HelloWorld.exe", click on "HelloWorld.nim" not exe, and "Open". Now your program is open in Nim. We must now install Nim's Extension for Visual Studio Code which will enable code, highlight, code completion, compilation with the press of a button etc, all the modern features to help you write code. Click on this little "Tetris like icon", now type Nim in the search field, now click this little green "Install" button, now Visual Studio Code will download and install your extension for you. Now click "HelloWorld.nim" tab, now press F6, it should now compile and run your very first Nim program again this time by the press of a button, and output "Hello World!". This is your first step into programming with Nim, to continue learning more, check out and subscribe to my channel to find out and be notified about any more Nim videos, so i can teach you way more than just a simple "Hello World!", i'll see you in the next video, have fun!
-
- Must restart computer after installing Nim using finish.exe if VsCode cannot find it(multiple nim compiler versions bug ?)!