On Tue, 2 Jan 2001, Derek M Jones wrote:
> Arthur,
>
> > > It usually does lead to erroneous readings and it is often a pointless
> > > optimization.
> >
> >These statements are very true. However, programming languages do not only
> >come with grammar, they also come with idiom. That idiom is not only made up
>
> Yes, every language has its own look and feel.
> Idiom is certainly used as a justification, for how they structure code, by
> developers. The creators and early users of C do have something to
> answer for.
Yes and no. What they have done is adapted a language to actual use,
thereby trying to make the language as expressive as possible for the
tasks they were asking of it: operating systems implementation. The ANSI
standard for C is a nice codification of those principles, even in adding
prototypes. Besides, Algol68 is way worse, in certain respects... but the
assignment looks like :=, which is something of a redeeming factor. ;)
> Another reason that I did not mention was reduction in typing effort (yes,
> developers do use some kinds of structuring because it reduces the
> amount of typing they have to do).
True, but given more advanced editors and programming environments this has
the possibility of becoming less of an issue. Note that in this case the
input form and the visual form of programs diverge even farther from each
other than with simple editors. Still, given the ease-of-use of for example
the Visual Basic editor with it's dynamic completion facilities and such,
these reasons are, in my opinion, less important.
Besides, many programmers write code to write more code for them...
I know I've done so, writing a tool with a size of about 4 kloc, to
generate a sourcefile of about 15 kloc. That saved me a lot of typing... ;)
> >In the case of assignments in if statements there's a powerful idiom,
> >and that is if((file=fopen(file))==NULL) { handle_open_error(); }
> >This makes for the least visual distraction from the main flow of the
> >code, and is therefore very accepted practice.
>
> Visual distraction? Isn't assignment an important event that is worth being
> distracted for?
The assignment is important, yes. But at some level you abstract from the
assignment and parse the assignment as the opening of a file. And *that* is
even more important, for it allows you to more easily understand what is
actually going on at a higher level. The visual distraction that I meant was
handling the possible error that could result from opening the file. Compare
for instance:
file = fopen(fname);
if (file == NULL) {
handle_open_error();
}
with
if ( (file=fopen(fname)) == NULL ) { handle_open_error(); }
Reading code top-down the latter has the effect of taking error-handling
(which is usually secondary to the main intention of the code) out of the
main flow of the code, *visually*. When the idiom is known, it is easier to
parse chunks of program code, which improves productivity...
Ofcourse, the first thing I tend to do when writing simple programs in C is
build a safe_fopen that will handle the error for me, so that all that you
see is
file=safe_fopen(fname);
but that takes a bit more planning... ;)
> What is the balance between ease of reading and likelihood of making mistakes?
> Does anybody know of any published research in this area?
Good question. Does anybody?
Doei, Arthur.
--
/\ / | [EMAIL PROTECTED] | Work like you don't need the money
/__\ / | A friend is someone with whom | Love like you have never been hurt
/ \/__ | you can dare to be yourself | Dance like there's nobody watching
- Automatic footer for [EMAIL PROTECTED] ----------------------------------
To unsubscribe from this list, mail [EMAIL PROTECTED] unsubscribe discuss
To join the announcements list, mail [EMAIL PROTECTED] subscribe announce
To receive a help file, mail [EMAIL PROTECTED] help
This list is archived at http://www.mail-archive.com/discuss%40ppig.org/
If you have any problems or questions, please mail [EMAIL PROTECTED]