I remember the first time I did a pair programming event and had to use a terminal for the first time... It seemed like a thousand different steps with no real logic. Whatever instructions I was given sounds like: "OK Matt, type 'bash dash m and a plus sign and the words cp dash r and the letter y.'" What is that?
However, it has become so intuitive to me now. Whenever I create a program, it is second nature to me to "subble" it (subl programname.rb or .js or .html whatever it is). In fact, my friend and I were working on a small side project this weekend in HTML and CSS. He's a very skilled programmer who learned HTML, CSS, and JavaScript through Free Code Camp. I highly admire FCC, but they teach you nothing about how to use the terminal. I was able to teach him a lot of what I've learned.
While it's cool to manipulate files and seem like a genius doing it, I must admit there is much for me to learn. I am nearing the end the Zed Shaw's Learn Ruby the Hard Way and I made it to exercise #50. The goal was to create a simple "Hello, World!" web application. I made the application and ran it with the ruby command in the terminal. My intuition, from doing mathematics, is to break it down. So I change directory (cd) all the way down to the specific file. While the program ran without a flaw, Zed was one step ahead of me (and probably a lot of other aspiring developers) and pointed out the mistake.
When you run something in the terminal, you need to run everything from the top down. My program worked because it simply did not have any other dependencies. Whenever it does have dependencies, you need to specify to run the program within a directory rather than changing the directory the computer is looking at. Whenever you use the cd command into a directory, that directory is like the computer's whole world at that moment. To illustrate, I will show you a tinker project I came up with. I tinker in order to understand truly what's going on under the hood of anything, including a computer! Keep in mind, I'm writing these commands for the Mac.
mkdir Tinkering
cd Tinkering
mkdir TinkerOne TinkerTwo
cd TinkerOne
subl tinker_requirement.rb
inside tinker_requirement.rb:
class Tinker
def Tinker.test
puts "See you need to run from within the parent directory!"
end
end
(Command + S to save)
in the terminal again:
cd
cd Tinkering
subl tinker_test.rb
inside tinker_test.rb:
require './TinkerOne/tinker_requirement'
Tinker.test
(Save)
Now, if you know ruby, you know you have one program that contains a class with the method called ".test" that will print the string above. Whenever I run the program tinker_test.rb, it calls the class and method from tinker_requirement.rb to print that string into my terminal. Now try this
cd Tinkering/TinkerTwo
ruby tinker_two
You'll get a "cannot load such file" error meaning the computer doesn't know what file you're referring to in the require statement. Therefore the class and the class method cannot be executed. However back out:
cd
cd Tinkering
ruby TinkerTwo/tinker_two.rb
What do you get? You get the string defined in the method of the class Tinker.
"See you need to run from within the parent directory!"
Hope this helps! I still have a lot to learn, but teaching helps one learn faster!
Matt
No comments:
Post a Comment