Sunday, June 19, 2011

C++ final function solution

Simple explanation:

class FinalMethod1 { //all methods private
friend class ClassWithFinalMethod; 
// friend ClassWithFinalMethod ::theFinalMethod(); //this method also works but is not as portable.
FinalMethod1(){}
 FinalMethod1(const FinalMethod1& );
 FinalMethod1& operator=(const FinalMethod1& );
};

struct Base { //only ClassWithFinalMethod can override this one.
 virtual FinalMethod1 theFinalMethod ()=0;
};

struct ClassWithFinalMethod : public Base
{
 virtual FinalMethod1 theFinalMethod () { return FinalMethod (); }
};

More comprehensive one with Boost that allow to generate N number of classes that will implement final function:

#include <boost/preprocessor/repetition.hpp>
//specify desired number of classes will be used by default.
#ifndef NUMBER_OF_SLOTS
#  define NUMBER_OF_SLOTS 4
#endif
#if NUMBER_OF_SLOTS<1
#  define NUMBER_OF_SLOTS 1
#endif

//if
//#include <boost/mpl/identity.hpp>
// is included.
#ifndef BOOST_MPL_IDENTITY_HPP_INCLUDED
struct nothing {
      typedef nothing type;
};
#define ADD_FRIEND(z,n,name) friend class name##n::type;
#else
//identity will provide type where needed.
struct nothing {};
#define ADD_FRIEND(z,n,name) friend class boost::mpl::identity<name##n>::type;
#end

//generic class that return some return value.
//May need specialization for & and * implementation.
template< typename ReturnType, BOOST_PP_ENUM_PARAMS_WITH_A_DEFAULT(NUMBER_OF_SLOTS, typename T, nothing) > class final
 {
 BOOST_PP_REPEAT( NUMBER_OF_SLOTS, ADD_FRIEND, T )
 ReturnType _result;
 final( ReturnType result ): _result(result) {}
 final( const final& );
public:
 inline operator ReturnType() { return _result; }
};

//specialization for void return value.
template< BOOST_PP_ENUM_PARAMS(NUMBER_OF_SLOTS,typename T) > class final <void, BOOST_PP_ENUM_PARAMS(NUMBER_OF_SLOTS,T) >
{
 BOOST_PP_REPEAT(NUMBER_OF_SLOTS,ADD_FRIEND,T)
 final( ) {}
 final( const final& ){}
};

Friday, April 1, 2011

Lady Gaga meat headphones.

Her headphone model line has got new item with new earpads made of meat.

Friday, March 25, 2011

web entry forms, or be careful what you teach.

There is a lot of pages where you asked to provide credit card, SS or phone number. A lot of them requires to type data in specific format: no space, with space, numbers only etc. There is not much coding needed on the page to accept any format and parse out needed info. Some companies like Google do so. Why the other still asking for specific format? IMHO The reason is kind silly. Various validation code is posted as an example in the programming books. Programmers do what they were told to do: Validate to the hell (means to specific format). Annoying thing spread the world. Be careful what you give as example, it can spread the world.

Wednesday, March 23, 2011

to big to fail banks.

Here is a joke, one guy decided if government could not solve to big to fail banks, he will solve himself. He moved his account out of big to small regional bank. Hope was that big bank become eventually small. 8 months late original big bank bought small regional bank. He end-up exactly where started.

Monday, March 14, 2011

Daylight savings time

When we switch to daylight saving time we suppose to save some energy. But WHY do we switch back?
That is pure tradition. There is no enough light in winter to cover all day so why bother switch back?
Time of a day is pure human defined.
Lets stick with daylight time forever, and some other countries do!

Friday, March 11, 2011

restrict access to financial accounts for tax software.

Financial institutions should create a secondary login (username/password) for tax preparation only. It is kind a security brake to provide you full login to the turbo tax. How much do you trust them? Or you change  password after it?

Wednesday, March 9, 2011

Idea of financial stimulus

One of the way to have local stimulus it to convert USA system to metric. One of the part is to convert miles to kilometers on the road sign.  Since it will require changes on the local roads, it is not possible totally outsource abroad.

Tuesday, March 8, 2011

Flat tax

I favor flat tax, it simplifies life, but it has huge political obstacle. I suggest to have:
(income - some base deduction - number of kids*kids deduction)* tax rate. Nothing else and fix tax rate. But we should start on state level. Because it much easy to achieve in single state then in all.

Saturday, March 5, 2011

Theory of evolution

My thoughts about evolution: How are really new species appear? Suppose through series of mutation a "crocodile" was born from human. In order to survive and evolve he should share his genes with the other similar species. But there is no human species willing to share genes with "crocodile". So single mutation could change a little creature but could not produce a new class. There is big mutation needed in multiple species all together. I believe that super virus that spread across is the dominant source of change, If bunch of species have changed genes together, then a new born. So there should be some viruses that periodically emerge and penetrate a cell. Cell even may have a mechanism to understand what viruses or part of the virus it may accept to get beneficial state. Some kind low "potential energy" of cell. Some cells like nautilus is already in low energy state and because of this they do not evolve for a long period of time. The other like humans constantly accept mutations in search for batter state.

Friday, March 4, 2011

Dying bees and cell phones.

Bees are dying. That is a disaster. Mobile operators claim, that Cell's electromagnetic radiation is not involved. Some researchers question this statement. To dig more, I suggest to apply indirect statistic method, similar one that used in Freakonomics by Steven Levitt. Find correlation between dying bees on one side and cell phone tower expansion together with cell usage load on other side. Guess what could happen if it is close to 1?

Should we shut off our smart phones? I'll do it to mine.

Thursday, March 3, 2011

New York real estate

Financial industry employment is a leading indicator. While there is a good news about employment, I see that it is actually getting worse in Wall Street. Compensation are lowered in the same time. As a consequence housing prices in New York area will continue to hear giant sucking sound.

Wednesday, March 2, 2011

IPod 2 version

Companies like to label version with natural numbers. Would it better to name more rounded like: Apple's IPod 2.71828?
Predictions: IPod metallic covers will break first.