C Syntax

O

ozbear

Why? None of these examples count as indentation being semantically
significant. You're merely confusing the fixed format of certain
languages and indentation.

FYI: I've used both fixed format Fortran and fixed format assemblers,
but fixed format has nothing to do with *indentation* being semantically
significant.

Nope. "Fixed format" is just a ruse to cover up what is actually
fixed indentation. If those rules were violated you didn't even
get to what was semantically equivalent because you never got past
compilation.

If you put your Fortran continuation character in the wrong column
you could easily end up with errors.

The point is that those columns had meaning to the compiler hence one
had to indent, hence indentation had meaning.

Oz
 
D

Dik T. Winter

> C grew out of the same history as Pascal; they're both descendents of
> Algol, though C is less of a direct descendent.

Lessee. C if offspring from Jovial and the kind, which is offspring from
Algol 58. Pascal became because in the depelopment of Algol 68 Wirth did
not agree with the direction the committee was going.
 
A

Alan Balmer

Well, I had to place more IMO's, but check this:

foo = lambda x, y: [str (i+j) for (i,j) in zip(x,y)]

Well, it's not very clear, but how many lines of code in C
would be required to reproduce it? Types of x and y can be
either lists of lists, lists of strings, lists of numbers
or strings. And it maybe used for all that stuff.

I don't understand, how several dozens lines of code can be
better than ONE line of code in non-esoteric language.

As you said, it's not very clear ;-) Actually, you'll have to define
"better" before you're qualified to offer an opinion.
 
A

Alan Balmer

I've seen code in C and Java written by several Python-haters. Most of them
don't use indents at all, so their code is pretty hard to read. See below.

You need to expand your circle of acquaintances :) Most C and Java
programmers (in fact, all) that I know use indents, whether or not
they hate Python.
Well, main idea behind Python's syntax is "we use indentation anyway (most
of
us at least), so what's the reason to make syntax redundant and to use
_both_
indents and delimiters?"

Are you agree?
Nope.
 
D

Dan Pop

In said:
Nope. "Fixed format" is just a ruse to cover up what is actually
fixed indentation. If those rules were violated you didn't even
get to what was semantically equivalent because you never got past
compilation.

If you put your Fortran continuation character in the wrong column
you could easily end up with errors.

The point is that those columns had meaning to the compiler hence one
had to indent, hence indentation had meaning.

You're confusing fixed format and indentation. No amount of indentation
past column 7 has any semantic meaning in any Fortran version I'm familiar
with. Fixed format Fortran *completely* ignores any space character that
is not part of a "string literal". Because of this, it is sheer idiocy to
claim that indentation plays any *semantic* role in fixed format Fortran.

Dan
 
I

I. Appel

Alan Balmer said:

Well, it's a matter of taste and habits (some of had to tell that :))), so
let's stop discussion here. I like syntaxes of both C and Python, while I
consider,
that both have their disadvantages.

Ivan.
 
I

I. Appel

Alan Balmer said:
Well, I had to place more IMO's, but check this:

foo = lambda x, y: [str (i+j) for (i,j) in zip(x,y)]

Well, it's not very clear, but how many lines of code in C
would be required to reproduce it? Types of x and y can be
either lists of lists, lists of strings, lists of numbers
or strings. And it maybe used for all that stuff.

I don't understand, how several dozens lines of code can be
better than ONE line of code in non-esoteric language.

As you said, it's not very clear ;-) Actually, you'll have to define
"better" before you're qualified to offer an opinion.

What is the reason to have syntax that is clearer-per-line, if it
requires to write several times more lines of code?

Ivan.
 
A

Arthur J. O'Dwyer

"Alan Balmer" <[email protected]> wrote...
[I. Appel, watch your attributions! ISTR *you* wrote:]
foo = lambda x, y: [str (i+j) for (i,j) in zip(x,y)]

Well, it's not very clear, but how many lines of code in C
would be required to reproduce it?

As you said, it's not very clear ;-) Actually, you'll have to define
"better" before you're qualified to offer an opinion.

What is the reason to have syntax that is clearer-per-line, if it
requires to write several times more lines of code?

Let's suppose C is five times clearer per line than your brand
of (is that obfuscated Haskell?), and it takes five times as many
lines of C code to write the same thing as you can write in
(whatever language that is).
Five times clearer per line, multiplied by five times as many
lines, yields twenty-five times the clarity. Hence, C is better
than Haskell. Q.E.D.

[that was a joke, son]

And now can you take the language wars off to comp.lang.misc or
somewhere else that actually *needs* the traffic?

-Arthur,
nonce equitur
 
M

Malcolm

Old Wolf said:
Why do you say that? I thought the whole raison d'etre of VB
was so that people who grew up with BASIC would still be in the
familiar. Why else would anybody use such a horrible language?
Microsoft was built on BASIC interpreters, so I imagine they keep the
langauge going for sentimental reasons.
 
M

Mabden

Dr Chaos said:
Actually I think that's can be a worse idea---suggesting something
that 'almost works' the same, but in fact is subtly different is quite
dangerous.

Like, in the USA you might want to give your buddy who's had too much
to drink "a ride" home, but if you try offer that to your mates in
Sydney (as opposed to a "lift") you're likely to get socked. At least
in most straight bars.

Just don't "knock me up" in the morning!

When I began programming I used "Business BASIC" which compiled into an .exe
and (shockingly) didn't require line numbers unless you were going to "GOTO"
it. In those days a compile used to take 40 minutes or an hour or so. You
would "desk check" your code quite thoroughly, so after the compile it
actually worked. Programmers would time their builds - i.e. "You gonna
compile today?" "Yeah, I about an hour" "OK, meet you out back. See if Carl
is ready and we can play some craps..." "'K"

Then I learned Pascal and it was my language of choice for programming.
Remember Borland's "Turbo Pascal"? Compile times of 1 or 2 minutes, or less
for small stuff. It was amazing and I stopped losing so much money to Carl.
:)

Anyhow, the point is that when I learned C, it was quite a lot like Pascal.
In fact it was TOO alike. I loved Turbo Pascal but the syntax was just about
the same as C, but it was hard to keep both in my brain. I finally had to
pick C and I've never looked back.

I see new developments like C# as a similar "problem". You can be a C++
"generic OS" programmer, or you can buy into the Microsoft World (tm) and go
with C#, but I believe it will be hard to keep the two in one's mind at the
same time. This is where the programmer will have to make a conscious
decision. (Best Darth Vader voice) "Feel the Power of the Dark Side."
 
R

Richard Bos

Malcolm said:
Microsoft was built on BASIC interpreters, so I imagine they keep the
langauge going for sentimental reasons.

Micro$oft and sentiment... ya, right. They keep VB going because they
can sell large numbers of copies of VB to large numbers of
semi-professional suckers.

Richard
 
D

Dan Pop

Microsoft was built on BASIC interpreters, so I imagine they keep the
langauge going for sentimental reasons.

More likely, because BASIC is easier to learn than most other programming
languages. It's also well interfaced with other Microsoft products, like
Excel.

If someone is interested in becoming an amateur programmer on Windows,
I can't imagine anything more suitable for the purpose than VB.

Dan
 
D

Dan Pop

In said:
(As long as we have an '[OT]' tag on this thread ...)

I haven't played with Python enough to form a strong opinion about its
indentation-oriented syntax, but I think I like it. When I program in
a language that expressions nesting with delimiters (begin/end, {/},
case/esac), I maintain strictly consistent indentation anyway. I go
to the effort of indenting my code properly, and the compiler doesn't
even warn me if I get it wrong. Python lets me omit the delimiters;
the indentation is exactly what it would have been if Python required
delimiters as well.

C's use of delimiters to denote nesting allows some flexibility that
Python doesn't, but I see no virtue in that flexibility.

If the ASCII HT character (and its likes in other character sets,
represented as \t in C) hadn't been invented or had very solidly defined
semantics, I would have agreed with your analysis. Unfortunately, their
invention as loosely defined control characters opened Pandora's box...

The immediate reaction to this remark: "if you never use them, their
existence doesn't hurt you" is, unfortunately, too naive:

1. Even if you don't, someone else may. With different semantics than
your defaults. People dealing with other people's code are probably
well aware of the issue. But in C, the block delimiters provide all
the information needed for fixing the indentation broken by the HTs...

2. Even if you don't, some text processing utilities may do it behind your
back. A typical example is vi, which "optimises" the storage of the
saved text by replacing multiple spaces by HTs according to the ts
variable setting. Since I have found no portable way of disabling this
feature, I'm setting ts to 100 in my .exrc.

Dan
 
M

Mike

foo = lambda x, y: [str (i+j) for (i,j) in zip(x,y)]
What is the reason to have syntax that is clearer-per-line, if it
requires to write several times more lines of code?

The functional versional would be compact and neat, but almost certainly
slower to exectue; the imperative version would be bigger, uglier, but most
probably faster. No one can claim that one is better than another, as it
completely depends on what you are trying to achieve.

Mike
 
A

Arthur J. O'Dwyer

[re: hard tabs]
A typical example is vi, which "optimises" the storage of the
saved text by replacing multiple spaces by HTs according to the ts
variable setting. Since I have found no portable way of disabling
this feature, I'm setting ts to 100 in my .exrc.

I'm sure you've thought of this, but what happens if you set ts to 0?
I would expect either that it would disable the "feature" altogether,
or that you'd get an error from vi. If the former, then this would be
a better way than setting ts to an arbitrary large value like 100.

-Arthur
 
D

Dan Pop

[re: hard tabs]
A typical example is vi, which "optimises" the storage of the
saved text by replacing multiple spaces by HTs according to the ts
variable setting. Since I have found no portable way of disabling
this feature, I'm setting ts to 100 in my .exrc.

I'm sure you've thought of this, but what happens if you set ts to 0?
I would expect either that it would disable the "feature" altogether,
or that you'd get an error from vi.

The latter. vi's response to "set ts=0":

Argument must be positive: ts=0
If the former, then this would be
a better way than setting ts to an arbitrary large value like 100.

Not even then. Keep in mind that I have to use vi on texts/programs
written by other people, too (like, e.g. when replying to Usenet posts).
With a ts=0, I would *silently* lose indentation information present in
those texts. With ts=100 I see it as humongously indented text, in which
case I simply reset ts to 8 and get something close to what the author
intended.

Dan
 
C

cody

Well, I had to place more IMO's, but check this:
foo = lambda x, y: [str (i+j) for (i,j) in zip(x,y)]

Well, it's not very clear, but how many lines of code in C
would be required to reproduce it? Types of x and y can be
either lists of lists, lists of strings, lists of numbers
or strings. And it maybe used for all that stuff.

I don't understand, how several dozens lines of code can be
better than ONE line of code in non-esoteric language.


Now one question arises: What exactly does this piece of code do?
 
M

Malcolm

Dan Pop said:
More likely, because BASIC is easier to learn than most other
programming languages. It's also well interfaced with other
Microsoft products, like Excel.

If someone is interested in becoming an amateur programmer on
Windows,
I can't imagine anything more suitable for the purpose than VB.
I'm a BASIC implementer myself, so I wouldn't say anything against the
language. I'd say that the main strength of BASIC is that it is so easy to
write an interpreter - obviously that is now irrelevant to a company with
the resources of Microsoft. That's why it was included on all the 80s
vintage microcomputers, and why I learnt it as my first programming
language.
 
K

Keith Thompson

2. Even if you don't, some text processing utilities may do it behind your
back. A typical example is vi, which "optimises" the storage of the
saved text by replacing multiple spaces by HTs according to the ts
variable setting. Since I have found no portable way of disabling this
feature, I'm setting ts to 100 in my .exrc.

I'm not quite willing to do that, but I do have the following in my
$HOME/.exrc:

map ]^V^I :%!expand^M

where the carets denote the obvious cotro characters.

As I enter code, vi (I use nvi) insists on changing each 8 columns of
indentation to a tab, but before saving the file I can hit a
right-bracket followed by a tab and expand everything to spaces
(unless I'm writing a Makefile, of course).
 
S

Sam Dennis

Dan said:
A typical example is vi, which "optimises" the storage of the saved
text by replacing multiple spaces by HTs according to the ts variable
setting. Since I have found no portable way of disabling this
feature, I'm setting ts to 100 in my .exrc.

Is there a reason why you can't use, say, VIM, which doesn't have this
problem and has an 'expandtab' option and :retab for your convenience?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,114
Latest member
GlucoPremiumReview
Top