For a spilt second there I thought OP WAS THE JUNIOR DEV and that he was fixing issues created by a more senior dev. Not that it's unheard of... just rare.
Note to self: Need to be more attentive when reading.
For a spilt second there I thought OP WAS THE JUNIOR DEV and that he was fixing issues created by a more senior dev. Not that it's unheard of... just rare.
Note to self: Need to be more attentive when reading.
Or quickly tumbling down a hill for that matter.
So true, and we've recently decided to implement "agile" as in that kind of agile, you know the one where we still have to do all those features in that exact same order with the same deadline, only now we have to figure out ways of not getting in each other's way, fill worksheets in a webapp, and waste about 3/4 of a workday every week.
At least the agile trainer chastises our boss and he seems to be willing to listen... for now...
Okay, I'm going to stop ranting now. And probably discussing this subject. If I do come across other particularly bad or at least very weird pieces of code I may post them here... you know... as a learning experience.
When you refactor this thing to make it non-nauseating,
Oh, you must mean Never because, as in all corporate environments, that's all the time we'll get for refactoring anything.
I was the one in charge of that task, and I wrote an even dirtier hack around that (so I guess I CAN be a shit coder sometimes, as in a coder that writes SISO -> st goes in, st comes out).
Had to do it in 5 days, 2 spent "researching ", and 3 days to implement (and test for most of the the horribly mangled edge cases).
Then again it could be worse... At least I have a job...
Yes, why how on earth did you guess ?
Wow... 20 years... man I'm young.
That was written somewhere in between 2002-2006... i think...
Also, just to clarify the code has nothing to do with customers and suppliers, I just replaced it with that.
Basically we have an old tool (from 2006, binary only obviously ) that basically takes in... let's say excel files and parses them into that binary format that we then read into the app.
Oh, I've had my share of java alright. With J2EE & J2ME in the past and with android nowadays.
On a different note, the legacy codebase (that we got from the previous team) had this little gem in it (obviously edited, just like last time...).
Again, this code is not necessarily wrong per se it's just ... weird.
Yes, I guess it's faster than parsing but...
struct DATA
{
char cFormat[ 4 ];
short sMajorVersion;
short sMinorVersion;
DATA_CHUNK* pDataChunks;
int iDataChunksNum;
// ... more stuff here
};
struct DATA_CHUNK
{
CUSTOMER_DATA* pCustomers;
int iCustomersNum;
// ...More arrays defined just like the one above
};
// And loaded like this
DATA* pDATA = (DATA*)pSrc;
int iPos = sizeof( DATA );
iPos = align( iPos, DATA_CHUNK_ALIGN );
if( pData->iDataChunksNum)
pData->pDataChunks = (DATA_CHUNK*)(pSrc + uiPos);
else
pData->pDataChunks = null;
iPos += sizeof( DATA_CHUNK ) * pData->pDataChunksNum;
DATA_CHUNK* pDataChunk = pDATA->pDataChunks;
if( pDataChunk != NULL )
{
for( i=0; i!=m_pData->iDataChunksNum; ++i,++pChunk )
{
uiPos = align( iPos, DATA_CHUNK_ALIGN );
if( pDataChunk->iCustomersNum )
pDataChunk->pCustomers = (CUSTOMER_DATA*)(pSrc + iPos);
else
pDataChunk->pCustomers = NULL;
iPos += sizeof( DATA_CHUNK* ) * pDataChunk->iCustomersNum;
CUSTOMER_DATA* pCustomer = pDataChunk->pCustomers;
for( j=0; j!pDataChunk->pCustomers; ++j,++pCustomer )
{
uiPos = align( uiPos, AGS_FRAME_ALIGN );
if( pCustomer->sSomeOtherDataNum )
pCustomer->pSomeOtherData = (SOME_OTHER_DATA*)(pSrc + uiPos);
else
pCustomer->pSomeOtherData = NULL;
// It goes on like this for another 3 indentation levels
}
}
}
Try to guess what happened when we compiled for 64 bit processors...
Sorry for the delay in replying but I came down with a bit of a cold and felt really sick today.
First of all, C++ exceptions are not used at all.
Second, this is 100% C++98 code mostly because:
@EvanED
Virtual keyword is commented because that's how it is in the original source.
@tar
Yep, that's all it does. There are even some slightly more complex calls like:
BPMSet.add(auNew xBoundsPropertyModifier2Obj< float, &BOUNDS::GetTop, &BOUNDS::AllignYUpTo >( pCustomerImage, pTu2, AppScreen::GetScaledValue(10.0f) ));
Where it calls TWO functions inside that 1 call but that's about it.
Thanks for reassuring me I'm not THAT s**t of a coder (not implying that I'm a good coder , that's for others to decide during the code review ) ...although if I have to admit I did learn a few new things from this thread.
Hi, new guy here. Been lurking around tdwtf for a couple of years but up until now I never needed an account.
So, long story short, I worked with this guy, generally a great sport btw, very good at math, algorithms and physics, but he really liked pulling stuff like this (changed the class & variable names a little):
cTextBox* pTc1 = pParentGroup->xCreateChild<cTextBox>();
pTc1->SetText("This is a test!");
// more code here ...
BoundsPropertyModifierSet BPMSet;
BPMSet.add(new xBoundsPropertyModifierObj<float, &BOUNDS::SetHeight>(pTu1, pParentGroup->GetBounds().GetWidth()));
// more code here...
BPMSet.Execute();
Here's what xBoundsPropertyModifier
did:
template< typename T, void ( BOUNDS::*fn1 )(T) >
class xBoundsPropertyModifierObj: public IPropertyModifierSpec
{
public:
xBoundsPropertyModifier( cCtrl* pCtrl, const T& tValue )
: m_Value(tValue)
, m_pCtrl(pCtrl)
{
}
cCtrl* m_pCtrl;
T m_Value;
/*virtual*/ void Execute()
{
BOUNDS boundsTemp = m_pCtrl->GetBounds();
(boundsTemp.*fn1)(m_Value);
m_pCtrl->SetBounds(boundsTemp);
}
}
Please note that IPropertyModifierSpec
above was pure virtual.
What I want to know:
Given that the code he left behind is completely architecture like this, is it an abuse of templates ?
Am I a piss poor coder for barely being able to follow it during my first week with the codebase ?