For some reason , i have seen most find C/C++ pointer arithmatic bit convoluted. It takes some time to get used to it. if you take a step back and look at it , it is not as difficult as it is widely percieved.
C/C++'s Pointer semantics is a successful abstraction of an ideal memory model.
When we (programmers) use Pointers , there is an implicit machine model against which one is programming. The programmer thinks only about that. It is the duty of the compiler to map the model into a physical machine's memory architecture. Not only he has to map the stuff ...it has to guarantee a linear byte array mental model of the programmer
Take the case of a function like strlen ...
int StrLen( char *p )
{
if ( p == 0 ) { return -1; }
int n=0;
while (*p != 0 ) { p++; n++; }
return n;
}
In the above code , the programmer expects memory to be laid out in a linear byte array. At least there is an implicit contract with the developer that ..above code will work in any platform regardless of the machine architecture.
int StrLen( char *p )
{
if ( p == 0 ) { return -1; }
char *temp = p;
while (*p != 0 ) { p++; }
return p-temp;
}
Only a compiler which can guarantee the correctness of the above program is a ANSI C/C++ compiler. So, compiler has to choose a code generation mechanism which generates the code in
a particular way. Despite that , C/C++ runs in all the platforms in the world.. It even runs on
.NET as C++/CLI !!
Tuesday, September 29, 2009
Wednesday, September 23, 2009
Some useful code in C# - Part 2
I had posted some C# programs written by my wife . The reason for those code was to learn more about Bit level programming. One of my friend pointed out couple of mistakes in the code and i passed on the message to her. Here is the result of that
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace BitManipulation2
{
public class BitUtils
{
///
///
///
///
///
public static string ConvertIntToBit(int x)
{
int y = x;
string n = "";
while (y != 0)
{
if (y % 2 == 0)
n = '0' + n;
else
n = '1'+ n;
y = y >> 1;
}
return n;
}
///
///
///
///
///
public static int ConvertBitToInt(string x)
{
int z = x.Length-1;
int i = 0;
int n = 0;
int y = 0;
for (; i <= z; i++ )
{
if (x[i] == '0')
y = 0;
else if (x[i] == '1')
y = 1;
n = (y * (int)Math.Pow(2, i)) + n;
}
return n;
}
///
///
///
///
///
public static string ConvertIntToHex(int x)
{
int y = x;
string z = "";
while (y != 0)
{
int a = y % 16;
if (a >= 0 && a <= 9)
z = a + z;
else
{
int c = a - 10;
char b = Convert.ToChar( 'A' +c);
z = b + z;
}
y = y >> 4;
}
return z;
}
public static int ConvertHexToInt(string x)
{
int n = 0;
int z = 0;
int i = x.Length-1;
foreach (char y in x )
{
if (y >= '0' && y <= '9')
n = y - '0';
else if (y >= 'A' && y <= 'F')
n = 10 + (y - 'A');
z = (int)((n*Math.Pow(16, i)) + z);
i--;
}
return z;
}
/////////////////
//
// Test driver program
static void Main(string[] args)
{
string z = BitUtils.ConvertIntToBit(32);
Console.WriteLine(z);
int a = BitUtils.ConvertBitToInt("1001");
Console.WriteLine(a);
string x = BitUtils.ConvertIntToHex(365);
Console.WriteLine(x);
int b = BitUtils.ConvertHexToInt("A5");
Console.WriteLine(b);
Console.Read();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace BitManipulation2
{
public class BitUtils
{
///
///
///
///
///
public static string ConvertIntToBit(int x)
{
int y = x;
string n = "";
while (y != 0)
{
if (y % 2 == 0)
n = '0' + n;
else
n = '1'+ n;
y = y >> 1;
}
return n;
}
///
///
///
///
///
public static int ConvertBitToInt(string x)
{
int z = x.Length-1;
int i = 0;
int n = 0;
int y = 0;
for (; i <= z; i++ )
{
if (x[i] == '0')
y = 0;
else if (x[i] == '1')
y = 1;
n = (y * (int)Math.Pow(2, i)) + n;
}
return n;
}
///
///
///
///
///
public static string ConvertIntToHex(int x)
{
int y = x;
string z = "";
while (y != 0)
{
int a = y % 16;
if (a >= 0 && a <= 9)
z = a + z;
else
{
int c = a - 10;
char b = Convert.ToChar( 'A' +c);
z = b + z;
}
y = y >> 4;
}
return z;
}
public static int ConvertHexToInt(string x)
{
int n = 0;
int z = 0;
int i = x.Length-1;
foreach (char y in x )
{
if (y >= '0' && y <= '9')
n = y - '0';
else if (y >= 'A' && y <= 'F')
n = 10 + (y - 'A');
z = (int)((n*Math.Pow(16, i)) + z);
i--;
}
return z;
}
/////////////////
//
// Test driver program
static void Main(string[] args)
{
string z = BitUtils.ConvertIntToBit(32);
Console.WriteLine(z);
int a = BitUtils.ConvertBitToInt("1001");
Console.WriteLine(a);
string x = BitUtils.ConvertIntToHex(365);
Console.WriteLine(x);
int b = BitUtils.ConvertHexToInt("A5");
Console.WriteLine(b);
Console.Read();
}
}
}
Labels:
Software(.NET)
| Reactions: |
Exception handling in Harbour Development system
The Clipper Programming Language had structured Exception handling long before C++ had it part of the ANSI standard. I remember coding MS given TRY ...CATCH(e) macro (which was using setjmp/longjmp ) in my Visual C++ 4.2 programs.
The syntax of the Clipper Exception handling was as follows
BEGIN SEQUENCE ( TRY )
if ( < Some error Condition > )
Break < errorcode >
END IF
RECOVER USING < errorcode >(Catch ( Exception e ) )
//--- do the error processing
END SEQUENCE
Given below is a sample Clipper program which will throw an exception using Break statement. The Handler calls Qout ..to print the error code to the console.
//////////////////////////////
//
// Program to demonstrate Exception handling
//
// SEH.prg
FUNCTION MAIN()
BEGIN SEQUENCE
//------- have some code here
Break 20 // i am throwing an exception
RECOVER USING a
Qout(a) // i got the error code in a
END SEQUENCE
return nil
The syntax of the Clipper Exception handling was as follows
BEGIN SEQUENCE ( TRY )
Break < errorcode >
END IF
RECOVER USING < errorcode >
END SEQUENCE
Given below is a sample Clipper program which will throw an exception using Break statement. The Handler calls Qout ..to print the error code to the console.
//////////////////////////////
//
// Program to demonstrate Exception handling
//
// SEH.prg
FUNCTION MAIN()
BEGIN SEQUENCE
//------- have some code here
Break 20 // i am throwing an exception
RECOVER USING a
Qout(a) // i got the error code in a
END SEQUENCE
return nil
Labels:
Clipper Nostalgia
| Reactions: |
Code Block
The Clipper language had a nifty feature called Code Blocks . using Code Blocks , we can pass a piece of Code as a parameter to the function. The example given below demonstrates the use of Code Blocks
//////////////////////////////////
////Program to demonstrate Code blocks
////
//
Function MAIN()
LOCAL a; // Declare a local variable
//--------- initialize an array
a := {'PRASEED', 'PRAVEEN', 'SANDEEP','BINOJ'}
//------- Iterate the array ..evaluate the code block
//-------- The stuff is similar to C# Lambda
AEVAL(a, { | asingle | QOUT(asingle) } )
return;
Compile using the Harbour compiler and see the result for yourself.
//////////////////////////////////
////Program to demonstrate Code blocks
////
//
Function MAIN()
LOCAL a; // Declare a local variable
//--------- initialize an array
a := {'PRASEED', 'PRAVEEN', 'SANDEEP','BINOJ'}
//------- Iterate the array ..evaluate the code block
//-------- The stuff is similar to C# Lambda
AEVAL(a, { | asingle | QOUT(asingle) } )
return;
Compile using the Harbour compiler and see the result for yourself.
Labels:
Clipper Nostalgia
| Reactions: |
Return of the Clipper Language
I started my programming career with CA-Clipper. I started with their Summer 87 release. In retrospect, the Clipper system was far ahead of it's time. I was interfacing Clipper and C/C++ a lot to do graphics programming , Serial communication and Data Compression to name a few. I did use Turbo Assembler as well. The reason for getting advanced was a then famous book written by Rick Spence. I had the book's version written for Clipper summer 87,Clipper 5.1 and Clipper 5.2.
After downloading the Harbour Compiler , I wrote a Hello World program today.
// Program to Spit Hello World to the console
// Written by Praseed Pai
/// ( http://praseedp.blogspot.com )
////
function Main()
PRINT "Hello world!"
return nil
I keyed in the above program to a file ( First.prg ). After compilation and linking , i got the output. The Harbour compiler emits C code and we need to have a C/C++ compiler available in the system to compile the generated C program and link it. I am using a version intended for
Visual studio 2008. They have a batch file for automating the stuff. ( bld_vc.bat )
After downloading the Harbour Compiler , I wrote a Hello World program today.
// Program to Spit Hello World to the console
// Written by Praseed Pai
/// ( http://praseedp.blogspot.com )
////
function Main()
PRINT "Hello world!"
return nil
I keyed in the above program to a file ( First.prg ). After compilation and linking , i got the output. The Harbour compiler emits C code and we need to have a C/C++ compiler available in the system to compile the generated C program and link it. I am using a version intended for
Visual studio 2008. They have a batch file for automating the stuff. ( bld_vc.bat )
Labels:
Clipper Nostalgia
| Reactions: |
A wonderful speech
Alain de Botton is a philosopher who is famous for his book , The Consolations of Philosophy . It chronichles the life of some noted western philosophers. He made
a spirited presentation at TED 2009. I have already blogged about his other works some time back. I was revisiting his work for the preperation of a BarCamp presentation.
a spirited presentation at TED 2009. I have already blogged about his other works some time back. I was revisiting his work for the preperation of a BarCamp presentation.
Labels:
BarCamp,
Philosophy
| Reactions: |
Tuesday, September 22, 2009
Some useful code in C#
To get a grip on Binary numbers and Hexadecimal numbers , my wife wrote couple of programs today. I thought , it will be useful for some one out there. The Programs are not meant to be efficient. It has been written with learning in mind.
Note :- Since i do not know how to esacpe Pipe character...i have converted the code into ifmodel of coding... ( The code contain some minor errors and has been superceded by the following post... available here )
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace BitManipulation
{
public class BitUtils
{
///
///
///
///
///
public static string ConvertIntToBit(int x)
{
int y = x;
string n = "";
while (y != 0)
{
if (y % 2 == 0)
n = n + "0";
else
n = n + "1";
y = y >> 1;
}
return n;
}
///
///
///
///
///
public static bool isBitString(string x)
{
foreach (char y in x)
{
if (y == '1')
continue;
else if (y == '0')
continue;
return false;
}
return true;
}
///
///
///
///
///
public static int ConvertBitToInt(string x)
{
int z = 0;
int a = 0;
int i = (x.Length-1);
foreach (char y in x)
{
if (y == '1')
{
z = 1;
}
else if (y == '0')
{
z = 0;
}
a = a +( z*(int)Math.Pow(2, i));
i--;
}
return a;
}
///
///
///
///
///
public static string ConvertIntToHex(int x)
{
int y = x;
string n = "";
while (y != 0)
{
int a = y %16;
if ((a >= 0) && a <= 9) { n = a.ToString()+n; } else { switch (a) { case 10: n = "A"+n; break; case 11: n = "B"+n; break; case 12: n = "C"+n; break; case 13 : n = "D"+n; break; case 14: n = "E"+n; break; case 15: n = "F"+n; break; } } y = y >> 4;
}
return (n);
}
///
///
///
///
///
public static string StringReverse(string x)
{
string a = "";
foreach (char y in x)
{
a = y + a;
}
return a;
}
///
///
///
///
///
public static bool IsHexString(string x)
{
foreach (char y in x)
{
if ((y >= '0' && y <= '9')) { continue; } else if ( (y >= 'A' && y <= 'F')) continue; return false; } return true; } public static int ConvertHexToInt(string x) { int z=0; int a = 0; int i = x.Length-1; foreach (char y in x.ToCharArray() ) { if (y >= '0' && y <= '9') { z = y-'0'; } else if (y >= 'A' && y <= 'F')
{
z = 15-('F' - y) ;
}
a = a+((z*(int)Math.Pow(16, i))) ;
i--;
}
return a;
}
static void Main(string[] args)
{
string s = "65";
int x = Int32.Parse(s);
string a=BitUtils.ConvertIntToBit(x);
Console.WriteLine(a);
if (BitUtils.isBitString("101001"))
{
Console.WriteLine("Valid bit string");
}
int z = BitUtils.ConvertBitToInt("1001");
Console.WriteLine(z);
string c = BitUtils.ConvertIntToHex(65);
Console.WriteLine(c);
if (BitUtils.IsHexString("FFFG"))
{
Console.Write("Valid HexaDecimal");
}
int y = BitUtils.ConvertHexToInt("FF");
Console.WriteLine(y);
Console.Read();
}
}
}
Note :- Since i do not know how to esacpe Pipe character...i have converted the code into if
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace BitManipulation
{
public class BitUtils
{
///
///
///
///
///
public static string ConvertIntToBit(int x)
{
int y = x;
string n = "";
while (y != 0)
{
if (y % 2 == 0)
n = n + "0";
else
n = n + "1";
y = y >> 1;
}
return n;
}
///
///
///
///
///
public static bool isBitString(string x)
{
foreach (char y in x)
{
if (y == '1')
continue;
else if (y == '0')
continue;
return false;
}
return true;
}
///
///
///
///
///
public static int ConvertBitToInt(string x)
{
int z = 0;
int a = 0;
int i = (x.Length-1);
foreach (char y in x)
{
if (y == '1')
{
z = 1;
}
else if (y == '0')
{
z = 0;
}
a = a +( z*(int)Math.Pow(2, i));
i--;
}
return a;
}
///
///
///
///
///
public static string ConvertIntToHex(int x)
{
int y = x;
string n = "";
while (y != 0)
{
int a = y %16;
if ((a >= 0) && a <= 9) { n = a.ToString()+n; } else { switch (a) { case 10: n = "A"+n; break; case 11: n = "B"+n; break; case 12: n = "C"+n; break; case 13 : n = "D"+n; break; case 14: n = "E"+n; break; case 15: n = "F"+n; break; } } y = y >> 4;
}
return (n);
}
///
///
///
///
///
public static string StringReverse(string x)
{
string a = "";
foreach (char y in x)
{
a = y + a;
}
return a;
}
///
///
///
///
///
public static bool IsHexString(string x)
{
foreach (char y in x)
{
if ((y >= '0' && y <= '9')) { continue; } else if ( (y >= 'A' && y <= 'F')) continue; return false; } return true; } public static int ConvertHexToInt(string x) { int z=0; int a = 0; int i = x.Length-1; foreach (char y in x.ToCharArray() ) { if (y >= '0' && y <= '9') { z = y-'0'; } else if (y >= 'A' && y <= 'F')
{
z = 15-('F' - y) ;
}
a = a+((z*(int)Math.Pow(16, i))) ;
i--;
}
return a;
}
static void Main(string[] args)
{
string s = "65";
int x = Int32.Parse(s);
string a=BitUtils.ConvertIntToBit(x);
Console.WriteLine(a);
if (BitUtils.isBitString("101001"))
{
Console.WriteLine("Valid bit string");
}
int z = BitUtils.ConvertBitToInt("1001");
Console.WriteLine(z);
string c = BitUtils.ConvertIntToHex(65);
Console.WriteLine(c);
if (BitUtils.IsHexString("FFFG"))
{
Console.Write("Valid HexaDecimal");
}
int y = BitUtils.ConvertHexToInt("FF");
Console.WriteLine(y);
Console.Read();
}
}
}
Labels:
Software(.NET)
| Reactions: |
Monday, September 21, 2009
Controversy
The controversial (??) Sister Abhaya Murder case is in the news once again. This time on the way CBI has conducted Narco Analysis test and subsequent leakage of tapes to the media.
Prem => "Now , there is ample proof that two preists and a nun are responsible for the murder."
Guruji => "That was known way back in 1992..."
Prem =>"Then , why did not poped up then...?"
Guruji =>"The culprits were so powerful that , they knew lot of misdeeds of their superiors...To save the name of the instituition and to save themselves , their superiors are also helping them to cover up the misdeed.."
Prem =>"Why then political parties did not take up the challenge ?"
Guruji =>"Prem , Are u mad ? A political party who talks against the church will
be branded as fascist , anti christian and church people will make it's followers to vote against them.."
Guruji =>"Any way , this case is making people literate ..in kerala "
Prem =>"How...?"
Guruji => "In the media , Lawyers and Politicians are talking about human rights...and various angles of it."
Guruji =>"There were programs in channels about the Narco Analysis tests..and the science ,history and methodology of it.."
Guruji =>"The scene of Narco Analysis test itself will prevent future crimes from happening ...!!.. That is the biggest advantage of this controversy.. Now , people will think twice before comitting any crime.."
Prem => "Now , there is ample proof that two preists and a nun are responsible for the murder."
Guruji => "That was known way back in 1992..."
Prem =>"Then , why did not poped up then...?"
Guruji =>"The culprits were so powerful that , they knew lot of misdeeds of their superiors...To save the name of the instituition and to save themselves , their superiors are also helping them to cover up the misdeed.."
Prem =>"Why then political parties did not take up the challenge ?"
Guruji =>"Prem , Are u mad ? A political party who talks against the church will
be branded as fascist , anti christian and church people will make it's followers to vote against them.."
Guruji =>"Any way , this case is making people literate ..in kerala "
Prem =>"How...?"
Guruji => "In the media , Lawyers and Politicians are talking about human rights...and various angles of it."
Guruji =>"There were programs in channels about the Narco Analysis tests..and the science ,history and methodology of it.."
Guruji =>"The scene of Narco Analysis test itself will prevent future crimes from happening ...!!.. That is the biggest advantage of this controversy.. Now , people will think twice before comitting any crime.."
Labels:
Prem and Tilak
| Reactions: |
Self Study
Prem and Tilak were respectful of the Guruji, for learning nuances of Programming by referring books.
Prem => "Guruji is a remarkable character .."
Tilak =>"It depends ....."
Prem =>"Why did u say so ?"
Tilak =>"He is rusty in electronics and electrical stuff..."
Prem =>"Let us go and ask him about that..."
Together they barged on to the Guruji's place.
Prem =>"Guruji , how come you're wise in programming and not so wise in electronics stuff ..."
Guruji =>"Reason is simple ...Had I experimented ( by trial and error ) with electronics and electrical stuff the way I did with Programming ...i would have long gone from this universe..."
Prem => "Guruji is a remarkable character .."
Tilak =>"It depends ....."
Prem =>"Why did u say so ?"
Tilak =>"He is rusty in electronics and electrical stuff..."
Prem =>"Let us go and ask him about that..."
Together they barged on to the Guruji's place.
Prem =>"Guruji , how come you're wise in programming and not so wise in electronics stuff ..."
Guruji =>"Reason is simple ...Had I experimented ( by trial and error ) with electronics and electrical stuff the way I did with Programming ...i would have long gone from this universe..."
Labels:
Prem and Tilak
| Reactions: |
Sunday, September 20, 2009
Design Patterns for Dummies
To my surprise , Design Patterns for Dummies seems to be one of the best book on Design patterns. Even though the code is in JAVA , i could help one to transliterate the code into C# without much ado. One of the nice things which a C# developer is fortunate is the presence of large amount of Java Code samples. Porting them into C# is not that difficult ...in that process one learns a lot about the stuff in question. Writing Java code from the book will result in blind copying. We are conscious when we do port into another language.
Labels:
Software(.NET)
| Reactions: |
It is SEPTEMBER...!!
Prem visited Tilak's home one day and were discussing various things which often does not concern them. Tilak's nephew who is a primary school student ran away to the playground alone and his mother was worried about it.
Tilak => "I think there is no need to worry ..as kids has to learn to do everything themselves.."
MOM =>"Now the month is september , the dogs are mad.... "
Tilak =>"Prem , Why did she say so ?"
Prem => "Now it is the mating season for the dogs "
Tilak => "when they are busy , will they bother about a kid ...?"
Prem =>"Unlike humans , there is no marriage among dogs ...a dog which does not get
a mate will go mad...so, it is the time of mad dogs too..."
Tilak => "I think there is no need to worry ..as kids has to learn to do everything themselves.."
MOM =>"Now the month is september , the dogs are mad.... "
Tilak =>"Prem , Why did she say so ?"
Prem => "Now it is the mating season for the dogs "
Tilak => "when they are busy , will they bother about a kid ...?"
Prem =>"Unlike humans , there is no marriage among dogs ...a dog which does not get
a mate will go mad...so, it is the time of mad dogs too..."
Labels:
Prem and Tilak
| Reactions: |
Thursday, September 17, 2009
Outliers - Read that Book
Malcom Gladwell's Outliers is a good book to have in the personal collection of any serious person. It will help you to think in new ways in matters which are dear to our life. The substitle of the book is "The Story of Success". As per the author , We are too much obsessed with attributing invidividual talent as a (sole ) reason for the success of any person. We ignore the environmental factors , place and time of his birth and the surrounding contexts. This book will help you to take a look in that direction. In a way, you will get answers for the questions which has puzzled you for long. I studied the book in connection with my presentation at a BarCamp.
| Reactions: |
How To retrieve the table names and it's metadata in SQL server
To find out the list of tables in your current database ( In MS SQL )
select column_name, data_type, ordinal_position
from information_schema.columns
To retrieve the structure of a table in your current database
select column_name, data_type, ordinal_position
from information_schema.columns
where table_name = 'TableName'
select column_name, data_type, ordinal_position
from information_schema.columns
To retrieve the structure of a table in your current database
select column_name, data_type, ordinal_position
from information_schema.columns
where table_name = 'TableName'
Labels:
SQL
| Reactions: |
A SQL Query
With the some help from me , my wife is writing an Accounting and Inventory software for my brother's pyrotechnic shop. To Print the trial balance , she wrote a query which went as follows
select fas.s_desc,total from
( select j_code , sum(j_amount) as total from JournalDetail where j_drcr = 'DR'
group by j_code
union all
select j_code , sum(-j_amount) as total from JournalDetail where j_drcr = 'CR' group
by j_code ) jtd , FaSubGroup fas where fas.s_code = jtd.j_code
What essentially done here is she is aggregating all the Debit accounts and Credit Accounts .
The reason union all is used because an account can appear in the debit side in some transactions and it can be on the credit side in some other .
Later , by consulting a friend of mine ..we reduced the query to some thing like this
select pas.s_desc,total from (
select j_code ,sum( case j_drcr when 'DR' then j_amount else -j_amount end) as total
from JournalDetail group by j_code) test , FaSubgroup pas where test.j_code = pas.s_code;
I could eliminate the union clause thanks to case When construct.
select fas.s_desc,total from
( select j_code , sum(j_amount) as total from JournalDetail where j_drcr = 'DR'
group by j_code
union all
select j_code , sum(-j_amount) as total from JournalDetail where j_drcr = 'CR' group
by j_code ) jtd , FaSubGroup fas where fas.s_code = jtd.j_code
What essentially done here is she is aggregating all the Debit accounts and Credit Accounts .
The reason union all is used because an account can appear in the debit side in some transactions and it can be on the credit side in some other .
Later , by consulting a friend of mine ..we reduced the query to some thing like this
select pas.s_desc,total from (
select j_code ,sum( case j_drcr when 'DR' then j_amount else -j_amount end) as total
from JournalDetail group by j_code) test , FaSubgroup pas where test.j_code = pas.s_code;
I could eliminate the union clause thanks to case When construct.
Labels:
SQL
| Reactions: |
Wednesday, September 16, 2009
BarCamp Kerala 6 announced
The Rajagiri College of Engineering will be the venue for the next edition of BarCamp Kerala. Barcamp is an event where techies ( and not so techies ) will assemble and discuss about matters concering our lives(with emphasis on science ,techonology and social issues). I have attended BarCamp kerala 3 (held at CUSAT ) and BarCamp kerala 5 ( held at Technopark , Trivandrum ). We get to know and meet some cool people who has some real stuff between their ears.
Orielly Publishing hosts an event to invite a (chosen ) group of technology gurus and named them Friends Of Orielly ( FOO ). Or it was a FOO (conference) camp.
FOO and BAR are meta syntatic variables used to explain programming idioms ( as in
suppose there is a function called FOO and a parameter called BAR then ... stuff ).
So , A group of enthusiasts started BarCamp. They call it unconferencing.
You can register at
http://www.barcampkerala.org/blog/register/
The List of sessions can be found @
http://www.barcampkerala.org/blog/sessions/
Orielly Publishing hosts an event to invite a (chosen ) group of technology gurus and named them Friends Of Orielly ( FOO ). Or it was a FOO (conference) camp.
FOO and BAR are meta syntatic variables used to explain programming idioms ( as in
suppose there is a function called FOO and a parameter called BAR then ... stuff ).
So , A group of enthusiasts started BarCamp. They call it unconferencing.
You can register at
http://www.barcampkerala.org/blog/register/
The List of sessions can be found @
http://www.barcampkerala.org/blog/sessions/
Labels:
BarCamp
| Reactions: |
Bill vs Stall
Being an Open source aficionado , Prem is always critical of any thing Microsoft. One day , Prem visited Tilak and they were chit chatting on various issues...
Prem :- "MS is making people do the testing for them..."
Tilak :- "They say Software is beta quality ..r8 ?"
Prem :- "Bill Gates will Bill us Billions of Times over without a Bill"
Tilak - "Ya , ur right.As much as STALLMAN is stalling our progress without a STALL"
Prem :- "MS is making people do the testing for them..."
Tilak :- "They say Software is beta quality ..r8 ?"
Prem :- "Bill Gates will Bill us Billions of Times over without a Bill"
Tilak - "Ya , ur right.As much as STALLMAN is stalling our progress without a STALL"
Labels:
Prem and Tilak
| Reactions: |
Tuesday, September 15, 2009
Chandrayan - A chinese angle
ISRO people were very jubilant when the chandrayan ( mission to the moon ) was successfully launched . Being from Trivandrum , Tilak was proud about the project.
Tilak :- "After this Project , we are going to be like NASA ..."
Prem :- "I think ,it is already a NASA ..."
Tilak :- "Why did u say so ? "
Prem :- "NASA - Nairs Aero Space Academy ...All the Trivandrum Nairs are there "
Tilak :- "You are offending Trivandrum Nairs.....a typical outsiders mentallity .."
Prem :- "any way project bumped...u know the reason ?"
Tilak :- "???"
Prem :- "They used lot of Open Source Software into the mission software..."
Tilak :- "So,What ?"
Prem :- "Since chinese are really active in the OSS movement , the OSS software has started to be like Chinese Goods... Software cracked after couple of months..so the mission failed...!"
Tilak :- "After this Project , we are going to be like NASA ..."
Prem :- "I think ,it is already a NASA ..."
Tilak :- "Why did u say so ? "
Prem :- "NASA - Nairs Aero Space Academy ...All the Trivandrum Nairs are there "
Tilak :- "You are offending Trivandrum Nairs.....a typical outsiders mentallity .."
Prem :- "any way project bumped...u know the reason ?"
Tilak :- "???"
Prem :- "They used lot of Open Source Software into the mission software..."
Tilak :- "So,What ?"
Prem :- "Since chinese are really active in the OSS movement , the OSS software has started to be like Chinese Goods... Software cracked after couple of months..so the mission failed...!"
Labels:
Prem and Tilak
| Reactions: |
Substract vs Subtract
In my previous blog post , i was referring about Subtraction ( or Substraction ). Any way , i was teaching my kid to deduct a number from another. Today morning , when i was revisiting his book , i saw Subtract being used. I was using Substract. Which one is correct ? It seems , both can be used.... any pundits who can share their thought ?
Labels:
Ways of Life
| Reactions: |
Teaching To Subtract
Today , i wrestled with my kid to make him subtract two numbers. The teachers in his school are using a procedural method (with elaborate rituals ) for that. The process was unknown to me and i tried our conventional method on him.. Even though I lost my patience , I still persisted with it. Finally , my wife came out of the kitchen and within a matter of minute he could subtract well. So, be careful , For teaching kids u need to learn a Lingo familiar to them ( Each school will have their own method ..! ).
Labels:
Ways of Life
| Reactions: |
Saturday, September 12, 2009
Russian Multiplication in C#
Russian Peasent Multiplication is an algorithm which can be used to multiply two numbers. Here is an implementation in C# ( The program was written by my wife to teach my brother in law ).
using System;
class Russian {
public static void Main( String [] args )
{
if ( args.Length != 2 ) {
Console.WriteLine("Usage Russian <a> <b> ");
return;
}
try {
int x = Convert.ToInt32(args[0]);
int y = Convert.ToInt32(args[1]);
if ( x < 0 || y < 0 ) {
Console.WriteLine("The values should be positive");
return;
}
long z = Calc( x , y );
Console.WriteLine("Product is " + z.ToString() );
}
catch( Exception e )
{
Console.WriteLine(e.ToString());
}
}
public static long Calc(int x,int y) {
int a = x; int b = y; long sum = 0;
while(a >= 1) {
if( a % 2 !=0)
sum = sum+b;
a = a >> 1;
b = b<<1;
}
return sum;
}
}
using System;
class Russian {
public static void Main( String [] args )
{
if ( args.Length != 2 ) {
Console.WriteLine("Usage Russian <a> <b> ");
return;
}
try {
int x = Convert.ToInt32(args[0]);
int y = Convert.ToInt32(args[1]);
if ( x < 0 || y < 0 ) {
Console.WriteLine("The values should be positive");
return;
}
long z = Calc( x , y );
Console.WriteLine("Product is " + z.ToString() );
}
catch( Exception e )
{
Console.WriteLine(e.ToString());
}
}
public static long Calc(int x,int y) {
int a = x; int b = y; long sum = 0;
while(a >= 1) {
if( a % 2 !=0)
sum = sum+b;
a = a >> 1;
b = b<<1;
}
return sum;
}
}
Labels:
Software(.NET)
| Reactions: |
An Example of XML
I was explaining XML to a friend of mine. As an example to demonstrate XmlDocument class in the System.XML namespace in .net , i created a document whose content is as give below
<?xml version="1.0" ?>
<shapelist>
<rectangle color="red" y2="40" x2="30" y1="20" x1="10">
</rectangle>
<ellipse color="red" y2="40" x2="30" y1="20" x1="10">
</ellipse>
<line color="blue" y2="40" x2="30" y1="20" x1="10">
</line>
</shapelist>
Then I , wrote a C# program which rendered the XML document into a Winforms .
<CODE SNIPPET>
XmlDocument doc = new XmlDocument();
doc.Load("D:\\Praseed\\Xml\\Drawing\\s.xml");
XmlNodeList shapelist = doc.SelectNodes("/ShapeList");
foreach (XmlNode st in shapelist)
{
foreach (XmlNode st2 in st)
{
if (st2.Name == "Rectangle")
{
int x1 = Convert.ToInt32(st2.Attributes["x1"].Value );
int y1 = Convert.ToInt32(st2.Attributes["y1"].Value);
int x2 = Convert.ToInt32(st2.Attributes["x2"].Value);
int y2 = Convert.ToInt32(st2.Attributes["y2"].Value);
Color rst_color = this.GetColorFromString(st2.Attributes["color"].Value);
Graphics bm = pictureBox1.CreateGraphics();
bm.DrawRectangle(new Pen(rst_color), x1, y1, x2, y2);
}
else if (st2.Name == "Ellipse")
{
int x1 = Convert.ToInt32(st2.Attributes["x1"].Value);
int y1 = Convert.ToInt32(st2.Attributes["y1"].Value);
int x2 = Convert.ToInt32(st2.Attributes["x2"].Value);
int y2 = Convert.ToInt32(st2.Attributes["y2"].Value);
Color rst_color = this.GetColorFromString(st2.Attributes["color"].Value);
Graphics bm = pictureBox1.CreateGraphics();
bm.DrawEllipse(new Pen(rst_color), x1, y1, x2, y2);
}
else if (st2.Name == "Line")
{
int x1 = Convert.ToInt32(st2.Attributes["x1"].Value);
int y1 = Convert.ToInt32(st2.Attributes["y1"].Value);
int x2 = Convert.ToInt32(st2.Attributes["x2"].Value);
int y2 = Convert.ToInt32(st2.Attributes["y2"].Value);
Color rst_color = this.GetColorFromString(st2.Attributes["color"].Value);
Graphics bm = pictureBox1.CreateGraphics();
bm.DrawLine(new Pen(rst_color), x1, y1, x2, y2);
}
}
}
<CODE SNIPPET>
Here is the output..... I think this demonstrates XML file reasonably well...
<?xml version="1.0" ?>
<shapelist>
<rectangle color="red" y2="40" x2="30" y1="20" x1="10">
</rectangle>
<ellipse color="red" y2="40" x2="30" y1="20" x1="10">
</ellipse>
<line color="blue" y2="40" x2="30" y1="20" x1="10">
</line>
</shapelist>
Then I , wrote a C# program which rendered the XML document into a Winforms .
<CODE SNIPPET>
XmlDocument doc = new XmlDocument();
doc.Load("D:\\Praseed\\Xml\\Drawing\\s.xml");
XmlNodeList shapelist = doc.SelectNodes("/ShapeList");
foreach (XmlNode st in shapelist)
{
foreach (XmlNode st2 in st)
{
if (st2.Name == "Rectangle")
{
int x1 = Convert.ToInt32(st2.Attributes["x1"].Value );
int y1 = Convert.ToInt32(st2.Attributes["y1"].Value);
int x2 = Convert.ToInt32(st2.Attributes["x2"].Value);
int y2 = Convert.ToInt32(st2.Attributes["y2"].Value);
Color rst_color = this.GetColorFromString(st2.Attributes["color"].Value);
Graphics bm = pictureBox1.CreateGraphics();
bm.DrawRectangle(new Pen(rst_color), x1, y1, x2, y2);
}
else if (st2.Name == "Ellipse")
{
int x1 = Convert.ToInt32(st2.Attributes["x1"].Value);
int y1 = Convert.ToInt32(st2.Attributes["y1"].Value);
int x2 = Convert.ToInt32(st2.Attributes["x2"].Value);
int y2 = Convert.ToInt32(st2.Attributes["y2"].Value);
Color rst_color = this.GetColorFromString(st2.Attributes["color"].Value);
Graphics bm = pictureBox1.CreateGraphics();
bm.DrawEllipse(new Pen(rst_color), x1, y1, x2, y2);
}
else if (st2.Name == "Line")
{
int x1 = Convert.ToInt32(st2.Attributes["x1"].Value);
int y1 = Convert.ToInt32(st2.Attributes["y1"].Value);
int x2 = Convert.ToInt32(st2.Attributes["x2"].Value);
int y2 = Convert.ToInt32(st2.Attributes["y2"].Value);
Color rst_color = this.GetColorFromString(st2.Attributes["color"].Value);
Graphics bm = pictureBox1.CreateGraphics();
bm.DrawLine(new Pen(rst_color), x1, y1, x2, y2);
}
}
}
<CODE SNIPPET>
Here is the output..... I think this demonstrates XML file reasonably well...
Labels:
Software(.NET)
| Reactions: |
Why do we need Philosophy ?
I was sitting in front of my brother's cracker shop reading a book. One friend of ours dropped in and we started to chit chat on various topics. The discussion drifted to improving scientific knowledge. When i explained the Philosophy of science like reductionism to him , he asked "Why should we learn philosophy for understanding Science ?". Given below is my explanation to him..
Every discipline starts as a result of Philosophical inquiry . When the discipline reaches a large body of organized ideas , it becomes science. Even then , Philosophy helps to decipher the central ideas of any discipline, the common problems encountered by practioners , the boundary conditions for investigation etc... . The Problem with the P word is in our part of the world , Philosophy is associated with moral philosophy. I highlighted the role of Philosophers like Artistotle , Descartes , Kant , Russel in contributing to our mental model of the world..
Every discipline starts as a result of Philosophical inquiry . When the discipline reaches a large body of organized ideas , it becomes science. Even then , Philosophy helps to decipher the central ideas of any discipline, the common problems encountered by practioners , the boundary conditions for investigation etc... . The Problem with the P word is in our part of the world , Philosophy is associated with moral philosophy. I highlighted the role of Philosophers like Artistotle , Descartes , Kant , Russel in contributing to our mental model of the world..
Labels:
Philosophy
| Reactions: |
Friday, September 11, 2009
Expert C# 2008 Business Objects
CSLA.NET is a capable framework for writing scalable , distributed applications on the .net platform. The brain behind the project has written a book which goes into the thought process which he underwent while designing the framework. The book does assume that you know ur objects really well. An intermediate programmer will really benifit from the book. Highly recommended.
Labels:
Web Programming
| Reactions: |
Thursday, September 10, 2009
From Trivandrum to Aluva on a Motor Bike
To Bring my Honda Unicorn ( 2004,November make) bike to Aluva from Trivandrum , i chose to ride it from there. I started around 11.00 pm (September 9 ) from Thampanoor ( heart of the Trivandrum City ) and reached Kazhakoottam around 11.30 pm. After a two hour chit chat with friends , i slept around 1.30 Am. Got up around 6.30 am and gave a nice answer to Nature's call.
September 10
9.30 AM - started from Kazhakoottam.
9.35 AM - Filled Petrol ( 6 litres ) from a HP dealer. Got a mug from them for winning a lucky draw .
I was bit tensed to start as some of my friends had warned me against riding all the way from Trivandrum to Aluva. Traffic was bit light today and that made the journey relatively smooth. I was riding at 40/50 Kmph.
10.45 AM - Reached Kollam ByePass. Out of curiosity , i took the bye pass route. After travelling six/seven kilmeters i reached a junction. Asked a Auto Wallah about the road to take to go towards Karunagapally. I had to ride another 4-5 kms to the Kollam Town and took the road towards Alleppy. I thought , i will take a break at Kayamkulam.
11.45 AM - My Phone rang when i reached Karunagappally and i saw a missed call . I called back the number and it turned about be a call from Ebay for an interview. I explained to them the situation and has asked them to call today evening. I sipped a cup of tea and washed my face there. I urinated really well after that. Alleppy was 64 kms away and i thought i will halt at Alleppy for Lunch.
1.10 PM - Reached Alleppy town and had a nice lunch at Hotel Raiban. Couple of guys had messaged me to know about my whereabouts and i called them back.
1.30 PM - I started from Alleppy and decided to move to Aluva in a single rally.
3.10 PM - I reached Aluva and moment i arrived my kid's school bus also arrived and he was happy to see my bike. Called some friends and Wife was also happy to see me back in good shape.I took a nap and flipped through a book i purchased from Modern Book House Ytd...
In the End , All went well .... 225 kms in 5 hrs and 40 mintues.
September 10
9.30 AM - started from Kazhakoottam.
9.35 AM - Filled Petrol ( 6 litres ) from a HP dealer. Got a mug from them for winning a lucky draw .
I was bit tensed to start as some of my friends had warned me against riding all the way from Trivandrum to Aluva. Traffic was bit light today and that made the journey relatively smooth. I was riding at 40/50 Kmph.
10.45 AM - Reached Kollam ByePass. Out of curiosity , i took the bye pass route. After travelling six/seven kilmeters i reached a junction. Asked a Auto Wallah about the road to take to go towards Karunagapally. I had to ride another 4-5 kms to the Kollam Town and took the road towards Alleppy. I thought , i will take a break at Kayamkulam.
11.45 AM - My Phone rang when i reached Karunagappally and i saw a missed call . I called back the number and it turned about be a call from Ebay for an interview. I explained to them the situation and has asked them to call today evening. I sipped a cup of tea and washed my face there. I urinated really well after that. Alleppy was 64 kms away and i thought i will halt at Alleppy for Lunch.
1.10 PM - Reached Alleppy town and had a nice lunch at Hotel Raiban. Couple of guys had messaged me to know about my whereabouts and i called them back.
1.30 PM - I started from Alleppy and decided to move to Aluva in a single rally.
3.10 PM - I reached Aluva and moment i arrived my kid's school bus also arrived and he was happy to see my bike. Called some friends and Wife was also happy to see me back in good shape.I took a nap and flipped through a book i purchased from Modern Book House Ytd...
In the End , All went well .... 225 kms in 5 hrs and 40 mintues.
Labels:
Ways of Life
| Reactions: |
Tuesday, September 08, 2009
Interview Question books
I am having .NET interview Questions and Java/J2ee interview Questions (both ) written by Shiv Prasad Koirala in my shelf. I think , books in this genre is good to have in the personal library. Now a days , i read some questions from these books every day to test my knowledge about .net and java platforms. I highly recommend his books to anyone who is .NET/J2EE developer.
Labels:
Software (General)
| Reactions: |
Monday, September 07, 2009
Java to C# porting
For an Accounting Package , I asked a friend of mine to port a HTML rendering Kit (from Java to C# )found in a circa 1999 book by the title , Developing Java Servlets published by SAMS/TechMedia. The effort turned out be a good learning excersise. The first notable thing was Java do not have a property mechanism. But get/set methods takes over the role.
The (getXXX and setXXX ) Pattern is used by Java Bean hosts like BDK . Another notable twist was lack of Enum support in Java. The code became better from a aesthetic perspective once we ported the code to C# using Properties and Enums.
The most interesting twist is Java's always virtual function attitude. Unlike C# , Java assumes that every method in Java is overridable ( virtual by default ). Here , C#'s insistence on override keyword or new keyword made the stuff bit tedious. To use Override , we need to declare the base class method as virtual in C#.
One more area where C# has got complication is ValueTypes vs Reference Types. Java do not have a notion of Value Type in the case of user defined types (In C# struct is always a value type. Java has got primitive value types like float , int etc ). I am sure C# compiler writers might have had some nightmare regarding this.
The (getXXX and setXXX ) Pattern is used by Java Bean hosts like BDK . Another notable twist was lack of Enum support in Java. The code became better from a aesthetic perspective once we ported the code to C# using Properties and Enums.
The most interesting twist is Java's always virtual function attitude. Unlike C# , Java assumes that every method in Java is overridable ( virtual by default ). Here , C#'s insistence on override keyword or new keyword made the stuff bit tedious. To use Override , we need to declare the base class method as virtual in C#.
One more area where C# has got complication is ValueTypes vs Reference Types. Java do not have a notion of Value Type in the case of user defined types (In C# struct is always a value type. Java has got primitive value types like float , int etc ). I am sure C# compiler writers might have had some nightmare regarding this.
Labels:
Computer Programming
| Reactions: |
Sunday, September 06, 2009
Relational Database - Conceptual underpinnings
I started programming with CA-Clipper and Turbo C++ back in the year 1993. CA-Clipper was a DBMS system + a Procedural Programming Language. It had a Query language which was used by all XBase Products. The Clipper language was far ahead of it's time. It had stuff like Code Blocks , which is roughly equivalent to LINQ technology from Microsoft. After that , i moved to Visual C++ programming , Computer Graphics etc.. . I never worked with RDBMS ( DBMS + referential integrity ) much for next ten years. RDBMS technology eventually caught up with me after that.
I was teaching one of my friend some rudimentary SQL. The Fundamentals behind SQL can be summed up as follows...
A) Data can be stored in simple Data Structure called Relations. ( A table is a Relation )
B) There are four Operators which we can apply on Relations
a) Cartesian Product :- Each of the record from the first table will be paired with every record in the second table. So A (x) B will have Cardinality(A) x Cardinality(B) records. Cardinality(X) will return the Count of number of records . ( see Cartesian Product )
b) Project Operator :- Project Operator drops some columns from the result.
c) Select Operator :- It applies a Filter ( Predicate ) on each record to see whether it should be included in the result relation. It is what you put in the where clause.
d) Rename Operator :- You can rename a column or a table
The advantage of all these Operators are After Application of these Operators we will always get another relation. So Relational Operators are having a property called Closure. Another important constructs where Closure property is present is Regular Expressions. Functional Programming languages has got support for Lexical Closure which makes them powerful for writing multithreaded programs.
C) Relations are Bags or MultiSets. So, We can apply Union , Instersection , Difference and Set membership Operators. After application of these Operators u will get Relations as the Output.
Later they extended Relational Algebra with Outer Join , Group Operations to create a full blown Declarative Query Language. If you take a closer look at it , Even LINQ is using the same constructs to implement a declarative type safe Query language inside the .net platform.
I was teaching one of my friend some rudimentary SQL. The Fundamentals behind SQL can be summed up as follows...
A) Data can be stored in simple Data Structure called Relations. ( A table is a Relation )
B) There are four Operators which we can apply on Relations
a) Cartesian Product :- Each of the record from the first table will be paired with every record in the second table. So A (x) B will have Cardinality(A) x Cardinality(B) records. Cardinality(X) will return the Count of number of records . ( see Cartesian Product )
b) Project Operator :- Project Operator drops some columns from the result.
c) Select Operator :- It applies a Filter ( Predicate ) on each record to see whether it should be included in the result relation. It is what you put in the where clause.
d) Rename Operator :- You can rename a column or a table
The advantage of all these Operators are After Application of these Operators we will always get another relation. So Relational Operators are having a property called Closure. Another important constructs where Closure property is present is Regular Expressions. Functional Programming languages has got support for Lexical Closure which makes them powerful for writing multithreaded programs.
C) Relations are Bags or MultiSets. So, We can apply Union , Instersection , Difference and Set membership Operators. After application of these Operators u will get Relations as the Output.
Later they extended Relational Algebra with Outer Join , Group Operations to create a full blown Declarative Query Language. If you take a closer look at it , Even LINQ is using the same constructs to implement a declarative type safe Query language inside the .net platform.
Labels:
Software (General),
SQL
| Reactions: |
Animals are smarter than Humans ??
Some time back , (from a old book shop ) i purchased a book by the title Covenant of the Wild. I think the year was 2001. Ytd, i happen to pull out this book and started reading it with great enthusiasm. I am almost half way into the book. The Author gives convincing arguments regarding why animals chose domestication . So far , we are accustomed of hearing Men domesticated animals. Animals through their innate instinct clubbed their future with the "Uber species" for their own advantage. Now tell , Who is (are?) smarter ??
| Reactions: |
Subscribe to:
Posts (Atom)