C Syntax

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.
 
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)
 
J

Joona I Palaste

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.
Gonads. This is nothing more than a style thing. French people put two
spaces after a full stop. English people don't. Same idea.

I've seen plenty of English-speakers (at least USAns) write two spaces
atfer a full stop. Now the French, they put a space before an
exclamation or question mark. Like this: "Regardez moi ! Je suis
français !". What's with that, then?
 
K

Keith Thompson

C# Learner said:
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.

I'm beginning to think your argument boils down to
I like Python.
I don't like C.

If you'd stated it that way, I'm sure everyone here would be in
complete agreement with you. We all agree that you like Python, and
we all agree that you don't like C.

Yes, I'm oversimplifying your argument and having a little fun at your
expense.

I think there's a valid point in here somewhere. Perhaps what you're
really looking for is a language with something like C's relatively
low-level semantics, but with Python's <OPINION>superior</OPINION>
syntax. I'm not aware that any such language exists. If it did, I
might prefer it to C myself. But of course it would be off-topic
here.

Another valid question is why C's <OPINION>ugly</OPINION> syntax has
had such an effect on later languages. As I mentioned elsethread,
that's probably a good topic for comp.lang.misc; you might check the
Google archives of that newsgroup.

Significant changes to C's syntax are not possible due to the need to
accomodate existing code. And such changes would be considered
undesirable by most C programmers, who either have gotten used to C's
quirks or actually like them. There are certainly some things I would
do differently if I were designing C from scratch today, but that's
probably very different from the set of changes someone else would
want to make.
 
K

Keith Thompson

C# Learner said:
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?

I don't believe that Python has the ?: operator. C does. I don't
know whether it would cause any genuine ambiguities for the proposed
"if ... :" syntax, but it could certainly cause confusion.

If I were going to propose such a change (I'm not), I might suggest
dropping the parentheses and making the braces around the controlled
statement mandatory. For example:

if foo &&
bar
{
foobar();
}

I think similar changes could consistently be made for other compound
statements.

Of course, it's never going to happen.
 
C

C# Learner

Keith said:
[...] There are certainly some things I would
do differently if I were designing C from scratch today, [...]

This is basically what I've had set in my mind while participating in
this thread.

I think I've finally found someone who's tuned into my wavelength,
perhaps; in any case, someone who truly understands my motive.

:)
 
J

Justin Rogers

C# Learner said:
Keith said:
[...] There are certainly some things I would
do differently if I were designing C from scratch today, [...]

This is basically what I've had set in my mind while participating in
this thread.

I think I've finally found someone who's tuned into my wavelength,
perhaps; in any case, someone who truly understands my motive.

:)

While Keith points out there are some things he would do differently, C#
is in essence the attempt at an entirely new language, and yet they kept all
of the older syntax. Anders was a Pascal guy, and yet he chose the
constructs he did in his custom tailored language why? Well, because he
thought they provided the most power for the language without denying users
access to some commonly used programming tools.

The first tool is debugging and error assessment. The strict language
guidelines
of C# make it very easy to discover the root of a lexical or parsing error. At
the same time they make it easy to point out and find common programming
mistakes.

Verbosity or the lack thereof as a tool:
Take language constructs like begin...end to designate blocks... They
are verbose, why not just type { and }, after all this is much shorter. Why do
I need to separate my code by all that whitespace:

if something:
foobar

When I could easily write it on one line without all of that crappy whitespace

if ( something ) { foobar; }

What about intellisense and other features users have grown to love? Are they
easier,
faster, more efficient when written against a C type language? Does the explict
bounding of statement/expression/block scopes help the underlying intellisense
processor
to more accurately understand what the user is doing? Does it remove levels of
ambiguity
that would otherwise exist? When does whitespace become important, when is it
not,
does tabs to spaces or spaces to tabs affect the compilation of your
application? What
happens to whitespace nested blocks when I use two spaces per indent, but
convert to
tabs that are 4 to 8 spaces per indent? Does my code resize properly or do all
of my 2/4/6
spaces get turned into a single tab. Does a tab count as a single indention
character or
multiple? For instance, does a single space or a single tab have the same
nesting depth?

There are so many more aspects to programming today than loading up your
favorite
text editor and hacking away in the most efficient form that you can manage.
Code generators,
intellisense, auto-complete, are all tools taking up precious processor time
trying to figure
out what you want to do, and I think the trade-off between some extra semantics
versus
confusing the hell out of the computer that is making my life a bit easier, is
something I'm quite
happy with.
 
M

Michael Voss

From a thread started in comp.lang.c

Irrwahn said:
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.

<COMPLETELY OFF TOPIC EXCEPT FOR C.L.F>
My Google search revealed nothing except that other people are searching the
c.l.f FAQ, too. Any hint where I could find them ?
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.

If a functional language is defined as:

--"The idea of functional languages is that functions are
--completely determined by their parameters. If you put
--the same parameters to a function, then you must get the
--same return values. So a function which does not take any
--parameters should always return the same result."
(Christian Szegedy ([email protected]) in comp.lang.functional
at 2004-03-19 07:19:21 PST),

In my eyes and regarding the above definition, Smalltalk is not a functional
language.

Since I crossposted this to comp.lang.smalltalk and comp.lang.functional:
What do you think ? Is Smalltalk an object-oriented "mere functional"
language ?


Since this is completely off-topic for c.l.c and m.p.d.l.c, and my
newsreader does not support a proper followup-to (blush): Please followup to
comp.lang.smalltalk and comp.lang.functional. Please remove the C /
C#-groups.

Thanks,
Michael
 
R

Richard Bos

C# Learner said:
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?

Because it is _not C_. If you want to design your own language, fair
enough. Hundreds if not thousands of people have done so before. Hey,
why don't you try to get M$ to change their Stolen-Java-with-an-
inappropriate-name syntax to include your pet love? At least then you
wouldn't have to convince so many people to change code that's been
working correctly for years or even decades.
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.

_Your_ opinion does not count for much (any more than mine) against an
existing language with probably tens (if we count all hobbyists,
hundreds) of thousands of users all over the world.
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?
No.

An ideal pair would be a pair that isn't used
elsewhere in the language, for readability's sake.

Name one.
So those who invented C's syntax are necessarily brighter than those who
invented, say, Python's syntax?

Not necessarily, though I must say I find Python's forced indentation a
veritable pain in the butt, and it is one of the main reasons why I
don't use the language.
I honestly wonder what that reason is.

People found them useful. Better programmers than you found them useful.

Richard
 
R

Richard Bos

C# Learner said:
Keith said:
[...] There are certainly some things I would
do differently if I were designing C from scratch today, [...]

This is basically what I've had set in my mind while participating in
this thread.

Then I suggest you bloody well _do_ so, instead of bothering the users
of two existing languages, only related to eachother in name, about it.
If your language really does turn out to be superior to the existing
candidates, I'm sure you'll have no problems getting people to program
in it.

Richard
 
C

C# Learner

Justin said:
While Keith points out there are some things he would do differently, C#
is in essence the attempt at an entirely new language, and yet they kept all
of the older syntax. Anders was a Pascal guy, and yet he chose the
constructs he did in his custom tailored language why?

Good question! :)
Well, because he
thought they provided the most power for the language without denying users
access to some commonly used programming tools.

I also wonder to what extent he was required to keep the language
looking like C++/Java, and therefore attractive to current C++/Java
programmers. This is pure speculation on my part, of course; but I see
signs of it in the language, with an example being the 'switch'
construct. The syntax of 'switch' constructs is very different to that
of other syntactical elements of C#, and it seems to stick out like a
sore thumb. It appears that it was copied straight from C (although
with a difference in that C#'s version doesn't allow implicit fall-through).

<snip>
 
T

The Real Andy

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

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

%<

I am a former embedded programmer. I started programming with
assembler. C was a godsend. If you think the C syntax is uneasy on the
eye, then try learning 10 different assembler languages and using them
on a day to day basis. Try then to go back a year to maintain the
flavour of assembler from that period.
 

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

Top