Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > A[x][y][z]

Reply
Thread Tools

A[x][y][z]

 
 
Anonymous 7843
Guest
Posts: n/a
 
      10-03-2005
In article <3OR%e.20$(E-Mail Removed)>,
Mabden <mabden@sbc_global.net> wrote:
>
>
> "Frodo Baggins" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed) ups.com...
> > > Let's combine the goodies from each language !

> >
> > Reminds me of Perl ; best of sed,awk,sh,etc combined.

>
> C#


PL/I.
 
Reply With Quote
 
 
 
 
C Wegrzyn
Guest
Posts: n/a
 
      10-03-2005
Anonymous 7843 wrote:

>In article <3OR%e.20$(E-Mail Removed)>,
>Mabden <mabden@sbc_global.net> wrote:
>
>
>>"Frodo Baggins" <(E-Mail Removed)> wrote in message
>>news:(E-Mail Removed) roups.com...
>>
>>
>>>> Let's combine the goodies from each language !
>>>>
>>>>
>>>Reminds me of Perl ; best of sed,awk,sh,etc combined.
>>>
>>>

>>C#
>>
>>

>
>PL/I.
>
>

Bliss/10
 
Reply With Quote
 
 
 
 
sterten@aol.com
Guest
Posts: n/a
 
      10-05-2005

> >>>Reminds me of Perl ; best of sed,awk,sh,etc combined.
> >>>
> >>>
> >>C#
> >>
> >>

> >
> >PL/I.
> >
> >

> Bliss/10



why always create a new incompatible language when you
just have some small improvements ?

you need a new compiler and your old programs will
no longer run.

 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      10-05-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) writes:
>> >>>Reminds me of Perl ; best of sed,awk,sh,etc combined.
>> >>>
>> >>>
>> >>C#
>> >>
>> >>
>> >
>> >PL/I.
>> >
>> >

>> Bliss/10

>
>
> why always create a new incompatible language when you
> just have some small improvements ?
>
> you need a new compiler and your old programs will
> no longer run.


Because sometimes a new dialect with small improvements is too close
to the original language. It can be unclear which version of the
language you're using.

I might even argue that C++'s closeness to C is a disadvantage. C and
C++ are far enough apart to be two distinct languages, but they're
still close enough that a lot of programmers think there's such a
thing as "C/C++".

--
Keith Thompson (The_Other_Keith) (E-Mail Removed) <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
 
Reply With Quote
 
bqbert@gmail.com
Guest
Posts: n/a
 
      10-05-2005
C Wegrzyn wrote:
> >>>Reminds me of Perl ; best of sed,awk,sh,etc combined.
> >>>
> >>>
> >>C#
> >>
> >>

> >
> >PL/I.
> >
> >

> Bliss/10


bliss was (is) actually cool. No C#, PL/I, Java, etc please.

 
Reply With Quote
 
James Dow Allen
Guest
Posts: n/a
 
      10-06-2005

(E-Mail Removed) wrote:

> So, who will be the first to write that useful command line utility
> converting occurrances of A[x,y] to A[x][y]...


This would be a simple one-liner in the elegant Snobol language.Sadly,
the references to Snobol that show up
with Google are mostly 6-year old messages, complaining
that Snobol has disappeared!

But this is comp.lang.c not comp.lang.snobol.
Let me try to help OP.

<diatribe>
C is a victim of its own success!

I don't think Fortran programmers ever say
"Let's make our language more like Pascal."
Ones that might ... switch to Pascal!
Similarly, while most consider some languages,
e.g. Forth or APL, to have perverse syntax,
those who go out of their way to use Forth or
APL, almost by definition, like the "perversity"!

But C's rich elegant combination of simplicity
and flexibility and the fact that it was better
suited than prior languages to a wide variety of
applications recommended itself to many expert
programmers in the 1970's and 80's and it soon
become widespread ... even among many who
couldn't appreciate its elegance.

One of the most elegant features of C is the
identity between the referencing of pointers
and array elements. Yet this seems to be
consistently confused by novices! Why? It
can't be that C is "too complicated" -- C is
based on a tiny set of elegant principles.
I think the problem is that novices can't
believe such a powerful language is *so simple*!

One example of such simplicity is the fact, as
Keith Thompson points out, that arrays are always
one-dimensional: a 2-D array is an array of
arrays.

Viewed in total isolation, the question of whether
to start array indexes at 0 or 1 may be a legitimate
open question, but in C the question answers itself
once one notices that the following expressions
(outside sizeof, etc.) must be identical in C:
*p
*(p+0)
0[p+0]
p[0+0]
p[0]
Anyone who suggests that C indexes should start at 1,
doesn't even understand this much: the idea that their
opinion on C might have merit is laughable.

Similarly, since in the 4-D array expression
a[b][c][d][e]
one can't know, without studying the declarations,
whether 'a' is an array of pointers to arrays
of pointers, a pointer to an array of pointers
to arrays, or one of several other possibilities,
the idea of obfuscating this further by writing
a[b,c,d,e]
suggests lack of understanding. (We're sorry if
'[' and ']' are hard to produce on German keyboards
but I'm sure there's workarounds for that.)

(Do any other languages, besides C++ and others that
model their syntax on C, have a similar elegant
array/pointer model?)

Finally, it shows grave confusion to suggest that
someone who prefers to see C syntax when they're reading
a C program should simply run 'cc -E'. We all look
at intermediate compilation results when there's a
reason, but viewing unobfuscated source shouldn't be
one of them. To give only one of the most obvious
objections, on all compilers I've tried 'cc -E' will
remove comments; did OP overlook this?

No one claims the C language is a perfect panacea, but
it has an enviable elegance. Novices should devote
themselves to grasping that elegance before offering
"improvements."
</diatribe>

James Dow Allen

 
Reply With Quote
 
sterten@aol.com
Guest
Posts: n/a
 
      10-06-2005
James Dow Allen wrote:

....
>Anyone who suggests that C indexes should start at 1,
>doesn't even understand this much: the idea that their
>opinion on C might have merit is laughable.


I didn't suggest, that indices should start at 1,
starting at 0 is fine, but
I just suggested that e.g. int A[n]; should reserve n+1
memory-cells instead of n. Or that we have a preprocessor utility
to change int A[n] into int A[n+1] before the compiler
gets it from batch file or in a child process.
Very often you are using A[n] and want it to hold integers 1..n,
with or without 0.
I guess, this is a quite common error for C-programmers,
that they define int A[n]; and then access A[n] , e.g.
A[n]=x;
Now this may overwrite some other variable stored at [A+n]
causing strange behaviour in the program which is hard to debug.
I do consider this one of the worst problems with C.
If you think, arrays should be defined usually on A[0,..,n-1],
that's quite uncommon. Look at any math. or combinatorics
or numerics textbook or paper.
You are just _producing_ thousands of invain hours of
debugging by suggesting this A[n] - behaviour.
No matter how "beautiful" or "elegant" or
"logical" you might consider it. As I said, a programming
language has to be functional and easy to use and debug,
that's what it has been designed for, that's what it is
being used for, not elegance.

>Similarly, since in the 4-D array expression
> a[b][c][d][e]
>one can't know, without studying the declarations,
>whether 'a' is an array of pointers to arrays
>of pointers, a pointer to an array of pointers
>to arrays, or one of several other possibilities,
>the idea of obfuscating this further by writing
> a[b,c,d,e]


your opinion that
a[b,c,d,e] is more "obfuscated" than
a[b][c][d][e] seems very strange to me.
The first one is shorter and has fewer parentheses,
parentheses are always hard to follow, since you have
to keep track where they open and where they close.
It's even worse when you have nested expressions
like A[A[x][y]][z]=A[x][A[y][z]] which is nothing
more than simple associative law.
It's also completely uncommon in textbooks,papers.

>suggests lack of understanding. (We're sorry if
>'[' and ']' are hard to produce on German keyboards
>but I'm sure there's workarounds for that.)


yes. Give a link to the utility I'm looking for.

>(Do any other languages, besides C++ and others that
>model their syntax on C, have a similar elegant
>array/pointer model?)
>
>Finally, it shows grave confusion to suggest that
>someone who prefers to see C syntax when they're reading
>a C program should simply run 'cc -E'. We all look
>at intermediate compilation results when there's a
>reason, but viewing unobfuscated source shouldn't be
>one of them. To give only one of the most obvious
>objections, on all compilers I've tried 'cc -E' will
>remove comments; did OP overlook this?


I don't know about cc -E

>No one claims the C language is a perfect panacea, but
>it has an enviable elegance. Novices should devote
>themselves to grasping that elegance before offering
>"improvements."
></diatribe>


that seems to me a bit as if you enjoyed presenting problems to
novices just in order to be able to demonstrate your superior
concept of elegance.


-Guenter.

 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      10-06-2005
"James Dow Allen" <(E-Mail Removed)> writes:
> (E-Mail Removed) wrote:

[...]
> <diatribe>
> C is a victim of its own success!
>
> I don't think Fortran programmers ever say
> "Let's make our language more like Pascal."
> Ones that might ... switch to Pascal!


Well, that's not quite true. Google "Ratfor" for details. (It's
almost topical; Brian Kernighan invented it.)

[...]

> One of the most elegant features of C is the
> identity between the referencing of pointers
> and array elements. Yet this seems to be
> consistently confused by novices! Why? It
> can't be that C is "too complicated" -- C is
> based on a tiny set of elegant principles.
> I think the problem is that novices can't
> believe such a powerful language is *so simple*!


Hmm. Elegence is in the eye of the beholder, but I've never found C's
relationship between arrays and pointers particularly elegant. My
preference would be for arrays to be first-class objects, and for
array indexing to be defined as array indexing rather than being
derived from lower-level operations.

It confuses novices because it's confusing.

Of course it can't be "fixed" without breaking existing code (and
plenty of people like it the way it is).

[...]

> Viewed in total isolation, the question of whether
> to start array indexes at 0 or 1 may be a legitimate
> open question, but in C the question answers itself
> once one notices that the following expressions
> (outside sizeof, etc.) must be identical in C:
> *p
> *(p+0)
> 0[p+0]
> p[0+0]
> p[0]
> Anyone who suggests that C indexes should start at 1,
> doesn't even understand this much: the idea that their
> opinion on C might have merit is laughable.


They *must* be identical because existing code would break if they
weren't. That doesn't necessarily imply that a C-like language
couldn't be devised in which they aren't identical, and arrays behave
differently.

We agree that it's not a particularly good idea, at least in the form
the OP suggested, but we disagree about why.

[...]

> Finally, it shows grave confusion to suggest that
> someone who prefers to see C syntax when they're reading
> a C program should simply run 'cc -E'. We all look
> at intermediate compilation results when there's a
> reason, but viewing unobfuscated source shouldn't be
> one of them. To give only one of the most obvious
> objections, on all compilers I've tried 'cc -E' will
> remove comments; did OP overlook this?


I don't think that's what the OP was suggesting. He was proposing a
"preprocessor" (call it a translator or precompiler) that, for
example, changes arr[x][y] to arr[x,y]. The output of this translator
would be legible standard C.

> No one claims the C language is a perfect panacea, but
> it has an enviable elegance. Novices should devote
> themselves to grasping that elegance before offering
> "improvements."
> </diatribe>


Other that the "elegance" part, I agree.

--
Keith Thompson (The_Other_Keith) (E-Mail Removed) <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      10-06-2005
(E-Mail Removed) writes:
> James Dow Allen wrote:

[...]
> >suggests lack of understanding. (We're sorry if
> >'[' and ']' are hard to produce on German keyboards
> >but I'm sure there's workarounds for that.)

>
> yes. Give a link to the utility I'm looking for.


As far as I know, it doesn't exist. Sorry.

--
Keith Thompson (The_Other_Keith) (E-Mail Removed) <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
 
Reply With Quote
 
Skarmander
Guest
Posts: n/a
 
      10-06-2005
Keith Thompson wrote:
> (E-Mail Removed) writes:
>
>>James Dow Allen wrote:

>
> [...]
>
>> >suggests lack of understanding. (We're sorry if
>> >'[' and ']' are hard to produce on German keyboards
>> >but I'm sure there's workarounds for that.)

>>
>>yes. Give a link to the utility I'm looking for.

>
>
> As far as I know, it doesn't exist. Sorry.
>

It's called a C compiler with digraph support. <: and :> will be
replaced internally with [ and ] on compilation. GCC is such a compiler.

A much better idea is to remap the keyboard or customize the editor to
produce some easy hotkey for [ and ] (easier than AltGr + some number),
since <: and :> aren't necessarily convenient either (and serves as a
nice illustration of why most people consider digraphs (and trigraphs)
next to useless).

That said, since the German QWERTZ keyboard is about as unfriendly as
possible for the standard C characters (just about anything is hidden
behind Alt or even Alt+Shift), I recommend just using a slightly
modified layout with [/{ instead of /, and ]/} instead of /. It
depends on your OS how easy or hard it is to define a custom layout.

You won't need German characters unless you're entering comments or
string literals, and that is easily taken care of with a hotkey for
switching layouts.

It will take a little getting used to, but it'll make for much easier
typing in the long run.

S.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments