Shorter way to write "x := x + 1;" and others

MagnoMagno Member Posts: 168
edited 2006-11-24 in NAV Tips & Tricks
I suppose most of you will know this,

but as i see in many examples and code many people work with
x := x + 1;
dito for - , * and /
x := x - 1;
x := x * 1;
x := x / 1;

This is much simpler and shorter:
x += 1;
x -= 1;
x *= 1;
x /= 1;
There are no bugs, only random undocumented features...
---
My Blog: http://NAV-Magno.be

Comments

  • kinekine Member Posts: 12,562
    Yes, but it is wasn't recommended because the NDT had problems with that. I do not know actual situation...

    And main thing> it was not supported and never guaranteed that this :feature: will be in next versions too (it is something what is working but is not documented and without warranty)
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • krikikriki Member, Moderator Posts: 9,112
    Changed title from "I'm lazy too" to "Shorter way to write "x := x + 1;" and others"
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • Miklos_HollenderMiklos_Hollender Member Posts: 1,598
    Standard C/C++/C# stuff, I see no reason why should they remove it.
  • Alex_ChowAlex_Chow Member Posts: 5,063
    Standard C/C++/C# stuff, I see no reason why should they remove it.

    Because they're Microsoft. :mrgreen:
  • DenSterDenSter Member Posts: 8,307
    I seriously doubt that this wil be removed, because it is used a lot in standard NAV code. Besides it is a very common notation in many programming languages, and there really is no reason for them to remove it.
  • kinekine Member Posts: 12,562
    Yes, but for example, there can be problem in NDT connected to that and it will be without support. Officially. And this was point of view from time of "old" Navision, not Microsoft :-)
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • DenSterDenSter Member Posts: 8,307
    Well Microsoft won't even modify existing code if there is a valid reason (SQL Server performance anyone?), so I don't really see them modifying existing code to accommodate removing this from the syntax. Not to mention the kind of trouble they will get from the partner channel that will have to review THEIR code. It's not worth it for them to remove it, I really don't see that happening.
  • kinekine Member Posts: 12,562
    I agree with you :-) I am not arguing with you... (just want to be sure you know it - written word is too weak to describe all) 8)

    Time's changing and what I wrote is about something few years old. Now is another time.
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • DenSterDenSter Member Posts: 8,307
    I know you agree with me on this one, I wasn't trying to argue with you, just discussing :mrgreen:
  • ProntiolProntiol Member Posts: 10
    I encountered problems with += in certain cases (NAV3.7).
    It just didn't work, so I had to use x:=x+1 instead of x+=1
    Unfortunately, i don't have examples, but i would not recommend to use such expressions.
  • DenSterDenSter Member Posts: 8,307
    I need specific examples before I concede on this one. I've been using += etcetera for almost 7 years and never had any issues with it.
  • krikikriki Member, Moderator Posts: 9,112
    DenSter wrote:
    I need specific examples before I concede on this one. I've been using += etcetera for almost 7 years and never had any issues with it.
    Me too and I used it in all versions of Navision (starting from 1.3 or 2.0).
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • ProntiolProntiol Member Posts: 10
    Okay, I made some investigations and have to say, that += does not work only with CODE variables, though it works ok with TEXT ones.
  • David_SingletonDavid_Singleton Member Posts: 5,479
    DenSter wrote:
    I need specific examples before I concede on this one. I've been using += etcetera for almost 7 years and never had any issues with it.

    Definitely thereare some cases where it does not work, but they are rare. For example in 2.00 there was an issue with
    MyDate += 1; to increment date even though it worked fine in 1.3 and then again in 2.01 (It may not be exactly that, butsomehting similar, itwas along time ago).

    I have never seen a problem with integer, text or Decimal though.
    David Singleton
  • DenSterDenSter Member Posts: 8,307
    Well I would never use a math operator to increase a date, I would use CALCDATE.
  • David_SingletonDavid_Singleton Member Posts: 5,479
    I wouldn't use it either, I was just answering your question ](*,)
    David Singleton
  • DenSterDenSter Member Posts: 8,307
    I didn't think I had a question though :wink:
  • David_SingletonDavid_Singleton Member Posts: 5,479
    DenSter wrote:
    I didn't think I had a question though :wink:
    DenSter wrote:
    I need specific examples before I concede on this one. I've been using += etcetera for almost 7 years and never had any issues with it.

    I guess I took that as a question. THough looking closely I see there is no "?" mark at the end, so technically it wasn't really a quesiton :roll:


    Sorry, moving from town to town stopping at internet cafes checking for news from police and consulates, is probably not the ideal time to be replying on forums, but it gives me some time to relax I suppose.
    David Singleton
  • MTCMTC Member Posts: 159
    DenSter wrote:
    Well I would never use a math operator to increase a date, I would use CALCDATE.

    I don't see why not, the operator should only be a direct mapping to the CALCDATE function in any case.

    No different to what overloaded operators in C++ would do in such a case of a date class which would provide a CALCDATE function and map the mathematical operators directly onto it. If one method works, so should the other.
  • DenSterDenSter Member Posts: 8,307
    I'm just a simple soul, I don't have a degree in advanced mathmatics. When I need to manipulate a date, I always use CALCDATE. It has never occurred to me that you could ever use + to add a day to a date. For large text concatenations I always use text constants and string substitutions. This just makes sense to me, to me that is less cluttered.
  • DenSterDenSter Member Posts: 8,307
    I guess I took that as a question.
    No, it was meant as a remark. If indeed you interpreted it as a question, it would have been a rhetorical one :mrgreen:
Sign In or Register to comment.