C Syntax

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
 
R

Richard Bos

Joona I Palaste said:
I've seen plenty of English-speakers (at least USAns) write two spaces
atfer a full stop.

USAnians != English, and I believe you know Inform? Guess what its -d
option is for?

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.
 
D

Dmitry Zamotkin

--"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."

he-he.
C is not functional too.
Try rand() function.
 
J

Justin Rogers

I'll actually bite on the below since I have some input. There was a Java
to IL compiler written before C# made it's first test runs, so I can't see
Java being the *look*. Managed C++, while syntactically appearing to
be a hack, was powerful enough to handle the C++ style syntax.

The reason for the way the switch statement in C# is works is the manner
in which the underlying IL construct works. In IL a switch is nothing more
than a simple jump table. They don't provide fall through because that
would require automatic generation of goto statements within the case
statement body. In most cases fall-through in C led to unexpected results
as users failed to close the syntax when that is what they meant to do.

As for the strange look of a switch, it is a balance of verbosity and function.
You might say that each case statement could indeed be it's own block and
should use french braces the way the rest of the language does, but that
doesn't allow for any form of fall-through.

case 10 { block } case 20 { block }

Where do you fall through in the above block? How do you have the
equivalent limited fall through syntax that C# does allow?

case 10:
case 20:
break;

Note, you are also building from the concepts of a label, each case
statement is terminated by a colon, something you don't find anywhere
else in C#, yet it is there. Each case statement semantically becomes a
label of some sort, a jump table label if you will. No different from having
an OUTER: label within a loop so that you can break out of the internal
loop and continue processing the outer loop.

What I'd highly recommend is write a lexer/parser that targets C# and then
change the language the way you'd like to see it changed. See how hard/easy
it is to format the code in your new manner and see how scalable that is for
adding new features. Would, for instance, you changes to the language have
affected the almost transparent addition of generics? What about namespace
aliasing and anonymous delegates? The future of the language is just as
important
as it's past, and C# is quickly becoming a very unique and promising language in
many ways.
 
I

Irrwahn Grausewitz

Michael Voss said:
<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 ?

The first hit googling for "functional language faq"
(without the quotes) is:

http://www.cs.nott.ac.uk/~gmh//faq.html

See section 2.1
</COMPLETELY OFF TOPIC EXCEPT FOR C.L.F>
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.

Done.

Regards
 
C

C# Learner

Justin Rogers wrote:

Would, for instance, you changes to the language have
affected the almost transparent addition of generics? What about namespace
aliasing and anonymous delegates?

Well, I'm not really thinking /that/ much into it -- I'm just thinking
about very basic syntax.

In any case, I look forward to generics, which I feel will make for
slightly more readable code, and perhaps more efficient code.

Anonymous delegates look nice too -- I read an article awhile back about
the ability to use them in an elegant fashion to marshall calls from a
worker thread onto the UI thread.
> The future of the language is just as
important
as it's past, and C# is quickly becoming a very unique and promising language in
many ways.

Yeah, definitely. These are exciting times for programmers.
 
D

Dan Pop

In said:
I've seen plenty of English-speakers (at least USAns) write two spaces
atfer a full stop.

It has nothing to do with the language. It's a common (albeit not
universal) typographic convention to leave more space after the
punctuation sign terminating a sentence then after punctuation signs
inside a sentence. Examine a few printed books carefully and you may
notice it (it's not twice as much, so it's not immediately obvious).

The only way to follow this convention in a plain text document is by
using two spaces instead of one. This is what I'm consistently doing,
no matter in which of the three languages I'm familiar with I'm writing.
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?

Yet another bogus generalisation coming from Joona. Quoting from a post
from a French mailing list:

ton enfant ? quel age?

:)

Dan
 
D

Dan Pop

In said:
The language of makefiles?

Indentation per se is meaningless there. It's just that the language
syntax requires a TAB character as the first character on a line in
certain contexts.

Dan
 
I

I. Appel

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.

Pascal and C are of the same age almost. Pascal maybe 2-3 years older than
C, not more
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.

Python programs are easier to read and understand, that's what I understand
as "clear". And I had never such problems as leaving behind tabs or spaces,
it's generally no problem with good text editor.
 

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
474,145
Messages
2,570,826
Members
47,371
Latest member
Brkaa

Latest Threads

Top