Showing posts with label software engineering. Show all posts
Showing posts with label software engineering. Show all posts

24 February 2011

Git - ignoring files using .gitignore

When you work on a project with Git, sometimes you don't want Git to track certain files, what you can do is edit .gitignore file so that Git knows the files listed in .gitignore should not be tracked. You should use .gitignore to keep annoying irrelevant files out of your development process.

Check out link here for more elaborated explanation: http://bit.ly/geMoTy

05 February 2011

What is focus in computing?

'In computing, the focus indicates the component of the graphical user interface which is currently selected to receive input. Moving the focus away from a specific user interface element is known as a blur event in relation to this element.'

By convention, the tab key is used to move the focus to the next focusable component and shift + tab to the previous one.

There are several window management policies for focus:

Click to focus

On most mainstream user-interfaces, such as ones made by Microsoft and Apple, where one must click the mouse inside of the window for that window to gain focus.

Focus follows pointer

Another common policy on UNIX systems using X11 is the "focus follows mouse" policy (or FFM), where the focus automatically follows the current placement of the pointer.

31 January 2011

Virtual function

In object-oriented programming, a virtual function or virtual method is a function or method whose behaviour can be overridden within an inheriting class by a function with the same signature. This concept is a very important part of the polymorphism portion of OOP.

The purpose of having a virtual function is as follows:

In OOP when a derived class inherits a base class, an object of the derived class may be referred to (or cast) as either being the base class type or the derived class type. If there are base class methods overridden by the derived class, the method call behaviour is ambiguous.

The distinction between virtual and non-virtual resolves this ambiguity. If the function in question is designated "virtual" in the base class then the derived class's function would be called (if it exists). If it is not virtual, the base class's function would be called.

Virtual functions overcome the problems with the type-field solution by allowing the programmer to declare functions in a base class that can be redefined in each derived class.

Programming language supports for virtual function:

C++: virtual methods are declared by using the virtual keyword followed by the function name and the parenthesis ().

Java: In Java, all non-static methods are by default "virtual functions." Only methods marked with the keyword final, which cannot be overridden, along with private methods, which are not inherited, are non-virtual. To override a method, use an annotation '@Override' (could be omitted) followed by function definition.

Python: In Python all class functions (methods) are virtual. And no special keywords needed to make overriding or virtualization happen. It just works automatically!

Reference: wiki

07 December 2010

Deep copy vs. Shallow copy vs. Lazy copy

There are basically three strategies for copying objects; each has its own advantages and disadvantages.

Shallow Copy

Shallow copy is basically passing references, not actually copying data inside objects. That is why shallow copy is otherwise known as address copy. The main advantage of shallow copy is it is very fast and does not depend on the size of data; however, if the language does not support automatic garbage collection, a shallow copy could lead to a memory leak if not cautious enough. In addition, two object references refer to the same data block on memory after shallow copy.

Deep Copy 

This is the opposite of shallow copy. The data from one object is actually copy over to another object. Therefore, two object bare the same data after deep copy and yet there are still different objects! The disadvantage of this strategy is it is slow and expensive; however, deep-copied objects do not depend on each other and are independently modifiable.

Lazy Copy

A lazy copy is a combination of both strategies above. When initially copying an object, a shallow copy is used. A counter is also used to track how many objects share the data. When the program wants to modify an object, it can determine if the data is shared and can do a deep copy if necessary. This is also very similar to 'copy-on-write' technique used in most OSes.

So, how are copy actually implemented in programming languages?

In Java:  

Using clone method of a class.

In Python: 

the library's copy module provides shallow copy and deep copy of objects through the copy() and deepcopy() functions, respectively. Programmers may define special methods __copy__() and __deepcopy__() in an object to provide custom copying implementation.

17 October 2010

Git - SVN Crash Course

Posted from Diigo. The rest of my favorite links are here.

SVN Tutorial fo Unix

Posted from Diigo. The rest of my favorite links are here.