Newsgroups: comp.lang.python,comp.lang.tcl,comp.lang.scheme,comp.lang.misc,comp.lang.perl
Path: cantaloupe.srv.cs.cmu.edu!das-news2.harvard.edu!news2.near.net!bloom-beacon.mit.edu!gatech!howland.reston.ans.net!EU.net!sun4nl!cwi.nl!olaf
From: olaf@cwi.nl (Olaf Weber)
Subject: Re: Comparing syntaxes  (Re: What language would you use?)
In-Reply-To: behrends@buran.fb10.tu-berlin.de's message of 11 Nov 1994 15:25:57 GMT
Message-ID: <Cz4K2o.93F@cwi.nl>
Followup-To: comp.lang.misc
Sender: news@cwi.nl (The Daily Dross)
Nntp-Posting-Host: zeus.cwi.nl
Organization: CWI, Amsterdam
References: <39b7ha$j9v@zeno.nscf.org> <39mi58$aeu@brachio.zrz.tu-berlin.de>
	<id.33KE1.GY@nmti.com> <39pel5$qls@brachio.zrz.tu-berlin.de>
	<id.6ALE1.TW6@nmti.com> <3a02e5$a1d@brachio.zrz.TU-Berlin.DE>
Date: Fri, 11 Nov 1994 22:35:12 GMT
Lines: 91
Xref: glinda.oz.cs.cmu.edu comp.lang.python:2603 comp.lang.tcl:21733 comp.lang.scheme:11186 comp.lang.misc:19068 comp.lang.perl:38713

[ Followups restricted to comp.lang.misc ]

In article <3a02e5$a1d@brachio.zrz.TU-Berlin.DE>, behrends@buran.fb10.tu-berlin.de (Reimer Behrends) writes:
> Peter da Silva (peter@nmti.com) wrote:
> : In article <39pel5$qls@brachio.zrz.tu-berlin.de>,
> : Reimer Behrends <behrends@buran.fb10.tu-berlin.de> wrote:

> Then you have never written something like

>         if ((x = foo()) != BAR) ...

> Or have you?

I have.  However, the above hardly qualifies as "cramming" in my book,
and I don't find it particularly unreadable.  In fact code like

	while ((x = foo()) != BAR) ...

tends to be more readable than the alternatives in less expression-
oriented languages.

> But the piece of code I love most is straight from stdio.h:

> #define putc(x, p)      (--(p)->_cnt >= 0 ?\
>         (int)(*(p)->_ptr++ = (unsigned char)(x)) :\
>         (((p)->_flag & _IOLBF) && -(p)->_cnt < (p)->_bufsiz ?\
>                 ((*(p)->_ptr = (unsigned char)(x)) != '\n' ?\
>                         (int)(*(p)->_ptr++) :\
>                         _flsbuf(*(unsigned char *)(p)->_ptr, p)) :\
>                 _flsbuf((unsigned char)(x), p)))

On another system:

#define putc(x, p)	putc_locked((x), p)
#define putc_locked(x, p) \
		( __us_rsthread_stdio \
		? __semputc(x,p) \
		: ( --(p)->_cnt < 0 \
		  ? __flsbuf((x), (p)) \
		  : (int)(*(p)->_ptr++ = (x)) \
		  ) \
		)

Although I have to admit to cheating by reformatting the above.

> I should like to point out that this is a single logical line. What other
> languages even _allow_ such a mess?

Well, Pascal (and I suppose its relatives) allows you to put the
entire program on a single line.  In C, at least the preprocessor
statements need their own lines.  :-)

> C has assignment operators that return results, allowing them to be
> used inside expressions. For me that is encouraging such abuse as
> above. Same for stuff like pre/post-increment/decrement, ?: or the
> comma operator.  The predominant purpose of these features is to
> allow more operations per line.

The predominant _use_ of these features is to put more operations on a
single line.  Their _purpose_ is to make some constructs more natural
to express.

> Like it or not, there is a greater tendency to write unreadable code
> in C than in other languages.

So it seems, although this is at least partly a function of its
popularity.  You need to be fairly involved in programming to have
heard of (say) Eiffel at all, and that level there are fewer truly bad
programmers.

> Then why are char *argv[] and char **argv both possible?

Because the ANSI C committee made a mistake on this point (IMHO).

> In addition, there are many cases where a variable occurs on both
> sides of an assignment. Some examples: [ ... ]  You just can't take
> care of them all.

You can, by introducing a generalisation of the system.  Just have a
special token for "same as left-hand side of assignment".  This is
part of a language of which I've forgotten the name.

> And for some reasons, non-C programmers don't find x := x+1
> unnatural at all.

Which doesn't mean they relish typing

	very_long_but_doubtlessly_meaningful_name
		:= very_long_but_doubtlessly_meaningful_name + 1

-- Olaf Weber
