Article View: comp.lang.c
Article #1352Re: Rationales for result type of operations using operators like '+='
From: bartc
Date: Fri, 06 Nov 2026 12:14
Date: Fri, 06 Nov 2026 12:14
198 lines
8111 bytes
8111 bytes
On 06/11/2026 09:25, Janis Papanagnou wrote:
> On 2026-11-06 01:27, bartc wrote:
>> On 05/11/2026 22:41, Janis Papanagnou wrote:
>>> On 2026-11-05 13:17, bartc wrote:
> [...]
>>
>>>> i +:= 2 *:= i;
>>>
>>> What is that supposed to implement in the first place is the question!
>>> I suggest to explain a sensible task,
>>
>> The task doesn't matter.
>
> For a sensible consideration a sensible example (not a made up
> one) from a practical application is imperative. Otherwise, as
> was already pointed out multiple times in various communications
> with you, you stupidly construct just bad code that no one would
> write that way in the first place and for no practical use.
>
>> The behaviour needs to be well-defined.
>
> The fine thing here is that programming languages are typically
> "well-defined". (Algol 68 is. In "C" there's unfortunately quite
> some places where you need a lot deep knowledge to avoid things
> that are unreliable because of being undefined, yet accepted by
> the compilers.)
>
>> And here that might be unintuitive.
>
> What's intuitive is a subjective matter. You said already that
> you have problems with it, that it "confuses" you. (Repetitions
> don't make your opinions and your personal problems a fact.)
It appears to be you who has a problem with the concept that
intuitiveness might play any role in PL design.
So, let's forget about it completely shall we? If some individuals have
issues with a feature, it is 100% their fault, and not the language?
If MOST people have problems and avoid using the feature; it is still
those users' fault?
>>
>>>> The second 'i' will have the new value i + 2, not the original, even
>>>> though it has not obviously been modified.
>>>
>>> Are you now speaking about a left-associative interpretation?
>>
>> I'm speaking about observed behaviour from A68G:
>
> Okay, so you speak about a left-associative interpretation here.
>
>>
>> INT i:=100;
>> i +:= 2 *:= i;
>> print(i)
>
> Hardly any professional programmer would write such expressions
> with side-effects; "C" is full of such. ("If it hurts just don't
> do it!")
It's not always obvious:
a +:= b +:= c
a and c might refer to the same variable (eg. one might be a reference).
So as soon as 'a' changes, so does whatever c refers to. Maybe b is a
reference to a too!
Doing multiple updates to different entities (any of which may be
aliases to each other) within the same expression is an undesirable
pattern. Especially when there is no indication that a term may be modified.
> It would really help to make the discussion more serious
If you are doing PL design AND implementation, then you ALWAYS have to
consider the edge-cases. Not cherry-pick a few use-cases that look useful.
It's you who are not being serious about this. You think you're safe
because the two languages under discussion already exist, but it is
still possible to criticise.
You've done it yourself by asking why C does something one way while A68
does it another way (which you clearly think is superior).
if you'd
> choose sensible examples without side-effects, which always cause
> confusion in any language or language-construct where it's used!
>
>>
>> Output is 10404, or 102 * 102. It is not the same as either of:
>>
>> i := i + 2 * i; # 300 #
>> i := (i + 2) * i; # 10200 #
>
> Your example appears still nonsensical and bad.
DOESN'T MATTER. The point is that the behaviour is not obvious. In fact
you can't, in general, express LTR compound assignments as one regular
assignment, it needs to be separate assignments performed in sequence.
My i +:= 2 *:=i example would be:
i +:= 2;
i *:= i;
Here it is much clearer to everyone exactly what's happening.
> I suggested using
> examples from real applications and observe the various choices
> you have to model such functionality in the respective languages.
I'm sure you can scour codebases for examples that could save a few
terms if only a special feature was available. I've fallen into this
trap myself.
Funnily enough, this example is related to your 'number *:= base +:=
digit' fragment, but it is converting a number to, rather than from decimal:
d := a rem base
a := a / base
So, in C terms, both a / base and a % base are needed. It is well known
that hardware divide often calculates both at the same time, so why not
take advantage:
(a, d) := a divrem base
With this in place, no optimising compiler is needed to combine the two ops.
Great! Except - this is pretty much the only use-case.
>> It is also confusing in that here:
>>
>> number *:= base +:= digit
>>
>> It looks as though 'base' is being modified too.
>
> Only if you don't know the semantics.
That doesn't always help: you see this at the top of your screen:
b +:= c;
Adding 'c' to 'b'; simple enough! Then you scroll up one line and find
it is really this:
a +:= ...
b +:= c;
So 'b' isn't modified at all despite appearances.
>> [ snip another, yet more pathological example with side-effects ]
>>
>>> I understand that it is confusing to you. I understand that you seem
>>> to consider it to be "fiddly". I understand that you are incapable of
>>> defining a clear semantics
>>
>> The point is that the semantics are necessarily more obscure and less
>> obvious compared with plain code which only has one assignment.
>
> But they aren't at all obscure. The semantics are really most simple!
That is your opinion. That you think Algol68 is a fine language explains
a lot. I find most examples of it, not helped by its typical
presentation, fairly impenetrable.
> But (in Algol 68) you should also understand that expressions may not
> only be comprised of "level-0-values" but also that "level-1-values"
> (references, "names", "variables") can be returned. Maybe different
> from the languages you know but all most consistent; Algol 68 is known
> for its orthogonality and consistency,
Take REF REF REF INT x, and this term:
x
What is its value, or rather the type of its value? It could be INT, or
REF INT etc, all depending on context. In C, with the equivalent 'int
***x', then 'x' will ALWAYS yield a value of type 'int***'.
So which is more consistent? In the A68, given REF INT x, y, what does
this actually copy:
x := y
Experiments show that it dereferences both, so suppose I wanted to copy
the references themselves? Those language qualities you value don't make
it simpler to use!
Technical Details
Message-ID:
<11ckgbj$2gmak$1@dont-email.me>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mailReferences:
<11ceoa2$85p3$3@dont-email.me> <11chs5e$1jlqr$1@dont-email.me> <11cj0n7$85p3$8@dont-email.me> <11cj6t3$242aq$1@dont-email.me> <11ck6e8$23539$6@dont-email.me>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail From: bartc <bc@freeuk.com> Newsgroups: comp.lang.c Subject: Re: Rationales for result type of operations using operators like '+=' Date: Fri, 6 Nov 2026 12:14:42 +0000 Organization: A noiseless patient Spider Lines: 198 Message-ID: <11ckgbj$2gmak$1@dont-email.me> References: <11ceoa2$85p3$3@dont-email.me> <11chs5e$1jlqr$1@dont-email.me> <11cj0n7$85p3$8@dont-email.me> <11cj6t3$242aq$1@dont-email.me> <11ck6e8$23539$6@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Fri, 06 Nov 2026 12:14:44 +0000 (UTC) Injection-Info: dont-email.me; logging-data="2644308"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/7ppjynwk09soTt6J9uUfI"; posting-host="06e92dab06e7bbad2d3f6c6728786274" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:Fb+jPh9MqmATeypxrOi7+IjaW8U= sha256:adygrvSejza0gm1Y+WTirUaNs51WembWquM0XtoFteU= sha1:m/vxBEMCRl6fA6R6seDDmqmdOxY= sha256:DF1E1ijQqgMvwP2MBMZ5RIybOB2+t5GzpBA9lyZNyjg= In-Reply-To: <11ck6e8$23539$6@dont-email.me> Content-Language: en-GB