Video Coming Soon...
02: Important Basic Information
WARNING This exercise is in DRAFT status, so there may be errors. If you find any, please email me at help@learncodethehardway.com so I can fix them.
In this exercise I'll teach you a random selection of important computer related topics that programmers generally know. If you're a total beginner with programming then I highly recommend you spend some time studying this exercise. If you know how to use your computer already then just review it and take note of things you don't already know.
0. Linux
The very first thing we have to get out of the way is the use of Linux. I'm aiming this course at anyone, and Go definitely works on Linux. I'd say it works better on Linux, but only if you're actually a professional. If you're just starting out Linux is the absolute worst thing you could possibly inflict on yourself.
That's not because Linux is bad. It's definitely not if you're a programmer. It's because Linux is really for professionals who don't mind constantly fixing their computer and don't mind some things not working. There's also the problem that there is no "Linux." There's actually a bunch of different variants of Linux (called "distros") that all do something different, and that variability makes it nearly impossible to support.
The other problem with Linux for beginners is Linux encourages you to tweak and customize your setup, and many people customize their setup until nobody can help them fix it. If you want me or anyone else to help you, then at least don't customize your Linux and pick one that I use. I use Ubuntu. If you use Ubuntu then I can help you. If you use ArchLinux running inside Qubes OS inside a docker for "securitay" then you're on your own my friend.
Thankfully Go is so portable and easy to use that Linux users will have no problems using it even though I use Windows. But, but if you do run into problems then it's up to you to fix it. Linux is your problem, and I'm assuming that you know what you're getting into. It's for professionals, and professionals are able to fix their own computer when it isn't working.
If you can't fix your own problems, then don't install Linux. It's not good for beginners, and will only make it harder for me to help you.
I will say though, if you have an older computer that can't run Windows well, then go ahead and install Ubuntu Linux. Be sure to backup everything. I repeat BACKUP EVERYTHING. Then install Linux, and keep it as vanilla boring as possible. If you start tweaking things and getting creative then I can't help you.
1. Terminal Basics
Every operating system has something called a "terminal." It comes from the old days when people accessed computers through little televisions connected to big mainframes. A terminal provides a textual way to control your computer. To use a terminal you must:
- Find it and run it. On Windows it's called
Windows Terminal
. On OSX it's calledTerminal
. I will call all variants of this "the terminal." - When terminal opens you'll see a "prompt". This usually some text, a
>
or$
character, and then a blinking cursor. - If you type something there it will act as an input, and if you hit
ENTER
it will run what you type. - After the computer starts your command, the command will output some information about what it's doing. This could be a good result, nothing, or an error. Usually "nothing" means a good result.
- You can then keep repeatedly typing these commands and doing this will allow you to make your computer do things you need like copy files, create directories, open files, share your code, etc.
Go ahead and open your Terminal and type just this:
ls
Every operating system has this command, and when you type this and hit ENTER
you'll get a list of the files in your "home directory." You'll learn many more commands as the course progresses.
2. Files and Folders
On most operating systems there are two general ways to work with your files:
- Click around on icons in some kind of windows and use the right-click to do things.
- Type commands into the terminal.
I use both ways but generally programmers prefer to type commands over click with the mouse. This is because terminal commands can apply actions on many files at once fits better with programming.
Your files are organized in a kind of hierarchy, or tree, with files being inside directories (aka folders). Folders (directories) can also be inside folders, and this makes a tree. Programmers say "tree" because these folders inside folders create branching paths similar to branches on a tree. I suppose it's actually an upside down tree.
Take the time now to read what I wrote above, then pick random directories and follow their path to files with your mouse. Write down the list of directories you follow to understand the "path."
3. Files and the Terminal
The problem you may experience is that you only know how to access your files with the mouse. To fix this you're going to learn about the wonderful start
and open
commands.
On Windows there's a command for you Terminal named start
. On OSX it's called open
but it basically does the same thing. What these commands do is "double-click" any file from inside your Terminal. To learn how to use it do this:
- Open your terminal and type:
cd ~
- This will make sure you are in your "home directory."
- On Windows type:
start .
On OSX type:open .
- You should then see your familiar "folder window" and can use your mouse to browse around.
- Find a new directory ("folder") with your mouse, but stop.
- Go back to the Terminal and type:
cd
. That's "cd" then hit space. - Now go back to your folder window, grab that directory and drag it onto your Terminal with the mouse.
- Hit
ENTER
and you will now be in that directory. You can repeat this or just close the terminal.
You now know how to translate from "files with my mouse" to "files in my Terminal." Keep using this until you don't need to use your mouse anymore.
4. Effectively Using a Web Browser
These are just a few things I see beginners getting wrong when they use a web browser:
- Scroll! For some reason people think a browser is like a video game. They go to a website and then stop at whatever is on the screen. It's more common that a page has all of the relevant content further down, so always scroll the page.
- Fully expanding the browser on giant monitors. Don't expect everyone to accommodate your giant monitor. It's up to you to change your browser's width to fit the websites you use. I recommend big monitor people to place windows side-by-side for easier use.
- Using only one browser. If you constantly click on Edge or Safari because it's convenient then you're missing out. You should at least also download Firefox and Chrome so if a website doesn't work in one you can try it in another.
5. Asking for Help
6. Taking a Screenshot...Or Not
If you run into problems you'll need to send me something to see. You can usually copy-paste the text in your terminal, or attach your code .go
file for me to view. Screenshots are best if it's something visual I need to see, and text is best if it's code or an error output.
On Windows you can hold down the Windows/Start key, hold Shift, and hit 's'. This will then show a tiny menu on top and let you select a part of the screen to copy. This copy is then put into your copy-paste buffer and most app will allow you to hit CTRL-v to paste it. If you want to get the image then open any paint program and CTRL-v or go to your notifications and there should be a message about this image. Click that notification and it'll open it.
On OSX you hold CMD-SHIFT-4 and you can select a region of the screen. After you do this a file named Screenshot-DATE.png
will be on your Desktop
and you can open it.
To copy-paste text in the terminal just select it with your mouse, then usually hit ENTER
to copy it.
7. Searching Online for Help
Google is great for finding answers when programming, but you have to format your query to weed out any junk results. In most programming languages you search for "LANGUAGE PROBLEM site:OFFICIAL_SITE" to get the best results. If that doesn't work then remove "OFFICIAL_SITE" and see what you get.
For example, if I want to find out how to remove a character from a string in Go I would search for go remove character from string site:go.dev
and if that doesn't work then I search for go remove character from string
.
This is very important when you encounter an error you've never seen before. Instead of staring at the error, take it and drop it into Google with this format to see if other people can explain what it means. Most error messages from all programming languages are terrible, but other people can help.
8. Useful Terminal Commands
Pending. This will probably be a list of command and a link to a cheat sheet.
9. Configuring Your Editor
I recommend you make these changes to your editor while you're learning to code:
- Disable all help, code completion, and pop-ups. You want only the code and you want to force yourself to try to remember things before looking them up manually. This will help you retain the information.
- Get rid of the file browsing panels. Try to find the key sequence that will allow you to quickly open a file based on its name instead.
- Also disable the fake terminal window. Run an actual terminal in another window instead of the fake one in your editor. This will give you more screen space to read the code.
- Disable the feature that tries to auto-complete bounding characters like
{}()[]
. This almost never works right, breaks the flow of typing, doesn't let you edit as you go, and keeps you from learning to type them. - Any telemetry in the editor. Nobody at Microsoft needs to know what you do all day.
- Disable tabs for indentation characters. Tab characters are inconsistent and a key part of programming is being exact in what you write. 4 space characters is always 4 spaces. 1 tab could be 8, 2, 3, or one day it will become 1 tab and 1 space if an Emacs user ever opens your code.
10. Reducing Your Mouse Usage
I highly recommend you try to reduce your mouse usage as a programmer. Programming involves a lot of keyboard use, and the physical act of lifting your arm up to grab the mouse and move causes problems with your arm, shoulder, and wrists. It's also way slower and breaks you out of "code mode." Finding key sequences that get you access to files and do other things is way better.
The best way to break you of your mouse habit is to move it to the other hand. If you're right handed and put the mouse on your left side then you'll habitually reach for it with your right hand, realize it's not there, then remember to not use it. If you do actually need to use it then you can just use your left hand or cross your right hand over temporarily.
Of course, if you're a real addict then you'll eventually get ambidextrous and in that situation just move the mouse to the whole other side of your desk or unplug it so it's more annoying to use than your keyboard.
11. Easily Installing Software
Most platforms have something that lets you install software easily from the Terminal. On Windows you can use winget which I helped you install in the installation instructions. On OSX there's brew to do the same thing.
12. Avoiding Beginning Coder Mistakes
These are things that I see nearly every beginner doing that doesn't help them learn. I'm not sure why they do this, but hopefully you'll remember this list and try to avoid them. If you catch yourself doing one of these while writing some code then I recommend you simply delete your code and start over. I start over all the time so there's no shame in trying again if you did it wrong.
- Not typing everything in exactly. Programming language are usually case sensitive and always care about punctuation. If you see
fmt.Println("hello")
then type it exactly like that. No,fMt.printLn(hell")
is not "exactly the same." - Typing in all of the code and then compiling/running it once. I have no idea why beginners do this, as it's way more work, but you need to type only a little bit of code, then compile it and run it. This will help you catch errors early and get the compiler to help you. If you find that you typed all the code in and there's tons of errors then just delete it and do it again incrementally.
- Refusing to google errors. If you see an error your first reaction should be to Google it. It's usually the only way to figure out what it means, especially in Go.
- Staring at the code praying for answers. Sometimes you can figure it out by reviewing your code, but it's better to print out your variables and see what they contain. You should also make small changes and experiment with whether they fix things.
- Refusing to lookup documentation. There's no shame in looking things up. I do it constantly.
- Memorizing everything before starting. No amount of memorization will make your code suck less. The only thing that will make your code better is writing a whole ton of code. Typically memorization is just used as a way to evade the real issue of being humiliated by your terrible code, but you're a beginner. Embrace your bad code and if you keep writing more your code will stop being bad.
- Not experimenting with the code. You own your programming experience. I'm only giving you code that is a "starter" for each topic, so it's up to you to explore the topic with my starter and make it your own. Don't be afraid of "doing it wrong" since doing it wrong many times is how you get better.
- Thinking I'm a mind reader. Don't send me an email that says, "It doesn't work." I cannot see your screen. I have no idea why people think I can see their screen but you should be sending me copy-paste output and screenshots so I know what you're doing. Make sure to google those errors before you do that though.
- Giving up too soon. There's a particular class of person who feels that if they can't do something easily after 30 minutes then they're never going to learn it. This is an entirely unrealistic view of programming. Programming is a slow meditative activity and 30 minutes is chump change in our world. I spent a whole month making it so a player could move a torch from their inventory to the floor. If you keep trying to solve it you'll get better at solving problems, and many of the really juicy problems take weeks to solve. If you give up in shame after 30 minutes then you'll never get to the good stuff.
But, always remember, if you do run into trouble then email me and I'll help you out. Just be sure to google the errors first and give yourself about 1 day to solve it. I also predict that right after you send me an email you'll figure it out. Not sure why this happens but it's a known phenomenon in the programming world that talking to someone else about your bugs helps you solve the bugs.
13. Abstract Thinking
Programming is almost entirely abstract thinking. This means when I say, "It's on your Desktop," I don't mean it's literally sitting on your desk. I mean it's a piece of information that is represented by an icon in the folder named "Desktop" on your computer.
Nothing in your computer is real, so don't take the things people say as literal. It's all abstract and usually kind of nonsense. This will take time to get used to, but it's probably the most important skill that programming teaches you.
Register for Learn Go the Hard Way
Register today for the course and get the all currently available videos and lessons, plus all future modules for no extra charge.