Design philosophy

What is UNIX philosophy? This has been explained in detail in Eric Raymond’s book The Art of Unix Programming.

The Unix philosophy (like successful folk traditions in other engineering disciplines) is bottom-up, not top-down. It is pragmatic and grounded in experience. It is not to be found in official methods and standards, but rather in the implicit half-reflexive knowledge, the expertise that the Unix culture transmits. It encourages a sense of proportion and skepticism — and shows both by having a sense of (often subversive) humor The more detailed explanation and views of  Doug McIlory the inventor of unix pipes, Robert Pike, Ken Thompson and others can be found here. 

Here is the classic example of doing things in the Unix way. I read this post of question and answers from page. I am listing the question and answers which will help to appreciate the beauty of unix and getting ourselves to arrive at simple and beautiful solutions for all kind of problems.

Question : We have entered some text .How to find out the frequency of each word entered ? What can be  the various techniques used to tackle this problem. ? Answer 1:  Use hashing to store words..If collission occurs, check for similarity.. If the words are same increment the counter the u should have associated with each word  Answer 2: Can it be done using Trees.I need to know the approach for taht method.Vivek,Can you provide a pseudocode for the method u said. 

Answer 3: Use binary search tree with node structure below
struct node
{
  int count;
  char *word;
  struct node *left;
  struct node *right;
}
and start inserting words as when you entered. if  you hit same word twice just increment the count.
Below I given is just Pseudo code not a rugged onestruct node *insert(struct node *node, char *word)
{
    if(node == null)
    {
      node = malloc(sizeof(struct node));
      node->word=strdup(word);
      node->left=NULL;
      node->right=NULL;
    }else if( strcmp(word, node->word)==0)
            count++;
    else if(strcmp(word, node->word)<0)
          node->left=insert(node->left, word);
    else
          node->right=insert(node->right, word);
    return node;
}
 print(struct node *node)
{
  if(node!=NULL)
  {
    print(node->left)
    if(node->count > 0)
    printf(“%s->%d”, node->word, node->count);
    print(node->right);
  }
} 

Answer 4: Let’s be practical. 

cat file | tr -s ‘ 11’ ‘1212’ | sort | uniq -c | sort -nr
  gives a list of tab or space separated tokens, with their frequencies, sorted in decreasing order of frequency. The last one is the unix way. The solution is clean, simple and beautiful to look at. There is no new code, no pains of testing and debugging the code. The solution is obtained by using the existing set of tools. Nifty! More on Unix Philiosophy

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




Pages

Thru Lens



More Photos

Tweets

View Karthikeyan S's profile on LinkedIn
Alltop, confirmation that we kick ass

%d bloggers like this: