"No one is harder on a talented person than the person themselves" - Linda Wilkinson ; "Trust your guts and don't follow the herd" ; "Validate direction not destination" ;

September 22, 2012

Learning Ruby - Part I

In continuation with previous post Ruby Getting Started we will look at examples for loop, multiplication tables, File I/O operations. I am referring to Beginning Ruby by Peter Cooper for learning Ruby Programming Syntax

Example program multiple.rb

x = 1;
#Example 1 - Multiplication using 10.times;
puts "From 1 to 10 Multiplication of 5";
10.times do
       a = x*5;
       puts a;
       x = x+1;
end;
#Example 2 - Loop using upto;
puts "From 10 to 20 Multiplication of 5";
1.upto(10) do
       a = x*5;
       puts a;
       x = x+1;
end;
puts "Arrays"
#Example 3 - Arrays list all elements;
arrayA = [1,2,3,4,5];
arrayA.each {|y| puts y};
puts "Array & Strings"
arrayB = [1,2,"One","Two","Three"];
arrayB.each {|y| puts y};
#Example 4 - List the program line by Line;
File.open("d:\multiply.rb").each { |line| puts line }

 
 
Happy Learning!!! 

September 09, 2012

C# Fundamentals


This time is all about fundamentals of C# . Going beyond theoretical basics.

Tip #1 - Why Value Types are stored in Stack and not in Heap
This blog post (The Truth About Value Types) was the answer. It is a recommendation that CLR does on your behalf to store value types in stack. Short Lived storage (value types) live in stack. Long duration (reference types) live in heap

Tip #2 - Garbage Collection process, Phases Involved
Mark, Sweep and Compact. More details refer The Stack Is An Implementation Detail, Part Two

Tip #3 - Abstract Class VS Interfaces
  • Interface - Can define methods but not implement them
  • Abstarct Class - Can define/implement methods/members but cannot instantiate abstract classes
using System;
namespace examplecode
{
    abstract class AClass
    {
        int aMember;
        public void printVal()
        {
            Console.WriteLine("Example AbstractClass");
        }
    }
    interface iTest
    {
        void printValInterface();
    }
    class Program:AClass,iTest
    {
        public void printValInterface()
        {
            Console.WriteLine("Example printValInterface");
        }
        public static void Main()
        {
            Program RunProgram = new Program();
            RunProgram.printVal();
            RunProgram.printValInterface();
            Console.ReadLine();
        }
    }
}
 
Tip #4 - Why multiple inheritance is not supported in .NET
Answer from stackoverflow question (Why is Multiple Inheritance not allowed in Java or C#?) is realistic and impressive. The benefits are too less and adds a lot of complexity to support multiple inheritance.
 
Tip #5 - Disassembly Good Example
 
Couple of MSDN blog posts were very very impressive. A must read for every developer
 
Happy Learning!!!

September 04, 2012

Ruby Getting Started


This post is about learning ruby. Tried it online using rubyfiddle. rubbyfiddle did not work with global variables i.e Variables using $ symbol.

Basic Commands

Very Usual Hello World Example


Dynamic Typing



Global variables didn't work using ruby fiddle. Installed ruby for Windows. Using Interactive Ruby Option under Programs->Ruby tried below examples

While Loop


Next example is trying out for loop. Below is the test file


Start Command Prompt with Ruby. Run the test file


Pretty easy to learn. Looking forward for more interesting posts.

More Reads
Ruby Tutorial with Code Samples
A Wealth Of Ruby Loops And Iterators
Ruby Procs And Lambdas (And The Difference Between Them)
A Unit Testing Framework In 44 Lines Of Ruby


Happy Learning!!!