Computer Old Farts Forum
 help / color / mirror / Atom feed
From: Peter Pentchev <roam@ringlet.net>
To: coff@tuhs.org
Subject: [COFF] Re: Of PL/I
Date: Fri, 5 Apr 2024 01:53:29 +0300	[thread overview]
Message-ID: <Zg8vaSU0VGE32Jig@straylight.ringlet.net> (raw)
In-Reply-To: <516a4019-d987-4ca4-ac62-bd6b40841f93@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 2036 bytes --]

On Thu, Apr 04, 2024 at 04:37:23PM +1300, Wesley Parish wrote:
> On 4/04/24 06:30, segaloco via COFF wrote:
> > On Wednesday, April 3rd, 2024 at 9:18 AM, Paul Winalski <paul.winalski@gmail.com> wrote:
> > 
> > > In the PL/I shops I worked at it was required that all declarations be at the beginning of the scope block.
> > > -Paul W.
> > I get (friendly) flack for this from some of my coworkers, context is we're a C# and Java(Type)Script shop.  They poke fun at how I write these languages like a C programmer but I don't ever hear anyone complaining about the readability of my code :)
> > 
> > Declarations anywhere else but the top of blocks irks me, even if the language is totally fine with it.  The only exception is asm, putting all the data and bss at the bottom of assembly units instead.
> 
> I learn C by reading Tanenbaum and Comer's OS books, and I cannot imagine
> how putting variable declarations anywhere other than the top of the
> function they belong to, would make sense. Unless they are global, in which
> case they go in a suitably global header file.

TBH, the fact that variables can now be declared in the middle of
a block is one of the things that I use most in C90 and C99.
Caveat: I only use it in combination with the "const" keyword for
single-assignment variables, similar to the bindings in some
functional languages. The result is that even the compiler will
yell at me if I try to do something funny to a variable that
I have declared as "this is its value; it is really, really not
supposed to change during its lifetime, but I'm storing it into
a variable mainly to cache it for reuse". A side effect is that
the compiler has another optimization hint.

It also prevents me from using the same name for two different
variables, even by accident.

G'luck,
Peter

-- 
Peter Pentchev  roam@ringlet.net roam@debian.org pp@storpool.com
PGP key:        http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  parent reply	other threads:[~2024-04-04 22:53 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-02 15:06 [COFF] " Dave Horsfall
2024-04-02 16:40 ` [COFF] " Clem Cole
2024-04-02 17:01   ` Charles H Sauer (he/him)
2024-04-03 16:18     ` Paul Winalski
2024-04-03 17:30       ` segaloco via COFF
2024-04-03 20:44         ` Paul Winalski
2024-04-04  3:37         ` Wesley Parish
2024-04-04 15:40           ` Paul Winalski
2024-04-04 22:53           ` Peter Pentchev [this message]
2024-04-07 23:10     ` Dave Horsfall
2024-04-07 23:25       ` Charles H Sauer (he/him)
2024-04-09 21:41         ` Stuff Received
2024-04-10  0:50           ` [COFF] SNOBOL, ICEBOL, SPITBOL, et al William H. Mitchell
2024-04-10  1:42             ` [COFF] " Dave Horsfall
2024-04-08  1:13       ` [COFF] Re: Of PL/I Paul Winalski
2024-04-02 19:25   ` Stuff Received
2024-04-02 20:31     ` William H. Mitchell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Zg8vaSU0VGE32Jig@straylight.ringlet.net \
    --to=roam@ringlet.net \
    --cc=coff@tuhs.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).