Good god man! I just ran C-Metrics on my system and discovered I have only 116,077 lines of my own [strictly C++] code on this entire computer.
What, C doesn't count anymore? /*sigh*/
Better edit my post to read "15" then...
Here's how I would differentiate between the two:
Clever code is code that solves the "impossible", or else utterly simplifies things for you. Eg:
I am working on a Windows library. One day I was grumbling about Windows structures to myself as I was having to look up the names of variables I had forgotton the names of (lpfnFooBar, et al). Suddenly I realized that there was a very simple solution altogether. Here is an example:
Code:
class Menuiteminfo : public MENUITEMINFO { public:
Menuiteminfo(){
reset();
}
void reset(){ zero(this), cbSize = sizeof(Menuiteminfo); }
UINT id(){ return wID; }
UINT id(int iD){ return wID = iD; }
UINT mask(){ return fMask; }
UINT mask( int Mask ){ return fMask |= Mask; }
UINT type(){ return fType; }
UINT type( int Type ){ return fType |= Type; }
UINT state(){ return fState; }
UINT state( int State ){ return fState |= State; }
HMENU submenu( HMENU sub = NULL ){ return hSubMenu = sub ? sub : hSubMenu; }
HBITMAP checked( HBITMAP chk = NULL ){ return hbmpChecked = chk ? chk : hbmpChecked; }
HBITMAP unchecked( HBITMAP uchk = NULL ){return hbmpUnchecked = uchk ? uchk : hbmpUnchecked;}
UINT item(){ return dwItemData; }
template <typename T>
UINT item(T Item){ return dwItemData = (UINT)Item; }
template <typename T>
char * data( T * Data = NULL ){ return dwTypeData = Data ? (char*)Data : dwTypeData; }
bool insert(HMENU menu, UINT ID, UINT insert_before, bool if_by_position = false){
insert_mask();
id(ID);
return InsertMenuItem(menu, insert_before, if_by_position, this);
}
bool set(HMENU menu, UINT item_handle, bool if_by_position = false){
return SetMenuItemInfo(menu, item_handle, if_by_position, this);
}
bool get(HMENU menu, UINT item_handle, bool if_by_position = false){
return GetMenuItemInfo(menu, item_handle, if_by_position, this);
}
UINT insert_mask(){ return mask(MIIM_DATA | MIIM_ID | MIIM_TYPE); }
};
So basically, this solved the issues of:
1) having to memset the structure.
2) having to set the cbSize.
3) having to remember windows names.
Bonus: It's still the same structure!
Bonus: A windows structure w/member functions-yay!
Clever, huh?
Brilliant code is code that solves itself, and/or unexpectedly accepts changes with little modification. Eg:
I was once writing a class that would need to encapsulate roughly 30~40 operations on an object. To my pleasant surprise, I realized the combinations of less than 5 or so member functions could completely process the rest of the members, and in a very clean way. So in essence, the class repeated very little if any code, since most calls were either directly or recursively solved by the small handful of workers.