the fact that in c a language/compiler sees only functions or variables
that are up in code is a disaster
it is a disaster becouse it dont alow you to split code on N files
each file has realted functions and variables and not to care on the
global order of it
If you have something to say about splitting a C translation unit(something I don't think I've ever had a need to do), perhaps because
I don't recall refactoring existing code, primarily because theoriginal programmers used multiple translation units logically
Having said that, I don't remember it ever being a big deal. Ifsome source file needs to be subdivided, you simply subdivide it
you should not care becouse it has no sense those separate files are
then like in parralel dimensions and that is good (they will not go in conflict as it had to have unique names anyway)
the thing that yu need to care is some kind of bad annoying design flaw
as those historic goto abuse or other like that
So the solution is give at least compiler extension that would allow you
to have it changed that it see up and down
the fact thet this switch is not present is another flaw..so you have
two flaws here
On 16/05/2026 23:03, fir wrote:
the fact that in c a language/compiler sees only functions or
variables that are up in code is a disaster
it is a disaster becouse it dont alow you to split code on N files
each file has realted functions and variables and not to care on the
global order of it
I mentioned something like this a week ago, suggesting that in C it
was harder work than necessary to split one source file up into two or
more.
the fact that in c a language/compiler sees only functions or
variables that are up in code is a disaster
On Sun, 17 May 2026 00:03:40 +0200, fir wrote:
the fact that in c a language/compiler sees only functions or
variables that are up in code is a disaster
Back in those days, languages that needed multipass compilers (e.g.
Algol 68) were considered complicated and expensive to implement.
ThatrCOs why C went for a single-pass language design, like Pascal. And
like Pascal, it has forward declarations to mitigate this somewhat.
You need some kind of use-before-define facility in any realistic
language, if you want to allow recursion, and in particular mutual
recursion.
ItrCOs amusing to think that C++, that behemoth that, in terms of sheer complexity, leaves old-style monsters like Algol 68 or PL/I in the
dust, is still essentially a single-pass language design.
Bart <bc@freeuk.com> writes:
On 16/05/2026 23:03, fir wrote:
the fact that in c a language/compiler sees only functions or
variables that are up in code is a disaster
it is a disaster becouse it dont alow you to split code on N files
each file has realted functions and variables and not to care on the
global order of it
I mentioned something like this a week ago, suggesting that in C it
was harder work than necessary to split one source file up into two or
more.
And you offered no evidence for your claim, not even telling us
that you had tried it and found it difficult.
On 16/05/2026 23:03, fir wrote:
the fact that in c a language/compiler sees only functions or
variables that are up in code is a disaster
it is a disaster becouse it dont alow you to split code on N files
each file has realted functions and variables and not to care on the
global order of it
I mentioned something like this a week ago, suggesting that in C it was harder work than necessary to split one source file up into two or more.
static T A();
static T B();
static T E();
static T F();
T A(){}
T B(){}
T C(){}
T D(){}
Bart pisze:
static T A();
static T B();
static T E();
static T F();
T A(){}
T B(){}
T C(){}
T D(){}
imo the variables (call if file variables or block of code variables)
makes probably more problem than functions
good way of design is imo to have few functions and variables/arrays who work on this together - like in small c file...in another file you make another set of functions and variables...bad design is to split those variables out of its functions, and today i would need move the
variables like up (enforcing BAD DESIGN) of make extern declarations for visibility (enforcing even more BAD DESIGN imo) it also involves CODE JUMPING which is BAD
solution - add this f**kin switch to compiler...what i said is
mathematical (logical) proof its bad design
On 17/05/2026 02:21, Keith Thompson wrote:
Bart <bc@freeuk.com> writes:
On 16/05/2026 23:03, fir wrote:
the fact that in c a language/compiler sees only functions or
variables that are up in code is a disaster
it is a disaster becouse it dont alow you to split code on N files
each file has realted functions and variables and not to care on the
global order of it
I mentioned something like this a week ago, suggesting that in C it
was harder work than necessary to split one source file up into two or
more.
And you offered no evidence for your claim, not even telling us
that you had tried it and found it difficult.
Everyone here will know what is involved. But nobody wants to admit
that it can be onerous.
Here is a very simple example [...]
Bart pisze:
On 16/05/2026 23:03, fir wrote:
the fact that in c a language/compiler sees only functions or
variables that are up in code is a disaster
it is a disaster becouse it dont alow you to split code on N files
each file has realted functions and variables and not to care on the
global order of it
I mentioned something like this a week ago, suggesting that in C it
was harder work than necessary to split one source file up into two or
more.
ye i remember we afair both agree on that point even few years ago (that
it is bed - the fact you need to bother if it is up makes DEPENDENCY
more worse it is a CURSED DEPENDENCY
in this post above hovever i-a mentioned slightly other thing - that not only this is bad (which was talken already) but that there is real need
for compiler extension/switch - i know it would violate standard c, but there is a need a switch that violates c imo - for practicel reasons of
get rid of this annoyance
Bart <bc@freeuk.com> writes:
On 17/05/2026 02:21, Keith Thompson wrote:
Bart <bc@freeuk.com> writes:
On 16/05/2026 23:03, fir wrote:
the fact that in c a language/compiler sees only functions or
variables that are up in code is a disaster
it is a disaster becouse it dont alow you to split code on N files
each file has realted functions and variables and not to care on the >>>>> global order of it
I mentioned something like this a week ago, suggesting that in C it
was harder work than necessary to split one source file up into two or >>>> more.
And you offered no evidence for your claim, not even telling us
that you had tried it and found it difficult.
Everyone here will know what is involved. But nobody wants to admit
that it can be onerous.
It could be onerous. The point is, in actual practice it almost
never is onerous.
Here is a very simple example [...]
The example is not evidence but a strawman argument. It just
doesn't match the experience of actual practice of other C
developers (speaking for myself, and other developers I have
known personally, and the comments of other newsgroup folks who
have participated in the conversation).
ItrCOs amusing to think that C++, that behemoth that, in terms of sheer complexity, leaves old-style monsters like Algol 68 or PL/I in the
dust, is still essentially a single-pass language design.
On Sun, 17 May 2026 06:48:06 -0700, Tim Rentsch wrote:
Bart <bc@freeuk.com> writes:
On 17/05/2026 02:21, Keith Thompson wrote:
Bart <bc@freeuk.com> writes:
On 16/05/2026 23:03, fir wrote:
the fact that in c a language/compiler sees only functions or
variables that are up in code is a disaster
it is a disaster becouse it dont alow you to split code on N files >>>>>> each file has realted functions and variables and not to care on the >>>>>> global order of it
fir, "You are doing it wrong".
I mentioned something like this a week ago, suggesting that in C it
was harder work than necessary to split one source file up into two or >>>>> more.
Bart, in reality, a smart developer almost never has to "split one source file up into two or more". Instead, they /plan/ for isolation and encapsulation
of the functional parts of their code, and /intentionally/ develop
multiple source files from the start. That's the way professionals do it.
You, for instance, might write the parser, calling external functions
to generate output code. For your purposes, those external functions
can be debugging stubs in a separate source or object module.
Fir, OTOH, might write the code generator functions, with a simple
debugging driver as a separate source or object module. Once both of
you have tested your parts to success, you can combine your two works,
with fir supplying the code generator and you the parser, to create a
single compiler program. None of this has to be "onerous". The hard
part is agreeing on the contract between your code and fir's code, and
that's part of what a professional does /before/ (s)he starts coding.
And you offered no evidence for your claim, not even telling us
that you had tried it and found it difficult.
Everyone here will know what is involved. But nobody wants to admit
that it can be onerous.
It could be onerous. The point is, in actual practice it almost
never is onerous.
Here is a very simple example [...]
The example is not evidence but a strawman argument. It just
doesn't match the experience of actual practice of other C
developers (speaking for myself, and other developers I have
known personally, and the comments of other newsgroup folks who
have participated in the conversation).
Agreed. Bart and fir have a "special" view of coding, which is
at odds with my 30+ years experience in the profession (and
my 20+ years of post-professional (amateur) programming.
On Sun, 17 May 2026 06:48:06 -0700, Tim Rentsch wrote:
Bart <bc@freeuk.com> writes:
On 17/05/2026 02:21, Keith Thompson wrote:
Bart <bc@freeuk.com> writes:
On 16/05/2026 23:03, fir wrote:
the fact that in c a language/compiler sees only functions or
variables that are up in code is a disaster
it is a disaster becouse it dont alow you to split code on N files >>>>>> each file has realted functions and variables and not to care on the >>>>>> global order of it
fir, "You are doing it wrong".
I mentioned something like this a week ago, suggesting that in C it
was harder work than necessary to split one source file up into two or >>>>> more.
Bart, in reality, a smart developer almost never has to "split one source file up into two or more". Instead, they /plan/ for isolation and encapsulation
of the functional parts of their code, and /intentionally/ develop
multiple source files from the start. That's the way professionals do it.
You, for instance, might write the parser, calling external functions
to generate output code. For your purposes, those external functions
can be debugging stubs in a separate source or object module.
Fir, OTOH, might write the code generator functions, with a simple
debugging driver as a separate source or object module. Once both of
you have tested your parts to success, you can combine your two works,
with fir supplying the code generator and you the parser, to create a
single compiler program. None of this has to be "onerous". The hard
part is agreeing on the contract between your code and fir's code, and
that's part of what a professional does /before/ (s)he starts coding.
And you offered no evidence for your claim, not even telling us
that you had tried it and found it difficult.
Everyone here will know what is involved. But nobody wants to admit
that it can be onerous.
It could be onerous. The point is, in actual practice it almost
never is onerous.
Here is a very simple example [...]
The example is not evidence but a strawman argument. It just
doesn't match the experience of actual practice of other C
developers (speaking for myself, and other developers I have
known personally, and the comments of other newsgroup folks who
have participated in the conversation).
Agreed. Bart and fir have a "special" view of coding, which is
at odds with my 30+ years experience in the profession (and
my 20+ years of post-professional (amateur) programming.
Lew Pitcher pisze:
Agreed. Bart and fir have a "special" view of coding, which is
at odds with my 30+ years experience in the profession (and
my 20+ years of post-professional (amateur) programming.
were talking here about pices of c code..name it c files for example
say you have N of such pices - when i code my app i got the pices just
as i sait ..one is for example setup_window.c another is timer.c another
is blitter.c and so on
each have set of functions and "global" variables related to
them..mostly to them but some of them also may be accesed by other pices/files
if you have such system that those functions in each pice see all other pieces up and down its ideal and proper situation becouse all thise
files like orthogonal one to another and thus like separated only they
see other by names
adding a rigiud constrain that you must keep that files in artifical
linear order from up to down ias absolute crazyy becuose
1) naturally given order dont exist
2) ist absolutly sill and tiresome to manage such stupid order
its absolute FLAW and its a disaster
bartc simplyhas a dose of intelligence to see it too (though such things some may see in different extent..with time im even more angry than
before (when i was writing on this many years ago)
c also has other flaws (also mentioned) - language should be designed
such way not to make code jumping and unnecessary dependencies which
kill codes making work on it more tiresome and stupid
On 17/05/2026 17:24, fir wrote:
Lew Pitcher pisze:
Agreed. Bart and fir have a "special" view of coding, which is
at odds with my 30+ years experience in the profession (and
my 20+ years of post-professional (amateur) programming.
were talking here about pices of c code..name it c files for example
say you have N of such pices - when i code my app i got the pices just
as i sait ..one is for example setup_window.c another is timer.c
another is blitter.c and so on
each have set of functions and "global" variables related to
them..mostly to them but some of them also may be accesed by other
pices/files
if you have such system that those functions in each pice see all
other pieces up and down its ideal and proper situation becouse all
thise files like orthogonal one to another and thus like separated
only they
see other by names
adding a rigiud constrain that you must keep that files in artifical
linear order from up to down ias absolute crazyy becuose
1) naturally given order dont exist
2) ist absolutly sill and tiresome to manage such stupid order
C does allow you to have them in arbitrary order.
But it means writing and maintaining function prototypes at the top of
the file. That is what's tiresome.
its absolute FLAW and its a disaster
bartc simplyhas a dose of intelligence to see it too (though such
things some may see in different extent..with time im even more angry
than before (when i was writing on this many years ago)
c also has other flaws (also mentioned) - language should be designed
such way not to make code jumping and unnecessary dependencies which
kill codes making work on it more tiresome and stupid
My personal language allows anything to be defined in any order,
including types, variables, enums and macros, at module scope or inside
a function.
So if you wanted, you could define all local variables at the end of a function rather than at the top; in C syntax:
-a-a void GF() {
-a-a-a-a-a-a F(&x, &y, &z);
-a-a-a-a-a-a ...
-a-a-a-a-a-a int x, y, z;
-a-a }
This doesn't look that useful at first, but in a current project where I
am generating code in that language, it is invaluable, as I don't know exactly how many tempory variables need to be defined until I'm done generating code for the body.
Bart, in reality, a smart developer almost never has to "split one
source file up into two or more". Instead, they /plan/ for isolation
and encapsulation of the functional parts of their code, and
/intentionally/ develop multiple source files from the start. That's
the way professionals do it.
On 17/05/2026 02:21, Keith Thompson wrote:
Bart <bc@freeuk.com> writes:
On 16/05/2026 23:03, fir wrote:
the fact that in c a language/compiler sees only functions or
variables that are up in code is a disaster
it is a disaster becouse it dont alow you to split code on N files
each file has realted functions and variables and not to care on the
global order of it
I mentioned something like this a week ago, suggesting that in C it
was harder work than necessary to split one source file up into two or
more.
And you offered no evidence for your claim, not even telling us
that you had tried it and found it difficult.
Everyone here will know what is involved. But nobody wants to admit that
it can be onerous.
Here is a very simple example of one 'module', which involves two source >files, 'a.h' and 'a.c':
[snip]
So, yes, I believe a decent module scheme means stuff like this is less
work than in C.
On 17/05/2026 17:24, fir wrote:
Lew Pitcher pisze:
Agreed. Bart and fir have a "special" view of coding, which is
at odds with my 30+ years experience in the profession (and
my 20+ years of post-professional (amateur) programming.
were talking here about pices of c code..name it c files for example
say you have N of such pices - when i code my app i got the pices just
as i sait ..one is for example setup_window.c another is timer.c
another is blitter.c and so on
each have set of functions and "global" variables related to
them..mostly to them but some of them also may be accesed by other
pices/files
if you have such system that those functions in each pice see all
other pieces up and down its ideal and proper situation becouse all
thise files like orthogonal one to another and thus like separated
only they
see other by names
adding a rigiud constrain that you must keep that files in artifical
linear order from up to down ias absolute crazyy becuose
1) naturally given order dont exist
2) ist absolutly sill and tiresome to manage such stupid order
C does allow you to have them in arbitrary order.
But it means writing and maintaining function prototypes at the top of
the file. That is what's tiresome.
its absolute FLAW and its a disaster
bartc simplyhas a dose of intelligence to see it too (though such
things some may see in different extent..with time im even more angry
than before (when i was writing on this many years ago)
c also has other flaws (also mentioned) - language should be designed
such way not to make code jumping and unnecessary dependencies which
kill codes making work on it more tiresome and stupid
My personal language allows anything to be defined in any order,
including types, variables, enums and macros, at module scope or inside
a function.
So if you wanted, you could define all local variables at the end of a function rather than at the top; in C syntax:
-a-a void GF() {
-a-a-a-a-a-a F(&x, &y, &z);
-a-a-a-a-a-a ...
-a-a-a-a-a-a int x, y, z;
-a-a }
This doesn't look that useful at first, but in a current project where I
am generating code in that language, it is invaluable, as I don't know exactly how many tempory variables need to be defined until I'm done generating code for the body.
On Sun, 17 May 2026 14:43:28 -0000 (UTC), Lew Pitcher wrote:
Bart, in reality, a smart developer almost never has to "split one
source file up into two or more". Instead, they /plan/ for isolation
and encapsulation of the functional parts of their code, and
/intentionally/ develop multiple source files from the start. That's
the way professionals do it.
Meanwhile, back in the real world, programs evolve and need to adapt
to changes in the problems they were written to solve.
What starts out as one source file might later grow to two or more.
For instance, I start out with one program for performing the main
functions of my time-and-billing system, then later discover the need
for additional utilities driven by the same config settings: so this necessitates breaking out some common routines into a new module that
is common to all the executables.
ItrCOs called rCLrefactoringrCY.
On 17/05/2026 06:50, Lawrence DrCOOliveiro wrote:
On Sun, 17 May 2026 00:03:40 +0200, fir wrote:
the fact that in c a language/compiler sees only functions or
variables that are up in code is a disaster
Back in those days, languages that needed multipass compilers (e.g.
Algol 68) were considered complicated and expensive to implement.
ThatrCOs why C went for a single-pass language design, like Pascal. And
like Pascal, it has forward declarations to mitigate this somewhat.
You need some kind of use-before-define facility in any realistic
language, if you want to allow recursion, and in particular mutual
recursion.
ItrCOs amusing to think that C++, that behemoth that, in terms of sheer
complexity, leaves old-style monsters like Algol 68 or PL/I in the
dust, is still essentially a single-pass language design.
The way it works in Python is peculiar.
This fails for example:
-a def F():
-a-a-a-a-a G()
-a F()
-a def G():
-a-a-a-a print("G")
But it works if that F() call is moved to the end, even though G is
defined after F.
This is because 'def' is an executable statement, so executing 'def G' before doing F() is sufficient to get G into the global symbol table.
All languages I develop have out-of-order definitions so this stuff is
never a problem.
C does allow you to have them in arbitrary order.
But it means writing and maintaining function prototypes at the top
of the file. That is what's tiresome.
[...]
Much better, IMHO, is to use a language that lets you mix declarations
and statements as needed.
I see declaring your local variables in a
list at the top of a function - or, far worse, at the bottom - as
archaic style.
On 18/05/2026 01:30, Lawrence DrCOOliveiro wrote:
[...]
ItrCOs called rCLrefactoringrCY.
Yes, I think some people have been overstating their claims that they
rarely or never split a source file into two or more parts.-a Certainly
with good planing you reduce the likelihood of having to split code
later, but it's rare that you start a project with a clear enough specification and that never changes during the lifetime of the code.
But I also think Bart is wildly overstating his claims of how much of an effort it is.-a Usually it's just something you do, without needing much extra effort or risk - the thought and planning effort going in to how
you are doing your re-structure is the time-consuming part, not the mechanical copy-and-paste or adding a couple of extern declarations to a
new header.
On 18/05/2026 01:30, Lawrence DrCOOliveiro wrote:
On Sun, 17 May 2026 14:43:28 -0000 (UTC), Lew Pitcher wrote:
Bart, in reality, a smart developer almost never has to "split one
source file up into two or more". Instead, they /plan/ for isolation
and encapsulation of the functional parts of their code, and
/intentionally/ develop multiple source files from the start. That's
the way professionals do it.
Meanwhile, back in the real world, programs evolve and need to adapt
to changes in the problems they were written to solve.
What starts out as one source file might later grow to two or more.
For instance, I start out with one program for performing the main
functions of my time-and-billing system, then later discover the need
for additional utilities driven by the same config settings: so this
necessitates breaking out some common routines into a new module that
is common to all the executables.
ItrCOs called rCLrefactoringrCY.
Yes, I think some people have been overstating their claims that they
rarely or never split a source file into two or more parts.-a Certainly
with good planing you reduce the likelihood of having to split code
later, but it's rare that you start a project with a clear enough specification and that never changes during the lifetime of the code.
But I also think Bart is wildly overstating his claims of how much of an effort it is.-a Usually it's just something you do, without needing much extra effort or risk - the thought and planning effort going in to how
you are doing your re-structure is the time-consuming part, not the mechanical copy-and-paste or adding a couple of extern declarations to a
new header.
On 2026-05-18 08:56, David Brown wrote:
[...]
Much better, IMHO, is to use a language that lets you mix declarations
and statements as needed.
Indeed. But not "mixing" as a value per se, but to keep declarations
locally is a good thing, IMO.
I see declaring your local variables in a list at the top of a
function - or, far worse, at the bottom - as archaic style.
Well, "archaic" expresses a time-related qualification. But even in
earlier times we saw, depending on the actual programming language,
both styles existing.
Anyway we need forward declarations or other means (e.g. multi-pass)
to make mutual recursions or circular data structures possible.
[...]-a But in the C world, pre-C99 code is often written in a style with local variables all declared at the top of the function - after C99, it
is common to declare them when you need them.-a So as a C programmer, I
see declaring local variables in one clump together as archaic.
[...]
On 2026-05-18 09:02, David Brown wrote:
On 18/05/2026 01:30, Lawrence DrCOOliveiro wrote:
[...]
ItrCOs called rCLrefactoringrCY.
Yes, I think some people have been overstating their claims that they
rarely or never split a source file into two or more parts.-a Certainly
with good planing you reduce the likelihood of having to split code
later, but it's rare that you start a project with a clear enough
specification and that never changes during the lifetime of the code.
In C++ I had usually written a class first in one source file, tested
its basic function, and then separated the declaration in a header and
the implementation in a separate implementation file. It was just for convenience, and no issue at all, or rather trivial, to separate the
parts. That was no refactoring, though.
In real refactoring projects I've done _complex transformation_ tasks,
not just the mundane and trivial task of separating code across files.
But I also think Bart is wildly overstating his claims of how much of
an effort it is.-a Usually it's just something you do, without needing
much extra effort or risk - the thought and planning effort going in
to how you are doing your re-structure is the time-consuming part, not
the mechanical copy-and-paste or adding a couple of extern
declarations to a new header.
Indeed. - Actually I'm unsure whether he's making up these statements
because he really has a mental problem and difficulties handling that,
or whether he has some satisfaction in making up peculiar claims just
for the sake of an argument.
In article <10uc81u$1kd2r$1@dont-email.me>, Bart <bc@freeuk.com> wrote:
On 17/05/2026 02:21, Keith Thompson wrote:
Bart <bc@freeuk.com> writes:
On 16/05/2026 23:03, fir wrote:
the fact that in c a language/compiler sees only functions or
variables that are up in code is a disaster
it is a disaster becouse it dont alow you to split code on N files
each file has realted functions and variables and not to care on the >>>>> global order of it
I mentioned something like this a week ago, suggesting that in C it
was harder work than necessary to split one source file up into two or >>>> more.
And you offered no evidence for your claim, not even telling us
that you had tried it and found it difficult.
Everyone here will know what is involved. But nobody wants to admit that
it can be onerous.
Here is a very simple example of one 'module', which involves two source
files, 'a.h' and 'a.c':
[snip]
So, yes, I believe a decent module scheme means stuff like this is less
work than in C.
The example is you have two files, a.h and a.c; a.c has (say) a
bunch of `static`-qualified functions; obviously these are
file-scope, but have internal linkage. They can call each
other.
Now you split the file into two, and these functions need
external linkage and prototypes in a header file. Instead of
just creating a new `.c` file, you've got to change some stuff
in a header file (possibly newly created) as well.
I'll admit: you have a valid point.
Yes, this happens. I do it pretty frequently. It's a chore,
though I don't think it's quite as bad as you are making it out
to be; annoying, certainly, but probably not in my list of top
10, 15, or 20 annoyances about C.
But it is an annoyance, nonetheless.
On 17/05/2026 18:56, Bart wrote:
But it means writing and maintaining function prototypes at the top of
the file. That is what's tiresome.
/If/ you want to write your functions in an arbitrary order, then you
need to declare your static functions before you use them.-a That is certainly true.
-a I accept that you like it, and I appreciate
that you are not alone in that.-a But other people have different preferences.-a I /like/ having a fixed order.-a I almost never declare static functions, and when programming in a language that allows
arbitrary order (such as Python), I still order my code bottom-up.-a This means when you look at my code, if you want to know the definition of an identifier, you only need to look in one direction - upwards.
I am not saying that this ordering is somehow universally or objectively better than arbitrary order.-a But I am saying that arbitrary order is
not universally or objectively better in a programming language.
Flexibility has its downsides, and there's a lot of personal opinion and preferences involved.
But I agree that if you use a language that has a "declare before use"
rule (as many languages do), and you want to write in an arbitrary
order, then it will involve extra effort.-a Such effort may be annoying,
but it is entirely self-imposed.
So if you wanted, you could define all local variables at the end of a
function rather than at the top; in C syntax:
-a-a-a void GF() {
-a-a-a-a-a-a-a F(&x, &y, &z);
-a-a-a-a-a-a-a ...
-a-a-a-a-a-a-a int x, y, z;
-a-a-a }
This doesn't look that useful at first, but in a current project where
I am generating code in that language, it is invaluable, as I don't
know exactly how many tempory variables need to be defined until I'm
done generating code for the body.
It does not just look useless at first sight, it looks horrible.-a But I write my code myself, for the most part - generated code does not need
to be as easily read and understood.-a (I can't imagine how this
"feature" is useful for generating code - surely it would be negligible effort to build up your list of variables as you build up the generated statements, and output the whole function in one lump.-a You are no
longer trying to fit this into a few KB of ram on a Z80.)
Much better, IMHO, is to use a language that lets you mix declarations
and statements as needed.-a I see declaring your local variables in a
list at the top of a function - or, far worse, at the bottom - as
archaic style.
On 18/05/2026 02:22, Dan Cross wrote:
In article <10uc81u$1kd2r$1@dont-email.me>, Bart <bc@freeuk.com> wrote:
On 17/05/2026 02:21, Keith Thompson wrote:
Bart <bc@freeuk.com> writes:
On 16/05/2026 23:03, fir wrote:
the fact that in c a language/compiler sees only functions or
variables that are up in code is a disaster
it is a disaster becouse it dont alow you to split code on N files >>>>>> each file has realted functions and variables and not to care on the >>>>>> global order of it
I mentioned something like this a week ago, suggesting that in C it
was harder work than necessary to split one source file up into two or >>>>> more.
And you offered no evidence for your claim, not even telling us
that you had tried it and found it difficult.
Everyone here will know what is involved. But nobody wants to admit that >>> it can be onerous.
Here is a very simple example of one 'module', which involves two source >>> files, 'a.h' and 'a.c':
[snip]
So, yes, I believe a decent module scheme means stuff like this is less
work than in C.
The example is you have two files, a.h and a.c; a.c has (say) a
bunch of `static`-qualified functions; obviously these are
file-scope, but have internal linkage. They can call each
other.
Now you split the file into two, and these functions need
external linkage and prototypes in a header file. Instead of
just creating a new `.c` file, you've got to change some stuff
in a header file (possibly newly created) as well.
I'll admit: you have a valid point.
Yes, this happens. I do it pretty frequently. It's a chore,
though I don't think it's quite as bad as you are making it out
to be; annoying, certainly, but probably not in my list of top
10, 15, or 20 annoyances about C.
So you admit you have a list too! Mine had 100 items.
On 18/05/2026 07:56, David Brown wrote:
On 17/05/2026 18:56, Bart wrote:
But it means writing and maintaining function prototypes at the top
of the file. That is what's tiresome.
/If/ you want to write your functions in an arbitrary order, then you
need to declare your static functions before you use them.-a That is
certainly true.
-a I accept that you like it, and I appreciate that you are not alone
in that.-a But other people have different preferences.-a I /like/
having a fixed order.-a I almost never declare static functions, and
when programming in a language that allows arbitrary order (such as
Python), I still order my code bottom-up.-a This means when you look at
my code, if you want to know the definition of an identifier, you only
need to look in one direction - upwards.
I am not saying that this ordering is somehow universally or
objectively better than arbitrary order.-a But I am saying that
arbitrary order is not universally or objectively better in a
programming language. Flexibility has its downsides, and there's a lot
of personal opinion and preferences involved.
But I agree that if you use a language that has a "declare before use"
rule (as many languages do), and you want to write in an arbitrary
order, then it will involve extra effort.-a Such effort may be
annoying, but it is entirely self-imposed.
In my C compiler project, there are nearly 3000 top-level functions, variables, types, enumerations, named constants and macros. That is, declared at module scope, and including local and exported names.
(My non-C compiler generates that list which is picked up by my IDE.)
I really don't want the extra hassle of managing a dependency order. In
any case, there are also mutual out of order references.
So it is a necessity. Once you use such a language yourself, C will seem archaic.
So if you wanted, you could define all local variables at the end of
a function rather than at the top; in C syntax:
-a-a-a void GF() {
-a-a-a-a-a-a-a F(&x, &y, &z);
-a-a-a-a-a-a-a ...
-a-a-a-a-a-a-a int x, y, z;
-a-a-a }
This doesn't look that useful at first, but in a current project
where I am generating code in that language, it is invaluable, as I
don't know exactly how many tempory variables need to be defined
until I'm done generating code for the body.
It does not just look useless at first sight, it looks horrible.-a But
I write my code myself, for the most part - generated code does not
need to be as easily read and understood.-a (I can't imagine how this
"feature" is useful for generating code - surely it would be
negligible effort to build up your list of variables as you build up
the generated statements, and output the whole function in one lump.
You are no longer trying to fit this into a few KB of ram on a Z80.)
It is for simplicity. I don't want an extra pass generating internal
data structures when I can just generate source text as I go. But then
some details are not known until later.
There are ways of injecting new text into an earlier spot, but they are hairy. Since the target language has this feature, then why not use it?
Since either it has 'out-of-order' definitions, or it hasn't. In this
case it has.
Much better, IMHO, is to use a language that lets you mix declarations
and statements as needed.-a I see declaring your local variables in a
list at the top of a function - or, far worse, at the bottom - as
archaic style.
I allow definitions anywhere, including mixed with executable statements.
But I prefer to keep executable code clean and free of type-related
clutter, and to have separate summary of locals in one place.
This also allows easier transitioning between my static language, which needs type annotations, and my dynamic one, which doesn't. Or porting to other languages where details of my algorithm are relevant, but language specific types aren't.
I don't routinely declare locals at the end of a function. Especially if they are initialised, as that assignment takes place at that spot. So
then placement is important.
In article <10uepa5$2dpee$1@dont-email.me>, Bart <bc@freeuk.com> wrote:
On 18/05/2026 02:22, Dan Cross wrote:
In article <10uc81u$1kd2r$1@dont-email.me>, Bart <bc@freeuk.com> wrote: >>>> On 17/05/2026 02:21, Keith Thompson wrote:
Bart <bc@freeuk.com> writes:
On 16/05/2026 23:03, fir wrote:
the fact that in c a language/compiler sees only functions or
variables that are up in code is a disaster
it is a disaster becouse it dont alow you to split code on N files >>>>>>> each file has realted functions and variables and not to care on the >>>>>>> global order of it
I mentioned something like this a week ago, suggesting that in C it >>>>>> was harder work than necessary to split one source file up into two or >>>>>> more.
And you offered no evidence for your claim, not even telling us
that you had tried it and found it difficult.
Everyone here will know what is involved. But nobody wants to admit that >>>> it can be onerous.
Here is a very simple example of one 'module', which involves two source >>>> files, 'a.h' and 'a.c':
[snip]
So, yes, I believe a decent module scheme means stuff like this is less >>>> work than in C.
The example is you have two files, a.h and a.c; a.c has (say) a
bunch of `static`-qualified functions; obviously these are
file-scope, but have internal linkage. They can call each
other.
Now you split the file into two, and these functions need
external linkage and prototypes in a header file. Instead of
just creating a new `.c` file, you've got to change some stuff
in a header file (possibly newly created) as well.
I'll admit: you have a valid point.
Yes, this happens. I do it pretty frequently. It's a chore,
though I don't think it's quite as bad as you are making it out
to be; annoying, certainly, but probably not in my list of top
10, 15, or 20 annoyances about C.
So you admit you have a list too! Mine had 100 items.
Of course. I never said that I did not.
Indeed, no one I've seen engage with you seriously recently has
suggested that they think C is perfect; most have said there are
things they wish were different about C.
Dan Cross pisze:
In article <10uepa5$2dpee$1@dont-email.me>, Bart-a <bc@freeuk.com> wrote: >>> On 18/05/2026 02:22, Dan Cross wrote:in fast this "only see up" is on top or near top on that list..what you
In article <10uc81u$1kd2r$1@dont-email.me>, Bart-a <bc@freeuk.com>
wrote:
On 17/05/2026 02:21, Keith Thompson wrote:
Bart <bc@freeuk.com> writes:
On 16/05/2026 23:03, fir wrote:
the fact that in c a language/compiler sees only functions or
variables that are up in code is a disaster
it is a disaster becouse it dont alow you to split code on N files >>>>>>>> each file has realted functions and variables and not to care on >>>>>>>> the
global order of it
I mentioned something like this a week ago, suggesting that in C it >>>>>>> was harder work than necessary to split one source file up into >>>>>>> two or
more.
And you offered no evidence for your claim, not even telling us
that you had tried it and found it difficult.
Everyone here will know what is involved. But nobody wants to admit >>>>> that
it can be onerous.
Here is a very simple example of one 'module', which involves two
source
files, 'a.h' and 'a.c':
[snip]
So, yes, I believe a decent module scheme means stuff like this is
less
work than in C.
The example is you have two files, a.h and a.c; a.c has (say) a
bunch of `static`-qualified functions; obviously these are
file-scope, but have internal linkage.-a They can call each
other.
Now you split the file into two, and these functions need
external linkage-a and prototypes in a header file.-a Instead of
just creating a new `.c` file, you've got to change some stuff
in a header file (possibly newly created) as well.
I'll admit: you have a valid point.
Yes, this happens.-a I do it pretty frequently.-a It's a chore,
though I don't think it's quite as bad as you are making it out
to be; annoying, certainly, but probably not in my list of top
10, 15, or 20 annoyances about C.
So you admit you have a list too! Mine had 100 items.
Of course.-a I never said that I did not.
Indeed, no one I've seen engage with you seriously recently has
suggested that they think C is perfect; most have said there are
things they wish were different about C.
find
worse?
i never make a list but this "see only up" is definitelly near top
other very annoing is that long x = 'dhbsf00d' is not standarized afaik (such 8-char tags would be extremely handy sometimes)
also annoying is thet if {} has its own scope
also annoying if you cant foo( float x,y,z) {}-a (this ia somewhat disputable if its allowed but x, y are ints but im not sure if it work
in today c
also annoying is that foo() {} has return type int instead of void
(though this could be eventually disputable)
b instead of *a.b THAT is annoying (esp im not sure does not a.*b is notjust avaliable?)
annoying are also things that are not in c like "int x, y = foo(2,3);"
but those dont belong to that list
On 18/05/2026 12:57, Bart wrote:
In my C compiler project, there are nearly 3000 top-level functions,
variables, types, enumerations, named constants and macros. That is,
declared at module scope, and including local and exported names.
(My non-C compiler generates that list which is picked up by my IDE.)
I really don't want the extra hassle of managing a dependency order.
In any case, there are also mutual out of order references.
So it is a necessity. Once you use such a language yourself, C will
seem archaic.
You are simply incorrect.
You have a personal style that is somewhat anarchic and you prefer to be able to jumble your declarations around.-a Okay, I accept that's what you like.
-a But you are wrong to think it is somehow an objectively better
way to organise code or an objectively good language feature.-a You are wrong to guess what I or anyone else might think or prefer.
You really need to stop assuming that you have found some kind of
nirvana of programming.-a All you have found is what you happen to like - nothing more than that.
It is for simplicity. I don't want an extra pass generating internal
data structures when I can just generate source text as I go. But then
some details are not known until later.
I don't care.-a This is a limitation of your own making, and there is no good technical reason for that limitation.-a So your "solution" to your
own invented problem does not provide any evidence or justification for
why declaring after usage is a useful feature in a language.-a Of course
you can make your own language the way you prefer, and use it the way
you want - but don't imagine that it is "better" in any sense, or that others would also like it.-a Similarly, I don't claim to know that others would /not/ like it - I can only answer for myself.-a And I can only
point to the strong bias of real-world imperative languages where
"declare before use" is the norm as an indication that people see that
as a better way for a language to work.
fir pisze:
Dan Cross pisze:
i never make a list but this "see only up" is definitelly near top
other very annoing is that long x = 'dhbsf00d' is not standarized
afaik (such 8-char tags would be extremely handy sometimes)
also annoying is thet if {} has its own scope
also annoying if you cant foo( float x,y,z) {}-a (this ia somewhat
disputable if its allowed but x, y are ints but im not sure if it work
in today c>> also annoying is that foo() {} has return type int instead of void
(though this could be eventually disputable)
(*Q)->m; -> only fixes one level!
annoying is alos that "'" dont work more like
if(a) a=3,c=3,print(2), x=10;
AND ye i forgot
b instead of *a.b THAT is annoying (esp im not sure does not a.*b is notjust avaliable?)
m is equivalent to (*P).m. However, (**Q).m cannot be reduced to
annoying are also things that are not in c like "int x, y = foo(2,3);"
but those dont belong to that list
On 18/05/2026 12:57, David Brown wrote:
On 18/05/2026 12:57, Bart wrote:
In my C compiler project, there are nearly 3000 top-level functions,
variables, types, enumerations, named constants and macros. That is,
declared at module scope, and including local and exported names.
(My non-C compiler generates that list which is picked up by my IDE.)
I really don't want the extra hassle of managing a dependency order.
In any case, there are also mutual out of order references.
So it is a necessity. Once you use such a language yourself, C will
seem archaic.
You are simply incorrect.
You have a personal style that is somewhat anarchic and you prefer to
be able to jumble your declarations around.-a Okay, I accept that's
what you like.
-a But you are wrong to think it is somehow an objectively better way
to organise code or an objectively good language feature.-a You are
wrong to guess what I or anyone else might think or prefer.
You really need to stop assuming that you have found some kind of
nirvana of programming.-a All you have found is what you happen to like
- nothing more than that.
This is more fundamental. You seem think all top-level entities, even
within one source file, need to be some sort of ordered set, which
depends on which interactions there may or may not be between then.
Interactions which can change as code is developed, which may require a change in the order.
Nobody should really need to care about such things; they are plenty of other matters to deal with.
You only thing it is a 'good' thing because C requires it.
If you were using a language where order didn't matter, would you go to
the same trouble?
Maybe some people prefer their functions in alphabetical order!
So it's not question of liking or not liking, but doing anyway with an irrelevant distraction.
In any case, when I look at open source C code, I do see loads of
forward function declarations, even for non-exported functions.
I guess not everyone is as meticuluous as you. So for those people,
needing those declarations is a nuisance.
It is for simplicity. I don't want an extra pass generating internal
data structures when I can just generate source text as I go. But
then some details are not known until later.
I don't care.-a This is a limitation of your own making, and there is
no good technical reason for that limitation.-a So your "solution" to
your own invented problem does not provide any evidence or
justification for why declaring after usage is a useful feature in a
language.-a Of course you can make your own language the way you
prefer, and use it the way you want - but don't imagine that it is
"better" in any sense, or that others would also like it.-a Similarly,
I don't claim to know that others would /not/ like it - I can only
answer for myself.-a And I can only point to the strong bias of real-
world imperative languages where "declare before use" is the norm as
an indication that people see that as a better way for a language to
work.
also annoying if you cant foo( float x,y,z) {}-a (this ia somewhat
disputable if its allowed but x, y are ints but im not sure if it
work in today c>> also annoying is that foo() {} has return type int
instead of void
(though this could be eventually disputable)
Not sure what either of these mean.
AND ye i forgot
b instead of *a.b THAT is annoying (esp im not sure does not a.*bis notjust avaliable?)
m is equivalent to (*P).m. However, (**Q).m cannot be reduced to(*Q)->m; -> only fixes one level!
A post-fix '*' operator would mean being able to type P*.m and Q**.m.
You wouldn't really need -> here.
(My language uses post-fix '^' for derefs. However, the language allows
you to drop the explicit '^'; it will add in the derefs as needed.
That means those examples can be written as P.m and Q.m. This is very nice.
I was against allowing P->m in C to be written as P.m in C at one time,
but I've changed my mind; the cleaner code is too big an advantage.)
annoying are also things that are not in c like "int x, y =
foo(2,3);" but those dont belong to that list
Huh? This is legal C.
annoying are also things that are not in c like "int x, y =
foo(2,3);" but those dont belong to that list
Huh? This is legal C.
Bart pisze:
also annoying if you cant foo( float x,y,z) {}-a (this ia somewhat
disputable if its allowed but x, y are ints but im not sure if it
work in today c>> also annoying is that foo() {} has return type int
instead of void
(though this could be eventually disputable)
Not sure what either of these mean.
i simply mean that repeating that float is annoying
Something(float x1, float y1, float x2, float y2 ) {}
should be
Something(float x1,y1,x2,y2 ) {}
esp if those last 3 are not ints by default in present c - it was in
old, but in present i dont remember
checked they are not
_WAVE_SAMPLES.C:62:18: error: unknown type name 'y'
-avoid foo(float x,y,z) {}
in old c it would be disputable if foo(a,b,c) {} having a b c ints it is
not good but if it not work then thise repeating floats are annoying
one of two should work
-avoid foo(float x,y,z) {}
either x y z are all floats or x float y z ints..
present compile error is bad
Huh. This is C:
uint64_t F(uint64_t s, uint64_t t, uint64_t u, uint64_t v) ...
This is my language:
func F(u64 s, t, u, v)u64 ...
That's awful.
Bart pisze:
(*Q)->m; -> only fixes one level!
AND ye i forgot
b instead of *a.b THAT is annoying (esp im not sure does not a.*bis notjust avaliable?)
m is equivalent to (*P).m. However, (**Q).m cannot be reduced to
A post-fix '*' operator would mean being able to type P*.m and Q**.m.
You wouldn't really need -> here.
(My language uses post-fix '^' for derefs. However, the language
allows you to drop the explicit '^'; it will add in the derefs as needed.
That means those examples can be written as P.m and Q.m. This is very
nice.
I was against allowing P->m in C to be written as P.m in C at one
time, but I've changed my mind; the cleaner code is too big an
advantage.)
from sorta cpmpatibility only to repair flaws imo *a.b should work as
(*a).b and a.*b should work as *(a.b) i guess
if to skip pointers at all
void foo(int*a)
{
-a a=2; print(a); //woring as *a=2; print(*a);
}
im maybe not 100% sure but it seem im like 75% convinced that those
pointers in fact should be dropped
(i was writing back then on this but i dont remember fully my conclusions)
probbaly you should use labels a, and p instead of present *a, *p
and only at lace of definition it should be noted as pointer
float x = 3.4;
float* xf = &x;
-a-a xf+=0.1;
Bart pisze:
(*Q)->m; -> only fixes one level!
AND ye i forgot
b instead of *a.b THAT is annoying (esp im not sure does not a.*bis notjust avaliable?)
m is equivalent to (*P).m. However, (**Q).m cannot be reduced to
A post-fix '*' operator would mean being able to type P*.m and Q**.m.
You wouldn't really need -> here.
(My language uses post-fix '^' for derefs. However, the language
allows you to drop the explicit '^'; it will add in the derefs as needed.
That means those examples can be written as P.m and Q.m. This is very
nice.
I was against allowing P->m in C to be written as P.m in C at one
time, but I've changed my mind; the cleaner code is too big an
advantage.)
from sorta cpmpatibility only to repair flaws imo *a.b should work as
(*a).b and a.*b should work as *(a.b) i guess
if to skip pointers at all
void foo(int*a)
{
-a a=2; print(a); //woring as *a=2; print(*a);
}
im maybe not 100% sure but it seem im like 75% convinced that those
pointers in fact should be dropped
(i was writing back then on this but i dont remember fully my conclusions)
probbaly you should use labels a, and p instead of present *a, *p
and only at lace of definition it should be noted as pointer
float x = 3.4;
float* xf = &x;
-a-a xf+=0.1;
the usage of *xf has probably not much sense becouse you much more
operate on values-a even if you use pointers than on pointers itself
i know people often use
char *P = "akjsnjksnk";
while(*p++!=0) something;
but still imo use by value is more common
so it would be more
while(p!=0) { &p++; something; }
assuming you still use int*p; as a definition of pointer
and &p as deference to its addres value (which is not obvious becouse eventually one could use *p as a deference to pointer value - just
oposite it is now
int *P; - definition
p - pointer value,
-a*p - value
where it could be
int *P; - definition
p - value
-a*p - pointer value
this "swap" is probably quite sane
annoying are also things that are not in c like "int x, y =
foo(2,3);" but those dont belong to that list
Huh? This is legal C.
Bart pisze:
annoying are also things that are not in c like "int x, y =
foo(2,3);" but those dont belong to that list
Huh? This is legal C.
ye i know , but it is probably not work like i would have
you can deturn structure like int2{int x, y;}
but as thsi structure is not builtin it makes a SIN/FLAW
of making unnecesary dependency (on structure definition)
alos makes unnecesary names and so on
you know that ** unnecesary dependencies are bad **, and
** unnesesary things (objects ) are bad **
(of i would like to return two values and assign it to two separate variables)
As for the return type, I think that needs to be specified. As you
showed, it wasn't clear what it is, which is bad.
C is not high enough level to do type inference, but even if it was,
users would need to apply the same algorithms, and do the same analysis,
to figure out what some return type actually was. It's better to just
state it.
float x = 3.4;
float* xf = &x;
-a-a-a xf+=0.1;
Tricky one. Of that was 1 on the RHS, then 'xf += 1' might increment the pointer, or it might increment the float it points to. So ambiguous.
On 18/05/2026 16:04, fir wrote:
Bart pisze:
annoying are also things that are not in c like "int x, y =
foo(2,3);" but those dont belong to that list
Huh? This is legal C.
ye i know , but it is probably not work like i would have
you can deturn structure like int2{int x, y;}
but as thsi structure is not builtin it makes a SIN/FLAW
of making unnecesary dependency (on structure definition)
alos makes unnecesary names and so on
you know that ** unnecesary dependencies are bad **, and
** unnesesary things (objects ) are bad **
(of i would like to return two values and assign it to two separate
variables)
OK, I used to have such a feature, but dropped it because it wasn't used enough; it wasn't worth the extra complication. But it worked like this:
-a func foo:int, int =
-a-a-a-a-a return (10, 20)
-a end
It was used like this:
-a int x, y
-a (x, y) := foo()
(You can't combine with the declaration.) It also worked like this:
-a x := foo()-a-a-a # discard 2nd value
-a foo()-a-a-a-a-a-a-a-a # discard both
The implementation didn't use a struct, more of a tuple, but it simply returned N values (limited to 3/4) in the first N registers.
Bart pisze:
float x = 3.4;
float* xf = &x;
-a-a-a xf+=0.1;
Tricky one. Of that was 1 on the RHS, then 'xf += 1' might increment
the pointer, or it might increment the float it points to. So ambiguous.
this aboe may be flawed as it probably should be
-afloat x = 3.4;
-afloat* xf = x;
-a-a-a-a xf+=0.1;
here-a float* xf = x; copies the adress but it also look like it copies a value
this swapped * arithmetic is not ambigious imo - its just swapped
a meand value of pointer a and *a means adress/pointer value as adress
this is probably better for all people who do not like to se such many *
in codes as they would be very reduced
and when you would see it you would see it in two cases
1) in definitions
2) in places where realadres arithmetic is done
now you see it in places where values are used and sometimes you dont
see it when dres arithmetic is done - which is sorta swapped to reality
it seems (becous when you see * you should hae places when pointer arithemetic is really done imo)
in fact you culd ewen get rid it in definitions using this reference
like in c++
int& c = a;
-a-a c is value
-a-a *c would mean pointer
i dont like c++ but it is the option
option is also drop * and use & in both cases
int& c = a;
-a-a c is value
-a-a &c would mean pointer
this is maybe enough to say that
I.-a reference (if it behaves how i assumed here above) is a swapped pointer II. swapped probably has more sense then normal
(so eventually they really coud add references to c)
On 18/05/2026 16:04, fir wrote:
Bart pisze:
annoying are also things that are not in c like "int x, y =
foo(2,3);" but those dont belong to that list
Huh? This is legal C.
ye i know , but it is probably not work like i would have
you can deturn structure like int2{int x, y;}
but as thsi structure is not builtin it makes a SIN/FLAW
of making unnecesary dependency (on structure definition)
alos makes unnecesary names and so on
you know that ** unnecesary dependencies are bad **, and
** unnesesary things (objects ) are bad **
(of i would like to return two values and assign it to two separate
variables)
OK, I used to have such a feature, but dropped it because it wasn't used enough; it wasn't worth the extra complication. But it worked like this:
-a func foo:int, int =
-a-a-a-a-a return (10, 20)
-a end
It was used like this:
-a int x, y
-a (x, y) := foo()
(You can't combine with the declaration.) It also worked like this:
-a x := foo()-a-a-a # discard 2nd value
-a foo()-a-a-a-a-a-a-a-a # discard both
The implementation didn't use a struct, more of a tuple, but it simply returned N values (limited to 3/4) in the first N registers.
z means" output int z"
Sure. But in the C world, pre-C99 code is often written in a style with local variables all declared at the top of the function - after C99, it
is common to declare them when you need them. So as a C programmer, I
see declaring local variables in one clump together as archaic.
David Brown <david.brown@hesbynett.no> wrote:
Sure. But in the C world, pre-C99 code is often written in a style with
local variables all declared at the top of the function - after C99, it
is common to declare them when you need them. So as a C programmer, I
see declaring local variables in one clump together as archaic.
I agree about style. But AFAICS even in very early C there is block structure and one can put variable declarations in the middle of
sequence, just at the cost of introducing extra blocks. So C99
looks nicer as there is no need for extra blocks, but pre C99
already one could keep scopes tight and initialize variables in
declarations.
On 18/05/2026 09:22, Janis Papanagnou wrote:
On 2026-05-18 08:56, David Brown wrote:
[...]
Much better, IMHO, is to use a language that lets you mix
declarations and statements as needed.
Indeed. But not "mixing" as a value per se, but to keep declarations
locally is a good thing, IMO.
Yes - it is not the mixing itself that is good, it is what it allows.
You get to keep your scopes small, you don't need to declare variables
until you have an initial value for them (who cares if reading an uninitialised variable is UB if you never have them!), and you can often declare your variables as const.-a That means it's easy to know what the variable holds because it is only set once, and never changed.
I see declaring your local variables in a list at the top of a
function - or, far worse, at the bottom - as archaic style.
Well, "archaic" expresses a time-related qualification. But even in
earlier times we saw, depending on the actual programming language,
both styles existing.
Sure.-a But in the C world, pre-C99 code is often written in a style with local variables all declared at the top of the function - after C99, it
is common to declare them when you need them.-a So as a C programmer, I
see declaring local variables in one clump together as archaic.
David Brown <david.brown@hesbynett.no> wrote:
Sure. But in the C world, pre-C99 code is often written in a style with
local variables all declared at the top of the function - after C99, it
is common to declare them when you need them. So as a C programmer, I
see declaring local variables in one clump together as archaic.
I agree about style. But AFAICS even in very early C there is block >structure and one can put variable declarations in the middle of
sequence, just at the cost of introducing extra blocks. [snip]
In article <10uffq4$m4se$1@paganini.bofh.team>,
Waldek Hebisch <antispam@fricas.org> wrote:
David Brown <david.brown@hesbynett.no> wrote:
Sure. But in the C world, pre-C99 code is often written in a style with >>> local variables all declared at the top of the function - after C99, it >>> is common to declare them when you need them. So as a C programmer, I
see declaring local variables in one clump together as archaic.
I agree about style. But AFAICS even in very early C there is block >>structure and one can put variable declarations in the middle of
sequence, just at the cost of introducing extra blocks. [snip]
Maybe. But on projects based on older variants of C, it was
common as a matter of local policy to mandate that locals were
declared at the top of a function; this enabled readers to get
a sense of how much stack space was required at a glance.
On 18/05/2026 09:35, David Brown wrote:
On 18/05/2026 09:22, Janis Papanagnou wrote:
On 2026-05-18 08:56, David Brown wrote:
[...]
Much better, IMHO, is to use a language that lets you mix
declarations and statements as needed.
Indeed. But not "mixing" as a value per se, but to keep declarations
locally is a good thing, IMO.
Yes - it is not the mixing itself that is good, it is what it allows.
You get to keep your scopes small, you don't need to declare variables
until you have an initial value for them (who cares if reading an
uninitialised variable is UB if you never have them!), and you can
often declare your variables as const.-a That means it's easy to know
what the variable holds because it is only set once, and never changed.
I see declaring your local variables in a list at the top of a
function - or, far worse, at the bottom - as archaic style.
Well, "archaic" expresses a time-related qualification. But even in
earlier times we saw, depending on the actual programming language,
both styles existing.
Sure.-a But in the C world, pre-C99 code is often written in a style
with local variables all declared at the top of the function - after
C99, it is common to declare them when you need them.-a So as a C
programmer, I see declaring local variables in one clump together as
archaic.
I hate dealing with code that just declares variables higgledy-piggledy
all over the place; it is so lazy. I'm not into block scopes either.
I /like/ to have them all in one place for easy reference. Then the code itself will have less clutter.
There are several places in C where it is common to declare stuff in one place:
* In parameter lists (at least we always have that, except when
parameter 'x' is used, and you see 'x' in the body, your practice means
I have to scan backwards from that point to see if it is parameter 'x',
or some other 'x' in a nested scope that shadows it).
* #includes
* Imported variables
* Imported functions
* Forward function declarations
Imagine how annoying it would be if any of those last were used inside a block within a function. Well, that's how annoying local declarations
mixed with code are.
On 18/05/2026 19:35, Bart wrote:
I hate dealing with code that just declares variables higgledy-
piggledy all over the place; it is so lazy. I'm not into block scopes
either.
Um, okay.-a You seem to define a lot of your programming life around
hating things a large proportion of programmers consider good practice.
But you are free to have your preferences.
People who mix declarations and statements in their C programming do so knowing full well that they could put their local variable declarations
all at the top of the function - but they feel that mixing them gives
the best quality code, with the least risk of mistakes and the clearest, most understandable and most maintainable results.
Or perhaps they only do so specifically to annoy you.
I appreciate that /you/ find declarations after statements to be
annoying - yet you sing the praises of your own language because it
allows declarations to occur anywhere mixed with statements, including
after their usage. I suppose it is annoying when someone else does it,
yet innovative and god's gift to the programming world when /you/ do it.
You know, all it takes is to admit that out-of-order definitions can
be a desirable and convenient language feature. It's one that other
languages have, it's not something that only exists in my language
(though I take it a bit further).
I hate dealing with code that just declares variables
higgledy-piggledy all over the place; it is so lazy. I'm not into
block scopes either.
I /like/ to have them all in one place for easy reference. Then the
code itself will have less clutter.
I think you would have liked my language! That does have char
constants up to 'ABCDEFGH' (When I supported 128-bit types, up to 'ABCDEFGHIJKLMNOP'.)
C will support them up to 'int' width, which means 'ABCD' for 32-bit
int. In theory a C with a 64-bit int would allow longer constants, but
that's not going to happen on any common platforms.
As it is, even anything above 'A' is implementation-defined, unless
C23 has changed that.
[...]also annoying is thet if {} has its own scope
annoying are also things that are not in c like "int x, y =
foo(2,3);" but those dont belong to that list
Huh? This is legal C.
| Sysop: | Amessyroom |
|---|---|
| Location: | Fayetteville, NC |
| Users: | 65 |
| Nodes: | 6 (0 / 6) |
| Uptime: | 02:08:53 |
| Calls: | 862 |
| Files: | 1,311 |
| D/L today: |
10 files (20,373K bytes) |
| Messages: | 264,321 |