indentation

  • Thread starter Bill Cunningham
  • Start date
J

Jean-Marc Bourguet

Ben Bacarisse said:
Most systems can be made to pass a zero, but Unices (I prefer *nix)
don't do so as a matter of course.

Ever used ldd? At least on linux it runs the executable with argc==0
which is catched by the dynamic linker. So if your program is dynamicly
linked, you'll never get that case but running by mistaken ldd on a
statically linked executable can lead to that.

Yours,
 
C

cr88192

Eligiusz Narutowicz said:
Anyone using notepad to write C should be fired. There are lots of
productivity tools which make programming more sure fire and certainly
easier - not to use at least some of them is silly.

I have, personally, never really had that much motivation...

notepad is simple, effective, and edits text files.

I can jump to line numbers, I can search for things, ...

about the only thing it really lacks IMO is a better search-and-replace
feature (so that I don't end up resorting to things like sed, ...). but,
only very rarely is this an issue...


when it comes to C, really, I am not sure what would be added that would
really help all that much...

also note that, often, I have anywhere from 10 to 50 notepad's open at once,
and this was one thing that was a major problem in Vista: it setting a
critically low limit on the number of open windows I could have open before
stuff went weird...
 
C

cr88192

Eligiusz Narutowicz said:
I agree with people who write real apps accessed by many peoples. And
these are:

It is clear and it works.

http://www.linuxjournal.com/article/5780

I will agree with this for the most part, as a general rule the Linux
codebase is fairly readable.

however, I do disagree with it on a few points, namely in that I tend to use
rather different naming conventions (including, on occasion, variants of
hungarian notation, including in function names...).

I do agree that globals should be avoided whenever possible, and especially
not be used between subsystems. however, even there, this is not absolute
(there are some rare cases where I believe this is acceptable).


I tend to encode in the names at least some info about where in the codebase
the code is located, and also because of my modularity practices (this helps
both in avoiding accidental clashes or dependencies, and also in locating
where some particular code is at in the project).

of course, newer languages (such as C++, C#, Java, ...) provide other
mechanisms for this, but it is a tradeoff (shorter easier names, of which
one is no longer certain where exactly in the codebase this function is
located, albeit "jump to" features and similar are common in modern IDE's).

it works...
 
N

Nick Keighley

Nick Keighleywrote:

... snip ...
[mutter, one project had a standard of 4 column indent
and 8 space tabs. So you mixed tabs and spaces. eek!]

That is one more reason to use 3 space indentation.  Mixing spaces
with tabs is very likely to show up early, and get corrected.

you misunderstand. It wasn't an error to mix tabs and spaces
it was compulsary. If you didn't indent with mixed tabs and
spaces you couldn't check your source in!

(actually the checkin system ran your program through
indent and indent was set to this standard)
 
C

cr88192

rio said:
Joe Wright said:
Bill said:
I have had several complaints by some people who wish to help me and
I wish to get the problem straight. I wrote this small utility myself
and
added some indentation and I wonder if it is acceptable. It does make
source easier to read.

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char **argv) {
if (argc!=3) {
fprintf(stderr,"usage error\n");
return -1;
}
double x,y;
x=strtod(argv[1],NULL);
y=strtod(argv[2],NULL);
printf("%.2f\n",y/x);
return 0;
}

Is this a good example of a properly indended program?
Bill

i like below

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char **argv)
{double x, y;

if (argc!=3) { fprintf(stderr,"usage error\n"); return -1;}

x=strtod(argv[1], 0);
y=strtod(argv[2], 0);

return (x!=0.0) ?
(printf("%.2f\n", y/x), 0): (printf("Error: x==0\n"), -1) ;
}

ICK...

these are not exactly the way I would personally use the trinary and comma
operators...



of course, I do have something vaguely similar, but it is more of a
"compact" style:

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char **argv) {
double x, y;
if (argc!=3) { fprintf(stderr,"usage error\n"); return(-1); }
x=strtod(argv[1], 0); y=strtod(argv[2], 0);
if(x==0.0) { printf("Error: x==0\n"); return(-1); }
printf("%.2f\n", y/x), 0); return(0); }

usually, this is done for code that:
I usually wont really be reading or editing much;
my compulsion for reducing vertical space exceeded my need for clarity.

some elements of this style may sometimes be used in ordinary code though.
 
P

pereges

I have used pspad editor in the past but i think qed is much better
and less complicated.
 
D

David Thompson

If [parens] are superfluous, why use them at all? I can understand why you
might add them in places where the precedence isn't obvious, e.g. in
something like (a << b) + c - but surrounding an expression with
parentheses does nothing to clarify precedence within the expression
itself.
That's not an example of unobvious, but of wrong or at least
different. (a << b) | c is an example of clarifying/reinforcing.

- formerly david.thompson1 || achar(64) || worldnet.att.net
 

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

pow type problem 6
sh?tpile of errors 82
code question 74
Linux: using "clone3" and "waitid" 0
z error 12
root(s) 6
[C language] Issue in the Lotka-Volterra model. 0
completely stuck 14

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top