Is this a coding convention IF Rec.GET(x) THEN;

idiotidiot Member Posts: 651
I'd seen a few databases whose previous customization consultants from different VARs use
IF Rec.GET(x) THEN;
Is this a coding convention for C/SIDE?

Why not just Rec.GET(x); or IF NOT Rec.GET(x) THEN ERROR(errormsg);?

The reason for asking is this would not have been a good coding practice elsewhere.
NAV - Norton Anti Virus

ERP Consultant (not just Navision) & Navision challenger

Comments

  • canadian_baconcanadian_bacon Member Posts: 91
    This is basically a lazy way of getting around error messages if a specified primary key doesn't exist. It can be really dangerous if the proper consideration isn't taken.
  • kinekine Member Posts: 12,562
    It is good if you only want some related record and if it is not there, to have empty record (e.g. to show some values from that record on report). But of course, it assume that the record before this code is not initialized, else you will have previous values in the record. It means that it have meanig, but with all consequences...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • krikikriki Member, Moderator Posts: 9,110
    I sometimes use the technique described by kine.
    But if I use it I make sure the record is cleared just before it. Something like this:
    CLEAR(recTheRecord);
    IF recTheRecord.GET(.....) THEN ;
    
    IF recTheRecord."Some Field" = '' THEN BEGIN
      // or field "Some Field" is blank or the record does not exist.
      ...
    END;
    ...
    ...
    
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • idiotidiot Member Posts: 651
    Wouldn't this look neater & clearer?
    IF NOT recTheRecord.GET(.....) THEN CLEAR(recTheRecord);...
    
    It looks really strange to not have any conclusion after testing for a condition...
    NAV - Norton Anti Virus

    ERP Consultant (not just Navision) & Navision challenger
  • DenSterDenSter Member Posts: 8,304
    idiot wrote:
    The reason for asking is this would not have been a good coding practice elsewhere.
    There are examples of bad coding practices in every language.

    Personally I don't like the IF MyRec.GET THEN; construction, to me it lacks proper design attention. To me when you start using an IF statement, you have to think about actions to take for both the TRUE and FALSE legs.

    On the other hand, I've used it from time to time to quicky go around an error message. When in a time crunch you don't always have the luxury to sit and think things through. As long as the code properly handles the situation it's just a means to an end really. Not very elegant, but if it works, it works.
Sign In or Register to comment.