C Syntax

A

Alan Balmer

Lew said:
I resemble that remark! :)

You resemble[1] that remark? Are you intangible?

Do you also resent[2] that remark?

[1] to be like or similar to
[2] to feel or express annoyance or ill will at

It's a joke. Obviously not a cross-cultural one.
 
A

Arthur J. O'Dwyer

As you study and understand the language, you'll find that it's all
nicely consistent, and that there are good reasons for most of the
features which seem odd to you. One of the characteristics of C is
terseness, and extra parens aren't required by the language for no
reason.

Not that I'm disagreeing, but *is* there any ambiguity avoided
by requiring parens around the condition in a 'do...while' loop?
E.g., what problem, if any (besides lack of symmetry), is introduced
by the "reform"

do stmt; while expr;
do { block } while expr;

replacing

do stmt; while (expr);
do { block } while (expr);

(Also, there's no ambiguity avoided by the requirement of a semicolon
following the label of a 'goto'. Just defusing potential "do you
know you're being utterly ridiculous" responses. ;)

-Arthur
 
G

Guillaume

Delphi is boring. IMO syntax of C is much more funny.

Delphi is Pascal with maybe a few bells and whistles.
Therefore, it's based on an older language than C, maybe that's why
it's a bit boring.

Well, rephrasing Paul Graham, I should say "Don't wait until C will become
as
clear as Python, use Python instead".

If you really think Python has clearer syntax than C, well, think twice.
One terrible fact is this indentation thing in Python to delimit code
blocks. One tab or space is left behind, and the whole thing is screwed.
To me, it's an unacceptable syntax issue.
 
D

Dan Pop

In said:
What you call a nicety <sic>, I call a liability.

None of the programming languages assigning semantics to indentation
has ever become mainstream. There must be a reason...

Dan
 
I

Irrwahn Grausewitz

Michael Voss said:
Irrwahn Grausewitz wrote:
[...snip...]
Smalltalk is a functional language.

How do you define "functional language" ?

I don't - others already did. If you're interested in this subject
I suggest to Go Ogle for the comp.lang.functional FAQ - it contains
a nice explanation of functional vs. procedural programming paradigms.

Ob the portion you snipped: While both C++ and Smalltalk are OO
languages, the former is a mere procedural, the latter a mere
functional language.

Regards
 
D

Dan Pop

Not that I'm disagreeing, but *is* there any ambiguity avoided
by requiring parens around the condition in a 'do...while' loop?
E.g., what problem, if any (besides lack of symmetry), is introduced
by the "reform"

do stmt; while expr;
do { block } while expr;

replacing

do stmt; while (expr);
do { block } while (expr);

To me, symmetry in the language syntax is an overriding concern. The
last thing I'd want to have to remember is when "while" requires a
parenthesised controlling expression.

Dan
 
A

Alan Balmer

Not that I'm disagreeing, but *is* there any ambiguity avoided
by requiring parens around the condition in a 'do...while' loop?
E.g., what problem, if any (besides lack of symmetry), is introduced
by the "reform"

do stmt; while expr;
do { block } while expr;

replacing

do stmt; while (expr);
do { block } while (expr);

(Also, there's no ambiguity avoided by the requirement of a semicolon
following the label of a 'goto'. Just defusing potential "do you
know you're being utterly ridiculous" responses. ;)
Symmetry and the avoidance of special cases. Prevents ambiguity in my
head, if nowhere else :)
 
C

C# Learner

Alan said:
[...]

Forgive me if I'm wrong, but my impression is that you don't have a
deep enough understanding of the C language, and indeed of programming
languages in general, to appreciate the reasons for the syntax
features you're commenting on.

I believe that I appreciate the reasons for these features. What I'm
saying is that I think that there are better (in terms of allowing the
user of the language to write readable code) alternatives that could
have been implemented instead.
Take your original example of
eliminating the deli meters around the conditional in an if statement.
Think about what this would mean for compound conditions. Combine that
with the Python-style blocking and then think about an if statement
which tests for several conditions, requiring more than one line to
write.

a) Valid C syntax:

if (foo &&
bar) {
foobar();
}

b) Similar code to the above but using my suggested syntax changes:

if foo &&
bar:
foobar();

Why wouldn't (b) be feasible here?

Everything from 'if' to ':' is considered the condition. After the
newline after ':', whitespace is required to form a code block.
As you study and understand the language, you'll find that it's all
nicely consistent, and that there are good reasons for most of the
features which seem odd to you.

The only way in which they seem odd to me is that they make code much
less readable than it could be, in my opinion.

Okay, if you don't agree with the 'if'..':' idea, then how about
changing the parentheses required for test conditions for a different
pair of characters? An ideal pair would be a pair that isn't used
elsewhere in the language, for readability's sake.
One of the characteristics of C is
terseness, and extra parens aren't required by the language for no
reason.

My point is that a different construct could be substituted in each case.
Also, think about the fact that language inventors and implementers
are, by and large, a pretty bright bunch. In general, they probably
have more and wider experience in the field than you do, and some of
them might even be as smart ;-)

So those who invented C's syntax are necessarily brighter than those who
invented, say, Python's syntax?
Those features which have passed
through to modern languages have done so for a reason.

I honestly wonder what that reason is.

Regards
 
C

C# Learner

Mark said:
(he prefers)



Okay, I'll bite. Why on earth do you consider this in any way an
improvement? What difference does it make to anything?

I believe that it'd improve code readability. Have you noticed how, in
langauges which use such syntax, people often write something like:

if ( FooBar(Parse(Process(GetInput())) )

i.e. they use spaces because of the fact that parentheses are used both
in test conditions and function calls. As far as I see, when doing so,
they're just attempting to work around a syntactical design flaw of the
language.
 
C

C# Learner

Grumble said:
#define if if (
#define then )

int main(int argc, char **argv)
{
if argc-1 == 0 then return 666;
return 0;
}

Point taken. :)

Still, though, if others don't do this, then, when reading others' code,
the problem (as I see it) is still there.
 
C

C# Learner

I. Appel wrote:

[...]
Delphi is boring. IMO syntax of C is much more funny.

<my opinion>
Delphi code is, in general, much more readable than C code. Therefore,
Delphi coders have an easier life than C coders.
</my opinion>

[...]
 
A

Alan Balmer

My point is that a different construct could be substituted in each case.

Making the syntax more complex, for no particular benefit that I can
see.

Parentheses, brackets and braces represent the general concept of
grouping. Even when seen in an unfamiliar context, one can get the
idea. I see no need to invent a different grouping symbology for each
use.

Everyone understands the symmetry between '(' and ')'. The symmetry
between 'if' and ':' is not nearly as intuitive. And now you propose
that each case that requires a grouping operator have a different
construct?

Of course, you say "could be substituted", which is obviously true. It
would certainly add a new dimension to the obfuscated C contests.
 
M

Mike Wahler

C# Learner said:
Point taken. :)

Still, though, if others don't do this, then, when reading others' code,
the problem (as I see it) is still there.

The 'problem' of not understanding a language's syntax,
is solved by learning it.

The 'problem' of disliking a language's syntax,
is solved by using a different language (whose syntax you
do like).

-Mike
 
E

E. Robert Tisdale

C# Learner said:
Why is C syntax so uneasy on the eye?

In its day, was it _really_ designed by snobby programmers to scare away
potential "n00bs"? If so, and after 50+ years of programming research,
why are programming languages still being designed with C's syntax?

These questions drive me insane. Every waking minute...

This is an obvious troll. Please Ignore it.
 
M

Mark McIntyre

I believe that it'd improve code readability.

I disagree. The delimiter helps mark the ends of the various parts of the
statement. With only whitespace to work with, compound statements become
almost impossible to correctly read.
Have you noticed how, in
langauges which use such syntax, .....
they use spaces because of the fact that parentheses are used both
in test conditions and function calls. As far as I see, when doing so,
they're just attempting to work around a syntactical design flaw of the
language.

Gonads. This is nothing more than a style thing. French people put two
spaces after a full stop. English people don't. Same idea.
 
K

Keith Thompson

Grumble said:
#define if if (
#define then )

int main(int argc, char **argv)
{
if argc-1 == 0 then return 666;
return 0;
}

Yes, that's very clever. Please don't do it in any code that I might
ever have to maintain, or read -- or that anyone else might ever have
to maintain or read.
 
K

Keith Thompson

C has plenty of ambiguity:

- Braces are optional if there is only one statement for if() or for() or
while(). (But not for do ... while(), switch, or structure/union
declarations.)

That's not an ambiguity, it just means there's more than one way to
write a given program. The fact that braces are optional in many
contexts does not imply that there is any C program that can be
interpreted in any of two or more ways; the interpretation is
unambiguous in each case.
 
K

Keith Thompson

C# Learner said:
Kieran Simkin wrote: [...]
Obviously this entire post is off-topic. Python is not C, C will never be
Python and you've cross-posted to C# which is not C either.

Hmm... I have to disagree. I feel that this discussion is about C's
basic syntax and its ubiquity in popular modern-day languages.

If such a discussion is off-topic for comp.lang.c, then I honestly
don't know quite where it would be /on/-topic. In fact, I even
considered renaming the subject of this post to 'Re: C Syntax', but
didn't want to enrage people by doing so.

Discussion of how other languages have influenced C would be topical
in comp.lang.c. Discussion of how C has influenced a hypothetical
language Foo would be topical (I presume) in comp.lang.foo. But if
you want to discuss how C has influenced other languages in general,
that's probably a good topic for comp.lang.misc.
 
O

Old Wolf

None of the programming languages assigning semantics to indentation
has ever become mainstream. There must be a reason...

The language of makefiles?
(Before you say "it isn't a language", it seems to be as much
a language as Prolog is)
 

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

Forum statistics

Threads
474,145
Messages
2,570,825
Members
47,371
Latest member
Brkaa

Latest Threads

Top