Tuesday, January 21, 2014

Code Snippet in Blogspot

I use the following code CSS to post the code snippets in this blog:

I use the following code CSS to post the code snippets in this blog:
<code style="color: black; word-wrap: normal;">
<! ... Your Code Here .... !>
</code>


Sunday, January 12, 2014

Programming Style

Every programmer will have a style of programming, the way they write the programs. But, when you work as a team, it would be very useful if you and your team follow one 'programming style' for code readability and consistency. 
Here are some of the standard practices:
  • Adhere to the existing style
    • If a source file already has a style, please adhere to the existing style
  • Indent Code Blocks
    • Use 4 space indented code blocks, making it 4 spaces make room of more code within 80 columns.
    •  Use expanded tabs. By this way your code won't look different in different environments
  • Follow only one brace-opening style
    • C++ Style
      if.(...).{
       ... 
      }
    • C Style(K&R)
      if.(...) 

      ... 
      }
  • Use White-spaces between keywords, variables, operators for better readability
    if.(x.>.10).{ 
    ... 
    }
  • Use a Standard Naming Convention
    • Use uppercase for macros
    • Add prefix for macros within a module to avoid conflict with global
    • "UpperCamelCase" for classes, structs, enums, constants and typedefs (use nouns)
    • "lowerCamelCase" for functions, variables, parameters  even for abbreviations (use verb for function names)
    • Use 'get', 'set' - function prefixes. 'is' prefix for functions which returns Boolean(true or flase) value
Reference: Read "The Elements of C++ Programming Style."

Thursday, September 12, 2013

My Programming Quotes#1

When the Map contradicts the Terrain, Trust the Terrain. - Swiss Army
When the Comment contradicts the Code, Trust the Code for god's sake.

Monday, August 5, 2013

Programming Tips#1: Don't Replicate Code Block

Programming Tips#1: Don't Replicate Code Block

Don't replicate code block, write a function instead. If you replicate any code block and later if you decide to do any change with the block, you might need to change all.

By localizing your changes to a Function or a Macro, you localize the knowledge. If there is any knowledge change, you need to change it in only one place.

Sunday, March 17, 2013

Linux Useful Apps

Here is the list of Useful Apps in Linux:

* KeepNote - Notes Organizing Software
* Osmo - Daily Diary Software
* Pomodoro App - Pomodoro with Today's List and Alarm Software
* BlueFish - C/C++ IDE
* Geany - C/C++ IDE

Thursday, November 8, 2012

Who Am I and Who Is My Parrent

An Unix Process got created, but it know its name (its ID) and who created it. How will is know its ID ?

In Unix Operating System, a process is a living entity.A process is a program in execution.

How does a Process knows its ID, also know as Process-ID. 

[incomplete]

Thursday, April 5, 2012

Reverse Linked List - Recursion - with code



#include <iostream>

using namespace std;

struct node {
int data;
struct node *next;
};

typedef struct node NODE;

class linklist {
private:
NODE *head;
public:
linklist():head(NULL) {}
void push(int);
void display();
void reverse();
NODE* reverse_driver(NODE*, NODE*);
};

void linklist::push(int data) {
NODE *tmp = new NODE;
tmp->data = data;
tmp->next = NULL;

if (head == NULL) {
head = tmp;
} else {
NODE *curr = head;
while (curr->next != NULL) {
curr = curr->next;
}
curr->next = tmp;
}
}

void linklist::display() {
NODE *curr = head;
cout<<"HEAD: ";
while (curr != NULL) {
cout<<curr->data<<"->";
curr = curr->next;
}
cout<<"NULL\n";
}

void linklist::reverse() {
if (head != NULL) {
NODE *last = reverse_driver(head, head->next);
// make the last_node->next to NULL
head->next = NULL;

// change the head to the last
head = last;
}
}

NODE* linklist::reverse_driver(NODE *currnode, NODE *nextnode) {
if (nextnode != NULL) {
NODE *last = reverse_driver(nextnode, nextnode->next);
nextnode->next = currnode;
return last;
} else {
// Last Node - to be set as Head node
return currnode;
}
}

int main () {
linklist ll;

ll.push(10);
ll.push(20);
ll.push(30);
ll.push(40);

ll.display();
ll.reverse();
ll.display();
return 0;
}