Stylistic note on loops

S

Stefan Ram

Thomas G. Marshall said:
I have argued against perl endlessly because of this. It seems to be
something that its designer was so very proud of, at least in the
beginning. $| is gross.

This is a somewhat »chauvinistic« or »egocentric« point of
view, by which Russian or Chinese should be »gross«, too,
because it does not use »readable« latin letters but
»unreadable« Cyrillic or Chinese symbols. However, it misses
that for someone who has grown up in a culture with Cyrillic
letters the inverse holds.

We cannot judge the readability of a language from the
outside, from the point of view of someone who does not know
the language well, but should judge it from the inside.

Moreover, the readability of »$|« is a very low-level
problem. Of course, low-level details, bits and pieces
matter a lot in programming, but we have:

- projects running over-budget,
- projects running over-time,
- software often does not meet requirements, and
- software is never delivered.

(After: http://en.wikipedia.org/wiki/Software_crisis )

I believe that the cause of these major problems are
predominantly errors in management, overall problem
definition, analysis, and large-scale design of the
development process and the code itself, not problems with
small-scale questions of wordings in source code.
 
S

Stefan Ram

Gene said:
I've also seen a riff on Griess's "skip" command:
while ( ... )
/* skip */ ;

Well, »the problem« might be related to languages which
use the end of the expression statement

<expression> ";"

as the empty statement

";".

We can imagine a language where the expression statement
is written as

<expression> ";",

while the empty statement is written as

"Ø";

then we would have:

while( *p++ = *q++ )Ø

.
 
M

Mike Schilling

Nick said:
/var/www/canal$ grep -B1 '^ *; *$' source/*.c
source/bigops.c- while(*tag && *tag==' ') // skip leading spaces
source/bigops.c: ;

That might run for a long time.
 
T

Thomas G. Marshall

This is a somewhat »chauvinistic« or »egocentric«
point of view, by which Russian or Chinese should be
»gross«, too, because it does not use »readable« > latin
letters but »unreadable« Cyrillic or Chinese symbols.
However, it misses that for someone who has grown up
in a culture with Cyrillic letters the inverse holds.

No, because most English speakers I know regard English as an inferior
language to other more structured, less idiomatic languages with fewer
irregulars.
We cannot judge the readability of a language from the
outside, from the point of view of someone who does not know
the language well, but should judge it from the inside.

Broken logic. You can likely become a proficient coder in anything
horrid given enough time---in fact there's a programming language
designed to be specifically difficult, it's name escapes me. You
might even become a very comfortable insider at using a screwdriver to
pound in a nail. That does not keep you from saying it's relatively a
terrible idea (an inside judgment), nor does it preclude a fair
outside judgment. It does not preclude someone from having tried it
as judging it as a bad idea. If such a thing as coding clearly
exists, then it's antithesis must also, and of all the degrees in
between. And some languages support this better than others---
regardless of how used to it you can be.
 
L

Lew

Stefan said:
We can imagine a language where the expression statement
is written as

<expression> ";",

while the empty statement is written as

"Ø";

then we would have:

while( *p++ = *q++ )Ø

To save trouble figuring out how to type "Ø" on, say, U.S. keyboards, let's
define a digraph "{}" to represent that construct:

while( *p++ = *q++ ){}
 
C

ClassCastException

Broken logic. You can likely become a proficient coder in anything
horrid given enough time---in fact there's a programming language
designed to be specifically difficult, it's name escapes me.

Perl?

:)

Intercal most likely.
You might even become a very comfortable insider at using a screwdriver
to pound in a nail. That does not keep you from saying it's relatively
a terrible idea (an inside judgment), nor does it preclude a fair
outside judgment. It does not preclude someone from having tried it as
judging it as a bad idea. If such a thing as coding clearly exists,
then it's antithesis must also, and of all the degrees in between. And
some languages support this

Lisp, Java
better than others

C++, Ruby, Perl
--- regardless of how used to it you can be.

I don't know if anyone can ever get used to Perl. Or any large C++
codebase that has had substantial operator overloading abuse done to it.
 
N

Niklas Holsti

Lew said:
To save trouble figuring out how to type "Ø" on, say, U.S. keyboards,
let's define a digraph "{}" to represent that construct:

while( *p++ = *q++ ){}

This trends towards the Ada form:

while some_bool_expr loop null; end loop;

where "null;" is the empty (do-nothing) statement in Ada.
 
N

Nick

Peter Duniho said:
Nah. He just didn't post the line that came before:

if (*tag != '\0') return;

Of course, even so, one wonders why the condition bothers with "*tag
&&". Surely the more restrictive "*tag==' '" would be sufficient.

Why such silly code is relevant in a discussion about the _right_ way
to do things, I have no idea.

That's flipping weird isn't it.

I've just discovered it's from a chunk of part-written code that has
been #defined out. It still makes me wonder why I wrote it like that
(there's another bit later that would be another endless loop that
didn't get picked up by the grep as there is a comment on the ; line).

So baffling but at least not live. And thanks for the reminder that I
need to weed my codebase.
 
L

Lew

Niklas said:
This trends towards the Ada form:

while some_bool_expr loop null; end loop;

where "null;" is the empty (do-nothing) statement in Ada.

So in effect you are saying that the C family of languages is "trending
towards" Ada since they already have "{}" as a way of representing an empty
(do-nothing) statement.

No, that's backwards. C came before Ada. So actually, Ada is trending
towards C because it has "null" as a synonym for C's "{}".

You had it backwards, Niklas.
 
M

Martin Gregorie

...[snip]...
Python has been called 'executable pseudocode'. If written cleanly, it
is highly readable, even to those who don't know it.

Seems to me I heard this of COBOL once. ;)
Anybody wrote pseudo-code that verbose deserves to be sentenced to write
RPG III for at least 10 years and immediately given life if they have
become RPG fans during their sentence.
I have argued against perl endlessly because of this. It seems to be
something that its designer was so very proud of, at least in the
beginning. $| is gross.
It still looks like its origin: a lightly disguised mixture of shell
script, sed, awk with a few common UNIX utilities such as tr and sort
thrown in.

Where others use Perl, I tend to use gawk + shell script because this is
generally less toxic. However, I must admit that Perl regexes are rather
good - up there with Java in that respect.
 
J

Joshua Cranmer

in fact there's a programming language
designed to be specifically difficult, it's name escapes me.

Malbolge is what you are looking for, I believe. The prototypical Hello
World program took two years to write, but even then it gave everything
in pretty unnatural casing (since then, it appears that someone has
found a program that gives Hello World with the correct casing!).
 
T

Thomas G. Marshall

I've seen 2 or 3 instances in FSF's gnu libc of the formula

#define  FOO(xxx) \
    do { floogy(xxx); } while (0);

Interesting. Presumably the compiler yanks the thing cleanly, and
you're still left with that IF syntax-able (<---homemade word) thing.

In C I used to use a home-crocked DBG() macro to >poof< lines out of
existance when DEBUG wasn't defined. I suppose C would have allowed
an empty {} instead of empty space for the definition which would
allow it to remain IF syntax-able.
 
L

Lew

Martin said:
Where others use Perl, I tend to use gawk + shell script because this is
generally less toxic. However, I must admit that Perl regexes are rather
good - up there with Java in that respect.

Java uses Perl(esque) regexes, so no coincidence.
 
A

Arved Sandstrom

Keith said:
ClassCastException said:
I don't know if anyone can ever get used to Perl. [...]

I have, but I'm not going to argue about it here.

I don't intend to argue about it either - there's nothing to be combative
about - but back in the early '90's when I needed to do "scripting" type
things on UNIX I had shell, awk and Perl to choose from, Python at the time
wasn't all that appealing. For an entire set of tasks I therefore used Perl,
starting with 4.019. I got good with it, and never understood why anyone had
serious problems with it, including the so-called "line noise" "problem"
that was never a problem for me. I found that universal software engineering
principles (modularity, proper naming conventions, understanding scope) took
care of problems in Perl that people always seemed to be complaining about,
that are in fact problems in practically every other programming language.

Again, not looking to incite here, but I look at all this from the
standpoint of a consulting developer. I don't have all that much leeway in
what I get to use, so I have to use practically everything. The languages
and libraries and tools I encounter are what they are, and I lose time
complaining about them. I've used Python nearly as much as Perl, now, with a
smattering of Ruby. I really don't much care which one I do use. I don't
much care whether I use C#/F# in .NET or Scala/Java in a J2EE environment.
My own-time dabbling has been Haskell and J for a few years now, and I'll
never get to use either in the real world. :) The way I see it, in the
final analysis, is that complaining about crappy or missing features is a
waste of time; do a Clint Eastwood and "improvise, adapt and overcome".

AHS
 

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

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,609
Members
45,253
Latest member
BlytheFant

Latest Threads

Top