[COFF] Of PL/I

Peter Pentchev roam at ringlet.net
Fri Apr 5 08:53:50 AEST 2024


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 at 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 at ringlet.net roam at debian.org pp at storpool.com
PGP key:        http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://www.tuhs.org/pipermail/coff/attachments/20240404/45e9d8cc/attachment.sig>


More information about the COFF mailing list