Assignments

mfabian
Member Posts: 187
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
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
Marcus Fabian
0
Comments
-
It's possible to do
but the guidelines say no.
it's more difficult to read the code if you don't use the guidelines0 -
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.
0 -
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.
bostjnl0 -
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.Bob0 -
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
Anybody that accesses code should know what the code means. If they don't understand the code, they should just stay away from it.0 -
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 Borsicsbhorton 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 Borsics0 -
text += textConstant
It doesn't works.0 -
Torben R. wrote:[...]
but the guidelines say no.Torben R. wrote:[...]
it's more difficult to read the code if you don't use the guidelines
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]0 -
Hi TimoTorben 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.0 -
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.
[...]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.Timo Lässer
Microsoft Dynamics NAV Developer since 1997
MSDynamics.de - German Microsoft Dynamics Community - member of [clip]0 -
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, AxiomProvis0 -
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."0 -
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]0 -
I did some performance tests. I += 1; is 25% faster than I := I + 1;
Guido0 -
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."0 -
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 grateful0 -
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.0 -
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
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯0 -
guidorobben wrote: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=-0 -
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 railgun0 -
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
But in order to get back to topic: Thanks for the nice tipRemco de Jong
Bachelor of Business Administration and Information Technology
minor Application Development
" Don't use comma (,) use dot (.) "0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions