On 31/01/2019 13:06, Bart wrote:
> On 31/01/2019 07:23, David Brown wrote:
>> On 31/01/2019 00:37, Bart wrote:
>
>>> Which you get with out of order declarations. I solved this long ago
>>> in my own languages, and wouldn't be able to do without the feature now.
>>>
>>
>> C, C++ and many other languages support declarations (or "prototypes",
>> or "forward declarations" - the terminology varies by language) before
>> definitions. That solves any circular dependency issues within a
>> module quite happily.
>
> That doesn't solve it at all. Actually it is /part/ of the problem we're
> trying to solve! And sometimes you can't neatly get around it:
>
> enum {a,b,c=y,d};
> enum {w=b,x,t,z};
It solves it for functions and types. It has never occurred to me that
anyone would have need of re-ordering enums like that. I think it could
be hard to get any solution here that does not involve multiple rounds
or general equation solving, which is hardly appropriate for a language
like C or C++. (You can do it in metafont or metapost, but those are
very different kinds of language.)
>
> You can't reorder these. And you can't split them up if a,b,c,d and
> w,x,y,z belong together, and you still want to rely on auto-increment.
> But it's easy to see that a,b,c,d should be 0,1,3,4 and w,x,y,z is
> 1,2,3,4 (see sig).
>
> Any 'solutions' will spoil the code.
>
>> Co-recursive functions are a rarity in code.
>
> Co-recursion has some technical meaning which I'm not sure is the one
> that is relevant here. If you mean that A() calls B() which calls A(),
> then I write such code all the time.
Mutual recursion is the term I wanted. There can be cases where this is
useful, in handling recursive data structures, but I think if you are
writing it a lot you have questionable coding structures. (Not
necessarily wrong, merely questionable.) However, the point is that is
only with such mutual recursion that you need to have forward
declarations for your functions - and it is not a hardship to use this
on occasion. It would be annoying to have to use forward declarations
for a large proportion of functions, but not for just a few.
>
>>
>> Some people like to organise their files "backwards" - they like to
>> define a function first, then further down in the file they define the
>> functions that it calls. That is fine, but will mean you need more
>> separate prototype declarations in C. For people who like that code
>> arrangement, C's methods are a little inconvenient. (As Paavo points
>> out, C++ no longer needs that if you feel it is an issue.)
>
> With an extra construct? Having this natively possible anywhere in a
> language, without having to worry about such things at all, is more
> desirable:
>
> E readexpr(void) { ... return readterm();}
> E readterm(void) { ... return readexpr();}
>
I quite agree that it would be convenient to be able to do this without
forward declarations, and I can well understand allowing it in a new
language. I just don't think it is a big issue - like many people, I
have programmed in C (and other languages that need forward
declarations) for many years without feeling this to be a concern.
>
>> Mutually dependent imports (circular imports) are an issue, but these
>> can almost always be avoided in your code structuring.
>
> I've had experience of this and often found it difficult to impossible.
Maybe you have a fundamentally different way of organising code than I
do. (I know we have quite different types of code). It simply doesn't
occur in my coding - either embedded C, C++ and assembly programming, or
PC programming in Python, Pascal, etc.