I
Ian Collins
Why? That's ridiculous.
The point of having no {} is that you realise that all the *serious*
stuff is going on inside the while loop statement itself.
It's a great way to confuse readers!
Why? That's ridiculous.
The point of having no {} is that you realise that all the *serious*
stuff is going on inside the while loop statement itself.
Ian Collins said:It's a great way to confuse readers!
Indeed, most people will be confused by this, since most
people do not know the C programming language at all.
However, a C programmer will not be confused by this (by
definition).
James Dow Allen said:>
> I prefer
> while (*p++ = *q++) {
> }
>
Ian Collins ha scritto:
and what if sometime in the future you need to meat up a bit the body of
the loop?
Ian Collins said:Restoring the context:
The confusion stems not from the syntax, but from the empty braces, did
he intend there to be some code in there?
Ian Collins ha scritto:
if braces are already there, then you have to type less...![]()
If I didn't know C at all I'd say that '/' is a line continuationOne exercise of my programming class for C beginners is
to predict the output of this program:
#include <stdio.h>
int main()
{ printf( "1\n" ); /* writes "1" *
printf( "2\n" ); * writes "2" */ }
Yesterday I translated a Python routine into C. I've don't know PythonWe must write code that is as readable as possible. But
we may assume that the reader
- knows C and
- reads every single character of the source code,
otherwise writing readable code is impossible (because we
cannot know upfront which specific part of C a specific
reader will not know or which specific part of our source
code he will miss to read).
It was an alignment algorithm. Whilst I know basically how it works,Is that a long winded way of saying you wrote some C?
If you are claiming that converting Python manually into C is
straightforward then you're right : you haven't got a clue about Python.
It's a great way to confuse readers!
James said:But finally, and more importantly, there is something else about
these responses that astounds me. My earlier post was on a
completely different matter -- languages that consider unused
variables to be "fatal errors" and my then-thought amusing
post on the topic. No one responded to that, focussing instead
on the trivial stylistic variation I mentioned at the end of
my post almost parenthetically.
Fine. *AND YET NONE OF YOU DELETED* the other matter from the
quoted text: it's still visible in this response, traveling
through two quoters! You quibble about the placement of
white space in a C program, yet don't know enough to do trivial
edits of quoted material in Usenet responses!!
Increasingly, this newsgroup cracks me up.
but, there are many other cases where one will end up using loops like
this.
it is often still a little slower, as the compiler will often calculate the
offset in a secondary register and then use an indirect memory load to
access it.
j=*p++;
is still often a little faster than:
j=p;
although, for most cases the differences are small enough to be ignored.
char *strcpyindex(char *dest, char *src)
{
int i;
for(i=0;src;i++)
dest = src;
dest = 0;
return dest;
}
char *strcpyptr(char *dest, char *src)
{
char *answer = dest;
while(*dest++ = *src++);
return answer;
}
Yesterday I translated a Python routine into C. I've don't know Python -
I've glanced at some source but I've never read a Python primer nor used
a Python compiler/interpreter (I don't even know which). However I was
able to complete the task successfully. It's a combination of knowing
what the function was intended to achieve and the fact that most
programming languages encode similar operations with similar syntax.
One exercise of my programming class for C beginners is
to predict the output of this program:
#include <stdio.h>
int main()
{ printf( "1\n" ); /* writes "1" *
printf( "2\n" ); * writes "2" */ }
Python has been called 'executable pseudocode'. If written cleanly, it is
highly readable, even to those who don't know it.
Crafty!
But will it even compile, given the lack of a return statement in a
non-void-returning method?
Maybe it will, being C. It bloody well shouldn't though!
Eric Sosman said:I agree heartily with your final sentence.
Patricia Shanahan said:Do you consider this rule a way of making the code as readable as
possible, or a substitute for that approach?
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.