Tuesday, September 15, 2009

[BCC] Intake for National ICT Internship (Batch-7)

Dear All
BCC has declared their National ICT Internship. You can apply if you are interested. Here, I enclose the notice in attachment.
--
[Regards]
Zohirul Alam Tiemoon.
Consultant.
BASIS (www.basis.org.bd), Dhaka.
Bangladesh.

~[ Details Info Here ]~

Monday, September 7, 2009

Classes (C# Programming Guide)

A class is a construct that enables you to create your own custom types by grouping together variables of other types, methods and events. A class is like a blueprint. It defines the data and behavior of a type. If the class is not declared as static, client code can use it by creating objects or instances which are assigned to a variable. The variable remains in memory until all references to it go out of scope. At that time, the CLR marks it as eligible for garbage collection.

Declaring Classes

Classes are declared by using the class keyword, as shown in the following example:

public class Customer
{
//Fields, properties, methods and events go here...
}


The class keyword is preceded by the access level. Because public is used in this case, anyone can create objects from this class. The name of the class follows the class keyword. The remainder of the definition is the class body, where the behavior and data are defined. Fields, properties, methods, and events on a class are collectively referred to as class members.

Creating Objects

Although they are sometimes used interchangeably, a class and an object are different things. A class defines a type of object, but it is not an object itself. An object is a concrete entity based on a class, and is sometimes referred to as an instance of a class.

Objects can be created by using the new keyword followed by the name of the class that the object will be based on, like this:

Customer object1 = new Customer();


When an instance of a class is created, a reference to the object is passed back to the programmer. In the previous example, object1 is a reference to an object that is based on Customer. This reference refers to the new object but does not contain the object data itself. In fact, you can create an object reference without creating an object at all:

Customer object2;


MS do not recommend creating object references such as this one that does not refer to an object because trying to access an object through such a reference will fail at run time. However, such a reference can be made to refer to an object, either by creating a new object, or by assigning it to an existing object, such as this:

Customer object3 = new Customer();
Customer object4 = object3;


This code creates two object references that both refer to the same object. Therefore, any changes to the object made through object3 will be reflected in subsequent uses of object4. Because objects that are based on classes are referred to by reference, classes are known as reference types.

Source : http://msdn.microsoft.com/en-us/library/x9afc042.aspx

Properties (C# Programming Guide)

Properties are members that provide a flexible mechanism to read, write, or compute the values of private fields. Properties can be used as if they are public data members, but they are actually special methods called accessors. This enables data to be accessed easily and still helps promote the safety and flexibility of methods.

In this example, the TimePeriod class stores a time period. Internally the class stores the time in seconds, but a property named Hours enables a client to specify a time in hours. The accessors for the Hours property perform the conversion between hours and seconds.

Example
class TimePeriod
{
private double seconds;

public double Hours
{
get { return seconds / 3600; }
set { seconds = value * 3600; }
}
}

class Program
{
static void Main()
{
TimePeriod t = new TimePeriod();

// Assigning the Hours property causes the 'set' accessor to be called.
t.Hours = 24;

// Evaluating the Hours property causes the 'get' accessor to be called.
System.Console.WriteLine("Time in hours: " + t.Hours);
}
}
// Output: Time in hours: 24



Properties Overview

# Properties enable a class to expose a public way of getting and setting values, while hiding implementation or verification code.

# A get property accessor is used to return the property value, and a set accessor is used to assign a new value. These accessors can have different access levels. For more information, see Asymmetric Accessor Accessibility (C# Programming Guide).

# The value keyword is used to define the value being assigned by the set accessor.

# Properties that do not implement a set accessor are read only.

Source : http://msdn.microsoft.com/en-us/library/x9fsa0sw.aspx

Saturday, September 5, 2009

Using enum in C# for smart coding








Most of us have written these (Sample 1 & Sample 2) kind of code snippet in our student or even professional life:


Sample 1 (C# Code):
string employeeType = employeeTypeComboBox.Text;
if (employeeType == "Permanent")
{
CalculateSalary();
}
else if (employeeType == "Worker")
{
CalculateWages();
}
else
{
// Do nothing
}




Sample 2 (C# Code):
string studentType = studentTypeComboBox.Text;
if (studentType == "Regular")
{
// Do Something
}
else if (studentType == "Private")
{
// Do Something
}
else
{
// Do nothing
}
In these two samples, user input is taken in a string valriable (employeeType /studentType) from a ComboBox and compare the variable with some discrete hard-coded string values (Permanent/Worker/Regular/Private).
What will happen if you type (some of you has faced these sad experiences) Parmanent instead of Permanent in Sample 1? Definitely, CalculateSalary() method will be not called and even program doesn’t show you any error message (any compile error). In best case, You will find out this problem during development and fix it immediately. But in worst case this problem arises after demployment.





Is there any solution where my typo will be detected earliar and show me a compile error?
Yes. Try emun.




See Sample Code 3, the more smart version of Sample code 1. Here you have no typo option.




Sample Code 3
enum EmployeeType
{
Permanent,
Worker
}
string employeeType = employeeTypeComboBox.Text;
if (employeeType == EmployeeType.Permanent.ToString())
{
CalculateSalary();
}
else if (employeeType == EmployeeType.Worker.ToString())
{
CalculateWages();
}
else
{
//Do Nothing
}




Believe me still you have chance to improve the code quality of Sample Code 3. Just see the Sample Code 4, I have wipe out all kinds of string variable from Sample Code 3.




Sample Code 4:
EmployeeType selectedEmployeeType = (EmployeeType)Enum.Parse(typeof(EmployeeType), employeeTypeComboBox.Text);
if (selectedEmployeeType == EmployeeType.Permanent)
{
CalculateSalary();
}
else if (selectedEmployeeType == EmployeeType.Worker)
{
CalculateWages();
}
else
{
//Do Nothing
}




Even, as your input comes from employeeTypeComboBox, don’t write hard-coded string in it’s item list, rather do it:
employeeTypeComboBox.DataSource = Enum.GetNames(typeof(EmployeeType));



So, why enum?

a) To improve code clarity


b) Make the code easier to maintain

c) Getting error at earlier stage


Note:

a) You can define enum inside or outside of class, but not inside of method or property.

b) The list of names contained by a particutar type of enum called enumerator list.





More About enum:

a) If you want you can keep value with each name in enumerator list. Example:




enum Priority
{
   Critical = 1,
   Important = 2,


  Medium = 3,

   Low = 4

};





You will get this value by type casting to the related type.

int priorityValue = (int) Priority.Medium;






b) Another nice thing, you can easily iterate through enumerator list.

foreach(Priority priority in Enum.GetValues(typeof(Priority)))
{
   MessageBox.Show(priority.ToString());


}

or even
for (Priority prio = Priority.Low; prio >= Priority.Critical; prio--)
{
   MessageBox.Show(prio.ToString());


}




Conclusion:

You should avoid string operation (specially comparison) because it decreases readability and introduces opacity. But using enum you can increase code readability, discover bugs in design time and keep your code more easy to maintain. So, Instead of string operation we should use enum (where applicable)  as described in this discussion.



Source : Using enum in C# for smart coding (http://ztiemoon.blogspot.com/)

Sufferings with switch smell


Introduction
In my first blog, Using enum in C# for smart coding, described code snippets suffer with switch smell. So, here, I am explaining what the switch smell is, what’s wrong with it and how to avoid it?
 
Most of the time, our source code suffers with several bad smells. Authors of a great book, Refactoring: Improving the Design of Existing Code, explain these smells with refactoring techniques. Here, I try to explain how switch smell introduces unnecessary complexity, reduces flexibility and leaves a class with vague responsibilities (from caller’s point of view).



Code Explanation
In the following two samples (Sample 1 & Sample 2), I have written a class, Calculator which can perform four basic arithmetic operation addition, subtraction, division and multiplication on two numbers.
Note: Here all code snippets are written in C#.


Sample 1:
public enum Operation
{
    Add,
    Subtract,
    Multiply,
    Divide
}
public class Calculator
{
    public double Calculate(double firstNo, double secondNo, Operation operation)
    {
        switch (operation)
        {
            case  Operation.Add:
            {
                return (firstNo + secondNo);
                break;
            }
            case Operation.Subtract:
            {
                return (firstNo - secondNo);
                break;
            }
            case Operation.Multiply:
            {
                return (firstNo * secondNo);
                break;
            }
            case Operation.Divide:
            {
                return (firstNo / secondNo);
                break;
            }
            default:
            {
                throw new ArgumentException("Incorrect Argument");
            }
        }
    }




Sample 2:
public class Calculator
{
    public double Add(double firstNo, double secondNo)
    {
        return (firstNo + secondNo);
    }
    public double Subtract(double firstNo, double secondNo)
    {
        return (firstNo - secondNo);
    }
    public double Multiply(double firstNo, double secondNo)
    {
        return (firstNo * secondNo);
    }
    public double Divide(double firstNo, double secondNo)
    {
        return (firstNo / secondNo);
    }
}




Calculator of Sample 1 provides these functionalities with its Calculate() method whereas Calculator of Sample 2 has four methods for four specific functionalities.
In Sample 1, I introduce switch statement inside Calculate() method to distinguish the request of client code whether it (client request) wants to add, subtract, multiply or divide. On the other hand, in Sample 2, as each functionality is implemented in separate method I haven’t bothered with condition-checking (switch statement).



Comparison
Now, the question is: Which class is better than other one?
From design point of view Calculator is responsible for four distinct arithmetic operations, so it should have four methods in implementation level.
In Sample 1, Calculator has only a single method, Calculate() which perform four arithmetic operations. As a result it represents poorly self-documentation and introduces unnecessary complexity. It suffers with switch smell. As a result Calculator responsibilities is not concrete here. So, caller of the Calculate() method has to decide what it (caller) wants from Calculate() method by setting the parameter.
On the other hand, in Sample 2, interface of Calculator is clearer and also it is self-documented.
Sample 2 is more flexible than Sample 1. Suppose if I want to provide another functionality to add three numbers.
For Sample 2, I quickly write overload Add() method as follows with reusability.





public double Add(double firstNo, double secondNo, double thirdNo)
{
    return Add(Add(firstNo, secondNo), thirdNo);
}




But what’s for Sample 1?  :-((. I have to follow some ugly and stupid ways to implement this functionality which introduces more complexity, code repetition, procedural thoughts etc.


More..
In Refactoring: Improving the Design of Existing Code, Authors explain this problem (Sample 1)  under bad small of switch statement and also show several ways (‘Replace type code with Subclasses’, ‘Replace type code with State/Strategy’, ‘Replace Parameter with Explicit Method’ how to refactor this smell. At the same time, authors describe ‘Parameterize Method’ which seems reverse of our discussion.


Conclusion
Each method of a class should represents a single activity, must be concrete and self-documented. One more activities in a single method (by switch smell) or one activity in several methods (I will discuss it another day) introduces complexicity and ambiguous interface, hinders changes, intencifies duplication and leave the class poorly self-documented.




Source : Sufferings with switch smell (http://ztiemoon.blogspot.com/)

OOP Training [BASIS]


Useful Article




First Project

Friday, September 4, 2009

Team [+ Pentium +]

[ 24 ] -- PJ
Name : Himadri Shekhar Sarder
Mobile : 01711-238088
Email :

[ 21 ]
Name : Wahed Khan
Mobile : 01819-138294
Email : irad33@gmail.com

[ 20 ]
Name : Abu Shalha Musa
Mobile : 01717-047835
Email : fahad351@gmail.com

[ 10 ]
Name : Md. Umor Farukh
Mobile : 01911-743002
Email : umor09@gmail.com

[ 07 ]
Name : MD.Harisur Rahman Sarker
Mobile : 01915-166878
Email : jewel09@gmail.com, jewel_1700@yahoo.co.in

Wednesday, September 2, 2009

Banglasavvy 0.0.5 (Beta Version)

Banglasavvy - Virtual Unicode Bangla Font Installer for
Windows XP/2000/98/NT


Author: Banglasavvy

License: Freeware!

Description:

Banglasavvy is a Virtual Unicode Bangla Font Installer for Windows XP/2000/98/NT. It will let you install ‘Bangla Font’ virtually to any system regardless of Administrator privilege. That means when you have limited access to some PC and do not have permission to install anything including fonts, this tool will be very handy then.

Instruction:

* Just download and run.

* The application will extract ‘Likhan’ font to the same folder for the first time and virtually Install the font; It also set the ‘Likhan’ as your default Bangla locale font for IE (Internet Exorer). A ‘Icon’ will be added to the ’systray’ of your system.

* Close all open window. Rerun, your application will see the ‘Likhan’ font and it will be usable while the banglasavvy.exe running.

* Right click on the systray Icon and select ‘Exit’ if you wants to close this Bangla tools.

Requirement:
No Installation will be required to run the application on Windows XP. It will also works on Windows 98/ME/2000 if there is Visual Basic Runtime files installed (download link avalaboe below).

Download: Click here to download

Additional Download: Visual Basic 6.0 Runtime Files (SP6) - For running Banglasavvy in Windows 98/ME/2000

Source : http://www.omicronlab.com/tools/banglasavvy.html

IComplex 2.0.0 (Full Edition)

Author: http://www.VistaArc.com/

License: Freeware!

Description:
Most of the time, when a new user tries to use Bangla on their system, complains that Bangla typing is not working in his/her system, Juktakkhor/Kar is not coming properly etc. This is the mostly asked support request in OmicronLab. All they make a simple mistake, that is, there system must be configured be fore they can use Bangla. Hence Bangla (and all east Asian languages) is a "complex script", it is not installed in Windows by default. Users need to install this support manually till Windows Xp (Windows Vista installs this by default).


All these days we are writing and publishing tutorials about "How to enable Bangla on your system". Here comes a simpler solution - IComplex. Within a simple interface, users can install/uninstall complex script support in their system. Now there is no need to bother with Control Panel>Regional settings, just use IComplex, enjoy the simplicity!



At a glance:

* Install Complex Script support (Bangla and all east Asian languages) on your system.
* Unstall Complex Script support anytime.


Who can be benefited:

* Any one, who wants to use Bangla Unicode (and all east Asian languages) based software (like Avro Keyboard).

* Software developers, who develop softwares for Bangla (and all east Asian languages) and want to let their users a simple method to enable this language.

* Bangla (and all east Asian languages) web page developers, who can distribute this tool to their visitors so that they can view the site properly.

Requirement: Windows 2000, Xp, 2003 Server



Download: Click here to download


Disclaimer: IComplex Full Edition doesn't require Windows CD because necessary system files are included in this package. Although this tool will work in any system (there is no genuine Windows version check), it is highly recommended that you will use original Windows if you don't want to break copyright law. Lite version of IComplex can be found here

Source : http://www.omicronlab.com/tools/icomplex-full.html

Avro Keyboard v4.5.1 (Portable Edition)

Avro Keyboard Portable Edition is the first ever Bangla software with portability. It has all the necessary features of Avro Keyboard, but the only difference is, unlike the standard edition, it doesn't need any installation, any font, any administrator access to the computer. Users can take it in there removable media like USB flash drives or iPods and run anywhere.


At a glance:

* - No Installation Needed

* - No Administrator Access Needed

* - No Bangla Fonts Needed, portable edition has built in Automatic Virtual Font Installer

* - Carry it in any media (like USB drives), use directly, use anywhere

* - All your settings/personalizations remain intact

* - Has all the features of Avro Keyboard Standard Edition.


At a glance:

* Download from below.

* Extract files.

* Carry the extracted files & folders together anywhere you need and directly run Avro Keyboard.

* Note: Some Anti-virus softwares may show warning about this portable edition due to presence of highly compressed and packed execurable. OmicronLab ensures that this is just a false positive warning and there is nothing to worry about.

Mirror 1: Download Portable Avro Keyboard (Courtesy: Niponwave )
Mirror 2: Download Portable Avro Keyboard (Courtesy: Maruf42 )
Mirror 3: Download Portable Avro Keyboard (Courtesy: Projanmo - Incredible Bangla Portal)
Mirror 4: Download Portable Avro Keyboard

Source : http://www.omicronlab.com/portable-avro-keyboard.html