what-is-a-program?
Last updated
Last updated
Describe a program.
Distinguish between interpreted and compiled programs.
How to run a Ruby program in your terminal.
List and describe the words that compose code: keywords, barewords, and data.
Identify when and why errors occur in programming.
<iframe width="960" height="720" src="" frameborder="0" allowfullscreen></iframe>
All programs are just files on your computer filled with text. That text has a special syntax we call code. The programming language you're using defines the syntax of the code you are allowed to write. Programs are converted to so that the computer can understand it.
Depending on the programming language you're using, it will either be a or an . Compiled programs will first be converted to machine code and then you will be able to run the program. Interpreted languages will be interpreted and converted to machine code at run time.
Once you have a Ruby program as a file, you can run it through the Ruby interpreter to execute it. Your Ruby interpreter is accessible via the ruby
command in your command line (assuming you have ruby installed correctly).
When you type in ruby -v
you should see the version of Ruby you are currently running.
As an example, to run a Ruby program that was stored in some-program.rb
you would simply type: ruby some-program.rb
.
Every word and character in a program has to be valid code for the Ruby language. Basically, every word can be one of three possible things:
A Ruby keyword, something that's part of the ruby language.
Literal data, things like "Strings" and numbers like 1 or 2.
Barewords you define and create, things like variables and methods.
Anything that isn't one of those is invalid and the Ruby interpreter will throw an error.
Let's say you ran a program, and saw the following output (pay attention to the last line):
That last line, lib/a_ruby_program.rb:23:in '<main>': undefined local variable or method 'see' for main:Object (NameError)
is telling you that there was an error caused by an unrecognized word in the source of our program, more specifically on line 23.
We'll soon learn all about reading error messages.
View on Learn.co and start learning to code for free.