I have what might be considered more of a "religious" type of question...

I have what might be considered more of a "religious" type of question...

Below is a snippet of some Delphi code I grabbed as an example, although my question is about general programmer behavior that is hardly specific to any one language. I've seen this in C/C++, php, and many other domains.

Basically, why do programmers do this? Some of you will look at this, roll your eyes and get what I'm saying immediately. Others will stare at it and not see anything unusual. (Note: WHAT the code is doing is pretty much irrelevant. It's the approach I'm pointing at.)

--------------------------------------------------------------
procedure TfwReferral.pbSaveClick(Sender: TObject);
var
sStartYear, sEndYear, sCurrentMonth: string;
sClosureDate: string;
sCloseVR, sPreviousVRStatus: string;

begin
Screen.Cursor := crHourglass;

if qryReferralInfo.FieldByName('Referral_DATE').AsString = '' then
begin
OKMessage('Referral Date is required to save. Please enter.');
Screen.Cursor := crDefault;
dtReferralDate.SetFocus;
Exit;
end;

if qryReferralInfo.FieldByName('Referral_DATE').AsDateTime > Now then
begin
OKMessage('Referral Date cannot be greater than today. Please enter.');
dtReferralDate.Field.Clear;
Screen.Cursor := crDefault;
dtReferralDate.SetFocus;
Exit;
end;

if qryReferralInfo.FieldByName('ReferredTo_CODE').AsString = '' then
begin
OKMessage('Referred To is required to save. Please enter.');
Screen.Cursor := crDefault;
cmbReferredTo.SetFocus;
Exit;
end;
--------------------------------------------------------------
There are SEVERAL DOZEN chunks of code that fit the pattern of the 7 lines above (repeated three times here).

Why does hardly anybody make any effort to simplify stuff like this? (Not to mention that it's poorly structured with every one setting the cursor and calling Exit.)

I'm told this code was originally written by some ridiculously highly paid contractors from one of the "Big Three" Accounting / Consulting firms.

There are dozens of examples of similar code that appears to be mindless copy-and-paste crap like this all over the project. I've already found a few typos that the compiler didn't catch that produce errors that I guess nobody has noticed in several years of use.

This approach often seem to be the rule rather than the exception, as I see it in most projects I've ever worked on. Trying to convince Management after-the-fact that it's cruft and leads to "technical debt" falls on deaf ears.

Why is this approach so common?

And why is it that some of us look at chunks of code like this, and after the third time we see it feel a compulsion to simplify it, while most others just keep on using it?

Comments

  1. Eric Grange a bad product owner will soon be kicked out of the team. That's where agile teams are for.

    ReplyDelete
  2. Jeroen Wiert Pluimers​ in the context here of big consulting firms working by contract, a "good" product owner is the one that delivers fastest on the contract at the lowest cost and damn the torpedoes (we can regret it, but that's what it is)

    Also in many (most?) agile teams, the product owner is also the one that pays the bills (either the boss or the senior contractor that makes the deals and gets the contracts in the first), he can fire the team, but reverse is not true.

    Big contractors is a different world, and one where I hope never to have to work in :)

    ReplyDelete
  3. Jeroen Wiert Pluimers we were taught in class that "Development owns the backlog", but the way this company chose to implement things, only tickets originating with the customer were allowed to go into the backlog. Dev was prohibited from putting things in. What was taught to us in the 2-day Agile intensive is what you said, but this is how this particular company chose to do things.

    I find it amusing that companies hire "certified" trainers to teach stuff correctly, then can do whatever they want and yet tell their customers that they employ an "Agile" development methodology. Nobody certifies what THEY do, so they can make any claims they want. I've worked places where they said they follow Agile, and all they did was have daily stand-ups for 10 minutes in the morning. That was all they did! But they felt this gave them the right to declare they're using "Agile methodologies".

    ReplyDelete

Post a Comment