Assignments

mfabianmfabian Member Posts: 187
edited 2005-08-29 in NAV Tips & Tricks
Instead of
var := var + const you can write var += const;
var := var - const you can write var -= const;
var := var * const you can write var *= const;
var := var / const you can write var /= const;

(source: This tip was posted by jkiss to www.navision.net)


Marcus Fabian
m.fabian@thenet.ch
+41 79 439 78 72
With best regards from Switzerland

Marcus Fabian

Comments

  • Torben_R.Torben_R. Member Posts: 99
    It's possible to do :D
    but the guidelines say no. :cry:
    it's more difficult to read the code if you don't use the guidelines
  • DenSterDenSter Member Posts: 8,307
    See I don't get that. It's programming code. Only developers should read this code. All developers should know those statements. They should not be confused by them. I really don't understand why it is more difficult to read.

    It's a matter of personal style I guess. :) If you like it, use it. If you don't, don't.
  • bostjanlbostjanl Member Posts: 107
    DenSter wrote:
    See I don't get that. It's programming code. Only developers should read this code. All developers should know those statements. They should not be confused by them. I really don't understand why it is more difficult to read.

    It's a matter of personal style I guess. :) If you like it, use it. If you don't, don't.

    Well if you are the only one that will ever have to read the codem then this is maybe OK, but when (an mostly is so) more thn one person have to dela with the code and over a longer period of time, then this is not good.

    bostjnl
  • bhortonbhorton Member Posts: 4
    CAUTION:

    I used the following

    Repeat
    [various code statements]
    NextDate := 1;
    Until NextDate >= Today;

    It went into an infinite loop.
    When I changed the code to
    NextDate := NextDate + 1;
    everything worked well.

    Apparently, the += assignment doesn't always work.
    Bob
  • DenSterDenSter Member Posts: 8,307
    bostjanl wrote:
    DenSter wrote:
    See I don't get that. It's programming code. Only developers should read this code. All developers should know those statements. They should not be confused by them. I really don't understand why it is more difficult to read.

    It's a matter of personal style I guess. :) If you like it, use it. If you don't, don't.

    Well if you are the only one that will ever have to read the codem then this is maybe OK, but when (an mostly is so) more thn one person have to dela with the code and over a longer period of time, then this is not good.

    bostjnl
    I still don't get that, because the second person, or the third, or the nth person that goes into the code should be able to read the code, so I still don't get why += is less readable. It's C/AL Code, so it should be readable by anybody that understands C/AL code. It has always meant what it means, and that will not change over time.

    Anybody that accesses code should know what the code means. If they don't understand the code, they should just stay away from it.
  • borsicsjborsicsj Member Posts: 32
    You get an infinite loop 'cause you hadn't increased the NextDate variable. In the repeat-until loop you typed NextDate := 1; instead of NextDate += 1;

    BUT, try the following code and you will see that there's some difference between the 2 syntaxes:
    Variables:
    Name DataType Subtype Length
    nextdate Date
    w Dialog

    The code:
    //++

    nextdate := CALCDATE('-9999D', TODAY);
    w.OPEN('#1#########', nextdate);
    REPEAT
    w.UPDATE(1, nextdate);
    nextdate += 1;
    UNTIL nextdate >= TODAY;
    w.CLOSE;
    MESSAGE(FORMAT(nextdate));

    nextdate := CALCDATE('-9999D', TODAY);
    w.OPEN('#1#########', nextdate);
    REPEAT
    w.UPDATE(1, nextdate);
    nextdate := nextdate + 1;
    UNTIL nextdate >= TODAY;
    w.CLOSE;
    MESSAGE(FORMAT(nextdate));
    //--

    Brg,
    János Borsics

    bhorton wrote:
    CAUTION:

    I used the following

    Repeat
    [various code statements]
    NextDate := 1;
    Until NextDate >= Today;

    It went into an infinite loop.
    When I changed the code to
    NextDate := NextDate + 1;
    everything worked well.

    Apparently, the += assignment doesn't always work.
    Brg,

    --
    János Borsics
  • DavisDavis Member Posts: 8
    text += textConstant
    It doesn't works.
  • Timo_LässerTimo_Lässer Member Posts: 481
    Torben R. wrote:
    [...]
    but the guidelines say no. :cry:
    As far as I know, it's allowed since version 3.60 or 3.70
    Torben R. wrote:
    [...]
    it's more difficult to read the code if you don't use the guidelines
    This syntax came from C-Code and everyone who can read C should be able to read this.

    By the way:
    It is also possible to comment out a large code block by typing { and } but this is still not allowed (see CALguide).
    // IF Cust."No." <> '' THEN
    //   Cust.INSERT;
    
    is equal to
    {
    IF Cust."No." <> '' THEN
      Cust.INSERT;
    }
    
    Timo Lässer
    Microsoft Dynamics NAV Developer since 1997
    MSDynamics.de - German Microsoft Dynamics Community - member of [clip]
  • StephenGStephenG Member Posts: 99
    Hi Timo
    Torben R. wrote:
    [...]
    it's more difficult to read the code if you don't use the guidelines
    This syntax came from C-Code and everyone who can read C should be able to read this.

    Thats fine, but what if you don't come from a 'C' or 'C' related background? I came from a Cognos(Powerhouse) backgound, you only have the guidelines to go by. The C/AL guidlines on the 3.70 disc still recomend the a := a + 1; approach, but I couldn't see anywhere, that you cannot use the 'C' notation.
    Answer the question and wait for the answer.
  • Timo_LässerTimo_Lässer Member Posts: 481
    StephenG wrote:
    [...]
    Thats fine, but what if you don't come from a 'C' or 'C' related background? I came from a Cognos(Powerhouse) backgound, you only have the guidelines to go by.
    [...]
    That's right! If you don't know C then this syntax is a little bit confusing.
    StephenG wrote:
    [...]
    The C/AL guidlines on the 3.70 disc still recomend the a := a + 1; approach, but I couldn't see anywhere, that you cannot use the 'C' notation.
    I think, Navision preferes the normal syntax, so they will never add this to the guidelines.
    Timo Lässer
    Microsoft Dynamics NAV Developer since 1997
    MSDynamics.de - German Microsoft Dynamics Community - member of [clip]
  • DoomhammerDoomhammer Member Posts: 211
    Syntax += is good for people, who worked with C-family languages. They are accustomed for this style. But... what shall do people, who never worked with C (like me) and they do not know, that shall += mean. I am sometimes confused, what is += in MBS-Navi 3.70.code.

    I think, C/SIDE is based on Pascal, so there should be no other things from other programming languages.
    Martin Bokůvka, AxiomProvis
  • eromeineromein Member Posts: 589
    I've got some inside information, but I don't know if it's true.

    It seems that on of the programmers in Denmark integrated this little feature (Easter egg) although it's against Navisions (C/AL) protocol.

    Changes could be they will delete this functionality in the future, this would mean everything you program using this kind of assignments stops working after an upgrade...

    This would be a bit unlikely

    btw, I think it's doesn't read the good, especially if you don’t expect it to be in the code.
    "Real programmers don't comment their code.
    If it was hard to write, it should be hard to understand."
  • Timo_LässerTimo_Lässer Member Posts: 481
    I think, Navision Denmark will not be so stupid to remove the support for this syntax.
    They tried something like this in the past with the comment syntax:
    // This is a style guide comment
    
    {
    This is not a
    style guide comment
    }
    
    In Version 3.00 (Navision Solutions Beta), the "{" and "}" was ignored by the compiler and the code inside this was executed.
    But many many individual solutions uses { and }, so that this will supported also Navision Denmark doesn't like it.

    So, I think, they will not remove the support for the +=, *=, ...

    But let us see what the .net version will bring to us :roll:
    Timo Lässer
    Microsoft Dynamics NAV Developer since 1997
    MSDynamics.de - German Microsoft Dynamics Community - member of [clip]
  • guidorobbenguidorobben Member Posts: 157
    I did some performance tests. I += 1; is 25% faster than I := I + 1;

    Guido
  • eromeineromein Member Posts: 589
    This is some really cool information! 25% FASTER!!! Wow! But still... i := i + 1 is the way to go.... I think!
    "Real programmers don't comment their code.
    If it was hard to write, it should be hard to understand."
  • mccizmt2mccizmt2 Member Posts: 21
    Hi Guys

    You'll have to forgive me, i'm new to this game. I can program a little in C++ and that's about it.

    The company that I work for doesn't have anybody that can program or write reports properly and they would like me to do it. I can do it. However I have been trying to find a complete list of all of the C/AL functions and commands etc, but I can't find any sort of literature anywhere.

    I've read the C/AL programming course notes and they're really elementary and provide nothing extremely useful.

    If anybody has any suggestions then I would be grateful
  • ArhontisArhontis Member Posts: 667
    Hi,

    Have you tried the:
    - CAL Programming Guide.pdf (provided to partners)
    - Introduction to CAL Programming.pdf (provided to partners)

    - or the w1w1adg.pdf (Application Designer's Guide) located in the product CD and easy to find.
  • RobertMoRobertMo Member Posts: 484
    after reading suggested pdfs check downloads for "quick reference":
    MBS-Navision 4.00 Quick Reference:
    http://www.mibuso.com/dlinfo.asp?FileID=355
    MBS-Navision 3.70 Quick Reference:
    http://www.mibuso.com/dlinfo.asp?FileID=288
               ®obi           
    ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
  • jantschjantsch Member Posts: 4
    I did some performance tests. I += 1; is 25% faster than I := I + 1;

    Guido

    If it's like java or C, the reason would be that the process to access a variable is quite slow! ( I += 1 could be done with bitshifting while I = I+1 need to access a var two times )
    -= Never argue with idiots: They'll drag you down on their level and hit you with experience=-
  • DakkonDakkon Member Posts: 192
    Ok, I had to comment here. C/AL is NOT Pascal. It may have been influenced by it, but to say C/AL shouldn't have anything that Pascal doesn't have is quite frankly stupid. C/AL is designed for Navision and is ultimately it's own language with it's own purpose.
    To say C/AL shouldn't have a feature that is more efficient because some other language doesn't have it makes no sense. The point is, Den Ster is right. If you are a C/AL programmer then deal with it, that's part of reading code, and besides that += is not exactly rocket science. If you are not a C/AL programmer then why are you complaining, you shouldn't be stressing over the code.
    I mean really folks, if you can't remember +=,-=,/=, and *= or at least look it up then maybe programming is not the right profession for you. if you want a language to hold your hand go write in VB.
    </end rant>
    Thad Ryker
    I traded my sanity for a railgun :mrgreen:
  • JopjeJopje Member Posts: 50
    A programmer would choose for efficiency instead of easy-reading,
    also if it is more confusing, it's just a matter of time before you get used to it.
    In the end of the day a "customer/partner" only wants "the best" and they don't care about how things are programmed and if they can read it back.
    The reading back is something for a programmer and the research involved in it.

    I just started to do some report design and programming in Navision,
    and with my underlying VB/Delphi-knowledge from school I don't have any trouble "reading" the code.

    The most important thing if you program is to keep your customer happy and to keep it effficient.

    Example:
    Search engine (difficult coding) 20% faster - Better for a normal person
    Search engine (easy to read coding) - Nice for a beginning student programmer :wink:

    But in order to get back to topic: Thanks for the nice tip
    Remco de Jong
    Bachelor of Business Administration and Information Technology
    minor Application Development


    " Don't use comma (,) use dot (.) "
Sign In or Register to comment.