473,785 Members | 2,440 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C Syntax

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...
Nov 14 '05
177 7088
In <40bafec8.17233 5531@news-server> oz****@bigpond. com (ozbear) writes:
On 29 May 2004 19:35:09 -0700, re********@yaho o.com (red floyd) wrote:
Da*****@cern. ch (Dan Pop) wrote in message news:<c9******* ***@sunnews.cer n.ch>...
In <bu************ *************** *****@4ax.com> Alan Balmer <al******@att.n et> writes:

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


Not true. You're living in the present. In the past, when punch card
input was the norm, indentation had a meaning. In particular, FORTRAN
IV required input to begin in column 7 (or was it 8?), with a '*' in
column 6(7) as continuation...

DISCLAIMER: It's been nigh onto 25 years since I've done FORTRAN IV.
My info on the specific columns may be incorrect.


Column 6 was for the continuation. Your code had to fit in columns
7 through 72. 73 through 80 was for a card sequence number, and
ignored by the compiler, IIRC.

Cobol also (originally) used column-positional syntax, Area A,
Area B, and so on.

Columns 1 through 6 (or 7) was for sequence numbers, followed by
Area A for paragraph names, and Area B for code, but its been a long
time.

At any rate, Dan is incorrect.


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.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #111
In article <79************ *************@p osting.google.c om>,
Paul Hsieh <qe*@pobox.co m> wrote:
"Justin Rogers" <Ju****@games4d otnet.com> wrote:
Note that they point out you can leave out parens only when it won't lead to
ambiguity. C doesn't make that mistake. They make sure there is no
ambiguity, and if you leave out a parens it doesn't make the statement
ambiguous, it makes it a different or erroneous statement altogether.
C has plenty of ambiguity:


I see no ambiguity here. Things that may not match what you want, yes.
If you hate C so much, why do you still use it?
- 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.)
There is always precisely one statement controlled by if, for, while, or
do..while (and even switch, though it's rather useless there). That one
statement may be a simple expression statement or a compound statement;
compound statements (by definition) begin with a '{' and end with a '}'.

struct and union declarations don't involve any statements, so your
claim is meaningless when applied to that.

- If a statement has multiple side effects, the order in which those side
effects take place can be unknown.
If a statement has multiple side effects whose order is relevant,
it shouldn't've been written as a single statement in the first place.
If the only purpose of defining something is so that you can look at the
language definition to find out what bad code is really doing, it's not
worth defining.

- The right shift operator may or may not sign extend signed integers. Its
implementation defined.
Is there any reason why it should be defined in some particular way?
If you want sign extension of signed integers, use the division operator;
any self-respecting compiler will use a shift instruction for that where
it's appropriate. If you want to move the bits around without worrying
about sign bits, use unsigned integers and avoid the sign bit entirely.

- The size of an integer is platforms specific.
So? Do you care if the machine gives you 16 more bits than you need?

- The number of bits in a bytes is platform specific.
So? Do you care if the system gives you 2 more bits than you need?

- Try this one on for size:

char a = -1, b = -2;
unsigned short x = (1 > 0) ? a : b;

printf ("x = %d\n", x);

What do you think is printed out? Explain it.


A number that, if you think about it hard enough, will give you some clue
about whether char is signed and possibly about how signed integers are
represented internally.
You're lying to printf; what did you expect, a compiler error saying
"That's not what you meant"?
dave

--
Dave Vandervies dj******@csclub .uwaterloo.ca

Conclusion: You are not only a masochist, but a stubborn masochist.
--Eric Sosman in comp.lang.c
Nov 14 '05 #112
Da*****@cern.ch (Dan Pop) wrote in message news:<c9******* ***@sunnews.cer n.ch>...

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


TTCN. It's mainstream if you work in telecoms, but, as your comment
implies, it's unpleasant in the extreme.
Nov 14 '05 #113
> Pascal and C are of the same age almost. Pascal maybe 2-3 years older than
C, not more
Well, technically, you're right. Pascal was officially unveiled at about
the same time as C appeared, but the whole history behind Pascal (and
Ada) is a lot older.

To me, Pascal remains the language of choice to teach a structured,
procedural language. C was originally made to be used by experienced
programmers, and (even if that will raise some eyebrows here and there)
I think this still applies nowadays.
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.


That's a matter of taste, I guess. Many of us seem to disagree, though.

As for the indentation-oriented syntax, I strongly advise against it.
To me, it's very unnatural. In the huge majority of languages (natural
or programming ones), spaces are meant to be separators and esthetic
elements. Even if indenting has become natural for most programmers
when writing different code blocks in most languages (C, Pascal, Ada...)
I still think it's a visual improvement for readability - and shouldn't
be anything else. I really can't figure out the whole rationale behind
the Python syntax. And even if you claim that "such problems as leaving
behind tabs or spaces, it's generally no problem", it's not quite what
I have in mind in terms of "syntactic robustness".
Nov 14 '05 #114
rl*@hoekstra-uitgeverij.nl (Richard Bos) writes:
Dr Chaos <mb************ ****@NOSPAMyaho o.com> wrote:
On Wed, 26 May 2004 22:02:42 +0100, C# Learner <cs****@learner .here> wrote:
> Why is C syntax so uneasy on the eye?
>
> In its day, was it _really_ designed by snobby programmers to scare away
> potential "n00bs"?


No, but the programmers who designed it didn't care about "n00bs";
their target audience was people who worked at Bell Labs. They were
all very very smart.


Erm...
> If so, and after 50+ years of programming research,
> why are programming languages still being designed with C's syntax?


Profound anti-intellectualism among practitioners, and cargo-cult
imitation.


...don't you think these two statements are contradictory?


No. The practitioners and imitators are (mostly?) not the people
who worked at Bell Labs and designed C.
--
int main(void){char p[]="ABCDEFGHIJKLM NOPQRSTUVWXYZab cdefghijklmnopq rstuvwxyz.\
\n",*q="kl BIcNBFr.NKEzjwC IxNJC";int i=sizeof p/2;char *strchr();int putchar(\
);while(*q){i+= strchr(p,*q++)-p;if(i>=(int)si zeof p)i-=sizeof p-1;putchar(p[i]\
);}return 0;}
Nov 14 '05 #115
On 29 May 2004 19:35:09 -0700, re********@yaho o.com (red floyd) wrote:
Da*****@cern.c h (Dan Pop) wrote in message news:<c9******* ***@sunnews.cer n.ch>...
In <bu************ *************** *****@4ax.com> Alan Balmer <al******@att.n et> writes:

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


Not true. You're living in the present. In the past, when punch card
input was the norm, indentation had a meaning. In particular, FORTRAN
IV required input to begin in column 7 (or was it 8?), with a '*' in
column 6(7) as continuation...

DISCLAIMER: It's been nigh onto 25 years since I've done FORTRAN IV.
My info on the specific columns may be incorrect.


Fortran IV had a fixed format for cards, but indentation was not
meaningful. The code area started in column 7, but you could use
whitespace any way you liked within that constraint. It did not assign
any semantics to indentation, as Python does.

BTW, your attributions are messed up - I didn't write anything you
quoted.

--
Al Balmer
Balmer Consulting
re************* ***********@att .net
Nov 14 '05 #116
Guillaume <gr*******@NO-SPAMmail.com> writes:

|> > The second is a typo. I work for a french bank, and the vast
|> > majority of french expats use spaces before and after emphatic
|> > punctuation. Only the anglicised french omit the space.

|> Well, in fact, both are wrong and right at the same time.

|> Typographically speaking, the kind of spacing that should be used
|> just before a punctuation mark such as a question mark or an
|> exclamation mark is NOT the same as the spacing used between two
|> words, for instance. It should be a "quart de cadratin", which is
|> much less wide.

Not much less. A "cadratin" is a quad in English -- originally, a
square piece of lead, whose width is the same as its height. The space
before "high" punctuation is an "espace fine", nominally a fourth of a
quad. The nominal width of a space between words is a third of a quad.
For twelve point type, we're talking about 3pt vs. 4pt. And the 4pt
interword space can be stretched OR SHRUNK somewhat to make the line
fit; on a tightly spaced line, it takes a good eye to see the difference
between an espace mot and an espace fine.

|> Unfortunately, plain ASCII text doesn't have much notion of
|> typographic spacing. It only knows of a basic space, which is as
|> wide as can be.

Agreed. It's even wider than a normal word space.

|> Thus, I consider putting extra spaces before punctuation marks a
|> typo when using plain ASCII text, and more esthetically pleasing to
|> the eye to omit them. French or not.

As someone used to reading French, I find it jarring if there isn't some
space. And the space I expect isn't that far from the normal word space
that it bothers me.

Of course, when I"m typing or reading English or German, I use different
rules.

|> I especially hate those who put a space before a period. Like this:
|> "This is fucked up ."

Quite. At least in the typographical conventions I'm familiar with:
French, German and English. Given the variety, I wouldn't really
surprise me if this were the norm for some language, however.

--
James Kanze
Conseils en informatique orientée objet/
Beratung in objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France +33 (0)1 30 23 00 34
Nov 14 '05 #117
Guillaume <gr*******@NO-SPAMmail.com> writes:
Pascal and C are of the same age almost. Pascal maybe 2-3 years older than
C, not more
Well, technically, you're right. Pascal was officially unveiled at about
the same time as C appeared, but the whole history behind Pascal (and
Ada) is a lot older.


C grew out of the same history as Pascal; they're both descendents of
Algol, though C is less of a direct descendent. C's declaration
syntax, at least in its simple forms, is more Algol-like than Pascal's
is:

Algol: integer i;
C: int i;
Pascal: i: integer;
As for the indentation-oriented syntax, I strongly advise against it.
To me, it's very unnatural. In the huge majority of languages (natural
or programming ones), spaces are meant to be separators and esthetic
elements. Even if indenting has become natural for most programmers
when writing different code blocks in most languages (C, Pascal, Ada...)
I still think it's a visual improvement for readability - and shouldn't
be anything else. I really can't figure out the whole rationale behind
the Python syntax. And even if you claim that "such problems as leaving
behind tabs or spaces, it's generally no problem", it's not quite what
I have in mind in terms of "syntactic robustness".


(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. C allows
incorrect, or even misleading, indentation:

if (cond1)
if (cond2)
some_statement;
else
some_other_stat ement;

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <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.
Nov 14 '05 #118
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.

Read "Succinctne ss is Power" and "Revenge of the Nerds" by Paul
Graham, if you want more.
Ivan.

"Richard Bos" <rl*@hoekstra-uitgeverij.nl> wrote in message
news:40******** ********@news.i ndividual.net.. .
"I. Appel" <ia****@rol.r u> wrote:

[ Please do not snip attribution lines of people whose text you leave in
your replies. I have no idea who wrote the following: ]
> 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.
Python programs are easier to read and understand, that's what I understand as "clear".


Pardon me: _you_ consider Python programs to be easier to read and
understand. Other people, amongst whom the twice-quoted contributer
above and myself, disagree.

Richard



Nov 14 '05 #119
"Guillaume" <gr*******@NO-SPAMmail.com> wrote in message
news:40******** *************@n ews.club-internet.fr...
Pascal and C are of the same age almost. Pascal maybe 2-3 years older than C, not more
Well, technically, you're right. Pascal was officially unveiled at about
the same time as C appeared, but the whole history behind Pascal (and
Ada) is a lot older.


The concepts behind them are almost the same. Maybe C is a bit more
influenced
by low-level programming and functional programming, but it's as structured
as Pascal.
To me, Pascal remains the language of choice to teach a structured,
procedural language. C was originally made to be used by experienced
programmers, and (even if that will raise some eyebrows here and there)
I think this still applies nowadays.
I can't disagree with you. When I studied programming at my university,
it was really hard for inexperienced people to code in C. I suppose, it
would be pretty simpler for them to learn Pascal first.

Some Python and Java zealots suppose their stuff to be the best learning
language instead of Pascal, but I'm not agree.
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.


That's a matter of taste, I guess. Many of us seem to disagree, though.


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.
As for the indentation-oriented syntax, I strongly advise against it.
To me, it's very unnatural. In the huge majority of languages (natural
or programming ones), spaces are meant to be separators and esthetic
elements. Even if indenting has become natural for most programmers
when writing different code blocks in most languages (C, Pascal, Ada...)
I still think it's a visual improvement for readability - and shouldn't
be anything else. I really can't figure out the whole rationale behind
the Python syntax. And even if you claim that "such problems as leaving
behind tabs or spaces, it's generally no problem", it's not quite what
I have in mind in terms of "syntactic robustness".


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?
Nov 14 '05 #120

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

699
34240
by: mike420 | last post by:
I think everyone who used Python will agree that its syntax is the best thing going for it. It is very readable and easy for everyone to learn. But, Python does not a have very good macro capabilities, unfortunately. I'd like to know if it may be possible to add a powerful macro system to Python, while keeping its amazing syntax, and if it could be possible to add Pythonistic syntax to Lisp or Scheme, while keeping all of the...
22
3433
by: Tuang | last post by:
I'm checking out Python as a candidate for replacing Perl as my "Swiss Army knife" tool. The longer I can remember the syntax for performing a task, the more likely I am to use it on the spot if the need arises. If I have to go off and look it up, as I increasingly have to do with Perl's ever hairier syntax, I'm more likely to just skip it, making me even less likely to remember the syntax the next time. So I hear that Python is easier...
14
2316
by: Sandy Norton | last post by:
If we are going to be stuck with @decorators for 2.4, then how about using blocks and indentation to elminate repetition and increase readability: Example 1 --------- class Klass: def __init__(self, name):
16
2609
by: George Sakkis | last post by:
I'm sure there must have been a past thread about this topic but I don't know how to find it: How about extending the "for <X> in" syntax so that X can include default arguments ? This would be very useful for list/generator comprehensions, for example being able to write something like: instead of the less elegant explicit loop version that has to check for the length of each sequence. What do you think ? George
23
2539
by: Carter Smith | last post by:
http://www.icarusindie.com/Literature/ebooks/ Rather than advocating wasting money on expensive books for beginners, here's my collection of ebooks that have been made freely available on-line by their authors. There are lots of them out there but this selection cuts out the junk. If you know of any other good books that are freely available please post a link to them here and I'll consider adding them to the site.
19
2975
by: Nicolas Fleury | last post by:
Hi everyone, I would to know what do you think of this PEP. Any comment welcomed (even about English mistakes). PEP: XXX Title: Specialization Syntax Version: $Revision: 1.10 $ Last-Modified: $Date: 2003/09/22 04:51:49 $ Author: Nicolas Fleury <nidoizo at gmail.com> Status: Draft Type: Standards Track
4
3785
by: Jeremy Yallop | last post by:
Looking over some code I came across a line like this if isalnum((unsigned char)c) { which was accepted by the compiler without complaint. Should the compiler have issued a diagnostic in this case? (I think it's not required to, but I'd like confirmation). Jeremy.
4
7625
by: Bob hotmail.com> | last post by:
Everyone I have been spending weeks looking on the web for a good tutorial on how to use regular expressions and other methods to satisfy my craving for learning how to do FAST c-style syntax highlighting in C# but I have yet to find anything useful I know there are people at MS that know this stuff like the front of their hand and I know there are many people out on the web that are proficient in doing this as well but it seems nobody...
3
16253
by: Manuel | last post by:
I'm trying to compile glut 3.7.6 (dowbloaded from official site)using devc++. So I've imported the glut32.dsp into devc++, included manually some headers, and start to compile. It return a very strange error. In your experience, where I should looking to find the real error? Surely the sintax of glut is correct... gcc.exe -c glut_bitmap.c -o glut_bitmap.o -I"C:/Dev-Cpp/include" -I"../../include" -D__GNUWIN32__ -W -DWIN32 -DNDEBUG...
0
9647
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10357
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10162
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10101
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7509
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5396
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5528
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4063
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3665
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.