Saturday, March 16, 2013

Critical non functional requirements

Critical non functional requirements of a software product 

Below wiki identifies the key quality elements of a software. This is a good exhaustive list that can speak about the quality of a software in a tangible or quantifiable manner.

http://en.wikipedia.org/wiki/List_of_system_quality_attributes 

Out of all the elements in the above wiki, I believe below are the top priorities for a software product.

  • Availability (SLA) 
  • Fault Tolerance 
  • Performance 
  • Scalability 
  • Configuration Management 
  • Documentation 
  • Testability 
  • Monitoring 
  • Resilience 
  • Audit and control 
  • Interoperability 
  • Maintainability 
  • Security

Tuesday, January 10, 2012

Going Green

I never really focused much on the Green concepts. People are being made aware on the environmental impacts with plastics, batteries, hazardous material usage. But I didnt really look into any of this and contribute to the Green movement.

As a new year resolution, I am planning to increase my understanding on the Green effect and take an active role in spreading the news.

How does batteries or Lithium cells affect the environment ?
It appears batteries release magnesium and zinc into the landfills which can effect the aquatic life. So use the local recycle centers to recyle the batteries. You should not mix these with the regular garbage.

Where to use a Builder pattern

The big difference between Builder pattern and Abstract factory pattern is that the builder pattern doesnt immediately return a complete product in a single call.

The Director uses various building blocks of the builder and builds the product. The director is responsible to call the builds of the components.

A good doc on this can be found in the below link.

http://en.wikipedia.org/wiki/Builder_pattern

The builder pattern can be used where the complete product cannot be built at one shot. For example consider a FeedBuilder which builds feed of a specific data. The raw data records is transformed into a flat file. The raw data records are added into the FeedBuilder as data is processed. Finally when all the data is added into the FeedBuilder, the Feed reference is obtained from the FeedBuilder by the Director.

Monday, December 26, 2011

LRU Cache Design

Q. How to design an LRU cache with the constraint that the LRU element should be obtained in 0(1) runtime.

A. I started off to use heap to store the hits and use the hits count to find LRU elements. It achieves all the requirements posed in the question. But every insertion and deletion from the heap involves 0(logn) complexity. There is a more optimal approach to this problem. The question has no requirement to have all the hits maintained.

We can leverage on the standard Java Collections Map and implement the LRU cache the below way. The crux is that we use a doubly linked list, a collection to store the access order of the elements in the cache. Whenever a key is accessed, it is moved to the top of the list.


Class LRUCache<K,V> {
Map<K, NodeEntry<V> > cache;
List<NodeEntry<V>> accessOrderList;

public V find(K key){
LRUNode nodeEntry = cache.get(key) ;
if( nodeEntry == null) { return null; }
accessOrderList.moveToTop( nodeEntry );
}
};

Wednesday, June 20, 2007

printing combinations

Problem:
Print all combinations of M members of a set of N elements in a sequence such that each set can be obtained from the previous set by deleting one member and adding one member.

=================================
Take an example to understand:

given str: abcd , n =4, m =3
abc, abd, acd, dbc

main()
{
string s = "abcd";
sub = s.substr(0,m);
rem = s.substr(m+1, n);
comb(sub, rem);
}
comb( string s, string remain)
{
// extract the rest apart from first char
sub = s.substr(1, s.len);
// get all the combinations of the substr.
comb(sub, remain);
foreach ( char r in remain )
{
s[0] = r;
remain.remove(r);
comb(substr, r);
}
}


// take an example and run through the code to better understand the above.

Friday, May 18, 2007

Deleting a const pointer

Never thought that one can delete a const pointer in c++ without performing a const_cast on it in c++.

Tested this with the below code sample
========================
class A { public: int l; };
void test ( const A *aObj) { delete aObj; }
main() {
A *aObj = new A();
test(aObj);
}

=========================

To my surprise the code works on gcc-4.0.

So one cant be relaxed by just giving away a const pointer. Only way you can restrict the user from deleting is by giving out a reference or using smart pointers.

Even if they dont allow delete on a const pointer. The user can still invoke the desctructor explicitly by calling 'aObj->~A()' which is just another public function. So it seems like its a conscious decision made by c++ gurus.

==================
main() {
const A *aobj = new A();
// there should be a way for him to cleanup this..
// So makes sense to have delete supported.
delete aObj;
}
=================

snippets of some discussion forums :

"

However, this was always a little bit inconsistent,
since C++ has always permitted destroying an object via a pointer to
const by explicitly invoking the destructor, as in `p->~Foo()'. When
the committee decided to allow `const Foo *p = new const Foo', it
became pretty clear that they also had to allow `delete p'. So since
November 94, C++ has allowed deleting a pointer to a constant object. "

References:
http://www.thescripts.com/forum/thread439679.html
http://cpptips.hyperformix.com/cpptips/delconst.txt

Wednesday, May 9, 2007

Reflection programming model

I have been hearing a lot about the Reflection programming model.
The initial impression has been that how could a program modify itself and
where in the world does a software engineer need this ?

So here goes my hunt to demystify the myth behind this Reflection pattern.

Reflection is the ability to determine the behavior of your program at runtime.
Whats great? I can have many if conditions to get this done...
Yes you can change the behavior of the program with if clauses, but you cant dynamically determine what function to call without knowing the function name at compile time.

Reflection provides you a way to retrieve the name of the data members and member functions of a class and invoke them selectively at run time.
This is a read only reflection which is provided by Java.

Some languages (interpreters like PHP ) provides you an ability to add data members and member functions to a class at runtime.

In C a minimal set of reflection features can be obtained by dynamic libraries. A function can be looked up in the shared libraries using dlopen, dlsym and invoked.

The advantage Less code modification.


References :

1. http://en.wikipedia.org/wiki/Reflection_%28computer_science%29

For people familiar with php
http://php.corp.yahoo.com/manual/en/language.oop5.reflection.php