Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2010-08

Proposal: Enhanced replacement for assignment operators

88 messages · 22 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Unknown author

Hello everybody,

I would like to propose an enhanced replacement for the special assignment operators += -= *= and /= :
More pascal-like would be constructs of the form "operator :=" such as
  a + := 1;
  a div := 3;
  a or := b;
  a xor := 3;
  a << := 1;
Together with my prior proposal of multiple assignments there could be stuff like below as well:
  a,b + := c+d;
  a,b << := 1;

I'm not sure as how to further enhance this to monadic operators such as "-" and "not".

Jasper
___________________________________________________________ Neu: WEB.DE De-Mail - Einfach wie E-Mail, sicher wie ein Brief! Jetzt De-Mail-Adresse reservieren: https://produkte.web.de/go/demail02

Reply by email

Florian Klämpfl
to Unknown author

Am 05.08.2010 22:19, schrieb

Show quoted text 13 lines
Hello everybody, I would like to propose an enhanced replacement for the special assignment operators += -= *= and /= : More pascal-like would be constructs of the form "operator :=" such as a + := 1; a div := 3; a or := b; a xor := 3; a << := 1; Together with my prior proposal of multiple assignments there could be stuff like below as well: a,b + := c+d; a,b << := 1;

And you think this is simply to read?

Reply by email

Unknown author

Hello Florian!

Show quoted text 13 lines
> I would like to propose an enhanced replacement for the special assignment operators += -= *= and /= : > More pascal-like would be constructs of the form "operator :=" such as > a + := 1; > a div := 3; > a or := b; > a xor := 3; > a << := 1; > Together with my prior proposal of multiple assignments there could be stuff like below as well: > a,b + := c+d; > a,b << := 1; And you think this is simply to read?

The C-operators can be thought of a composition of a binary operator (+,-,*,/) and the assignment operator, so my solution should be the natural pendant in Pascal.

I cannot think of a more readable and more Pascal-like solution. For me the C-like pendants are even less readable and appear to me as a too limited quick hack. The Delphi-style replacements such as inc/dec/include/exclude are even less usable since both assignment and the operation itself is no longer visible and to wordy. A new pseudo-proc for every such operator is for sure not the best idea.

There are some reasons for my solution:
* You still see that there is an assignment
* No new operators: just combinations of an existing a binary operator and :=
* Extendability: Any suitable (existing) binary operator can be used, even worded ones

BTW: I wrote << by mistake; it should have been shl.

Best regards
Jasper
___________________________________________________________ GRATIS für alle WEB.DE Nutzer: Die maxdome Movie-FLAT! Jetzt freischalten unter http://movieflat.web.de

Reply by email

Felipe Monteiro de Carvalho
to Unknown author

I guess that the problem which you want to solve is "having to type too much". If that is the case, you should rather work on improving code completion in Lazarus or whichever IDE you use. Then you could type something like += and Ctrl+Alt+C and it would expand to the natural Pascal version. Or whichever other key combination you figure out.

You are going in the wrong direction by trying to solve the problem of "having to type too much" by changing the language.

Felipe Monteiro de Carvalho

Reply by email

Michael Van Canneyt
to Felipe Monteiro de Carvalho
Felipe Monteiro de Carvalho wrote 9 lines
I guess that the problem which you want to solve is "having to type too much". If that is the case, you should rather work on improving code completion in Lazarus or whichever IDE you use. Then you could type something like += and Ctrl+Alt+C and it would expand to the natural Pascal version. Or whichever other key combination you figure out. You are going in the wrong direction by trying to solve the problem of "having to type too much" by changing the language.

Exactly.

Typing enhancements can be solved by a good ide.

Pascal as it is, is a very readable language as opposed to C. Proposals such as this diminish the readability.

Michael.

Reply by email

Alexander Klenin
to Florian Klämpfl: Am 05.08.2010 22:19, schrieb And you think this is simply to read?
Florian Klämpfl wrote 6 lines
Am 05.08.2010 22:19, schrieb > Hello everybody, > > I would like to propose an enhanced replacement for the special assignment operators += -= *= and /= : > More pascal-like would be constructs of the form "operator :=" such as >   a + := 1;

FPC already supports this (and I, for example, often use it). Syntax is a += 1; however

>   a << := 1;

"<<" is spelled "shl" in Pascal.

>   a div := 3; >   a or := b; >   a xor := 3;

Now, this is IMHO a good point -- at least div= and mod= operators should definitely be added to a set of "C-like" operators. or= and= xor= would be good too, although I can see some potential confusion regarding short-circuit behavior.

Show quoted text 5 lines
> Together with my prior proposal of multiple assignments there could be stuff like below as well: >   a,b + := c+d; >   a,b << := 1; And you think this is simply to read?

Heh, not even Perl 6 has these, and Perl 6 has *many* operators ;-)

Alexander S. Klenin

Reply by email

Alexander Klenin
to Michael Van Canneyt: Exactly. Typing enhancements can be solved by a good ide. Pascal as it is, is a very…
Michael Van Canneyt wrote
Pascal as it is, is a very readable language as opposed to C. Proposals such as this diminish the readability.

FWIW, while migrating to FPC/newer Delphi,
I specifically replace all usage of Inc/Dec and Include/Exclude in my Pascal programs
by += / -= *to increase readability*.
And I think it really helps ;-)

Alexander S. Klenin

Reply by email

Marco van de Voort
to Alexander Klenin

In our previous episode, Alexander Klenin said:

Show quoted text 7 lines
> as this diminish the readability. FWIW, while migrating to FPC/newer Delphi, I specifically replace all usage of Inc/Dec and Include/Exclude in my Pascal programs by += / -= *to increase readability*. And I think it really helps ;-)

I think they are unreadable, but a great help when translating C code.

Reply by email

Alexander Klenin
to Marco van de Voort
Marco van de Voort wrote 10 lines
In our previous episode, Alexander Klenin said: > > as this diminish the readability. > > FWIW, while migrating to FPC/newer Delphi, > I specifically replace all usage of Inc/Dec and Include/Exclude in my > Pascal programs > by += / -= *to increase readability*. > And I think it really helps ;-) I think they are unreadable,

C-like operators reduce the number of required punctuation -- I always think that the extra punctuation is bad for readability.

As for multiplication, floating-point and overloaded cases, they are simply required since Inc and Dec do not work at all.

but a great help when translating C code.

This is another argument supporting the notion that assignment operators should be extended to include div, mod and logical operators.

Alexander S. Klenin

Reply by email

Michalis Kamburelis
to Vinzent Höfler
Vinzent Höfler wrote 7 lines
Alexander Klenin : > C-like operators reduce the number of required punctuation -- > I always think that the extra punctuation is bad for readability. Rght. Shrt sntncs r mch sr t rd.

This is more about

  SomeReallyLongVariableNameX += 10;

being nicer to read than

  SomeReallyLongVariableNameX := SomeReallyLongVariableNameX + 10;

You don't have to spend time realizing that it's the same variable (not e.g. SomeReallyLongVariableNameY) if you read the 1st form.

Michalis

Reply by email

Graeme Geldenhuys
to Alexander Klenin: On Fri, Aug 6, 2010 at 08:29, Michael Van Canneyt FWIW, while migrating to FPC/newer…

Op 2010-08-06 05:05, Alexander Klenin het geskryf:

I specifically replace all usage of Inc/Dec and Include/Exclude in my Pascal programs by += / -= *to increase readability*. And I think it really helps ;-)

:-) I do the same, and use += and -+ more - simply to save on typing. But what Jane proposes is really not easy to read or understand. Only after he explained the syntax, I understood - which means he is going in the wrong direction for the pascal language.

Regards,
- Graeme -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://opensoft.homeip.net/fpgui/

Reply by email

Marco van de Voort
to Alexander Klenin: C-like operators reduce the number of required punctuation -- I always think that the…

In our previous episode, Alexander Klenin said:

Show quoted text 5 lines
> > I think they are unreadable, C-like operators reduce the number of required punctuation -- I always think that the extra punctuation is bad for readability.

No. Natural languages are also very redundant, and punctuation is not even 100% required to understand natural language.

As for multiplication, floating-point and overloaded cases, they are simply required since Inc and Dec do not and dec work fine as far as I know for over a decade.

Reply by email

Michael Van Canneyt
to Henry Vermaak
Henry Vermaak wrote 9 lines
On 6 August 2010 06:08, "Vinzent Höfler" wrote: > Alexander Klenin : > >> C-like operators reduce the number of required punctuation -- >> I always think that the extra punctuation is bad for readability. > > Rght. Shrt sntncs r mch sr t rd. Punctuation vowels.

Well, let's all communicate binary.

You then have to know only 2 letters: 0 and 1.
Things can't be made more simple than that.

Michael.

Reply by email

Marco van de Voort
to Michael Van Canneyt

In our previous episode, Michael Van Canneyt said:

Show quoted text 5 lines
Well, let's all communicate binary. You then have to know only 2 letters: 0 and 1. Things can't be made more simple than that.

Within 5 seconds somebody thinks that is too verbose, and applies a RLE (run length encoding).

Reply by email

Michael Van Canneyt
to Henry Vermaak: What does this have to do with punctuation not being readable? Also, simplicity …
Henry Vermaak wrote 10 lines
On 6 August 2010 09:34, Michael Van Canneyt wrote: > > Well, let's all communicate binary. > > You then have to know only 2 letters: 0 and 1. Things can't be made more > simple than that. What does this have to do with punctuation not being readable? Also, simplicity readability.

Hm.

Once again, a perfect illustration: I should never attempt humor on a mailing list. Any attempts at irony or even sarcasm are totally lost. Although I thought that in this case it would be dripping off everyone's monitor.

My mistake.

Michael.

Reply by email

Henry Vermaak
to Michael Van Canneyt: Hm. Once again, a perfect illustration: I should never attempt humor on a mailing list.…
Michael Van Canneyt wrote 23 lines
On Fri, 6 Aug 2010, Henry Vermaak wrote: > On 6 August 2010 09:34, Michael Van Canneyt > wrote: >> >> Well, let's all communicate binary. >> >> You then have to know only 2 letters: 0 and 1. Things can't be made more >> simple than that. > > What does this have to do with punctuation not being readable? > > Also, simplicity readability. Hm. Once again, a perfect illustration: I should never attempt humor on a mailing list. Any attempts at irony or even sarcasm are totally lost. Although I thought that in this case it would be dripping off everyone's monitor.

Heh, well it looks like Marco got something.

Reply by email

Alexander Klenin
to Graeme Geldenhuys: Op 2010-08-06 05:05, Alexander Klenin het geskryf: :-) I do the same, and use += and -+…
Graeme Geldenhuys wrote 10 lines
Op 2010-08-06 05:05, Alexander Klenin het geskryf: > I specifically replace all usage of Inc/Dec and Include/Exclude in my > Pascal programs > by += / -= *to increase readability*. > And I think it really helps ;-) :-) I do the same, and use += and -+ more - simply to save on typing. But what Jane proposes is really not easy to read or understand. Only after he explained the syntax, I understood - which means he is going in the wrong direction for the pascal language.

Sure. Note that I am supporting only a very limited subset of his proposal -- namely, that the set of assignment operators should be extended to include all Pascal operators, not just + - * / as it is now.

Alexander S. Klenin

Reply by email

Alexander Klenin
to Marco van de Voort: In our previous episode, Alexander Klenin said: No. Natural languages are also very…
Marco van de Voort wrote
In our previous episode, Alexander Klenin said: > C-like operators reduce the number of required punctuation -- > I always think that the extra punctuation is bad for readability.

[..]

punctuation is not even 100% required to understand natural language.

Correct. That is why reducing it to a required minimum is a good thing.

> As for multiplication, floating-point and overloaded cases, > they are simply required since Inc and Dec do not work at all. inc and dec work fine as far as I know for over a decade.

Hm, just re-checked -- no, they do not.
They never did and probably never will
(at least, I do not think there is a need to extend them, since a better alternative,
assignment operators, is already implemented).

Alexander S. Klenin

Reply by email

Marco van de Voort
to Alexander Klenin

In our previous episode, Alexander Klenin said:

Show quoted text 5 lines
>> I always think that the extra punctuation is bad for readability. [..] > punctuation is not even 100% required to understand natural language. Correct. That is why reducing it to a required minimum is a good thing.

It is not, for the same reason all redundancy is not stripped from natural languages either. It improves reading speed and integrity at only a small cost.

They never did and probably never will

They work perfectly fine.

(at least, I do not think there is a need to extend them, since a better alternative, assignment operators, is already implemented).

I don't see the need for them. I can see the logical ones being implemented for ease of conversion in e.g. compression code, but I never use them.

Reply by email

Martin
to Marco van de Voort: In our previous episode, Alexander Klenin said: It is not, for the same reason all…
Marco van de Voort wrote 10 lines
In our previous episode, Alexander Klenin said: >> punctuation is not even 100% required to understand natural language. >> > Correct. That is why reducing it to a required minimum is a good thing. > It is not, for the same reason all redundancy is not stripped from natural languages either. It improves reading speed and integrity at only a small cost.

Correct they are not: I/you have He has. The form of the Verb (partly) includes the the subject. And there are reasons for the duplicity: recovery if part of the info was lost (bad pronunciation, bad handwriting)

In a programming language, a certain duplicity, can help finding errors, because the 2nd part (duplicity) is either known or limited to a specific set => the compiler can raise an error if it doesn't fit

That is the problem with C: you can have embedded assignments to

if ((a=a+1)>2) { }
could be
if ((a+=1) >2) { }

but that may well be a typo, the += may have meant to be a simple +

-------------
Readability is not equal to the sortest form of expressing something, in fact, the shortest form often lacks readability => hence many people dislike reg expression (which infact can be wonderfully short. in perl:
$a := 11;
if ( ('x' x $a) =~ /^(..+)\1+$/ ) { print "$a is prime"; }

It's short, isn't it? readable? (and it doesn't work on $a=1, but anyway)

Readability, is also a lot do to with waht you are *used* to read. Once you are used to a language,m or to reg-exp, or to whatever, it appears easy to read. (and write). But before....

And this thread to me looks just like another: Well I am used to language "x" where it looks like that, couldn't we make pascal look the same, so it becomes all easier.
And imho the answer is: Why make pascal look more like every other language. If that's what is wanted, then let's create a new language, taking the best out of all other languages...

That "+=" is (sometimes) called "c style assignment" already says it all.

And, since I also refuse to learn from the faults of others, some sarcasm in the end:
begin end is awfull amount of typing => can we replace it with something shorter? "{" is unfortunately taken, but why need an actual char => just identify a block, by indenting each line of the block, much less clutter, all the extra begin/end can go....

Martin

Reply by email

Paulo Costa
to Michalis Kamburelis: This is more about SomeReallyLongVariableNameX += 10; being nicer to read than…
Michalis Kamburelis wrote 11 lines
This is more about SomeReallyLongVariableNameX += 10; being nicer to read than SomeReallyLongVariableNameX := SomeReallyLongVariableNameX + 10; You don't have to spend time realizing that it's the same variable (not e.g. SomeReallyLongVariableNameY) if you read the 1st form.

On the other side

     SomeReallyLongVariableNameX += SomeReallyLongVariableNameY - 1;

is too much similar (visually) to

     SomeReallyLongVariableNameX := SomeReallyLongVariableNameY - 1;

:(

(You can't please everyone...)

Paulo

Reply by email

Marc Weustink
to Martin: Correct they are not: I/you have He has. The form of the Verb (partly) includes the the…
Martin wrote 6 lines
And, since I also refuse to learn from the faults of others, some sarcasm in the end: begin end is awfull amount of typing => can we replace it with something shorter? "{" is unfortunately taken, but why need an actual char => just identify a block, by indenting each line of the block, much less clutter, all the extra begin/end can go....

then you have to type all those extra spaces

Marc ;-)

Reply by email

Graeme Geldenhuys
to Paulo Costa: On the other side SomeReallyLongVariableNameX += SomeReallyLongVariableNameY - 1; is too…

Op 2010-08-06 13:36, Paulo Costa het geskryf:

Show quoted text 6 lines
SomeReallyLongVariableNameX += SomeReallyLongVariableNameY - 1; is too much similar (visually) to SomeReallyLongVariableNameX := SomeReallyLongVariableNameY - 1;

Umm, hello... those two statements are not the same. To make the second statement the same as the first, you would have to write.

  SomeReallyLongVariableNameX := SomeReallyLongVariableNameX +
SomeReallyLongVariableNameY - 1;

Regards,
- Graeme -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://opensoft.homeip.net/fpgui/

Reply by email

Henry Vermaak
to Graeme Geldenhuys
Graeme Geldenhuys wrote 11 lines
Op 2010-08-06 13:36, Paulo Costa het geskryf: > >      SomeReallyLongVariableNameX += SomeReallyLongVariableNameY - 1; > > is too much similar (visually) to > >      SomeReallyLongVariableNameX := SomeReallyLongVariableNameY - 1; Umm, hello... those two statements are not the same. To make the second statement the same as the first, you would have to write.

He said it's _visually_ similar.

Reply by email

Graeme Geldenhuys
to Henry Vermaak

Op 2010-08-06 14:01, Henry Vermaak het geskryf:

He said it's _visually_ similar.

Ah, then I misunderstood. Apologies.

On a side note:
Maybe it's just me, but I clearly spot the difference between a := and += symbol. I guess it's years of experience looking at code, which counts in my favour. ;-)

Regards,
- Graeme -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://opensoft.homeip.net/fpgui/

Reply by email

Henry Vermaak
to Graeme Geldenhuys
Graeme Geldenhuys wrote 11 lines
Op 2010-08-06 14:01, Henry Vermaak het geskryf: > > He said it's _visually_ similar. Ah, then I misunderstood. Apologies. On a side note: Maybe it's just me, but I clearly spot the difference between a := and += symbol. I guess it's years of experience looking at code, which counts in my favour. ;-)

Yeah, I agree. I have more of a problem with commas and full stops on some fonts. I also hate it when people don't put spaces between operators and text, I find that really unreadable.

Henry

Reply by email

Graeme Geldenhuys
to Henry Vermaak

Op 2010-08-06 14:11, Henry Vermaak het geskryf:

I have more of a problem with commas and full stops on some fonts. I also hate it when people don't put spaces between operators and text, I find that really unreadable.

+1 [...and don't the FPC core team love to code like that. :-( ...] I found that changing the color of symbols in the text editor, to be different from surrounding text helps a bit.

My editor color scheme looks as follows:

http://wiki.lazarus.freepascal.org/New_IDE_features_since#divider_lines_in_editor

Regards,
- Graeme -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://opensoft.homeip.net/fpgui/

Reply by email

Alexander Klenin
to Marco van de Voort: In our previous episode, Alexander Klenin said: It is not, for the same reason all…
Marco van de Voort wrote 7 lines
In our previous episode, Alexander Klenin said: >>> As for multiplication, floating-point and overloaded cases, >>> they are simply required since Inc and Dec do not work at all. >> inc and dec work fine as far as I know for over a decade. >Hm, just re-checked -- no, they do not. >They never did and probably never will They work perfectly fine.
Sorry, but I do not believe you have ever tried.
Here are samples, please try compiling them before asserting that they
work fine:
---
var a: Double;
begin
  Inc(a, 2.0);
end.
---
{$mode objfpc}
type TPoint=record x, y: Integer; end;
operator+(const a, b: TPoint): TPoint; begin { ... } end;
var a, b: TPoint;
begin
  Inc(a, b);
end.
---
Show quoted text 5 lines
> (at least, I do not think there is a need to extend them, since a better > alternative, assignment operators, is already implemented). I don't see the need for them. I can see the logical ones being implemented for ease of conversion in e.g. compression code, but I never use them.

Logical ones are actually less important for me,
but mod= and especially div= are rather useful.
Last time I wished a had div= was just a week ago.

Alexander S. Klenin

Reply by email

Hans-Peter Diettrich
to Michalis Kamburelis: This is more about SomeReallyLongVariableNameX += 10; being nicer to read than…
>> C-like operators reduce the number of required punctuation -- >> I always think that the extra punctuation is bad for readability. > Rght. Shrt sntncs r mch sr t rd.

;-)

Show quoted text 10 lines
This is more about SomeReallyLongVariableNameX += 10; being nicer to read than SomeReallyLongVariableNameX := SomeReallyLongVariableNameX + 10; You don't have to spend time realizing that it's the same variable (not e.g. SomeReallyLongVariableNameY) if you read the 1st form.

Right, that's why I prefer Inc in this case - until properties stopped working this way :-(

DoDi

Reply by email

Martin
to Alexander Klenin: Sorry, but I do not believe you have ever tried. Here are samples, please try compiling…
Alexander Klenin wrote
Logical ones are actually less important for me, but mod= and especially div= are rather useful. Last time I wished a had div= was just a week ago.

I could see that in a language where div was some symbol (like % or :) but with a word?

Anyway, couldn't you just go the same way that inc does?

procedure div(var op1: Integer; op2: Integer); inline;
and then write
Div(a, 4);

Reply by email

Alexander Klenin
to Martin: Correct they are not: I/you have He has. The form of the Verb (partly) includes the the…
Martin wrote 7 lines
------------- Readability is not equal to the sortest form of expressing something, in fact, the shortest form often lacks readability => hence many people dislike reg expression (which infact can be wonderfully short. in perl: $a := 11; if ( ('x' x $a) =~ /^(..+)\1+$/ ) { print "$a is prime"; }

Not quite,

$a = 11;
print "$a is prime" if ('x' x $a) !~ /^(..+)\1+$/;

Is correct (and slightly more readable) Perl.
But the point is -- yes, this code is, aside from the horrible ineffectiveness, this is perfectly good code, easily understandable by anybody familiar with the language. That's not Perl Golf or anything like that.

And imho the answer is: Why make pascal look more like every other language. If that's what is wanted, then let's create a new language, taking the best out of all other languages...

On the one hand, that's reductio ad absurdum.
On the other, is not this exactly how Pascal developed in the last decade?

That "+=" is (sometimes) called "c style assignment" already says it all.

Actually FPC is the only place I know which calls them that.

Show quoted text 6 lines
And, since I also refuse to learn from the faults of others, some sarcasm in the end: begin end is awfull amount of typing => can we replace it with something shorter? "{" is unfortunately taken, but why need an actual char => just identify a block, by indenting each line of the block, much less clutter, all the extra begin/end can go....

Actually, your sarcasm misfires in that case ;-)
I do think that begin/end is an awful amount of visual clutter, and that Modula solution is a better one.
Unfortunately, this change is totally out of question because it will break literally all the existing code.

Alexander S. Klenin

Reply by email

Alexander Klenin
to Martin: I could see that in a language where div was some symbol (like % or :) but with a word?…
Martin wrote 8 lines
 On 06/08/2010 14:53, Alexander Klenin wrote: > > Logical ones are actually less important for me, > but mod= and especially div= are rather useful. > Last time I wished a had div= was just a week ago. I could see that in a language where div was some symbol (like % or :) but with a word?

What it the difference? I agree that "%" is slightly better notation than "mod", but that is totally insignificant, and since we are stuck with "mod", I see no reason to change it.

Anyway, couldn't you just go the same way that inc does? procedure div(var op1: Integer; op2: Integer); inline; and then write Div(a, 4);

1) No, because div is a keyword.
2) Also, the actual use case was for TPoints,
and I have already overloaded operator div.
I think that the need to duplicate code and pollute namespace with additional "DivAssign" procedure
did not improve the code
Alexander S. Klenin

Reply by email

Martin
to Alexander Klenin
Alexander Klenin wrote 10 lines
On Sat, Aug 7, 2010 at 01:12, Martin wrote: > On 06/08/2010 14:53, Alexander Klenin wrote: >> Logical ones are actually less important for me, >> but mod= and especially div= are rather useful. >> Last time I wished a had div= was just a week ago. > I could see that in a language where div was some symbol (like % or :) but > with a word? What it the difference? I agree that "%" is slightly better notation than "mod", but that is totally insignificant, and since we are stuck with "mod", I see no reason to change it.

Because mixing/combining a word (identifier) with a symbol, well for me: it hurts my eyes.

Show quoted text 5 lines
> Anyway, couldn't you just go the same way that inc does? > procedure div(var op1: Integer; op2: Integer); inline; > and then write > Div(a, 4); 1) No, because div is a keyword.

ok DivAssign, Divide, .....

Show quoted text 5 lines
2) Also, the actual use case was for TPoints, and I have already overloaded operator div. I think that the need to duplicate code and pollute namespace with additional "DivAssign" procedure did not improve the code readability at all
You don't duplicate code:
procedure Divide(var op1: TPoint; op2: TPoint);
begin
   op1 := op1 div op2; // using your overloaded operator.
end;

Reply by email

Alexander Klenin
to Martin
Martin wrote 10 lines
 On 06/08/2010 15:23, Alexander Klenin wrote: > > On Sat, Aug 7, 2010 at 01:12, Martin  wrote: > What it the difference? I agree that "%" is slightly better notation than > "mod", > but that is totally insignificant, and since we are stuck with "mod", > I see no reason to change it. Because mixing/combining a word (identifier) with a symbol, well for me: it hurts my eyes.

As I said, I agree, "a mod b" looks worse than "a % b", but that was Wirth's decision, and the difference is so small I do not think it is really an issue.

Show quoted text 11 lines
> 2) Also, the actual use case was for TPoints, > and I have already overloaded operator div. > I think that the need to duplicate code and pollute > namespace with additional "DivAssign" procedure > did not improve the code readability at all You don't duplicate code: procedure Divide(var op1: TPoint; op2: TPoint); begin  op1 := op1 div op2; // using your overloaded operator. end;

Sure, sure, it is all not a big deal.
Still, this is an awkward workaround for, IMO,
a trivial and arbitrary limitation of the compiler.

Alexander S. Klenin

Reply by email

Honza
Alexander Klenin wrote 17 lines
 Sorry, but I do not believe you have ever tried. Here are samples, please try compiling them before asserting that they work fine: --- var a: Double; begin Inc(a, 2.0); end. --- {$mode objfpc} type TPoint=record x, y: Integer; end; operator+(const a, b: TPoint): TPoint; begin { ... } end; var a, b: TPoint; begin Inc(a, b); end. ---

http://www.freepascal.org/docs-html/ref/refsu5.html#x27-260003.1.1

Inc and friends (Succ, ...) are defined on ordinal types only and actually they work just fine. The above examples are outside of that definition domain. Additionally, semantics of Inc is defined using the add operation, not using the add/plus operator, iirc.

-bflm

Reply by email

Martin
to Alexander Klenin: As I said, I agree, "a mod b" looks worse than "a % b", but that was Wirth's decision,…
Alexander Klenin wrote 12 lines
On Sat, Aug 7, 2010 at 01:37, Martin wrote: > On 06/08/2010 15:23, Alexander Klenin wrote: >> On Sat, Aug 7, 2010 at 01:12, Martin wrote: >> What it the difference? I agree that "%" is slightly better notation than >> "mod", >> but that is totally insignificant, and since we are stuck with "mod", >> I see no reason to change it. > Because mixing/combining a word (identifier) with a symbol, well for me: it > hurts my eyes. As I said, I agree, "a mod b" looks worse than "a % b", but that was Wirth's decision, and the difference is so small I do not think it is really an issue.

I don't have a problem with "a mod b" => only with "a mod= b"

mod is a keyword, it therefore follows the rule (as identifier) that it consists of certain chars only (a-z, underscore, digits, but not leading)

:= += are symbols => they do not consist of said chars

mod= is what exactly?

Reply by email

Alexander Klenin
to Honza: http://www.freepascal.org/docs-html/ref/refsu5.html#x27-260003.1.1 Inc and friends (Succ,…
Honza wrote
On Fri, Aug 6, 2010 at 21:31, Alexander Klenin wrote: >>> As for multiplication, floating-point and overloaded cases, >>> they are simply required since Inc and Dec do not work at all.

[...]

> Sorry, but I do not believe you have ever tried. > Here are samples, please try compiling them before asserting that they > work fine:

[...]

Show quoted text 6 lines
http://www.freepascal.org/docs-html/ref/refsu5.html#x27-260003.1.1 Inc and friends (Succ, ...) are defined on ordinal types only and actually they work just fine. The above examples are outside of that definition domain.

Which is exactly what I said in the original email, which both you and Marco magically forgot to quote ;-)

Additionally, semantics of Inc is defined using the add operation, not using the add/plus operator, iirc.

Of course. Semantics of add/plus is defined in terms of add operation too, so I'd say that they are equivalent except Inc/Dec are arbitrarily limited to a subset of types.

Alexander S. Klenin

Reply by email

Alexander Klenin
to Martin: I don't have a problem with "a mod b" => only with "a mod= b" mod is a keyword, it…
Martin wrote 10 lines
 On 06/08/2010 15:45, Alexander Klenin wrote: I don't have a problem with "a mod b" => only with "a mod= b" mod is a keyword, it therefore follows the rule (as identifier)  that it consists of certain chars only (a-z, underscore, digits, but not leading) := += are symbols => they do not consist of said chars mod= is what exactly?

Whatever you would like it to be ;-)
Really, I can see how it may require a special case in the tokenizer, but apart from that, who cares?

From the syntax highlighting POV, it should IMO be a symbol,

like "mod" and "div".

Alexander S. Klenin

Reply by email

Martin
to Alexander Klenin
Alexander Klenin wrote 16 lines
On Sat, Aug 7, 2010 at 01:50, Martin wrote: > On 06/08/2010 15:45, Alexander Klenin wrote: > > I don't have a problem with "a mod b" => only with "a mod= b" > > mod is a keyword, it therefore follows the rule (as identifier) that it > consists of certain chars only (a-z, underscore, digits, but not leading) > > := += are symbols => they do not consist of said chars > > mod= is what exactly? Whatever you would like it to be ;-) Really, I can see how it may require a special case in the tokenizer, but apart from that, who cares? > From the syntax highlighting POV, it should IMO be a symbol, like "mod" and "div".

It's not about implementation in the fpc parser/compiler, or syntax highlighter => you can implement any such thing...

But it's breaking the fundamentals of pascal, to differentiate between symbol and identifiers.

Obviously it acts like a symbol does, so it should be a symbol; but if symbol can have chars, then why can't identifiers have $+-... If we give up this barrier, then surely the following should be valid to? var a$b: Integer;
symbols may need to be surrounded by spaces always, since I also would want an identifier/variable named
var a+b : integer;

----------
if there should be a shorthand for "a:=a mod b" => ok => but please make it look like pascal.
Either inc style, or symbol style. maybe use "%=" (and "::=" for div (first ":" =divide))

I don't say I like those, but "mod=" is just the worst I can imagine.

Martin

Reply by email

Vinzent Höfler
to Michalis Kamburelis: This is more about SomeReallyLongVariableNameX += 10; being nicer to read than…

Michalis Kamburelis :

Show quoted text 16 lines
Vinzent Höfler wrote: > Alexander Klenin : > >> C-like operators reduce the number of required punctuation -- >> I always think that the extra punctuation is bad for readability. > > Rght. Shrt sntncs r mch sr t rd. > This is more about SomeReallyLongVariableNameX += 10; being nicer to read than SomeReallyLongVariableNameX := SomeReallyLongVariableNameX + 10;
Regarding "punctuation" this is the difference between "+=" (or even "+:=") and ":= +". Not much of a difference, I assume?
You don't have to spend time realizing that it's the same variable (not e.g. SomeReallyLongVariableNameY) if you read the 1st form.
But you can mistake the "+=" for a ":=". Replacing one possible reading error with another isn't much of an improvement.

Maybe if you've learned reading Cish books, the former version is easier to read, but the books I learned reading with contained text. ;)

But well, while we're at it, what about conditional expressions?

X := (if A then Y else Z);

(See <http://www.ada-auth.org/cgi-bin/cvsweb.cgi/ai05s/ai05-0147-1.txt> This is an Ada 2012 feature which I actually don't like at all for the same reasons as the C-like operators: they interrupt the normal flow of reading. But well...)

Vinzent.

GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT! Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01

Reply by email

Vinzent Höfler
to Graeme Geldenhuys: Op 2010-08-06 05:05, Alexander Klenin het geskryf: :-) I do the same, and use += and -+…

Graeme Geldenhuys :

Show quoted text 7 lines
Op 2010-08-06 05:05, Alexander Klenin het geskryf: > I specifically replace all usage of Inc/Dec and Include/Exclude in my > Pascal programs > by += / -= *to increase readability*. > And I think it really helps ;-) :-) I do the same, and use += and -+ more - simply to save on typing.

^^^^^^^^^^^^^^

Whilst IMO disrespecting the fellow reader.

BTW, what does "-+" stand for? Zero? ;)

Vinzent.

Neu: GMX De-Mail - Einfach wie E-Mail, sicher wie ein Brief! Jetzt De-Mail-Adresse reservieren: http://portal.gmx.net/de/go/demail

Reply by email

Alexander Klenin
to Vinzent Höfler: Michalis Kamburelis : Regarding "punctuation" this is the difference between "+=" (or…
"Vinzent Höfler" wrote
> You don't have to spend time realizing that it's the same variable (not > e.g. SomeReallyLongVariableNameY) if you read the 1st form. But you can mistake the "+=" for a ":=". Replacing one possible reading error with another isn't much of an improvement.

You can also mistake "." for ",", ">=" for "<=", or mix up "", "><", "<<" and ">>" --
which are all valid but different symbols in FPC. This is quite a minor problem.

Code bloat/duplication is much more serious.
It is usually not just SomeReallyLongVariableNameY, but something like: SomeFunctionReturningObject(param1, param2).PointArrayField[i] += FunctionReturningPointOffset(param);
Try rewriting that without "+=".

Maybe if you've learned reading Cish books, the former version is easier to read, but the books I learned reading with contained text. ;)

I have actually learned reading PL/I books, which is much worse ;-)

Show quoted text 5 lines
But well, while we're at it, what about conditional expressions? X := (if A then Y else Z); (See <http://www.ada-auth.org/cgi-bin/cvsweb.cgi/ai05s/ai05-0147-1.txt> This is an Ada 2012 feature which I actually don't like at all for the same reasons as the C-like operators: they interrupt the normal flow of reading. But well...)

That is half-covered by IfThen family of functions.

Alexander S. Klenin

Reply by email

Vinzent Höfler
to Michael Van Canneyt: Well, let's all communicate binary. You then have to know only 2 letters: 0 and 1. Things…

Michael Van Canneyt :

Show quoted text 17 lines
On Fri, 6 Aug 2010, Henry Vermaak wrote: > On 6 August 2010 06:08, "Vinzent Höfler" wrote: >> Alexander Klenin : >> >>> C-like operators reduce the number of required punctuation -- >>> I always think that the extra punctuation is bad for readability. >> >> Rght. Shrt sntncs r mch sr t rd. > > Punctuation vowels. Well, let's all communicate binary. You then have to know only 2 letters: 0 and 1. Things can't be made more simple than that.

Yes, back to the good old times where we typed hex listings out of badly copied magazines. Programming was so much easier when all was needed were the characters from 0-9, A-F, space, and newline.[1]

Vinzent.

[1] And a lot of time to find the typo that crashed the computer.

GMX DSL SOMMER-SPECIAL: Surf & Phone Flat 16.000 für nur 19,99 ¿/mtl.!* http://portal.gmx.net/de/go/dsl

Reply by email

Adem
to Alexander Klenin: [..] Correct. That is why reducing it to a required minimum is a good thing. Hm, just…
Alexander Klenin wrote
Correct.

I agree.

That is why reducing it to a required minimum is a good thing.

I agree with the idea.

But, not with the proposal.

Not the way it is made, anyway.

Why not come up with a small application/utility that caters for the opposition?

IOW, write a small/simple utility that converts a given source to/from those shorthand operators to/from their long form.

If there was such a thing and if it produced code that compiled to give identical results, I would have no problems with the proposal.

Reply by email

Vinzent Höfler
to Marc Weustink: then you have to type all those extra spaces Marc ;-)

Marc Weustink :

Show quoted text 9 lines
Martin wrote: > And, since I also refuse to learn from the faults of others, some > sarcasm in the end: > begin end is awfull amount of typing => can we replace it with something > shorter? "{" is unfortunately taken, but why need an actual char => just > identify a block, by indenting each line of the block, much less > clutter, all the extra begin/end can go.... then you have to type all those extra spaces

In strings the same char works for the beginning and the end of the string, so why have two different characters at all? You could use "%" instead.

Sometimes I really wonder if the buddies K&R when designing C actually looked at the keyboard and tried to assign a meaning to each special character they found there. Obviously, they seem to have missed "$". Probably this one was either too BASIC or too "establishment".

Vinzent.

Neu: GMX De-Mail - Einfach wie E-Mail, sicher wie ein Brief! Jetzt De-Mail-Adresse reservieren: http://portal.gmx.net/de/go/demail

Reply by email

Vinzent Höfler
to Graeme Geldenhuys: Op 2010-08-06 14:01, Henry Vermaak het geskryf: Ah, then I misunderstood. Apologies. On a…

Graeme Geldenhuys :

Maybe it's just me, but I clearly spot the difference between a := and += symbol. I guess it's years of experience looking at code, which counts in my favour. ;-)

Well, I am approaching forty now at high-speed (at least that's what it feels like) and my eyes aren't getting any better.

Vinzent.

GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT! Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01

Reply by email

Alexander Klenin
to Martin: It's not about implementation in the fpc parser/compiler, or syntax highlighter => you…
Martin wrote 6 lines
 On 06/08/2010 16:21, Alexander Klenin wrote: It's not about implementation in the fpc parser/compiler, or syntax highlighter => you can implement any such thing... But it's breaking the fundamentals of pascal, to differentiate between symbol and identifiers.

No, this is not fundamentals, this is minor syntactic point. The fundamentals are things like readability, orthogonality etc. (randomly chosen example:
http://xenia.media.mit.edu/~tpminka/PLE/linguistics.html#3)

Obviously it acts like a symbol does, so it should be a symbol; but if symbol can have chars, then why can't identifiers have $+-...

1) Since div and mod are already symbols, this distinction is already broken.
2) $+- in identifiers are disallowed because they will cause ambiguity. In fact, some other languages allow and even encourage them in identifiers (e.g. in Perl 6 and Lisp it is preferred style to separate words inside the identifier
with minus, not underscore).
3) Identifiers in FPC can start with "&" character, which further blurs the distinction you are trying to make.
So, famous "triple else" example can not be translated to Pascal: if &if = &then then &then := &else else &else := &if;

If we give up this barrier, then surely the following should be valid to?

So, the answer is that valid symbols are those which can not result in ambiguity.
AFAICS, {div|mod|or|and|xor}= satisfy this criteria.

Show quoted text 5 lines
---------- if there should be a shorthand for "a:=a mod b" => ok => but please make it look like pascal. Either inc style, or symbol style. maybe use "%=" (and "::=" for div (first ":" =divide)) I don't say I like those, but "mod=" is just the worst I can imagine.

Let's return to the orthogonality principle for the moment. It is, IMO, very simple and easily memorable rule: "a <op>= b" is equivalent to "a := a <op> b".
Instead, we now have "a <op>= b" is equivalent to "a := a <op> b" if <op> if is addition, subtraction, multiplication or floating-point (!) division.
I think that adding rule "a <op1>= b" is equivalent to "a := a <op2> b" where op1 and op2 are different is much worse than some allowing few more "mixed" tokens into the language.

If you see
a div= b;
operator, you may aesthetically dislike it, but you will instantly recognize what it does.

Alexander S. Klenin

Reply by email

Martin
to Alexander Klenin: On Sat, Aug 7, 2010 at 03:10, "Vinzent Höfler" You can also mistake "." for ",", ">="…
Alexander Klenin wrote 15 lines
On Sat, Aug 7, 2010 at 03:10, "Vinzent Höfler" wrote: >> You don't have to spend time realizing that it's the same variable (not >> e.g. SomeReallyLongVariableNameY) if you read the 1st form. > But you can mistake the "+=" for a ":=". Replacing one possible reading error with another isn't much of an improvement. You can also mistake "." for ",", ">=" for "<=", or mix up "","><", "<<" and">>" -- which are all valid but different symbols in FPC. This is quite a minor problem. Code bloat/duplication is much more serious. It is usually not just SomeReallyLongVariableNameY, but something like: SomeFunctionReturningObject(param1, param2).PointArrayField[i] += FunctionReturningPointOffset(param); Try rewriting that without "+=".

How is that defined?

I tried earlier to use += on a property => and got a compile error.

If it works like this for you, then obviously += work on some, but not all properties? Interesting...

Reply by email

Martin
to Alexander Klenin: No, this is not fundamentals, this is minor syntactic point. The fundamentals are things…
Alexander Klenin wrote 11 lines
On Sat, Aug 7, 2010 at 02:34, Martin wrote: > On 06/08/2010 16:21, Alexander Klenin wrote: > It's not about implementation in the fpc parser/compiler, or syntax > highlighter => you can implement any such thing... > > But it's breaking the fundamentals of pascal, to differentiate between > symbol and identifiers. No, this is not fundamentals, this is minor syntactic point. The fundamentals are things like readability, orthogonality etc. (randomly chosen example: http://xenia.media.mit.edu/~tpminka/PLE/linguistics.html#3)

"readability"
IMHO that would include the distinguishably of individual parts of the language .... "div=" just isn't readable at all (it is understandable, because it's meaning can be derived, but it isn't readable.

> Obviously it acts like a symbol does, so it should be a symbol; but if > symbol can have chars, then why can't identifiers have $+-... 1) Since div and mod are already symbols, this distinction is already broken.

Actually, are they? or are they keywords?
(in which case of course, I myself was to limited in my original statement, as it can also be said div= acts like a keyword)

Show quoted text 19 lines
> ---------- > if there should be a shorthand for "a:=a mod b" => ok => but please make it > look like pascal. > Either inc style, or symbol style. maybe use "%=" (and "::=" for div (first ":" =divide)) > I don't say I like those, but "mod=" is just the worst I can imagine. Let's return to the orthogonality principle for the moment. It is, IMO, very simple and easily memorable rule: "a<op>= b" is equivalent to "a := a<op> b". Instead, we now have "a<op>= b" is equivalent to "a := a<op> b" if<op> if is addition, subtraction, multiplication or floating-point (!) division. I think that adding rule "a<op1>= b" is equivalent to "a := a<op2> b" where op1 and op2 are different is much worse than some allowing few more "mixed" tokens into the language. If you see a div= b; operator, you may aesthetically dislike it, but you will instantly recognize what it does.

"aesthetically dislike " = bad readability => see above...

Well yes, having a different symbol, is not good (I wrote I did not like it) => but having "div=" is equally not good. That leaves the option of having neither. => Having neither is the answer you should always find to, if all known alternatives are at best a (bad) compromise.

But to follow up, if <op>= was allowed for all and any op:

BoolVal == OtherBool; // BoolVal := Boolval = OtherBool;

There is nothing wrong with it => except I wouldn't be to sure, how many people would actually read the correct meaning into it, if they did not know before?

Reply by email

Alexander Klenin
to Martin: How is that defined? I tried earlier to use += on a property => and got a compile error.…
Martin wrote 8 lines
 On 06/08/2010 17:38, Alexander Klenin wrote: > Code bloat/duplication is much more serious. > It is usually not just SomeReallyLongVariableNameY, but something like: > SomeFunctionReturningObject(param1, param2).PointArrayField[i] += > FunctionReturningPointOffset(param); > Try rewriting that without "+=". > How is that defined?

As usual, by-field addition.

I tried earlier to use += on a property => and got a compile error. If it works like this for you, then obviously += work on some, but not all properties? Interesting...

No, FPC team did a good job destroying this functionality ;-) This is why I specifically wrote PointArrayField, not PointArrayIndexedProperty.

Alexander S. Klenin

Reply by email

Vinzent Höfler
to Alexander Klenin: On Sat, Aug 7, 2010 at 03:10, "Vinzent Höfler" You can also mistake "." for ",", ">="…

Alexander Klenin :

Show quoted text 9 lines
On Sat, Aug 7, 2010 at 03:10, "Vinzent Höfler" > > But you can mistake the "+=" for a ":=". Replacing one possible reading error with another isn't much of an improvement. You can also mistake "." for ",", ">=" for "<=", or mix up "", "><", "<<" and ">>" -- which are all valid but different symbols in FPC. This is quite a minor problem.

Except for the ">=" "<=" the resulting error would not compile in most cases. THAT's the difference.

Show quoted text 5 lines
Code bloat/duplication is much more serious. It is usually not just SomeReallyLongVariableNameY, but something like: SomeFunctionReturningObject(param1, param2).PointArrayField[i] += FunctionReturningPointOffset(param); Try rewriting that without "+=".
Add (SomeFunctionReturningObject (param1, param2).PointArrayField[i],
     FunctionReturningPointOffset (param));

IMO, since the invention of subroutines, the expressive power of operators is overestimated. Consistently.

Vinzent.

GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT! Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01

Reply by email

José Mejuto
to Adem: I agree. I agree with the idea. But, not with the proposal. Not the way it is made,…

Hello Adem,

Friday, August 6, 2010, 6:48:22 PM, you wrote:

A> IOW, write a small/simple utility that converts a given source to/from A> those shorthand operators to/from their long form. A> If there was such a thing and if it produced code that compiled to give A> identical results, I would have no problems with the proposal.

Sone questions, what's the result of:

a:=2;
a*=a++;

and:

a:=1;
a:=a++1;

Algebra says one thing, and C a different one. Are ++ operators right to left ?

And how about non commutative operators ?

a:=1;
a:=2 div a;

How to write it shorter ?

a*=b - 2;
How is this resolved ? a:=a*b-2 or a:=a*(b-2) ?
Best regards, José

Reply by email

Unknown author

Hello all!

It seems like I have hit a very hot spot with my proposal - they must be something worth... Let me recapitulate and once more comment on this.

My proposal is to replace the operators "op=" by one operator "op" and a following ":=".
This can be further enhanced to work together with my other proposal "Multiple assignments".

Examples:

a + := 1;
a + := pi; // float
a + := 'bla'; // string
a + := [1,2]; // set
a < := b; // booleans, this is ugly but should be OK (but not with C-style operators), see PS
a div := 3;
a or := b;
a xor := 3;
a shl := 1;
f()^ + := 1; // f might have side-effects!
a[i+j] * := 2; // @a[i+j] only evaluated once
a,b + := c+d; // c+d only evaluated once
a,b shl := 1;
a^.b[f(i)], c^.d[g(j)] +:= h(k); // f,g,h might have side-effects, stuff evaluated only once

I object to the existing operators += -= /= *= because:
* the assignment nature is absent (i.e. the ":=" is missing), worse, "=" is the comparison operator
* every operator of this list introduces a new operator, i.e. all of them are real distict operators
* the list is incomplete: several operators are missing
* this syntax it is not really extensible: "mod=" and the like are not expressable as one symbol

Borland's alternative inc/dec/include/exclude is no better since they introduce a flood of names and hide the operator nature.

There are some reasons for my solution:
* You still see that there is an assignment
* No new operators: just combinations of an existing a binary operator and ":="
* Extendability: Any suitable (existing) binary operator can be used, even worded ones, self-defined (overloaded) and properties

The main reason for the proposal is not saving keystrokes but functionality and speed. It is meant to be an optimizing aid to the compiler being able to omit the common expression optimizer in this case without loss and to avoid side-effects. All parts of the statement should be evaluated once. Saving keystrokes and avoiding to write things twice are welcome side-effects. This has also been the reason for including these: inc dec include exclude += -= *= /= I have often missed e.g. "* :=" and "shl :=".

Semantic of "a op := expr":
; // only once!
p^:=p^ op expr;
Semantic of "obj.prop op := expr":
; // address of object, only once!
p^.prop:=p^.prop op expr; // access property
Semantic of "a,b := expr":
tmp:=expr; // only once!
a:=tmp;
b:=tmp;
Semantic of "a,b op := expr":
tmp:=expr; // only once!
; // only once!
p^:=p^ op tmp;
; // only once!
p^:=p^ op tmp;
BTW: "a[random(2)] + := 1" is not equivalent to "a[random(2)] := a[random(2)] + 1" due to the side-effect of random()!

Best regards
Jasper
PS: Using comparison operators on booleans (e.g. "if a=true then ...") should produce at least a hint due to bad style! ___________________________________________________________ WEB.DE DSL SOMMER-SPECIAL: Surf & Phone Flat 16.000 für nur 19,99 ¿/mtl.!* http://web.de/DSL-Doppel-Flatrate/

Reply by email

Alexander Klenin
to Vinzent Höfler: Alexander Klenin : Except for the ">=" "<=" the resulting error would not compile in most…
"Vinzent Höfler" wrote 11 lines
Alexander Klenin : > > But you can mistake the "+=" for a ":=". Replacing one possible reading > error with another isn't much of an improvement. > > You can also mistake "." for ",", ">=" for "<=", or mix up "", "><", > "<<" and ">>" -- > which are all valid but different symbols in FPC. This is quite a minor > problem. Except for the ">=" "<=" the resulting error would not compile in most cases. THAT's the difference.

I thought we were talking about reading errors, not writing errors?

Show quoted text 8 lines
> Code bloat/duplication is much more serious. > It is usually not just SomeReallyLongVariableNameY, but something like: > SomeFunctionReturningObject(param1, param2).PointArrayField[i] += > FunctionReturningPointOffset(param); > Try rewriting that without "+=". Add (SomeFunctionReturningObject (param1, param2).PointArrayField[i],     FunctionReturningPointOffset (param));

Exactly, and so we are back to square one -- you accumulate integers with "Inc", points with "AddPoint", doubles with "FloatInc", write extraneous four-line wrapper for every type and always forget which of MultVector and VecMultiply is procedure, and which is function. BTW, the above is almost-real example from the code base I worked with.

IMO, since the invention of subroutines, the expressive power of operators is overestimated. Consistently.

Ok, here is a real code from one of my Delphi 7 projects:

  mu :=
    MatrixMultiplyVector(
      InverseCoordMatrix(
        CoordMatrixAdd(
          CoordMatrixScale(dst.A, w), CoordMatrixScale(ASource.A, AWeight)
        ),
      ),
      VectorAdd(
        VectorScale(MatrixMultiplyVector(dst.A, dst.Mu), w),
        VectorScale(
          MatrixMultiplyVector(ASource.A, ASource.Mu), AWeight)
      ),
    );
  a :=
    CoordMatrixScale(
      CoordMatrixAdd(
        CoordMatrixScale(dst.A, w), CoordMatrixScale(ASource.A, AWeight)
      ),
      1 / (w + AWeight)
    );

Here is the same code after upgrading:

  mu :=
      InverseCoordMatrix(w * dst.A + AWeight * ASource.A) *
      (w * dst.A * dst.Mu + AWeight * ASource.A * ASource.Mu);
  a := w * dst.A + AWeight * ASource.A / (w + AWeight);

[Both versions slightly simplified to avoid overbloating the message]. Believe me, expressive power of operators is severely underestimated by those who did not try to do calculations without them ;-)

Alexander S. Klenin

Reply by email

Alexander Klenin
to Martin: "readability" IMHO that would include the distinguishably of individual parts of the…
Martin wrote
"aesthetically dislike " = bad readability => see above...

Not quite. For example I dislike indentation by three spaces, and "begin"s at the start of line, but both of those do not really impede my code reading. OTOH, inconsistent indentation and begin placement distract me so much that I sometimes prefer to reformat code before reading.

Show quoted text 12 lines
Well yes, having a different symbol, is not good (I wrote I did not like it) => but having "div=" is equally not good. That leaves the option of having neither. => Having neither is the answer you should always find to, if all known alternatives are at best a (bad) compromise. But to follow up, if <op>= was allowed for all and any op: BoolVal == OtherBool; // BoolVal := Boolval = OtherBool; There is nothing wrong with it => except I wouldn't be to sure, how many people would actually read the correct meaning into it, if they did not know before?

Yes, in that sense maybe original poster's proposal of retaining colon in assignment operator is a good idea ("+:=" vs "+="). Unfortunately, it is too late for that.
Another interesting but unrealistic option is something like a :=[+] b;

I can even concede to use a function-like syntax, as long as it is consistent between
all operations:
Reduce(a, +, b);

Alexander S. Klenin

Reply by email

Marco van de Voort
to Alexander Klenin

In our previous episode, Alexander Klenin said:

Show quoted text 9 lines
in assignment operator is a good idea ("+:=" vs "+="). Unfortunately, it is too late for that. Another interesting but unrealistic option is something like a :=[+] b; I can even concede to use a function-like syntax, as long as it is consistent between all operations: Reduce(a, +, b);

Why not RPN? You could signal an RPN expression, create local stacks etc.

Reply by email

Vinzent Höfler
to Alexander Klenin: On Sat, Aug 7, 2010 at 04:59, "Vinzent Höfler" I thought we were talking about reading…

Alexander Klenin :

Show quoted text 8 lines
On Sat, Aug 7, 2010 at 04:59, "Vinzent Höfler" wrote: > Alexander Klenin : > > Except for the ">=" "<=" the resulting error would not compile in most cases. THAT's the difference. I thought we were talking about reading errors, not writing errors?

If you'd like to think so. ;) I am talking about readability and that also means "spotting the actual bug" - which may be a typo being made in the first place.

A bug spotted by the compiler is a bug not needing to be found with the debugger.

Show quoted text 14 lines
>> Code bloat/duplication is much more serious. >> It is usually not just SomeReallyLongVariableNameY, but something like: >> SomeFunctionReturningObject(param1, param2).PointArrayField[i] += >> FunctionReturningPointOffset(param); >> Try rewriting that without "+=". > > Add (SomeFunctionReturningObject (param1, param2).PointArrayField[i], >     FunctionReturningPointOffset (param)); Exactly, and so we are back to square one -- you accumulate integers with "Inc", points with "AddPoint", doubles with "FloatInc", write extraneous four-line wrapper for every type and always forget which of MultVector and VecMultiply is procedure, and which is function.

Well, if you do it that way... I'd use overloading and use the same name (or, admitted, even the same operator) for the same concept.

Show quoted text 26 lines
> IMO, since the invention of subroutines, the expressive power of operators is overestimated. Consistently. Ok, here is a real code from one of my Delphi 7 projects: mu := MatrixMultiplyVector( InverseCoordMatrix( CoordMatrixAdd( CoordMatrixScale(dst.A, w), CoordMatrixScale(ASource.A, AWeight) ), ), VectorAdd( VectorScale(MatrixMultiplyVector(dst.A, dst.Mu), w), VectorScale( MatrixMultiplyVector(ASource.A, ASource.Mu), AWeight) ), ); a := CoordMatrixScale( CoordMatrixAdd( CoordMatrixScale(dst.A, w), CoordMatrixScale(ASource.A, AWeight) ), 1 / (w + AWeight) );

If you'd used just Add, Scale, and Multiply the code may be slightly more readable. :P

Show quoted text 10 lines
Here is the same code after upgrading: mu := InverseCoordMatrix(w * dst.A + AWeight * ASource.A) * (w * dst.A * dst.Mu + AWeight * ASource.A * ASource.Mu); a := w * dst.A + AWeight * ASource.A / (w + AWeight); [Both versions slightly simplified to avoid overbloating the message]. Believe me, expressive power of operators is severely underestimated by those who did not try to do calculations without them ;-)

Believe me, after all those years I still know what I am talking about. :) And why didn't you overload "-" for "Inverse"?

Surely, I didn't want to negate the fact that operator overloading can solve some problems, but why the hell does it always have to be the "add/sub/div/mul/mod/$whatever and assign" operator? Oh, this one doesn't exist at all, because it's two actions in one? My bad. Why didn't I think of the "multiply and add" operator, which was very common in DSPs once and meanwhile made it to mainstream CPUs? "*+:=" would be a proper symbol for it, wouldn't it?

So, I still do not find an occasion of a "reverse polish assignment" in this example. I even don't see what part of this example it would make more readable. Well, maybe it's just my eyes...

Vin"Sarcasm included."zent.

GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT! Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01

Reply by email

Ralf A. Quint
to Unknown author: Hello all! It seems like I have hit a very hot spot with my proposal - they must be…
Show quoted text 88 lines
Hello all! It seems like I have hit a very hot spot with my proposal - they must be something worth... Let me recapitulate and once more comment on this. My proposal is to replace the operators "op=" by one operator "op" and a following ":=". This can be further enhanced to work together with my other proposal "Multiple assignments". Examples: a + := 1; a + := pi; // float a + := 'bla'; // string a + := [1,2]; // set a < := b; // booleans, this is ugly but should be OK (but not with C-style operators), see PS a div := 3; a or := b; a xor := 3; a shl := 1; f()^ + := 1; // f might have side-effects! a[i+j] * := 2; // @a[i+j] only evaluated once a,b + := c+d; // c+d only evaluated once a,b shl := 1; a^.b[f(i)], c^.d[g(j)] +:= h(k); // f,g,h might have side-effects, stuff evaluated only once I object to the existing operators += -= /= *= because: * the assignment nature is absent (i.e. the ":=" is missing), worse, "=" is the comparison operator * every operator of this list introduces a new operator, i.e. all of them are real distict operators * the list is incomplete: several operators are missing * this syntax it is not really extensible: "mod=" and the like are not expressable as one symbol Borland's alternative inc/dec/include/exclude is no better since they introduce a flood of names and hide the operator nature. There are some reasons for my solution: * You still see that there is an assignment * No new operators: just combinations of an existing a binary operator and ":=" * Extendability: Any suitable (existing) binary operator can be used, even worded ones, self-defined (overloaded) and properties The main reason for the proposal is not saving keystrokes but functionality and speed. It is meant to be an optimizing aid to the compiler being able to omit the common expression optimizer in this case without loss and to avoid side-effects. All parts of the statement should be evaluated once. Saving keystrokes and avoiding to write things twice are welcome side-effects. This has also been the reason for including these: inc dec include exclude += -= *= /= I have often missed e.g. "* :=" and "shl :=". Semantic of "a op := expr": ; // only once! p^:=p^ op expr; Semantic of "obj.prop op := expr": ; // address of object, only once! p^.prop:=p^.prop op expr; // access property Semantic of "a,b := expr": tmp:=expr; // only once! a:=tmp; b:=tmp; Semantic of "a,b op := expr": tmp:=expr; // only once! ; // only once! p^:=p^ op tmp; ; // only once! p^:=p^ op tmp; BTW: "a[random(2)] + := 1" is not equivalent to "a[random(2)] := a[random(2)] + 1" due to the side-effect of random()! Best regards Jasper PS: Using comparison operators on booleans (e.g. "if a=true then ...") should produce at least a hint due to bad style!

How long are you programming in Pascal? You are aware that this is a list about an implementation of the Pascal programming language, right?

Ralf

Reply by email

Hans-Peter Diettrich
to Alexander Klenin: $a = 11; print "$a is prime" if ('x' x $a) !~ /^(..+)\1+$/; Is correct (and slightly more…
I do think that begin/end is an awful amount of visual clutter, and that Modula solution is a better one.

"begin" can be omitted in many cases, but "end" is inevitable to denote the end of any block (except "until"...).

Unfortunately, this change is totally out of question because it will break literally all the existing code.

A {$mode Modula} would not break anything - it only would make such units hard to read, for people with other language preferences.

DoDi

Reply by email

Hans-Peter Diettrich
to Vinzent Höfler: Michael Van Canneyt : Yes, back to the good old times where we typed hex listings out of…
Show quoted text 8 lines
Yes, back to the good old times where we typed hex listings out of badly copied magazines. Programming was so much easier when all was needed were the characters from 0-9, A-F, space, and newline.[1] Vinzent. [1] And a lot of time to find the typo that crashed the computer.

That's why in "those good ole times"[tm] at least one magazine published the construction of an barcode reader, and of the according "driver" software, and then replaced the hexdumps by barcode printouts :-)

DoDi

Reply by email

Hans-Peter Diettrich
to Vinzent Höfler: Marc Weustink : In strings the same char works for the beginning and the end of the…
Show quoted text 5 lines
Sometimes I really wonder if the buddies K&R when designing C actually looked at the keyboard and tried to assign a meaning to each special character they found there. Obviously, they seem to have missed "$". Probably this one was either too BASIC or too "establishment".

Perhaps the "$" was used for other purposes on their machines, or they found it inavailabe on other (non-U.S.) keyboards or character sets. Even Wirth introduced digraphs for not commonly available keys, like "(*" for "{", or "(." for "[".

DoDi

Reply by email

Alexander Klenin
to Vinzent Höfler: Alexander Klenin : If you'd like to think so. ;) I am talking about readability and that…
"Vinzent Höfler" wrote 8 lines
Alexander Klenin : > Exactly, and so we are back to square one -- you accumulate integers with > "Inc", > points with "AddPoint", doubles with "FloatInc", write extraneous > four-line wrapper for every type and always forget which of > MultVector and VecMultiply is procedure, and which is function. Well, if you do it that way... I'd use overloading and use the same name (or, admitted, even the same operator) for the same concept.

IIRC, overloading is not available in Delphi 7 either.

If you'd used just Add, Scale, and Multiply the code may be slightly more readable. :P

Argee, but only slightly.

Show quoted text 12 lines
> Here is the same code after upgrading: > >   mu := >       InverseCoordMatrix(w * dst.A + AWeight * ASource.A) * >       (w * dst.A * dst.Mu + AWeight * ASource.A * ASource.Mu); >   a := w * dst.A + AWeight * ASource.A / (w + AWeight); > > [Both versions slightly simplified to avoid overbloating the message]. > Believe me, expressive power of operators is severely underestimated > by those who did not try to do calculations without them ;-) Believe me, after all those years I still know what I am talking about. :) And why didn't you overload "-" for "Inverse"?

Because inverse is not negation, and Delphi does not have ** operator for power.

Surely, I didn't want to negate the fact that operator overloading can solve some problems, but why the hell does it always have to be the "add/sub/div/mul/mod/$whatever and assign" operator? Oh, this one doesn't exist at all, because it's two actions in one? My bad. Why didn't I think of the "multiply and add" operator, which was very common in DSPs once and meanwhile made it to mainstream CPUs? "*+:=" would be a proper symbol for it, wouldn't it?

No, that would be for "multiply, add and assign". Besides, is not it a ternary?

So, I still do not find an occasion of a "reverse polish assignment" in this example. I even don't see what part of this example it would make more readable. Well, maybe it's just my eyes...

Why "reverse polish"? Assign operators are infix (and do not form expressions in Pascal).
And true, this is not an example for using assignment operators, just operators in general.
It is the same principle, though -- Lisp is not a readable way to spell calculations,
whatever its other advantages ;-)

Alexander S. Klenin

Reply by email

Marco van de Voort
to Alexander Klenin

In our previous episode, Alexander Klenin said:

> > Well, if you do it that way... I'd use overloading and use the same name (or, admitted, even the same operator) for the same concept. IIRC, overloading is not available in Delphi 7 either.

Delphi4. But IIRC at first they only allowed it for methods, and only with D6 also for procedures.

Reply by email

Alexander Klenin
to Marco van de Voort
Marco van de Voort wrote 8 lines
In our previous episode, Alexander Klenin said: > > > > Well, if you do it that way... I'd use overloading and use the same name (or, admitted, even the same operator) for the same concept. > > IIRC, overloading is not available in Delphi 7 either. Delphi4. But IIRC at first they only allowed it for methods, and only with D6 also for procedures.

Right, I misremembered.

Alexander S. Klenin

Reply by email

Florian Klämpfl
to Alexander Klenin: On Fri, Aug 6, 2010 at 08:29, Michael Van Canneyt FWIW, while migrating to FPC/newer…
Alexander Klenin wrote 9 lines
On Fri, Aug 6, 2010 at 08:29, Michael Van Canneyt wrote: > Pascal as it is, is a very readable language as opposed to C. Proposals such > as this diminish the readability. FWIW, while migrating to FPC/newer Delphi, I specifically replace all usage of Inc/Dec and Include/Exclude in my Pascal programs by += / -= *to increase readability*.

Nevertheless inc/dec generates better code because fpc is too dump to convert += / -= into inc/dec etc. :)

Reply by email

Marc Weustink
to Alexander Klenin: On Sat, Aug 7, 2010 at 03:10, "Vinzent Höfler" You can also mistake "." for ",", ">="…
Alexander Klenin wrote 5 lines
Code bloat/duplication is much more serious. It is usually not just SomeReallyLongVariableNameY, but something like: SomeFunctionReturningObject(param1, param2).PointArrayField[i] += FunctionReturningPointOffset(param); Try rewriting that without "+=".

Again, we are back at lazy typing. Somehow typing the realy long valiable name is not a problem, but declaring an extra variable is. (and with lazarus even that isn't needed)

What is wrong with :

MyObj := SomeFunctionReturningObject(param1, param2);
MyObj.PointArrayField[i] := MyObj.PointArrayField[i] +
   FunctionReturningPointOffset(param)

Why are you still using pascal ?

Marc

Reply by email

Florian Klämpfl
to Martin
Martin wrote 11 lines
On 07/08/2010 08:28, Florian Klämpfl wrote: > > Nevertheless inc/dec generates better code because fpc is too dump to > convert += / -= into inc/dec etc. :) Better in which way? I did a quick test (on a very simple source only) (fpc 2.5.1) inc(a), a+=1; a:= a + 1; all generate "incl" inc(a,3); a := a + 3; generate "addl"

Yes, but only in simple situations.

Just compare the code in:

var
  i : longint;
begin
  while i>1 do
    i+=1;
  while i>1 do
    inc(i);
end.

Reply by email

Alexander Klenin
to Marc Weustink: Again, we are back at lazy typing. Somehow typing the realy long valiable name is not a…
Marc Weustink wrote 11 lines
Alexander Klenin wrote: > Code bloat/duplication is much more serious. > It is usually not just SomeReallyLongVariableNameY, but something like: > SomeFunctionReturningObject(param1, param2).PointArrayField[i] += > FunctionReturningPointOffset(param); > Try rewriting that without "+=". Again, we are back at lazy typing. Somehow typing the realy long valiable name is not a problem, but declaring an extra variable is. (and with lazarus even that isn't needed)

As I already said in this thread, "lazy typing" is a fallacious argument. The whole history of high-level programming languages may be summarized as "lazy typing advancements".

Show quoted text 5 lines
What is wrong with : MyObj := SomeFunctionReturningObject(param1, param2); MyObj.PointArrayField[i] := MyObj.PointArrayField[i] +  FunctionReturningPointOffset(param)

What's wrong with rewriting it in assembler?
It can be done, and it will as the project grows, code bloat becomes an impediment. 100 vs 200 lines of code is insignificant,
but 500000 vs 1000000 is a serious difference.

Why are you still using pascal ?

Mostly because of Lazarus and execution speed.

Alexander S. Klenin

Reply by email

Marc Weustink
to Hans-Peter Diettrich
Hans-Peter Diettrich wrote 8 lines
Marc Weustink schrieb: > What is wrong with : > > MyObj.PointArrayField[i] := MyObj.PointArrayField[i] + > FunctionReturningPointOffset(param) The need for duplicating a long expression, with chances for typos :-(

Choose shorter expressions and/or use ctrl+space

Marc

Reply by email

Hans-Peter Diettrich
to Marc Weustink
Show quoted text 8 lines
>> What is wrong with : >> >> MyObj.PointArrayField[i] := MyObj.PointArrayField[i] + >> FunctionReturningPointOffset(param) > > The need for duplicating a long expression, with chances for typos :-( Choose shorter expressions and/or use ctrl+space

And how do I find out, whether two expressions are the same, while *reading* the code?

DoDi

Reply by email

Martin
to Hans-Peter Diettrich
Hans-Peter Diettrich wrote 13 lines
Marc Weustink schrieb: >>> What is wrong with : >>> >>> MyObj.PointArrayField[i] := MyObj.PointArrayField[i] + >>> FunctionReturningPointOffset(param) >> >> The need for duplicating a long expression, with chances for typos :-( > > Choose shorter expressions and/or use ctrl+space And how do I find out, whether two expressions are the same, while *reading* the code?

Lazarus can highlight occurrences of equal text => select one as block, the other one will be highlighted....
Of course, that is beside the point, totally missing your argument (so save yourself from pointing out the deficiencies of the above statement).

But honestly, no matter if you use += or the above form, it is hard to read.

The data in MyObj.PointArrayField belongs to MyObj => so why not tell MyObj what to do with that data?

MyObj.AddOffsetToField(i, FunctionReturningPointOffset(param));

Or make fields them self objects (or a record-with-methods /fpc "type foo=object end"):
MyObj.Field[i].AddOffset( FunctionReturningPointOffset(param));

Oh, yes, it's another 3 or 4 line method... so what? (as for speed, inline it).
There are many usages for subroutines, not only the ability to call the same code from more than one location. Using a subroutine to extract and name a piece of code for better readabilit *can* be perfectly valid and desirable.

Martin

Reply by email

Adem
to Martin
Martin wrote
The data in MyObj.PointArrayField belongs to MyObj => so why not tell MyObj what to do with that data?

First I thought it meant 'therefore', 'hence' or 'thus', but replacing '=>' in the sentence above did not make much sense.

What is it supposed to mean?

Reply by email

Jonas Maebe
to Adem

Hi,

Please continue this discussion on the fpc-other list. Long arguments about how easy or hard it is to read or write long expressions (or about how hard it is to understand other people's explanations of this), the difficulty of typing certain characters, etc are not about the development of FPC.

Please try to limit discussions on this list *mostly* (note: not exclusively) to actual problems encountered while working on the FPC project's code base (or related programming issue). As a nice side effect, such threads also have less of a tendency to flood people's inboxes.

If a side discussion evolves from that, please try your best to keep those short (and especially do not send messages with the intention of heating up the discussion further just to prove your point).

Discussing new features are obviously also related to FPC development and can also be on topic. However, as soon as these evolve in to large "yes - no" discussions (which they often do), please move them to the fpc-other list so that they don't drown this list.

Thank you.

Jonas
FPC mailing lists admin

Reply by email

Vinzent Höfler
to Hans-Peter Diettrich: "begin" can be omitted in many cases, but "end" is inevitable to denote the end of any…

Hans-Peter Diettrich :

A {$mode Modula} would not break anything - it only would make such units hard to read, for people with other language preferences.

And you'd have to write the keywords all UPPERCASE then. Better to use {$mode Ada} for that. ;)

Vinzent.

GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT! Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01

Reply by email

Vinzent Höfler
to Alexander Klenin: As I already said in this thread, "lazy typing" is a fallacious argument. The whole…

Alexander Klenin :

As I already said in this thread, "lazy typing" is a fallacious argument. The whole history of high-level programming languages may be summarized as "lazy typing advancements".

Surely not. But that's a different matter.

Show quoted text 7 lines
> What is wrong with : > > MyObj := SomeFunctionReturningObject(param1, param2); > MyObj.PointArrayField[i] := MyObj.PointArrayField[i] + >  FunctionReturningPointOffset(param) What's wrong with rewriting it in assembler?

Oh, come on. Now you're overreacting. :D

It can be done, and it will work at first. But as the project grows, code bloat becomes an impediment. 100 vs 200 lines of code is insignificant, but 500000 vs 1000000 is a serious difference.

Considering that about 35% - 50% of our codebase here simply consists of comments, what do you make of that? You could cut the line count by two just by removing all the comments. They don't have any semantics anyway.

Vinzent.

GMX DSL SOMMER-SPECIAL: Surf & Phone Flat 16.000 für nur 19,99 ¿/mtl.!* http://portal.gmx.net/de/go/dsl

Reply by email

Vinzent Höfler
to Hans-Peter Diettrich: The need for duplicating a long expression, with chances for typos :-( DoDi

Hans-Peter Diettrich :

Show quoted text 8 lines
Marc Weustink schrieb: > What is wrong with : > > MyObj.PointArrayField[i] := MyObj.PointArrayField[i] + > FunctionReturningPointOffset(param) The need for duplicating a long expression, with chances for typos :-(

So we need Ada's renaming feature?

declare
   x : Some_Type renames MyObj.PointArrayField (i);
begin
   x := x + FunctionReturningPointOffset (param);
end;

Vinzent.

Neu: GMX De-Mail - Einfach wie E-Mail, sicher wie ein Brief! Jetzt De-Mail-Adresse reservieren: http://portal.gmx.net/de/go/demail

Reply by email

Michael Schnell
to Martin: How is that defined? I tried earlier to use += on a property => and got a compile error.…
Martin wrote
I tried earlier to use += on a property => and got a compile error.

A property can't be used as a var parameter. You can't do "inc (x.a)". The "+= procedure" - similar as inc() - needs a kind of var-parameter.

It seem like a nice enhancement to allow for properties as var parameters of functions that are resolved at compile-time such as inc (and +=).

BTW.: are there "inout" Parameters that are set on entry and written on exit of a procedure, but not modified during the course of the procedure ?

Same should be allowed to be read/write properties. Inc and "+=" could be defined in that way.

-Michael

Reply by email