Monday, January 31, 2011

Hair Cut and Prefactoring !

I went to the barber shop to have a hair cut today. Since , this is the only barber shop in our area , it will take some time of wait before your turn is reached. I take books with me .

At first , I will skim through film magazines and update myself about latest malayalam and tamil gossips . Today , after a half and hour , I read Ken Pugh's "PreFactoring" and for one hour , no one distrubed me.

What is a Statement ? ( in Programming Languages ! )

Statements and Expressions are primary building blocks of any programming Language.

Expression :- Some thing you evaluate for it's value

eg:- Eval("2*3")  , Eval("a*b+10")

Statement:- Something which you execute for it's Effect

Exec("a=b=2*3"); , Exec("b = 2*3");

After a statement is executed there is chance for state to be mutated ( state is managed by statements )

As per the above definition

STATEMENT means STATE MANAGEMENT

Sunday, January 30, 2011

GCC under Windows !

I have been playing with GCC's Objective C compiler for couple of days under Windows 7. One advantage of GCC is that you have got support for C , C++ , C/C++ , Objective C , Objective C/C++ and Java under one roof.

If you are a kind of guy who would like to play with Command line tools , you will be really at home with MSYS ( MingW console )  and there is option to use the plain old command prompt for compiling , linking and running your native code programs.

What else to be asked for something which you get for free !

Saturday, January 29, 2011

Splitsville - I happen to come across it again

Splits-ville is a term which I encountered a month back in the context of Shane Warne / Liz Hurley (Wife of Indian born Industrialist Arun Nayar ) link up. Today , I happen to come across in a news item where the matter of discussion is break up of Pooja Batra's ( Ammoomma kili vaayadi ..song fame !) marriage.

Splits-ville –noun Slang .


the state or condition of being divorced or separated.  

Eligibility vs Ability

Prem is from a conservative household who despise deficit financing , where as Tilak is a neo rich fellow who will buy anything which he can lay hands on , even if it is on credit.

Prem :=> "Now a days , Every software professional is a slave !"

Tilak =>"Why did you say so ?"

Prem => "All have got multiple loans and people are scared of loosing jobs now "

Tilak =>"What is wrong with it ? Even , I have got three loans and going for the fourth one !"

Prem =>"Tilak , Just because you have got eligibility for credit does not mean that you have got the ability to pay it back !"

Learn Objective C/C++ Programming under Windows

Now a days , Objective C language is gaining popularity due to the ascent of MAC OS X and iPhone /iPad( iOS )  development. You require a MAC OS X laptop or MAC mini to  write programs using Objective C.

To get a feel of Objective C language , we can use venerable GCC under Linux. Today , just for fun , I installed GNUStep (Apple's Cocoa can be considered a cousin of GNUStep )  development environment under Windows 7 and wrote some Objective C programs under Windows. You can even write GUI apps to get a feel of how Native MAC OS X development will be.

You can download GNUStep for Windows from

http://www.gnustep.org/experience/Windows.html

Tuesday, January 25, 2011

"Cross Platform C/C++ Programming" article is now published

I had written an article for the "REBOOT" magazine published by the students of Cochin University of Science and Technology.

The electronic version of the magazine can be retrieved from
http://issuu.com/renjithforever/docs/reboot . the article is on the 30,31,32,33 page.


Friday, January 21, 2011

Redundancy in Objective C language

A language like C , C# Or Java , use Positional parameters.

object f(x,y)  => { some .computation ... and return value }

if you invoke this as f(10,3 ) , 10 will get bound to x and 3 will get bound to y. This is determined based on the position.

Objective C has got named parameters.

-(object) f:(int)x yval:(int)y {   some computation...... return value }

Since the parameters are named , One will assume parameters can be given in any order. But, that is not the case.

So , Objective C has got Named /Positional Parameters  ...Name is redundant.

As you mature , abstraction kills attention

Now a days , I read textbooks of eigth , ninth and tenth standard for amusement. By revisiting the basics , I derive tremendous pleasure out of it. In the name of abstraction , we eliminate details from our thought process and soon , we end up becoming mortals who can only do stuff with other peoples help.

That is good , if you want to remain as manager and do not want to do something conrete. I suspect , reading literature , books meant for kids can enrich your life. It has enriched mine, at least that is what I believe.

A new exapansion for the term "BUSINESS"

A friend of mine cointed a new expansion for the term BUSINESS

Be
Useful
Somewhere
In
Newly
Emerging
Social
Scenario

As per him , Technology/People/trends change according to social scenario arising out of random actions by the people. What is going to emerge is not predictable and illusion of predictability is always there.

If you happen to posses right skills for the newly emerging social scenario (it is a random variable !) , u will be useful somewhere !




Wednesday, January 19, 2011

An Inteview

Prem sat with his boss for an interview . Together , they interviewed one Mr. Pranesh.

Boss => "Where do you see yourself in five years ?"

Pranesh =>" I would like to Rest in Peace !"

Boss =>"What kind of manager your looking forward ?"

Pranesh =>"Not one like you !"

Boss=>"What are your strengths ?"

Pranesh =>"To judge that you are sitting there , I believe"

Boss => " What are your weakness ?"

Pranesh =>" If you cannot find it out yourself , my trip down here is a waste !"

Prem was really happy for that day !

Tuesday, January 18, 2011

Waiting - a Poem

I Wait , for a better tomorrow

For somethings , You ought to wait
Wait ,for stars to get aligned
Wait , to escape the misery
I want all your prayer
I've done what can be done
Now , It is my turn to wait
How long , I have to wait ?
I wait , because I've hope



Sunday, January 16, 2011

Two nice articles on Functional Programming ( Patterns) In Java

The following article was written in the pre-generics days of java
http://www.ibm.com/developerworks/library/j-fp.html

This uses more modern constructs like Generics
http://www.drdobbs.com/java/184406320

Green Threads vs Real threads

Java and .net threads are also called Green Threads. The reason is they are not the threads provided by the Operating System Kernel. They are provided by the Virtual machine.

Desire - A Poem

We desire what is not possible

Some say , nothing is impossible
It gives us hope and mind is happy
Is anything possible for sure ?
Dawn breaks with an uneasy calm
Dusk comes in with turbulence
Desire is still out there
It will always be there
untill , we leave the life
If it runs away , It will comeback
It will comeback , In another guise
Desire is always there , to give
a tinge of misery.

Saturday, January 15, 2011

Rajasthan - The new Ranji Champion

Yesterday , I happen to learn that Rajasthan entered the finals of Ranji trophy and I had blogged about my "shock" . Today morning , despite my busy schedule I saw some live shots of the match. I happen to learn that Hrikesh Kanitkar and Akash Chopra is also part of the team.

They are now Ranji Champions based on the first innings lead. The last wicket partnership in the Rajasthan second innings dashed any hope which Baroda might have had.

Saturday Nap - A Nostalgic revisit

Back in late 1990s ,I used to take saturday afternoon naps around 1.00 pm. After three hours of sleep , I used to go to the City ( Kochi ) to prowl book stalls and will come home late into the night (after watching movie , most often ). I used to work with a Trivandrum Technopark based company then.

At Tvm , I used to watch three movies a week.

Monday - Vettu Road Sreekala ( Jayan , Naseer Movies )
Tuesday - City  ( some hindi movies )
Wednesday /Thursday - Either Kazahkootam Krishna or Mahadeva
Friday evening - Trivandrum new/central or some other theatre . After that , I used to board a bus to Aluva.


After a long time , today , I happen to relive the saturday afternoon nap (?) which deserted me !. Morning activities were so hectic and I slipped into my sleep while reading an Insteresting (!) book.



  

Friday, January 14, 2011

Thread vs Fiber

When I started Multi Threaded Programming , most operating systems at that time had support only for Process and Threads. Now a days , they support Light weight path of execution called Fiber. Fiber works at the user mode level and we need to implement our own scheduler . The scheduler in question has got better control over the scheduling decision by taking into the consideration the "local optima".

Rajasthan is a Ranji Finalist ( most probably winners !)

When I logged on to my Google Page , I happen to see score card of Rajasthan Innings for a cricket match. Out of curiosity , I clicked the link and was pleasently surprised to see the score card of the Ranji finals between Baroda and Rajasthan.

Out of disbelief , I asked a colleague about this. When I searched Wiki , I found that Rajasthan was runner up for 8 times between 1960 and 1974.

Beatification - a new word which I came across

Today , I happen to come across this word for the first time. It is  a recognition given by Catholic church to a dead person's ascension to heaven.

John Paul 2nd was beatified recently (may be today )

This is how some people ( of course , i do respect the fact that he was POPE of catholic church for 27 years )  become blessed and get transformed into a God.

Getting addicted to online forums

Last saturday  , One Mr. Yanesh Tyagi ( who took a session on Social networking for developers @ K-Mug ) has bugged my friend into fooling around the Stack Overflow. Now , like playing PACMAN , he is fond acquiring reputation points.

Why are we working ?

Most people feel that monetary reward is the most important thing while working.

In the olden days , when Govt. was the biggest employer , people used to revere their job like anything. Working for the govt. was regarded as something great. If you work for the central govt. , it is even more great.

Then , in the 1990s Multinationals began to arrive in India . Then , working for the white man ( "SAIP")
became more prestigious. In the fag end of the 90s , the first generation Indian Enterprueners arrived and they shared the stage with retreating "SAIPS" . I call the first generation Indian Enterprueners as neo-SAIPs.

In the mid 2000s , lot of Indian expatriates setup small shops all across India. The people who cannot reach the SAIPs , Murthys , Premjis and Rajus saw these small shops as a jumping board for their future rendezvous with SAIPs and neo-SAIPs.

The snob factor and pressures of modern life ( poor youngsters has to make at least 40 lakh+ to have a Gaadi and Bangla,so we cannot blame them for hoping job , honestly speaking ! )  forces all to despise these Expatrites who setup small shops. For them , Anyone lesser than SAIP and a "neo SAIPs" are lesser mortals.

What about Computer Programming and Software Engineering ? It has taken a back seat.

Thursday, January 13, 2011

Met two of my friends after a long time

A erstwhile colleague of mine who happens to stay very close by and I have not met for days. The funny fact is that when he used to be at Trivandrum we met more frequently than this. Today , we decided to make amend to this situation and happen to meet each other.

While we were about to part , I got a call from a friend who has landed here from the down under. He is departing for Australia tomorrow. I took a motor cycle ride of 6 kms to meet him. We had a meeting which lasted for an hour (it was 12.45 am , when we parted !).

Wednesday, January 12, 2011

if Nymphomania is for Women , What is for men ?

satyriasis


n.

Excessive, often uncontrollable sexual desire in and behavior by a man.

Note :- The source is Word Power Made easy

Just finished watching a Chakyar Koothu Performance

Just now , i have come back after watching a Chakyar Koothu Performance @ Sree Dharma Sastha Temple , Aluva (which is 15 meters away from where i am writing this - aerial distance !). The story was "Paanchali Swayamwaram" ( Draupadi Swayamwar ) and as usual , it was really humorous . The way he juxtaposed and juggled with the words was really a treat to enjoy. He did take a dig at me , when i entered the complex ! . No one was spared and It is a perfect example of collaborative fun.

Read about this amazing art form @ http://en.wikipedia.org/wiki/Chakyar_koothu

Tuesday, January 11, 2011

fulsome and vegetate - terms which i encountered

fulsome means

a) Offensively flattering or insincere.
b) Offensive to the taste or sensibilities

vegetate
- lead a passive existence without using one's body or mind

Classical Indian dance is a language !

The annual Makara Vilakku festivities @ Edakattil Sree dharma sastha Temple , Aluva got a kick start today. There was dance performance today and I saw one Bharathanatyam performance by a girl who might be 11 or 12.

She has studied her subject really well ( it seems ) and there was flow in her steps. I happen to see some women (when i was in school these women were representing my school at youth festivals ) in the audience who seems to follow their language.

Monday, January 10, 2011

Passing and returning structure by value

The following C/C++ program demonstrates the procedure to pass and return structures by value


///////////////////////////////
//
// A Program to demonstrate 
// 
// returning structure by value and 
// passing structure by value...
//
#include <stdio.h>

using namespace std;


typedef struct 
{
  int x;
  int y;

}POINT;



POINT GetPoint() {
   POINT pt;
   pt.x=100;
   pt.y=100;
   return pt;
}

POINT ScalePoint(POINT n) {

  n.x = n.x*10;
  n.y = n.y*10;
  return n;
}

int main( )
{

   POINT a = GetPoint();
   printf("%d\t%d\n",a.x,a.y);

   POINT c;
   c = ScalePoint(a);
   printf("%d\t%d\n",c.x,c.y);    
}

Calling a Function by Reference in C++

I have used Function Pointers extensively in my applications. The other day , I understood that u can call a Function by Reference as well. The following program demonstrates it how



///////////////////////
//
// func.cpp
// Calling Function by Reference....
//
//


#include <iostream>

using namespace std;


int Add( int a , int b ) {
      return a+b;
}

typedef int (&ADD_FUNC)(int , int );


int main()
{

   ADD_FUNC f = Add;

   printf("%d\n",f(2,6));

}


A nice introduction to Hindley-Milner type system

http://www.codecommit.com/blog/scala/what-is-hindley-milner-and-why-is-it-cool

What is your place ? - A Poem

Army is not about defence

It is for armymen


Police is not for law and order
It is for policemen


Hospital is not about care
It is to take care of it's employees


Software house is not about shipping software
It is for making a living in the name of software


It is all about Instituitions
which protects itself against all odds

What is the place of a Individual
In such a universe !









Sunday, January 09, 2011

Overloading new and delete in C++

Since new and delete are operators in C++ , we can overload them. This is a very powerful feature of the C++ Programming language. We can reduce memory fragmentation and even a garbage collector can be implemented using this technique


/////////////////////
// new_overload.cpp
// 
//
// A simple program to demonstrate
// overloading of new/delete operator
//

#include <iostream>
#include <new>

using namespace std;

class Test
{
   char name[35];
   int _age;


   public:
    void * operator new (unsigned int size ) {
        cout << "Funny ...stuff...." << endl;
        return malloc(size);
    }

    void operator delete( void *ptr ){
            cout << "free called....." << endl;
        free(ptr);
    }

};


int main( int argc , char **argv )
{

    Test *a = new Test();
    Test *b = new Test();

    delete a;
    delete b;

}

Subscript operator implementation for a Matrix class in C++

The following program uses operator overloading to implement a subscript operator [ M( r,c) ] for a almost useless Matrix class. The code is written for demonstration purpose only.

////////////////////////////////////
// FMatrix.cpp
//
// This program creates a array element access
// operator   ( , )     
// 
// Error checking is omitted for clarity... 
//

#include <iostream>

using namespace std;


template <typename T>
class TMatrix
{
    T *mat;
    int _rows;
    int _cols;

   public:
    TMatrix( int rows , int cols ):
        _rows(rows),_cols(cols)    
    {

        mat = new T[_rows*_cols];

    }

    ~TMatrix() { delete [] mat; }

    
     T& operator() (unsigned row, unsigned col) {
           return mat[_cols*row + col];
     }
 
         T operator() (unsigned row, unsigned col) const {
               return mat[_cols*row + col];
         } 

};



int main()
{
        TMatrix<float> m(5,5);
        m(4,4) = 20.0;
        cout << m(4,4) << endl;

}

It's time to Think Parallel

Now a days , most CPUs are having at least two cores. Most programmers are trained to think sequentailly and we need to re-train ourselves to think parallel.

Now a days excellent libraries like Intel's TBB , Microsoft's Task Parallel  libraries are out there to consume withough knowing much about parallel processing patterns.

Saturday, January 08, 2011

What is a Pointer ?

Pointer is a crisp notation given to programmers to instruct computers to do  efficient and effective address calculation.

K-MUG user group meeting - a personal perspective

The K-mug user group meeting was held at Orion Systems , Infopark , Kochi. I started around 8.15 am from my home on a motor bike. To avoid traffic , I took the pipeline road to reach Airport-Seaport road. In another thirty minutes , I was at the Infopark gate. This was my first visit to Infopark in four years . The whole place has changed and all the greenary is lost.

After "wrestling" with Security guards ,  I and two of my colleagues (Sanal , Rahul ) managed to get into the Tejomaya Building @ Infopark. There , a nice lady (seems to be Orion support staff ) helped us to reach the meeting venue. That made the day bit pleasent for us.

We were greeted by Saravana Kumar ( a speaker at the event) @ orion systems. Around 9.30 am, there were only five people at the venue. Soon ,  news also reached that the first speaker will be late.

So , I gave a quick community update and started the first session

C++ - News of my death was an exaggeration - By Praseed Pai
-----------------------------------------------------------------
The speaker started explaining Native devolopment , Managed development and Mixed Mode development. Then , he wrote the customary Hello World program in C/C++ and repeated the same using C# and C++/CLI.

A brief explanation about MFC was given . To make the contents more relevant for contemporary developers , the speaker talked about Windows Dynamic Link Libraries. The stuff like Name Mangling and how to avoid them , calling convention ( __stdcall  and  __cdecl ) were explained in detail. Using Microsoft Link , DLLs were created and also demonstrated Dumpbin.exe (to see exported functions). Later , Windows module definition files were used to remove Microsoft name mangling ( Add(int , int ) will become _Add@8  ) . Finally , there was demonstration about dynamic loading of DLLs and how .NET is using the same mechanism for implementing P/Invoke.

 Social networking for developers - Yanesh Tyagi
--------------------------------------------------
When i saw the topic @ k-mug site , I thought the stuff will be about how to call Twitter API or Facebook API. Instead , I was pleasently surprised to see a presentation without programs and yet, all the points were relevant for programmers. He talked about Forums , Blogs , Stack Overflow . The discussion about SO was really cool and he highlighted various features of the site and how it helps the people who visits there.

He did talk about his experience in networking with professionals across the world . He also showed a codeplex project ( http://keepfocused.codeplex.com/ ) and narrated his experience as a developer from a social networking ( community ) angle. The project has got 5,000+ downloads !

Tips and Tricks for WCF development  - Sarvan Kumar
--------------------------------------------------------
This is his third session at k-mug on WCF. In fact , he is the first person who talked about WCF development at k-mug event. This time , he explained NetTcpBinding ( for calling services within the network ), NamedPipesBinding ( for same Appdomain calls ) and Custom binding in rich detail. He showed how to use Channelfactory , Caching of Channelfactory instances .

He later wrote a Self Hosting extension and demonstrated techniques to specify the bindings when there are multiple bindings available. There were discussions about throttling and quotas. Audience actively participated in the session.

If you were already into WCF development , this would have given some really good tips.

.NET Debugging Tips and Tricks By Bijith KB
-----------------------------------------------
He started by giving rationale of choosing this particular topic for a session. That was really informative . Then , he explained about difference between BreakPoints and TracePoints. He showed some very advanced techniques to debug the code. He did show conditional breakpoints , macros , filters etc. This was a hands own session and audience was really appreciative about the usefulness of the topics he covered.

He showed how attributes can help us in sophisticated debugging experience was successful in injecting his passion for the topic to the audience really well. The other topics covered include Local window , Auto window , creating new objects while debugging etc.



Finally , I gave a summary speech to conclude the event around 1.20 pm.

Saurav Ganguly - I'm Indifferent on the IPL issue

After the memorable hundred against Pakistan at Dhaka (1998 ) by Saurav (India was chasing 316) , I have been a keen follower of Dada ever since. I used to rate him above Tendulkar in terms of effectiveness ( Still , i rate him so ~). In fact , Saurav pulled India out of the "Miandad Ghost" ( 1986, Sharjah Six . India lost lot of matches for the next decade ). He and Sachin piled up runs in many a Indian victories.

When he was dropped in the year 2005/2006 , I was disturbed and was critical of Kiran more , Greg chappel for it. Dada bounced back in 2007/2008 to get a memorable exit from Test and one day international.

I try to see repeat telecast of most of his innings in ESPN,Neo sports etc.

if Ganguly is not picked as a captain , I do not think any team will be interested in hiring him. I do not think anyone in India has balls to tell something straight at Saurav (IMHO, Even Tendulkar will hestiate ).

Dada is not picked up because he is not a DODO !. 

English Language - a boon for the glib tongued

One of my friend narrated an incident happenned in his company.

As part of a group discussion ( i think , some kind of PDP ), employees were asked to choose topic from a pallette of topics. A person who prides himself of being a master "social reformer" happen to take a topic which was about "Delhi High court judgement on HomoSexuality".

He started his polemic in his own idiosyncratic way. Due to his lack of command over the language , he transliterated and end up "abusing" the people who were listening to him. Girls were hard pressed to hide their emotions and it has been the topic of discussion  ever since in the office.

Had it been spoken in vernacular language , he would have been out of the company by now !

Long live the british for giving this wonderful language . I suspect , lot of people do not have emotional connect to the language while speaking it.  This is true with the audience as well. So , English ends up as a language well suitable to communicate "vexing" topics.

Throttling - finally i understood the meaning

I have come across the term throttle in the context of Distributed Computing . Today , while attending a session on WCF , the word popped up once again. Even though, I have used throttling features of WCF , I had not understood the meaning of the word "throttle"

Another guy from the audience explained throttling in the context of Network bandwidth.

The etymological meaning of word throttle is "to compress the throat of" !! . You throttle to reduce the flow of fluid ( bytes ! )

Thursday, January 06, 2011

Mundane Astorology - a discipline I happen to come across

Astrology used to predict world affairs and events are called Mundane astrology.

A remarkable observation

A friend of mine today , made a remark which is as follows .   "In God's own country , most people do not live their passion !".  When  I challenged him , he gave me lot of anecdotal evidence to back his claim. At least , i could not find out much counter argumenets against this assertive statement after some time.

Transformation

Prem and Tilak were stunned to know that their erstwhile idol Mr. Avinash has lost interest in
Programming.

Prem =>" Avinash was a unix guru "

Tilak => "Ya , his knowledge of X windows programming was next to none "

Prem => "Nothing has changed  , Instead of X Windows he is now a days interested in X-rated videos from youtube !!!"

"I and XXX " vs "me and XXX"

Imagine that , I have gone out with XXX to meet a friend by the name Goopi. How will i narrate it to Gopan ?

Earlier , I used to narrate it like this

Dear Gopan ,
     Me and XXX went to meet Goopi. ( Some times , it can be XXX and myself , myself and XXX or XXX and me )

But , the correct usage seems to be

Dear Goopi,
    XXX and I ( I and XXX is also fine ) went to meet Goopi.

I called lot of people and could not get the reason why it is so.


Today , I searched for the reason

I went to meet Goopi ( me went to meet Goopi seems to be wrong here )
XXX went to meet Goopi

This becomes XXX and I went to meet Goopi.

Eating Exceptions are a must for robust code

.NET Framework Class Library ( FCL ) has got coarse grained API for performing System functions. Most of these methods throw Exceptions. This makes it dangerous for inline use in applications.

Directory.CreateDirectory(dirstring ) can throw exceptions….

One strategy we can apply is


public static bool DirectoryCreate( stirng dirstring )
{
      try {
           Directory.CreateDirectory(dirstring);
     }
     catch(Exception e ) {

         return false;
    }
    return true;

}

We eat the exceptions here.

a blog post worth a read

Gone are the days of being a technology neutral and architecture centric Professional . To be a Programmer worth a hire , you need to have deep skills in some specialized technologies. There is substance behind this argument. Mr. Joymon has written a blog post which is along these lines.

Wednesday, January 05, 2011

Suffixing Technology specialization in names

I happen to come across a post where the author has suffixed the word ".NET Programmer" under his name.
This is sign of times ( branding themselves ) and at the same time perplexing. Why would one throw away opportunities in other technologies , by branding themselves as a specialist in a  particular platform . Is it rational ignorance (read here ) or simply plain ignorance ?

Usage of a word and discovering it's meaning later

I have come across the word "altercation" quite a few times in my life. Today , i happen to use that word in the context of a mother in law vs daughter in law discussion. When I used it , i had the notion that altercation involves mild physical push ( unthum thallum in malayalam ! )

After reaching home , i picked the book Word power made easy ( by Norman Lewis ) and found out that altercation means verbal duel. So  , nothing physical about it.

Tuesday, January 04, 2011

K-MUG User Group Meeting - 08th Jan 2011 - Kochi

Venue: Orion India Systems Pvt Ltd, 103, 2nd floor, Tejomaya, Info park SEZ, Kakkanad, Kochin-682030

Agenda

09:30 - 09:40 Community updates

09:40 - 10:30 .Net Debugging Tips and Tricks

10:30 - 11:15 Social networking for developers

11:15 - 11:30 Tea Break (15 min)

11:30 - 12:15 Tips and Tricks for WCF development

12.15 - 01:00 Ask the experts



Url :-


http://k-mug.org/content/UGMeet080111.aspx

A Five second primer on PKI given in ILUG,Kochi

Here is a short description of PKI given by me in a post there

In a Business to consumer scenario ( most common use of PKI ) , the server will have a digital certificate ( public key/private key pair , private key will be saved on the server not part of certificate ) and User agent ( in my parlance it is our browser ) will request for secure communication at a specified port ( 443 in the case of TLS/SSL ) .







Then server will give the certificate to the user agent and user agent will communicate to the CA to verify the authenticity . Once user agent has authenticated , the user agent will generate a session key (normally a symmetric key ) and will encrypt the session key with server's public key . In this case , server can get the key back by decrpyting with prviate key ( which is only available with server ).






Thus PKI is used for key exchange . That means exchange of session key.

Revisiting Intel Thread building blocks

Intel TBB is a generic programming library for writing multi core applications. The application uses C++ templates and generic programming techniques to implement parallel programming patterns.

If you are familiar with STL , then this library gives you yet another demonstration of generic programming. C++ Function Objects are extensively used to process partitioned data.

iPhone 3D Programming - a cool book from Orielly

Today , I purchased a book titled iPhone 3D Programming. The book gives excellent coverage of the OpenGL ES API. ( The OpenGL ES is based on OpenGL 2.0.)  The book covers some advanced techniques and the title is indeed misleading ( :) ) . The book's code is relevant for OpenGL desktop as well.

The code snippets are in C++ and uses templates extensively. There are classes for Vector ( math vector ) , Matrix , Quaternion , Texture , Lighting etc. With moderate effort , we can get a cool framework to play with Modern OpenGL programming in iPhone , Windows /Linux or MAC OS X.

Highly recommended.

Monday, January 03, 2011

Had a nice discussion about Ports and Shipping

While coming back from Office , I happen to come across a guy who is working at Cochin Shipyard. The conversation started on a light note and the discussion discussed about Trade unions , negotiations , rules , compliance , Vizhinjan port , Rotterdam port , Shipping business , Colombo port , drudging  etc. It was very informative for me.

Thanks to my stint at Trivandrum , i had picked some information about Vizhinjam port and ports in general.
This guy also confirmed that Vizhinjam is a natural port and there is no need for drudging.

People try to improve the skill , not their knowledge

Now a days , a software professional has to have exposure to lot of different technology offerings from multiple vendors ,to be effective in his work. Lot of people are resentful about this . They think , focusing on one technology is better for them as they can master one thing thoroughly.

I would like to see this scenario as an opportunity for these budding professionals. The perception is wrong about this mostly because , people are giving too much emphasis on Skill. Acquiring Knowledge should also be given some thought.

As a case in the point , I will explain something which I came across. A Person who has been working with Microsoft .net  was contemplating to move to a company where Adobe Flex development is in vogue. The Professional in question was skeptical about this. He feels , working with a company which is into Silverlight development is a better option.

The best approach for him is to see Adobe Flex and Silverlight are two instances of RIA (Rich Internet Application ) frameworks. Flex is RIA offering from Adobe and Silverlight is RIA framework from Microsoft. Both these technologies require some back end.  They might be either using .NET enterprise stack or Java stack.

This way , his knowledge can be factored to become a superior professional. Knowledge can substituite lack of skill , given time. Converse is always not possible.

Fixing Bugs - A Model Driven Approach

When system development is in final stages , it is hard to find a bug from the area where the code is breaking. An API call here or there might seem to break .

The best strategy here is to take a step back and review the architecture and model which the architecture is trying to implement. Most often , from this discussion alone we can zero into the problem area.

Today , something similar to this happened to me. We optimized a part of a Graphics subsystem to eliminate the transport of an unnecessary image between client and server. Instead of contents from a file , we generated image by dynamic memory allocation. The earlier architecture was persisting the memory data to the disk. That architecture had advantage in having a small footprint in memory.

This time , even though we created a image on the fly , we persisted it on to the disk when we moved from one frame to another. We eliminated the file and we did not have to change much code as well.

Sunday, January 02, 2011

My Pycon India 2010 talk is available

The Url is @ http://pyconindia.blip.tv/file/4533633/. The talk starts around 46 minutes into the video.

Boost Library - C++ programmers gasping to go C#/Java way

C++ boost libraries seems to be an attempt to answer the C++ critiques about the lack of support for certain classes in the core libraries of standard C++. The Learning curve is bit steep compared to Java or C# libraries. One needs to be really good at Templates to exploit most of the libraries.

Will C++ ever become a favorite application programming language ? I doubt that is going to be the case. The Boost Graph Library and Boost Regex seems to be the most useful libraries inside the boost distribution.

A useless SmartInt class

To teach some nuances of C++ operator overloading and templates to a friend of mine , i happen to write a SmartInt class. The idea was to demonstrate that C++ language can promote any class to the features available in a builtin type. We need to overload certain operators to achieve that objective. The Program was compiled using Visual C++ 2010 command line compiler.

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;


template <class T>
class SmartInt
{
     T _value;
   public:
      SmartInt(T value) : _value(value) {}

      SmartInt() : _value(0) {}

      SmartInt( const SmartInt& other ) {
             _value = other._value;
      }

      
      SmartInt& operator = ( const SmartInt& other ) {
                if ( this != &other )
                 {
            _value = other._value;

                 }
                 return *this;
      }

      ~SmartInt() {  }

      //////////////////////////////////////////
      //
      //
      SmartInt& operator ++ ()
      { 
           _value++; return *this; 
      }

      SmartInt operator ++ (int) 
      { 
          SmartInt nu(*this); 
          ++_value; 
          return nu; 
      }

      SmartInt& operator -- ()
      { 
           _value--; return *this; 
      }

      SmartInt operator -- (int) 
      { 
          SmartInt nu(*this); 
          --_value; 
          return nu; 
      }

      SmartInt& operator += ( int x ) 
      { 
           _value += x; return *this; 
      }

      SmartInt& operator -= ( int x ) 
      { 
         _value -= x; 
         return *this; 
      } 
  
      SmartInt& operator *= ( int x ) 
      { 
          _value *= x; return *this; 
       
      }

      SmartInt& operator /= ( int x ) 
      { 
            _value /= x; 
            return *this; 
      }   

      bool operator > ( const SmartInt& other ) {
               
        return _value > other._value;
      }

      bool operator < ( const SmartInt& other ) {
               
        return _value < other._value;
      }

      bool operator == ( const SmartInt& other ) {
               
        return _value == other._value;
      }

      bool operator != ( const SmartInt& other ) {
               
        return _value != other._value;
      }

       
      bool operator >= ( const SmartInt& other ) {
               
        return _value >= other._value;
      }

      bool operator <= ( const SmartInt& other ) {
               
        return _value <= other._value;
      }

      SmartInt  operator | ( const SmartInt& other ) {
               
        return SmartInt(_value |  other._value);
                
      }

      SmartInt operator & ( const SmartInt& other ) {
               
        return SmartInt(_value & other._value);
      }

      SmartInt operator ^ ( const SmartInt& other ) {
               
        return SmartInt(_value ^ other._value);
      }
        
      SmartInt&  operator |= ( const SmartInt& other ) {
               
        _value |= other._value;
                return *this;
                
      }

      SmartInt& operator &= ( const SmartInt& other ) {
               
        _value &= other._value;
                return *this;
      }

      SmartInt& operator ^= ( const SmartInt& other ) {
               
        _value ^= other._value;
                return *this;
      }

      SmartInt operator ! () {
             return SmarInt(!_value);

      }  
 
      operator int () { return _value; }      

};


int main()
{

   SmartInt<int> ps(10);
   SmartInt<int> test(ps++);

   cout << (int) test << endl;

   ++ps;
   ps /=2;
   ps *=4;
   cout << (int) ( ps | SmartInt<int>(2) )  << endl;

   vector< SmartInt<int> > vs(3);

   vs[0] = SmartInt<int>(20);
   vs[1] = SmartInt<int>(10);
   vs[2] = SmartInt<int>(30);

   SmartInt<int> sum;

   for_each( vs.begin() , vs.end() , [&] ( SmartInt<int>& o ) {

           sum += o;
    }); 

   cout << (int)sum << endl;

   sort(vs.begin() , vs.end() );

   for_each( vs.begin() , vs.end() , [&] ( SmartInt<int>& o ) {

           cout << (int)o << endl;
    }); 

  
   

}

Karishma vs Kareena

Karishma Kapoor and Kareena Kapoor are in limelight for more than a decase now. After a long time , i happen to see songs from Dil to Pagal hai and I feel Karishma was a better dancer than Kareena.

The only place where Kareena has fared better might be in the Tashan Song. That can be compared to any Western music album.

The Art of Enjoyment in Life

How do one enjoy life is a question which bothers every one . Too often , we are worried about things which are beyond our control. Only thing worry can do for you is to stay focused on your job.

Do u need to worry about some things when you cannot do anything to alieviate it ? Imagine , you have got a problem at hand . What we can do is to confront it and try to minimize the impact of that on your life. Then all we can do is to wait for a positive outcome. During evenings and early morning time , we cannot do much activities . So, why bother about such things during those times.

For enjoyment , all you need to do is stop bothering about things which u do not have control.

Saturday, January 01, 2011

Compile Time Computation in C++

C++ Templates are a great way to speed up your code while writing libraries . Using Templates and Templates specialization , the program given below computes Power of  numbers.

///////////////////////////////////////////
//
//  Power.cpp
//
//  A Program to demonstrate Compile time computation
//  using C++
//  We are using C++ templates and templates specialization
//  to achieve the objective
//
//  Written by Praseed Pai K.T.
//             http://praseedp.blogspot.com
//
//  At the Visual C++ command line 
//  cl /EHsc Power.cpp
//
//


#include <iostream>

using namespace std;


////////////////////////////////
//
//
// Define Power Function...
//

template<int n>
inline int POWER(const int& args)
{ 
  return POWER<n-1>(args)*args;
}


////////////////////////////////
//
// Specialized version of power 
// when exponent is 1  ( args^1 )

template<>
inline int POWER<1>(const int& args)
{ 
   return args;

}

//////////////////////////////////////////
//
//
//  Specialized version of Power when exponent is 
//  0 ( args ^ 0 )

template<>
inline int POWER<0>(const int& args)
{ 
   return 1;

}


////////////////////////////////////////////
//
//
// Entry point... this computes 10^3 
// The way templates work makes sure that it is computing the 
// value at the compile time itself...
// A simple example of Template Meta programming

int main() {
    cout << POWER<3>(10)<<endl;
}

My Rant @ Pycon India 2010

I just happen to find out that , the video of my extempore talk (a rant ) given @ Pycon 2010,India has been uploaded.

http://pyconindia.blip.tv/file/4533542/

GDI+ from a MFC Application

I have programmed GDI+ from my C# Winforms application and ASP.net applications. Today , a friend of mine who was using GDI for a program was interested in switching to GDI+ for getting some graphics effects. I did write a simple MFC program and played with GDI+ API from C++.

We can use GDI+ from native code !

A Bug !! - Can you spot it ? - Part 1

In the last K-MUG user group meeting , I had taken a presentation which was titled as "Lambda - it's uses and Abuses". One of the program which was shown there was a Bubble Sort which gives a Comparitor Function ( Comparison Function ) as parameter.  By  changing the Comparitor function , I used the same algorithm to sort an array in descending or ascending order.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Sorter
{
    class Program
    {
        /// <summary>
        ///   A naive bubble sorter...
        /// </summary>
        /// <param name="ars"></param>
        /// <param name="comp"></param>
        /// <returns></returns>
        public static bool BubbleSort(double[] ars, Func<double, double, bool> comp)
        {

            int length = ars.Length;
            for( int i=0; i < length; ++i )
                for(int j=0;j<length; ++j )
                    if (comp(ars[i], ars[j]))
                    {
                        double temp = ars[i];
                        ars[i] = ars[j];
                        ars[j] = temp;

                    }

            return true;
        }

        static void Main(string[] args)
        {
            double[] ars = { 10,-4, 1, 2,-3 };
            /////////////////
            // Sort in Ascending Order...
            //
            BubbleSort(ars, (a, b) => a > b ? true : false);
            foreach (double a in ars)
                Console.WriteLine(a);

            ////////////////////////////////
            // Sort in Descending order...
            //
            //
            BubbleSort(ars, (a, b) => a < b ? true : false);
            foreach (double a in ars)
                Console.WriteLine(a);
            Console.Read();

        }
    }
}



To my surprise , the Lambda I gave for ascending order was behaving as lambda for descending order and vice versa. I got confused and i asked for help from the audience. None of us could spot the bug here.

Can you spot it ? ( I will give the answer in one week's time.... )

Using Visual C# 2010 or 2008 , u can run the program. The program will print the series of numbers in descending order and then it will print the stuff in ascending order ( but , my intention was to show in reverse order ! )