When an individual encounters a new obstacle in his or her life, no matter the significance or severity, the odds are that said obstacle has stood in the way of challengers before. In most situations this individual is probably not the first to face this challenge. Depending on the difficulty of the challenge being faced, some challengers will succeed, while others will not--some may even find a way around it.
I experienced an obstacle that, for me, turned into a roadblock that over the past decade, I revisited several times with the same outcome until I finally asked for help. I wanted to learn how to code, but I neither knew where to start or what that path forward might look like.
I learned the basics of a couple languages by playing around with online platforms like codecademy and online koans. These tools are great for learning the basics of a language while exercising dusty, old math skills to solve simple albeit, sometimes challenging mathematical problems like those you find in Project Euler.
The problem is that all of this learning is restricted to the online platform that does all the real stuff for you. I wasn't going to be able to write my own application in an online interface. I needed to learn how to run these problems locally on my own machine, but I struggled to find references to even get set up.
Now that I’m past this roadblock that kept me stationary for so long and because I simply cannot believe that I was the first or the only one who has ever faced this roadblock, I want to share how to get your computing machine set up to do the basics locally.
The following procedure is for beginners; those who have had only a taste of learning a language, but are blocked from getting any further. It provides the steps and tools necessary to get your machine setup and running small, basic programs locally for solving problems from ProjectEuler.net as well as the ClojureKoans.
Let’s get started!
Before diving into all the downloads & installations, I felt it was important to share an overview of the software we will be installing on your machine. No need to do any downloads or installs in this first section as some of them are Operating System dependent.
Clojure is a very powerful & efficient language. It is a functional, lisp language. I've chosen clojure for this outline for three reasons.
Starting with a functional language like Clojure, gets you comfortable with it from the start. There's no doubt that you will learn procedural, object-oriented languages down the line.
There are newer versions, but for now, stick with version 8 as it is the most commonly used. Because of this, using newer versions could cause you unnecessary and seemingly unsolvable problems.
Homebrew and Chocolatey are Package Managers, which are essentially programs that do the work of downloading & installing other applications on the correct path for you. To learn more about Homebrew or Chocolatey, visit their sites Homebrew and Chocolatey. Macs will be using Homebrew; Windows will be using Chocolatey.
Leiningen is a tool that automates clojure and helps to manage dependencies. Trust me, you’ll want it and will come to need it, if you continue to use clojure.
This is for windows only and is a .NET Framework which is required for clojure & chocolatey to run.
While this little shell may look unimpressive upon opening, it is literally the window into your computer. With the right commands, it can read files, download data, search websites, and run applications. In fact, it is the command line for your computer. Anything that you do on your computer could theoretically be commanded through this little shell window. Terminal is for Mac while PowerShell is for Windows.
All instructions except downloading java (and .NET for Windows), will all be performed in Terminal/PowerShell.
Ensure java is installed which java
Double check the version type java -version
If the return value includes Java 1.8.xx, skip the rest of the Java8 section and go to the Homebrew section below.
Find the shell you’re using echo $SHELL
Note either /bin/bash or /bin/zsh
If /bin/bash, type: vim ~/.bashrc
If /bin/zsh, type: vim ~/.zshrc
You've now opened vim, which allows you to edit documents within the terminal
Push “i” to INSERT text
Copy/Paste:
export JAVA_HOME=/usr/libexec/java_home -v {{enter version i.e. 1.8}}
Push esc, then type: :wq
Check that it’s been set: echo $JAVA_HOME
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
brew install clojure/tools/clojure
brew install leiningen
Open Powershell as Administrator. First things first,
Get-Host
Update-Module PowerShell
The rest of the instructions will be in PowerShell. If you get errors between installations, close & reopen PowerShell as Administrator.
Note: If you are not using PowerShell, this part of the instructions may not work.
$Env:JAVA_HOME
java -version
Get-ChildItem "C:\Program Files\Java"
cd /
ls ".\Program Files\Java"
$env:JAVA_HOME="C:\Program Files\Java\jdk1.8.***X_XXX***\"
$Env:JAVA_HOME
This is what it should look like in the end:
Get-ExecutionPolicy
Set-ExecutionPolicy Bypass -Scope Process
Y
Set-ExecutionPolicy Bypass -Scope Process -Force; iwr https://community.chocolatey.org/install.ps1 -UseBasicParsing | iex
Unfortunately chocolatey only has version 6, and we need 7, so we’ll do this manually.
iwr -useb download.clojure.org/install/win-install-1.10.3.822.ps1 | iex
1
.choco install lein
Congrats! Whether you are a Mac or a PC, you have just made your first true requests, downloads, & installations through your powerful little shell! Pretty cool!
And, I know what you’re probably thinking: coding is really just a bunch of copying & pasting, isn’t it?! Here you thought we did truly special things... I hate to break it to you that your conclusion is not entirely untrue, but I promise, it does get better. In fact, let’s have some fun!
These instructions will also be in your shell.
Start the REPL: lein repl
The REPL is Clojure's free-coding arena. It stands for Read-Eval-Print-Loop. I use it frequently as my trial & error space while I’m working on projects.
Try something like this: (+ 3 3)
Did it return 6?
Now try this: (def hello “Hello, World!”)
and now: hello
Let’s write a function: (defn hello [name] “Hello, ” name “!”)
Call your function: (hello “Gina”)
Set your name: (def my-name “Gina”)
Call your function again with my-name: (hello my-name)
Cool!
The book Programming Clojure by Alex Miller is a part of The Pragmatic Programmer series, and is a very good resource for learning clojure.
This section is to get you setup and acquainted with github as well as to give you resources to learn the language basics of Clojure by way of the Clojure Koans and the practice of Test-Driven-Development (TDD) using the problems from Project Euler.
^d
git --version
brew install git
choco install git
Go ahead and sign up for or sign in into GitHub, so we can fork some stuff!
Forking puts copies of repositories created by others under your own repository. Anything you change in your repository will not affect the master repository, so don’t worry.
At the top right of each page I'm about to direct you to, there will be a button called Fork. That's the button to push when I say "Fork It!"
Let’s get your projects directory set up.
In your shell, note what directory you are in. It’s probably Users/{{user name}}. This is probably a good place, but feel free to select a different location:
The following commands will get you to where you want to go:
ls
cd /name-of-directory/
cd .\name-of-directory\\
cd ..
Once you’re in the directory where you want your projects folder
mkdir projects
cd projects
We need to make local repositories also for you to be able to do your work.
In your projects directory
git clone https://github.com/functional-koans/clojure-koans.git
git clone https://github.com/slagyr/euler.git
Finally, you are going to want a textEditor or IDE. I personally suggest using intelliJ by jetBrains. If you're using it for personal use only, they do offer a free community edition. One note on intelliJ, it does a lot for you! This is great, but you will come to depend on some of the tools and hints that intelliJ offers, which will impede your overall understanding of what you are doing especially while you are a novice. I started with intelliJ, so I’m not saying don’t, just be aware that it does things for you that you might need to understand as you progress in your new hobby/education/career.
There are also editors like SublimeText, TextMate, etc.
For the tasks I've supplied you with, any of those will do. Just save the files properly: .clj
I’ll leave you with that.
I’d walk you through starting & running each of these tools, but my goal today was to help you get over the biggest hurdle: installation of all the pieces and then direction forward. Perhaps in a future piece, we can mock-pair together to knock-out some of these puzzles.
The truth is that learning to code involves a great deal of figuring things out on your own. That being said, it doesn’t mean that you are on your own, so if you do get stuck, remember that you are probably not the first or the only person to have ever gotten stuck at your block. If you've tried everything and still can't get there, look me up; maybe I could help.
One last hint: I highly suggest that you read the READMEs! They will tell you how to run the program and/or the specs/tests.