Tuesday, February 28, 2012

Learning ASP.net - an approach

I have personally met at least one hundred people who feels that ASP.net is their primary skill-set. Some of them  are drifting to MS share-point due to some kind of "gravity" or "pull".  A sizable majority (more than 90% ) just fiddle with the pages and most of them are using the technology through some kind of home grown framework.

Recently,I happen to take a serious look at ASP.net MVC , from an architectural perspective. Being a person who has worked with Struts and Spring MVC ( through Groovy/Grails ) , I was trying to map my knowledge to the ASP.net pipeline.

Since ASP.net mvc was an open source project and the release of ASP.net mvc did not co-incide with a new realease of ASP.net web forms,I was sure that the ASP.net mvc technology might have been implemented using the existing ASP.net pipeline.

I began to ask about how ASP.net MVC is implemented through HTTP modules ( I suspected url routing might be module ) and handlers. To my surprise,even the most seasoned veterans of the technology do not have a clue regarding these stuff.

Now,I understand, why most people take months to learn ASP.net technology. They only have a peripheral familiarity with the request/response pipeline of the ASP.net.

In a week's time,I figured out the ins and outs of ASP.net by contemplation,consultation and digging into the code.

Ideally,Every developer should try to understand the ASP.net request processing pipeline to have command over this technology.

"Every ASP.net url request is passed through series of Modules (some kind of implementation of  IHttpModule  ) and finally reaches a Handler ( some kind of implementation of IHttpHandler ) "


1. ASP.net web forms are implemented through ASP.net modules and PageHandlerFactory
2. Web services are implemented in these fashion
3. Ajax.net is implemented this way
4. WCF web services follow the same pattern
5. ASP.net mvc follow this pipeline
6. For uploading large files,one needs to be familiar with IHttpModule interface


Invest time in learning the pipeline and have familiarity with how  above technologies are implemented. You will save lot of time for sure !

Thursday, February 23, 2012

Software Architecture notes - Part 2

While architecting a system,one needs to identify cross cutting concerns very early. Some of the dominant ones are authentication/authorization,security,audit/log,some business rules specific to domain or application,configuration management,compliance etc.

Modularization is a tool which we can use to battle complexity and care has to be taken to minimize the coupling between the modules. The Inversion of Control/Dependency injection is  a strategy by which implementations do not get coupled.

Pluggability is another stuff which helps to evolve the software to suit the changing requirements. Unlike a traditional architect,the product of software architect must evolve to suit the changing requirements.

Wednesday, February 22, 2012

Software Architecture notes - Part 1

Software Architecture is a set of structures , idioms, practices and ideas meant to reduce the ubiquitous complexity found in software systems.

Primary tools of trade  are abstraction and seperation of concerns.

Every software system is a solution to requirements (problem)  in the problem domain ( bounded by a context ) and requirements can be functional and non functional.

Since the complexity of the functional requirement is given and cannot be reduced beyond a point,the focus of the software architecture has been the reduction of accidental complexity at the non functional front.

A software architecture should satisfy some "illities" ( quality attributes ) which is dictated by the goal of the stake holder. Some may strive for manageability and in
another context,it might be usability or securability.




Tuesday, February 21, 2012

Procrastination is costly than we think

I assume that Loss aversion is one of the main reason why we procrastinate. Recently,I happen to get enough courage to tackle a problem which has been bothering me. I could come out of the issue in couple of days time and my hindsight bias (?) tells me that this should have been done earlier.

Anyway,the price paid for "flirting" with my problem is loss of close to six lakh rupees in five years time.

Thursday, February 16, 2012

History Channel - Hindi Avatar is helping me in improving my Hindi

I take breakfast at my ancestoral home and It has now been  a habit for me to watch the history channel. The programs are dubbed in Hindi and quality of translation is really good. Along with gyan,I am gaining good linguistic insights as well.

Monday, February 13, 2012

Computer Programming and Reductionism

Reductionism is  a  philosophical approach which states that a complex system is nothing but the sum of its parts, and that an account of it can be reduced to accounts of individual constituents.

Any complex computer program ( in an imperative language ) can be reduced into Expression and Statements. They are composed together using Sequence,Branching,Iteration,Function and Recursion.
Some Programs have got facility to group these stuff under entities called Classes. ( If the language in
question is Object Oriented )

The story is not complete,if we do not discuss the State (of the data in the program). We can see Program as a set of instruction which transforms the state as the program gets executed.

1. Expression is what you evaluate for it's value
2. Statement is what you execute for it's effect
3. Sequence of Statement forms a Function
4. Collection of Functions form a Module | Class
5. Collection of Modules form a Program







Sunday, February 12, 2012

Fidding with fsLex and fsYacc

One of the nice thing which happened to me in my programming career was early chance encounter with
the book,"Unix Programming environment" (Kernighan/Pike). I happen to learn about  Lex and Yacc through their example calculator progrom ( programming language ? ) named as HOC (Higher order Calculator ).

I have used Lex (Flex) /Yacc (Bison) , Abraxis PC Lex/Yacc , ANTLR and other parser generators in my projects. Today,I played with fsLex and fsYacc to port some of my old C/C++ code into F# and the conversion was easy.



Thursday, February 09, 2012

Predicament of Husbands and Bhima ad

പെണ്ണായാല്‍ പോന്നു വേണം
പൊന്നും  കുടം  ആയിരിക്കണം
പതരമട്ടു അവള്കെകാന്‍ ഭര്‍ത്താവിന്റെ കാശ് വേണം 

Monday, February 06, 2012

F# code snippets - part 11

This snippet demonstrates the TAKE function available in most functional programming languages


//////////////////////////


// eleven.fs

//

// A program in F# which demonstrates

// how to extract first n elements from a list

// 

//

// Written by Praseed Pai K.T.

// http://praseedp.blogspot.com

//

//

//

// fsc eleven.fs

// eleven.exe

//





//-----------function take extracts the first i elements

//-----------from the list...



let rec TAKE i lst =

match i , lst with

| i,[]-> []

| i,x::xs-> if (i > 0) then x::(TAKE (i-1) xs) else [];







//---------------extract a list from another list



let newlst = TAKE 3 [1;4;9;16;25;36]





//--------------- print the extracted list..



printfn "%A" newlst



F# code snippets - part 10

Here,we will learn to compute the square root of number using Newton Raphson's method.


//////////////////////////


// ten.fs

//

// A program in F# which demonstrates

// the computation of square root using 

// Newton Raphson method.. 

//

// Written by Praseed Pai K.T.

// http://praseedp.blogspot.com

//

//

//

// fsc ten.fs

// ten.exe

//







//------------ Search for the root....!



let rec SearchRoot ( a , x , precision ) =

let nextguess = ( a/x + x ) / 2.0

in if abs ( x - nextguess ) < precision *x then 

nextguess 

else 

SearchRoot ( a , nextguess,precision )





//------------ create a curried function...!



let SQRT a = SearchRoot(a,1.0,0.0000000001)





//---- compute and spit sqrt of two 



let result = SQRT 2.0

printf "%f\n" result



//---------- compute and spit sqrt of three



let result2 = SQRT 3.0

printf "%f" result2

F# code snippets - part 9

In this section,we will compute the Power ( Math.Pow in C# ) function recursively using F#


//////////////////////////


// ninth.fs

//

// A program in F# which demonstrates

// the computation of power ( x ^ n )

// 

//

// Written by Praseed Pai K.T.

// http://praseedp.blogspot.com

//

//

//

// fsc ninth.fs

// ninth.exe

//





//--- Recursive computation of Power

//

// x^ 1 = x

// x^(2*n) = (x^2)^n

// X^ (2*n + 1) = x * (x^(2*n) )

//



let rec Pow( a:float , b:int ):float =

if ( b = 1 ) then a 

else if b%2 = 0 then Pow(a*a , b / 2 ) 

else a*Pow(a*a , b / 2 )





//--- compute the power of 8^ 3



let result:float = Pow(8.0,3)



//--------- spit the result...



printf "%f" result

Sunday, February 05, 2012

F# code snippets - Part 8

The snippet given below shows how functional programming with pattern matching can help you in writing compilers and interpreters very fast.


//////////////////////////


// eight.fs

//

// A program in F# which demonstrates

// implicit creation of Abstract syntax tree

// to interpret expressions... 

//

// Written by Praseed Pai K.T.

// http://praseedp.blogspot.com

//

//

//

// fsc eight.fs

// eight.exe

//





//--- Define what an expression is ...

//--- it is a 

// Constant , Add followed by two Expressions,

// Mul followed by two expressions...etc 

//

//

type Expr = Const of int

| Add of (Expr * Expr)

| Mul of (Expr * Expr)

| Div of (Expr * Expr)

| Sub of (Expr * Expr)





//----------- Evaluate the function...it takes an 

//----------- Expr and a function which returns it's

//----------- own parameter ( i call it unity function )



let rec Eval (e:Expr) (f:int -> int) = 

match e with 

| Const x -> f x

| Add (a,b) -> Eval b (fun z -> z + Eval a f)

| Mul (a,b) -> Eval b (fun z -> z * Eval a f) 

| Sub (a,b) -> Eval b (fun z -> z - Eval a f)

| Div (a,b) -> Eval b (fun z -> z / Eval a f) 





//--- here is our unity function...



let unity = (fun a -> a)



//---- AST for (3 + 4) * 5



let expr_to_eval = Mul( Add(Const 3,Const 4), Const 5)





//---- Evaluate the expression...



let result = Eval expr_to_eval unity





//------------- spit the result..



printf "%i" result



F# code snippets - part 7

The program given below uses partial application to generate new function from existing function. This process is called currying


//////////////////////////


// seventh.fs

//

// A program in F# which demonstrates

// currying ( partial application )

// 

//

// Written by Praseed Pai K.T.

// http://praseedp.blogspot.com

//

//

//

// fsc seventh.fs

// seventh.exe

//







//--- generate a sequence of numbers recursively 





let rec upto_withstep l u s =

if ( l > u ) then [] 

else l::(upto_withstep (l+s) u s)





//--- we are creating a new function with a step value 

//--- of 1

//---- upto reduces the arity of upto_withstep by 1

//---- This is called currying ( namded after Haskell b Curry)



let upto l u = upto_withstep l u 1



//-- generate the sequence !



let nt = upto 10 17



//---- spit the result..

printfn "%A" nt 

F# code snippets - Part 6

This part demonstrates lambda functions and pipe forward operator ( |> )

eg of a lambda function is  { fun a , b -> a + b }


//////////////////////////


// sixth.fs

//

// A program in F# which demonstrates

// anonymous function (lambda),pipe 

// forward operator 

//

// Written by Praseed Pai K.T.

// http://praseedp.blogspot.com

//

//

//

// fsc sixth.fs

// sixth.exe

//





//---------- generate a sequence of numbers



let numbers = {0..100}





//------- chain methods using pipe forward operators



let OutputSequence =

numbers

|> Seq.filter (fun x -> x % 2 = 0)

|> Seq.map (fun x -> x * x)



//---------- spit the sequence ...



printfn "%A" OutputSequence

F# code snippets - Part 5

This section will show how to use pattern matching to recursively compute the length of a list .


//////////////////////////


// fifth.fs

//

// A program in F# which demonstrates

// Recursive computation of length of a list 

//

// Written by Praseed Pai K.T.

// http://praseedp.blogspot.com

//

//

//

// fsc fifth.fs

// fifth.exe

//





///////////////

//

// Recursively compute the length...!

//

//



let rec length lst =

match lst with

| [] -> 0

| head::tail -> 1 + length tail





//------------ declare a list 

//------------ and computes it length



let list_num = [1;2;4;8;10]



let len = length list_num





//------------- spit the length



printfn "%i" len;





 

F# code snippets - Part 4

In a pure functional programming language,recursion replaces loops. The following program demonstrates this by recursively calculating the GCD of two numbers


//////////////////////////


// fourth.fs

//

// A program in F# which demonstrates

// Recursion 

//

// Written by Praseed Pai K.T.

// http://praseedp.blogspot.com

//

//

//

// fsc fourth.fs

// fourth.exe

//





//-------- Recursive GCD 



let rec GCD m n =

if m = 0 then n

else GCD ( n % m ) m





//--------- invoke the GCD function...



let result = GCD 10 6



//------------- spit the result...



printfn "%i" result

F# code snippets - Part 3

In this part,we will learn about tuple. Here,we are trying to model two dimensional vectors .


//////////////////////////


// third.fs

//

// A program in F# which demonstrates

// a) tuples

// b) Function definition on tuples

// c) Function invocation on tuples

//

// Written by Praseed Pai K.T.

// http://praseedp.blogspot.com

//

//

//

// fsc third.fs

// third.exe

//







//---------------- declare a tuple 

//---------------- to model a 2D vector



let ar = ( 1.0 , 2.0 )



//---- A function to multiply two vectors



let mul (a,b ) (c,d ) = ( a*c , b*d )



//----------- scalar multiplication of vectors 



let scale (a,b) s = (s*a , s * b )



//----------- invoke scale and mul



let r =scale ( mul ar ( 4.0, 3.0 ) ) 2.0



//---- print the resulting vector 



printfn "%A" r





F# code snippets - Part 2

The following simple F# program demonstrates variable declaration,function definition and function
invocation.


//////////////////////////


// second.fs

//

// A program in F# which demonstrates

// a) variable definition

// b) Function abstraction (definition)

// c) Function invocation

//

// Written by Praseed Pai K.T.

// http://praseedp.blogspot.com

//

//

//

// fsc second.fs

// second.exe

//



open System



//----------- Define mathematical PI



let PI = 3.14159



//-------- Function definition



let area r = PI*r*r



//----------- invoke the function....



let result = area 3.0



//------------ spit the result 

printfn "%G" result

F# code snippets - Part 1

Here is a simple F# program. This program prints hello world on to the console.


//////////////////////////
//  first.fs
//
//  A Hello world program in F#
//
//  Written by Praseed Pai K.T.
//             http://praseedp.blogspot.com
//
//
//
//  fsc first.fs
//  first.exe
//
   
open System

[&lt;EntryPoint>]

let main(args) =
   printfn  "Hello world..."
   0

Peoples judgements are colored by their immediate priority

Today,I happen to go for a betrothel and chanced upon lot of faces which used to be in my midst a decade or two ago. It was a mess as meaningful conversation is not possible as frame of reference is so varied and curious pattern I noticed was I have to calibrate the sentence by sensing their immediate priorities.



Friday, February 03, 2012

There is Chaos in Pattern matching

I am going through Scala and F# to learn about Object/Functional Programming. To learn more about Functional Programming,I am fiddling with Haskell as well.

I have got good (reasonably ) understanding  of FP concepts and have been able to translate some examples from "ML for the working Programmer" to Scala,F# and Haskell. But,going is slow as
I switch languages.

One of the prime reason is Pattern matching. Each of these language has got it's own rules. It is like learning Regular Expressions where each variant has got different meta characters.


Wednesday, February 01, 2012

Swam across the river Periyar after six years (approx)

The Malayalam movie  "Naran"  was released in the year 2005 and I was on vacation during it's release. Inspired by the movie clips,I went to the river Periyar and swam across it. I liked the movie because of the
portrayal of certain river scenes. (It was also a good movie of Mohan lal in his "Savari Giri Giri" times )

Yesterday,a friend of mine and I went to the river and we spent close to two hours there.  I crossed the river
once (might be 50 meters on to one side ) and  re-discovered my "amphibious" nature.

I became euphoric after this feet ( of crossing the river ) and reflected back to those golden years (1984/1991) where I used to spent an average of three hours( most of the days) in the river. I used to swim across , swim along , swim against and swim even during the rainy season (water level and tide will be quite high).

Here are two funny things which I remember

 I was a ardent chess enthusiast and used to analyze most of the Karpov/Kasparov matches of their 1985 season (from a book ). Even though I was a Anatoly Karpov fan,I really got impressed by Kasparov's techniques. From a program called "World this week",I learned that Garry Kasparov used to swim a mile,
a day. I used to swim roughly a mile across the river ( with and against the tide ) for a month and finally
my father put an end to this "madness"

In those days,A tailor in my home town used to come to the banks and swim for hours. He was a peeping tom (in those days,ladies,in large numbers used to take bath in the river ) and to be frank,he was a great swimmer. After my "amphibious" years,I forgot the tailor and even my swimming. Last year,I was trying to
board a bus to Bangalore and chanced upon this fellow. Initially,he could not recognize me and later he
could. He used to come with a four year old boy and the boy used to wait at the river bank for hours.
Out of curiosity,I asked where the boy is and to my surprise,the boy is a management student at IIM
now. ( May be the boy learned patience from those waiting days! )