Tuesday 17 January 2012

Learning A New Programming Language Day 1

Hello and Welcome to my Day 1
Today I started the day by searching in google how can I install the environment and which setups do I need stuff. I found ruby installer for windows in http://rubyinstaller.org/downloads/ When I install it I found a ruby book in pdf format. This is even better to start a journey otherwise I probably now searching for a book.

I started to read the book, I skipped some story parts. (If you are experienced in 2 or more languages you can easily skip these parts) Later if I have time I may read the history, story etc.

Now I'm in Chapter One with the subtitle of (Strings, Numbers, Classes and Objects)
Like most of the programming languages there are some input and output commands. I can see that there are print and puts to print something on screen (I think I won't need them in the future but it's good to know) The first important thing is getting familiar with the syntax. If I can understand the logic and syntax then I jump thru the half way in once.

Now I will list the important parts I read in this book. I normally keep a small sized notebook and I suggest you to do so. It can fit into a pocket, no lines if possible and there should be more than 200 pages. And I write all the critical knowledge into this book with a permanent pen. Reason is simple 20 years ago I wrote my notes with other pens and in a rainy day I lost some of my writings. Since then I allways use permanent pens.

Normally I just read and take notes in the beginning, then I put those notes to their correct places. Unfortunatally not all the books follow my way of learning.

Ruby is case sensitive
Don't need to declare variables before use
Line remarks start with #
Multiline comments start with "=begin" end with "=end" and must be flushed with left margin
=begin
This is a
multiline
comment
=end

Condition Stuff
if (condition) then
do something
end
"if" condition can be in one line

global variables start with $

Class Declaration
Class name should begin with uppercase letter
class ClassName
  def subName(SubParameter)
    @MyName = SubParameter
  end

  def getName
      return @MyName
   end
end

variables starts with @ means instance variable which belongs to a class instance
variables starts with @@ means class variable which belongs to a class itself

mydog = Dog.new
mydog.subName('Fido')

When a class contains a method named initialize this will be automatically called when an object is created using the new method.

Ruby automatically de-stroys objects and reclaims the memory they used when they are no longer referenced in your program.

Inspecting Objects
ObjectName.inspect and p(ObjectName) are the ways to inspect objects - (I will look them later I think they are for debugging related)

Parent - Child / Super - Sub Classes
class Treasure < Thing means Treasure is a sub class of Thing

In a child class there is a keyword like "super" which pass child parameters to parent. and can be used standalone to pass all the parameters or with specific parameters

SET’ Accessor
When you write a set accessor in this way, you must append the = character to the method name, not merely place it somewhere between the method name and the arguments.
So this is correct: def name=( aName ) But this is an error: def name = ( aName )

Strings
Format Strings
%d – decimal number
%f – floating point number
%o – octal number
%p – inspect object
%s – string
%x – hexadecimal number

Now I need to do some work in .NET. See you in next session.

No comments:

Post a Comment