Giter Site home page Giter Site logo

ruby-lecture-intro-what-is-a-program-online-web-sp-000's Introduction

What is a Program?

Objectives:

  • 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.

What's a Program?

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 machine code so that the computer can understand it.

Interpreted vs Compiled

Depending on the programming language you're using, it will either be a compiled language or an interpreted language. 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.

Running a Ruby Program

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.

ruby -v
ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-darwin14]

As an example, to run a Ruby program that was stored in some-program.rb you would simply type: ruby some-program.rb.

Words in a Program

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:

  1. A Ruby keyword, something that's part of the ruby language.
  2. Literal data, things like "Strings" and numbers like 1 or 2.
  3. 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):

Programs are composed of basically three things:
A language's keywords, like 'if' or 'end' (approximately 43).
Literal pieces of data like this very sentence (or String).
Finally, barewords, or variables, that are set equal to things.
Anything that isn't one of those will cause an error.
lib/a_ruby_program.rb:23:in `<main>': undefined local variable or method `see' for main:Object (NameError)

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.

ruby-lecture-intro-what-is-a-program-online-web-sp-000's People

Contributors

annjohn avatar aviflombaum avatar danielseehausen avatar fs-lms-test-bot avatar ahimmelstoss avatar curiositypaths avatar loganhasson avatar maxwellbenton avatar bhollan avatar learn-co-bot avatar lizbur10 avatar matbalez avatar sophiedebenedetto avatar sarogers avatar sgharms avatar fislabstest avatar

Watchers

Mar avatar Kaitlin Vignali avatar Mohawk Greene avatar  avatar Joe Cardarelli avatar  avatar Dr. Chester Ismay avatar  avatar  avatar Matt avatar Alex Griffith avatar  avatar Amanda D'Avria avatar  avatar Ahmed avatar Nicole Kroese  avatar Dominique De León avatar  avatar Vicki Aubin avatar  avatar  avatar Blake Long avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.