Jump to content
xisto Community
Sign in to follow this  
DeM0nFiRe

The Basics Of Object Oriented Programming [lesson 1] Introduction; Installing Ruby; Ruby Basics

Recommended Posts

Hello everyone! I am hear to teach YOU GUYS how to do some computer programming! I did a search and I didn't really see any tutorials here about programming in general, only about how to do specific things. I am going to give you guys a crash course in:

 

The Basics of Object Oriented Programming

[Lesson 1] Tutorial by DeM0nFiRe

 

What is "Object Oriented Programming"?

Well, by now I am sure you know that programming is like writing the instructions for telling the computer what to do. When people started programming, each instruction was written one after another and the computer would just run each instruction down the line one at a time. This works fine, but it can get pretty hard to keep track of your programs flow, and it can get pretty annoying when you are trying to debug and you have to look through unorganized code. For this reason, Object Oriented Programming was created. Object Oriented Programming means exactly what it looks like it means. It is programming that focuses on the creation and control of objects. By breaking up the code into smaller pieces like that, it becomes easier for the programmer to keep track of his or her code and it makes diagnosing errors a whole lot easier.

 

What is an "Object"?

Now, I know in some cases programming can take on term that you already know and make it mean something else, but this is not one of those cases. An Object in programming is just like an object in like an object in the real world. It has characteristics (These are stored in something called Variables) and it has behaviors (And these behaviors are controlled with Methods) I will give you more information about what an object is and how you will use them in a later lesson.

 

Choosing a Language

As I am sure you already know, there are many many different programming languages to choose from. Java, C, C++, PHP, C# just to name some of the more popular ones. Even just choosing a language can be difficult, you have to be able to figure out what the pros and cons are of each language. Now, towards the end of the set of lessons I will go more in depth on different languages and what their pros and cons are, but for the bulk of this tutorial, we will be working with Ruby. I choose Ruby for this because it is very easy to understand what is going on just by looking at it. For instance, to print "Hello" the code is:

 

print "Hello"

I choose Ruby because it will create very few extra troubles for the beginner learning to program.

 

Installing the Ruby Programming Language

*Please note this will instruct you only on how to install Ruby on Windows. If you are on Linux, chances are you can figure out where you need to deviate from my instructions to install it :) *

The first step is to go to the Ruby Download Page. Once you are there, scroll down the site until you see the heading "Ruby for windows". Underneath that heading you will see "Ruby 1.8.6 One-Click Installer" Download that, run it, and follow the instructions to install it like you would any other program.

 

Your first piece of code

Alright, so now that we have that boring stuff out of the way, let's try out some code! Create a new file and name it lesson1.rb

Inside that file paste the following code:

 

print "Hello there! What is your name?"name = gets.chompprint "Really?!? No way, your name can't be " + name

Double click the file to run it, and see what happens!

 

Why does the code do that?

Ok, let's run through that one line by line. The first line is very simple. It prints out "Hello there! What is your name?" The next line is a bit more complicated (and incidentally, cooler as well :) ) the function gets will read a line from the keyboard. Now, a line will include "\n" which tells the computer to end the line and go down to the next line. We don't want that to happen to we will use chomp. chomp will remove that extra bit for us. the name = part takes the line we got from the keyboard and puts it in a variable called name. A variable, for now, we will say is just something that holds information. The last line will do exactly what it looks like, it will print out "Really?!? No way, your name can't be " and the name that we got from the keyboard the line before.

 

 

 

Alright guys, this should get you started! Keep watching for the next lesson and we'll get into some more cool programming stuff! :D

 

Lesson 2 Can be found here: http://forums.xisto.com/topic/63560-the-basics-of-object-oriented-programming-lesson-2-introduction-to-variables/

Edited by DeM0nFiRe (see edit history)

Share this post


Link to post
Share on other sites

But can i ask, when you say "ruby" do you mean "ruby on rails"? because i never heard of Ruby per say

Ruby and RoR are two different things, though RoR uses Ruby at its core. RoR is really for web development, Ruby is best at desktop application development. Think of Ruby like Python but with its own syntax and philosophies.

Share this post


Link to post
Share on other sites

Yup i also had the same doubt that RUBY and ROR are same or not :PThanx for clearing it up and can you provide me with an e-book on ruby because i am really eager to learn this language

Share this post


Link to post
Share on other sites

Yup i also had the same doubt that RUBY and ROR are same or not :P
Thanx for clearing it up and can you provide me with an e-book on ruby because I am really eager to learn this language


I wouldn't be able to recommend to you a good e-book because I've never found e-books very helpful. The way I learned was to just look at a working game engine that used Ruby as a scripting language XD


I have written lesson 2, and I am just waiting for a moderator to approve it.

Share this post


Link to post
Share on other sites

I may in the future, but this tutorial set is for learning Object Oriented Programming and Ruby is the easiest one to understand so I will be using this. If you want a C++ tutorial, I recommend looking at http://www.cplusplus.com/doc/tutorial/

It's very good tutorial, although you may have to look up answers to some specific questions elsewhere.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.