mercredi 1 avril 2015

Another Horror Story

I'm still working for the same client that I won't name.  I was asked to debug a program delivered few years ago by "Expert Consultants" from huge firms I won't name either.

So I start looking at the appengine... find the Peoplecode where the file is generated... OMG : 1953 Lines.

Well I start with a quick look, I scroll up and down quickly... I notice something strange : some blocks of lines repeated, but idented to another level at each time.


I look closer, try to understand... I finally understands : a record ( &RECORD1 ) contains some fields named the same way (a number is distinguish them) and having the same usage.   There are 23 clones same 5 fields in the record.  So 23 if statements.

I finally understand the context : the code is part of a While statement.  At each iteration, the program checks the iteration number (stocked in a variable named &n_loop_2) and set the values of the fields ending with this number.

Do expert peoplesoft programmers, in particular those who charge 200$ an hour, ignore that we can access to a record or a field (or other objects) by stocking his name in a variable ?  Can't they search a little bit in Peoplebooks ? Can't they try to find a way to do stuff dynamically instead of copy-paste ?  I discover that when I had less than a year of Peoplesoft background... maybe I'm too curious... :)

Ok, I continue looking... I found 2 more times the EXACTLY same issue; The little difference is that a letter differs in the fieldnames of the 3 blocks :

ZZ_zzz_G_030_A_xx
ZZ_zzz_G_030_B_xx 
ZZ_zzz_G_030_C_xx

With this new discovery, I decided to investigate more... I found out that there is another while at an higher level.  The student (we are in Campus Solutions) can have 3 differents plans, for each plan, there is a block of code... I separated the three blocks, and compared them (thanks to Beyong Compare). The results are crazy : the block of code for B is identical to the block for C and A's differs just a little bit. Only suffix differs.

So I start refactoring... There is no way I will try to understand such a code.  I noticed other folks who repeated their correction up to 53 times, I'm not doing that.

I find out some fields are named with a D instead of a B or a G instead of a C, so I introduce another suffix.  Also for B and C fields, there are only 20 clones by field instead of 23 for A.  I end up with 3 variables to manage :


and the 23 ifs statements are replaced by 5 those lines :


For block of code specific to the first iteration, I just need to add exceptions such as :


Finally, the code ends up with 814 lines

After this work, I can investigate the code and understand something, instead of wasting my time.  2-3 hours later, I could explain it to the Business Analyst.

Aucun commentaire:

Enregistrer un commentaire