Monday, November 22, 2010

Why Writing is Important?

Do I need to learn how to write? What does it mean? Does it only mean I should write correctly in terms of grammar? The answer for 'only grammar' is No.

Lets go to the fundamentals, why do we write? Um... one would say, for communication. Then why do we communicate? For making others understand our viewpoint. So understanding is the most important concept.

Now, whats special with writing provided that we can talk too? The key idea is preservation of clear thoughts and that's the magic of writing. Its not important to write in perfect grammar as compared to writing clear and unambiguous(which are interpretable in one way) thoughts. Grammar is a side hero in this area but the main hero is transfer of clear thoughts.
In this article, I took grammar as a general representative of syntax (i.e., spellings, tenses etc). Some people feel that writing is about bragging their fluency in a particular language but this is one common myth.

Let me give some examples of unambiguous writing so that I can transfer my thought in a clearer way.
1- This is a sentence where a/b is true.
Ans- How do I read that? This is a sentence where a or b or both are true. Common mistake in the interpretation could be a or b (at the reader’s end or at the writer’s end or at both ends).
2- This is example: This supports the example strongly.
Ans- How do I read that? This is example and following sentence strongly supports it due to colon. Common mistake would to ignore ‘:’ by reader/writer.
3- I am writing; I am sharing myself.
Ans- How do I read that? I am writing and one reason is to share myself. Common mistake could be to ignore ‘;’ or make it strongly associated with previous sentence by reader/writer i.e., I am writing because I want to share myself.

To conclude my short post, writing is a very effective way of communication. However, it brings complications because it does not involve body language (as we have in talks). Therefore, its important to understand the idea behind this style of communication in order to avoid being mis-reported or mis-read etc. It is also an important skill for both readers and writers.

If you find this post interesting please share it with your friends. This post is both applicable for general and technical writing purposes/practices.

Thursday, November 18, 2010

Normalization of data

Normalization

Normalization is a well-known standard that helps efficient storage and retrieval of data from the relational database systems. There are three important normalizations available. They are:
First Normal Form
Second Normal Form
Third Normal Form

This articles talks about these three normal forms with examples. Let us start.

First Normal Form

The first normal form says, "The information stored in the form of database table should be well split into columns. When you split make sure same information is not split into multiple columns".

Consider the table below
ID NAME
1 Syed Sharique Imam
2 Asaad Khurshid

Let us say there are 4000 such members in the table. If you want to retrieve the data in the descending order based on the last name then you need to perform string manipulation on the stored data. Also it is not always guaranteed that the information you split is fully qualified last name as you may perform string manipulation based on the space. The first statement in the Normalization (First Normal form) specifies this. Data should be well split into column. Why do I put "well split" into underline? Because we all know that data should be split into columns. Definitely no one will design the preceding table as below:


Below is the Well Split table:



Well, but the First normal form says "When splitting do not split same information into multiple column". It may confuse that I split the same information, the Name into multiple columns. OK. Do not look at the initial column before the split that is; the member name. Look at the final result and apply the rule:

"Do not split same information into multiple column"

First Name and Last Name are different, so it is not the same information. Each column is well categorized. So why the First Norm says "So not split same information into multiple columns"?

To explain that look at the below table:



The table stores the Orderid and which customer placed the order in custid. But, if you have look at the columns for products in the table, it is stored as separate column. The same information is repeated in multiple columns like product1, product2 etc., to show the products in each order. Number of product that belongs to the Order is not constant as it varies. So Data Manipulation should accommodate the change in data like inserting a row or Modifying a row. The schema should not change.

The correct design is shown below:



Second Normal Form

The Second Normal form says, "Entire columns in the table should functionally depend on a single key that uniquely identifies the row also should adhere to the first normal form". Note that, here the key may be a combination of more than one column.



In the above table say Orders, Customerid and OrderPrice are depending on the single key column Orderid. The CustomerName field is not related to OrderId and should go on a Customer table. If we remove the Customer Name fields from this field the table is in Second normal form.

Third Normal Form

The third normal form says, "Any columns in the table should not depend on column which is not a key column that uniquely identifies the row. Also, first it should be in second normal form".

It means if a table has some columns that depends on some other column that is not a primary key column then the table is not in third normal form. Let us consider the following example:



In the above example the TotalPrice column is dependent on UnitPrice and NoOfItems. Hence, this column should be removed from the database. The program that processes this table should calculate the TotalPrice or a view could be created to have the calculated column such as TotalPrice. Whatever the solution, for the preceding table to be in the third normal form the TotalPrice column should be removed from the table.

Monday, November 8, 2010

Document Object Model (DOM)

What is Document Object Model (DOM)?
  • is an API for valid HTML and well formed XML documents
  • defines the logical structure of documents and the way a document is accessed and manipulated
  • With DOM programmers can build documents, navigate thier structure, and add, modify or delete styles, attributes, elements and contents
  • Infact anything found in an HTML or XML document can be accessed, changed, deleted or added using DOM, with a few exceptions
  • Can be accessed via any language in the browser including Java, JavaScript/ECMAScript/JScript and VBScript (IE only)


Few Terms
  • Node: A reference to
    • an element (tag) and its attributes
    • or a piece of text
  • Element: A representation of a
  • Attribute: A property of an element. HREF is an attribute of element for example


Detecting Browser Compatibility
  • To detect browser support for a particular DOM property or method we want to use we have to use “object detection”
    • Example: In the DOM most commonly used method is document.getElementById. To detect browser support for this method before proceeding with our DOM related code, we have to check the suport like this:
      • If (document.getElementById)
      • document.getElementById(“div”).getAttribute(“align”)
      • Add Elements to the DOM
  • Steps
    • create the node (text node or element) you wish to append
      • To create a new text node use a createTextNode() method of document object that will return a node with given text in it
      • var txtNode = document.createTextNode("Hello. This is a new node.");
      • To create a new element and set attributes on it
      • var link = document.createElement('a');
      • link.setAttribute('href', 'mypage.htm');
    • find where you wish to append it within the document tree using getElementById method of document object that will return an object
      • var myDiv = document.getElementById("myDiv")
    • actually do the appending
      • To append at the end of the div
      • myDiv.appendChild(txtNode); or
      • document.getElementById('myDiv').appendChild(link);
      • To append at the beginning of the div
      • myDiv.insertBefore(link, document.getElementById('myDiv').firstChild);

  • Copy this working example to new html file and try it.


Click here to generate yahoo website link


This text is the first child of mylinkdiv


To Hide/Show any element
  • To dynamically hide/reveal any element on the page using DOM try this example


Click here to hide/show below element




You can see it now


To add textbox and define onchange event on it
  • To dynamically add textbox and define onchange event on it, try following:


http://www.w3.org/TR/DOM-Level-2-Core/introduction.html
http://www.javascriptkit.com/javatutors/dom.shtml

Sunday, October 31, 2010

C# ----- Language Interopability


Visual Studio -> 2008/2010

Open New Project.. Select Class Library of Visual Basic Project..

Make a Function..

Class1

Public Function Add(ByVal i as Integer, ByVal j as Integer) As Long

return i + j

End Function

End Class

(Check the Snapshot above)


Now Build the Project by pressing ALT+SHIFT+B,, and check the destination of this project, There must one one dll created in the bin-> debug folder..

Now Open another Project.. Select Console Application of C# Project...

On right side, there is a solution explorer... Click on Add Reference.. New window open,, Select Browse and then go to the destination of Class Library of Visual Basic Project.. and Add the file of dll from bin-> debug folder as said above..

Now In Main Function...

static void Main(string[] args)

{

ClassLibrary1.Class1 obj = new ClassLibrary1.Class1();

Console.WriteLine( obj.Add(3, 4));

}

This above example shows how a program written in VB.net does'nt make any difference due to the CTS, C# easily understand the code of VB.net due the CTS..