× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.


  • Subject: Re: Clever UNIX/C Constructs
  • From: Jim Langston <jimlangston@xxxxxxxxxxxxxxxx>
  • Date: Thu, 04 Jan 2001 09:55:03 -0800
  • Organization: Pacer International



Scott Klement wrote:
> 
> In C, I was always told that "A += 5" performs better than "A = A + 5".
> The reason being that the compiled code only needs to load the value of A
> from memory once instead of twice.

This at one point in time this was true.  But, with today's more sophisticated
...  they come down to about the same.  And, with today's increased processor
speed the time difference would be negligible anyway.
 
> My opinion is that there are circumstances when the "A +=" operator is
> more intuitive for the person reading the code than the "A = A + " would
> be.  Since this is a question of style, and style is purely a matter of
> opinion, you don't necessarily have to agree with me.

Another reason "they" came up with the += construct is because
A = A + 5
just does not make since from a algebraic point of view.  A can not be equal
to A plus 5.  That would evaluate to false.  So they came up with
A += 5
which is interpreted as add 5 to A.  But, since C uses == for logical 
expressions
it's a pretty moot point.  Pascal uses := for this reason to assign equality.

> The whole premise of this is that "+=" makes for code that isn't obvious
> to the reader.  I disagree with this premise.   This is NOT like putting
> indicators into C.
> 
> There are C expressions that I don't like.  For example code that looks
> like this:
>       newoption = (newoption == 0) ? newoption : newoption - 1;
> 
> Would be something that I would prefer not to add to RPG.  However, I just
> don't see "A += 5" as being hard to follow.

It is not "hard to follow" but harder to follow than a = a + 5.  The simple
expressions don't show the real issue, however.  Not until you get into those
expressions that are half a yard long and use += and -- and ++ all over the
place.

> The problem with RPG is we try to make the compiler writers decide what is
> "good code" and what is "bad code", and then force it upon everyone.  They
> don't try that in C.  They give you all the options, and leave it to the
> programmer to develop code thats easy to follow.
> 
> The result, IMHO, is easier to follow C code.  The compiler developer
> can't anticipate every piece of code we write, so give the programmer the
> tools to do it the way that seems intuitive to him.

Actually, I think IBM has been very good at asking the users, us, what we
want in the language.  No matter what someone likes, there will be 2 other
people who don't like it.  All in all, however, I think IBM is doing a rather
decent job of improving RPG.

I think we need to ask ourselves, however, do we just want another C language
that understands F specs?  Not saying I don't like C, I use MS C++ 6.0 pro at
home and is my current language of choice.

And, yes, I do us += -= ++ and -- at home.

Regards,

Jim Langston
+---
| This is the RPG/400 Mailing List!
| To submit a new message, send your mail to RPG400-L@midrange.com.
| To subscribe to this list send email to RPG400-L-SUB@midrange.com.
| To unsubscribe from this list send email to RPG400-L-UNSUB@midrange.com.
| Questions should be directed to the list owner/operator: david@midrange.com
+---

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.