nroberts said:
Perhaps you came in late and are unfamiliar with the original
statements and just found yourself on the wrong side of a discussion.
You weren't the one to originally claim that C syntax creates these
biases but you ended up arguing with me so I assumed you were
supporting it.
I think I've understood the origins of this thread. To be sure, I've
just reviewed it and I've not come up with any surprises.
Because in computers, memory is one large array like structure.
That's the fundamental abstraction that our hardware attempts to
create.
I disagree with this, but that could lead to a whole new (and off topic)
discussion. Even if this is universally true, are you saying that it is
why C links logical structure to memory layout? If so I don't see the
connection. My own view is that C does this because it is a low-level
language designed to be "close to the machine".
Which is why quite a while back I argued that what people claiming
that C's syntax causes a bias like this are actually arguing for is
abstractions. The further away you get from the fundamental
abstraction that the hardware provides, a long array, the more
operations have to be conducted to project the "higher" abstraction
onto the "lower" one. This is why languages like "language X" cost
more in terms of performance. C is an attempt to provide just enough
abstraction to be useful across all computers, which means it is as
close to the underlying abstraction as necessary.
There may be a cost, but it is not inevitable. In general, higher-level
languages have higher costs, but what has been called "language X" was
suggested by me because it would, in some cases, *reduce* run-time costs
(and there is no compulsion to use it's non-C features where they don't
improve performance).
It's incidental this argument, but, quite correctly, already distances
itself from the "large array" abstraction. It does so because a large
array is *not* the view of memory that all hardware provides, and
the designers of C wanted to include such hardware as possible targets.
Actually, C doesn't insist on this at all, it's just the simplest
mapping.
I mean contiguous as far as C's view of memory is concerned -- that you
can choose to view any object as a char array whose elements have
consecutive addresses. I don't think it matters to either of our points
of view how these are mapped by the hardware. The programmer sees only
one view of objects -- as contiguous regions of storage. Any access
that violates this model can't be supported by C's model of objects.
This was my original point. You could add the syntax to, say, access a
column from an array of rows, but such a thing could not be an object
like any other -- you could never pass a pointer to it to a function
that operates on an ordinary C array, for example.
This is an incorrect view of higher level languages. Since computers
are what they are, every language inevitably links logical structure
to memory layout. It has to. It can provide an interface that does
not, but that interface comes at a cost and underneath you can be sure
that it projects that interface into the hardware's abstraction in a
very determined manner, just like C does.
Maybe we are using the same words in different ways. Let's use an
example: I want an array of cons cells for my Lisp interpreter. The
logical way to define this is
struct cell { int car, cdr } heap[1000];
If I have a function
int find(int array[], int needle);
that can search an array for a particular value, C does not permit me to
speak of the whole array of car values in the heap. First, it has no
syntax for this (maybe heap[].car?) but, more significantly its object
model would not permit it.
Given what you've written above, I suspect we agree here. Your use of
"link" is might be "there must be *some* correspondence" and mine is
"there is a restricted correspondence".
Because C doesn't provide higher abstractions. The abstractions you
are looking for CAN be created in C though and the lower level
abstractions that it provides are a nice way to describe the mapping.
In fact, most languages that we can think of originally start by being
written in a language like C, if they ever even go past that point and
become self-hosting.
On the other hand, what you seem to want, and I agree that it would be
quite difficult to provide in C (or ANY language) is an abstraction
that can, through the way you use it, interpret what the best layout
would be. This is some sort of super-optimizer and indeed would
require a lot of research to provide. The easiest method would
probably be to invent a new language and provide a compiler that did
this; you'd probably write it in C or C++. On the other hand, for
most of the problems you'd attempt to solve with this abstraction it
would probably be best to let the programmer decide what to turn on
and when. This would, at least, be a lot simpler to implement and
would solve most real-world issues. This is probably why I can't
think of a single language that implements anything like what you seem
to expect from C.
I don't expect it all. I posted to say why it is more than a case of
tweaking C's syntax.
Also, I think I posted that I doubt the pay-off of being able to choose
the layout would be worth the effort due to the rarity of cases where it
matters. If that is true, the effort of doing it automatically is
surely beyond the pale. Just because I make a point on one side of a
debate does not mean that I am dedicated to the cause!
I am in favour, however, of languages that provide highly expressive
constructs, and being able to refer to both columns and rows of a matrix
in equally flexible ways is a big advantage. Algol 68 did this. I am
less sure about doing the same for structs of arrays and arrays or
structs, but it seems to be a nice feature.
Something similar that perhaps actually does provide what you'd
expect, would be a state based template pattern that switches
implementation based on statistics of its use to date. This would be
both more powerful and less powerful than a new language with a really
smart optimizer...depending on your needs. This, and anything more
determinable, can be made in C without much difficulty.
I think we have different metrics for difficulty! For one thing, I
would factor in the cost of lost expressiveness -- having a flexible
layout (in C) would affect how the objects can be referenced, would it
not?