W
websnarf
Al said:I've found that all cut-and-paste errors can be eliminated by avoiding
cut-and-paste.
Yes, and in fact all programming errors can be eliminated by avoiding
programming.
Al said:I've found that all cut-and-paste errors can be eliminated by avoiding
cut-and-paste.
Richard said:(e-mail address removed) said:
I don't agree that comments are superfluous. *You* said the structure was
superfluous, and "superfluous" means "redundant, unnecessary" (look in a
dictionary if you don't believe me).
If it's useful, how can it be redundant?
Taking a step forward again, "it works fine" is a fabulous *baseline* for
writing code.
[...] For example, fopen works fine, and I use it quite happily,
without worrying that my code is somehow of a low standard just because it
uses something that works fine.
[...] Using void pointers correctly does not
imply fragile code.
[...] Using void pointers incorrectly is a losing strategy.
But so is using casts incorrectly. So is using fopen incorrectly. So is
using *anything* incorrectly.
Yes - in fact I've almost certainly done so right here in comp.lang.c. And
I've debugged screwed-up macro calls, too. So?
"Think first, compute later" is always a good plan.
[...] I generally don't bother
too much with debuggers nowadays. They are occasional ports in a storm,
that's all.
[...] It can hide the non-inclusion of it's prototype,
On *SOME* older generation compilers. No modern compiler fails to
give a warning about this regardless of the cast.
So if anyone comes up with a counter-example, you can simply claim
that it's not a "modern" compiler. ("True Scotsman" argument.)
For development?
Sure. Just because an implementation doesn't give one particular
diagnostic message that Paul Hsieh thinks it should, that doesn't mean
it's a Bad Compiler.
Right ... but we're several posts into this, and you couldn't even come
up with one?
Why bother?
Indeed.
[...] The diagnostic message is not required by the Standard, so it
makes no sense to me to insist to compiler-writers that they provide it.
[...] So trying to make C type safe is a bit like
trying to make Ook! object-oriented.
Interesting observation. If you intersect C and C++ what are you left
with?
Either poor C, poor C++, or syntax errors.
I have no problem with free automated assistance, but free automated
dictation is another matter. Whether a pointer of type <foo> is meaningful
when interpreted as if it were a pointer of type <bar> is something that
I'll judge for myself.
No, you smell comp.lang.c, which is about C, not C++. If you want to discuss
C++, there's a whole nother newsgroup for that.
[...] And if you want to discuss
programming in general, there's a newsgroup for that, too.
Oh, okay, I see what you mean.
[...] I thought you were talking about types, not
objects. The reason I didn't "get it" immediately is probably because I
find it quicker to type p = malloc(n * sizeof *p); than to invoke a copy
operation, a move operation, a paste operation, and two edits. Copy-paste
is expensive compared to typing when the amount to be copied is low, and
silly when the amount to be copied is high (because you're missing an
opportunity for re-factoring).
Perhaps I need more practice. I generally don't manage to make debugging
last more than a few minutes.
Well, among high-performance computational folks, Fortran *is*Well this is what he said: "Fortran compilers are usually even better
than that." (responding my statement about compiler optimizers and
warnings). You see his *attempt* at sarcasm doesn't work unless he is
able to establish this premise. Otherwise, his statement doesn't make
any sense at all.
Uh, again, Fortran is a better tool for some sorts of work. This is inRichard said:(e-mail address removed) said:
As far as I can tell, he has more of both than you do. And that's likely toOk, [Chris Torek has] made two gross mistakes in premise. But he
clearly has a lot of experience, and at least some skill as far as I can
tell.
be the perception amongst others here too. That doesn't mean he's
infallible. But if you and he disagree over something, common sense and
experience will lead me to assume that he's right and you're wrong, unless
you can come up with some extraordinarily convincing counter-evidence. So
far, you have not done so.
Given a previous discussion the two of us were in, I have to resist
making the ridiculously obvious retort at this point. Let me put it in
the most polite way as possible -- do you really think that your
personal deference to him is somehow supposed to mean something to me?
If it helps, let me tell you that I am a naturally anti-authoritarian
person. I strongly feel that pedistals are meant to be knocked over
(they serve no other real purpose).
The possibility that he's right and you're either wrong or misinterpreting
what he's said.
Uh ... he said Fortran was better than C (at optimization and/or
diagnostics). No matter how much you delete this quote, he still said
it. If he can make a strong case for the diagnostics, then I will
concede that he just wasn't being clear (but bizarrely intentionally
so). As for the optimizations, he's barking up the wrong tree if he
wants to try to present that case to me.
Huh? I don't have a problem with the definition. Comments describe
what the code is doing (redundant, since the source itself does that)
and are ignored by the compiler (unnecessary).
So what is your problem?
(Note that this does not imply that Comments are a bad thing.)
Noted.
Well let's just pause and think about this for a second.
Most CPU caches have parity bits, or ECC which are *REDUNDANT* to the
raw data its already carrying. So the question is, how can parity bits
or ECC be useful? Perhaps we need a research project to figure that
out. You'll find the same thing on hard disks and CD Roms.
TCP/IP uses a ones completement checksum on its packets. This checksum
is obviously derivable from the rest of the data its delivering.
There are well known algorithms, in fact called "Cyclic Redundancy
Check".
In C or Pascal, you usually have a { or begin that matches the start of
a program block. Without any loss of correct grammar parsing, you
could obviously just drop those. So they should be considered
redundant.
[...] Using void pointers correctly does not
imply fragile code.
Well that's not exactly what I was saying. It becomes a place were an
error can *hide*. Fragile code is usually much better because it
breaks at the drop of a hat, and so you can isolate and debug it
easily, or with moderate testing.
[...] Using void pointers incorrectly is a losing strategy.
But so is using casts incorrectly. So is using fopen incorrectly. So is
using *anything* incorrectly.
So you live in such a dichometric universe that you can't see anything
other than black and white? Either something is wrong or it isn't, and
you are not even concerned at all with the path you take in getting
from wrong to right?
No, that's not a plan at all. Its a mantra, and an unachievable ideal.
People do not think with perfection, so this will inevitably lead to
manifestions of thoughtless code.
How about a more serious plan: "Use
your tools to assist you in ferreting out bugs before they happen to
the greatest degree possible".
[...] I generally don't bother
too much with debuggers nowadays. They are occasional ports in a storm,
that's all.
So you don't deal with large amounts of other people's code?
[...] To some people, type safety is a straitjacket.
Well to some people type safety is free automated assistance.
I have no problem with free automated assistance, but free automated
dictation is another matter. Whether a pointer of type <foo> is
meaningful when interpreted as if it were a pointer of type <bar> is
something that I'll judge for myself.
So why have any type safety at all?
When did I say I wanted to discuss C++? When did I imply this? What
is leading you to this ridiculous statement?
You can't read complete
sentences, that you didn't even snip out.
That's a blindness very common to fundamentalism.
[...] And if you want to discuss
programming in general, there's a newsgroup for that, too.
I'm not taking direction from you or anyone about where I post.
Evidently.
Oh, okay, I see what you mean.
It took this many posts?
Join my campaign for 64-bit ints.Enter the bizzaro world of Richard Heathfield's editting mind. You
usually end up doing this when you copy entire routines that are
similar in nature, but need to rework the insides of it a bit to match
different signatures and types. C doesn't have templates you know.
Join my campaign for 64-bit ints.
Then there will be no need for templates, since all numbers (well,
integers) will be represented in the same way.
Clever said:Uh, again, Fortran is a better tool for some sorts of work. This is in
part because the compilers can optimize better (i.e., due to the way
explicit pointers are implemented) and the diagnostics are more robust.
I certainly am not getting into a holy war over this, but in general it
is well accepted that Fortran emits much faster code, especially for
some sorts of computational work. And it is also generally accepted
that it is easier to make fast, optimized code without resorting to
special compilers, optimized libraries or clever optimization techniques.
There are plenty of split pixels out there comparing benchmarks and
discussing this stuff.
The details can be argued /ad infinitum/, but simply asserting that
Fortran might be better than C in terms of automatic optimizations and
robust diagnostics is not some crazy unfounded assumption. It reflects
a fair amount of scholarly evidence and years of experience.
Well let's just pause and think about this for a second.
Malcolm said:Join my campaign for 64-bit ints.
Then there will be no need for templates, since all numbers (well, integers)
will be represented in the same way.
Now on the flip side, things are not equal. Fortran has a very
different interface to its integer semantics. For example, its integer
shift is highly generalized to include negative and positive shifting
(and I believe it has to correctly saturate as well). The Fortran
compiler has no opportunity to be able to assume the shift count
variable is either positive or negative. This what is rendered as a
single and very parallelizable instruction in C, ends up taking about 8
instructions in Fortran. Fortran also does not have a concept of
pointers or unions.
WIth any objective analysis, the details don't look too good for
Fortran. The places where it had an advantage in the past, were of a
historical and engineering effort nature. Vectorizors have been ported
to C compilers nowadays, so the major ace up Fortran's sleeve is gone.
Old said:The problem is that Paul Hsieh thinks "redundant" means "useless".
In fact, the English word "redundant" means exactly that, in the
minds of many people.
But in computer science, "redundant" means that it performs a
function which is already being performed by something else.
This may or may not be useless.
Richard said:(e-mail address removed) said:
Good comments do more than merely describe what the code is doing - they
describe /why/ the code is doing it. They summarise, explain, and inform,
at a level that is not constrained by syntax rules. They also record other
useful information (e.g. algorithm sources, author info, and the like) that
cannot reasonably be shoehorned into the C code itself.
Parity bits are not redundant. They act as a check on the integrity of the
data.
Same example, dressed in different clothes. Same answer.
Sounds like a misnomer to me.
From another perspective, however, the language requires them to be present
in a correct program, and so they are far from redundant.
<Lots of silly stuff snipped - so silly that no comment other than this is
necessary>
[...] Using void pointers correctly does not
imply fragile code.
Well that's not exactly what I was saying. It becomes a place were an
error can *hide*. Fragile code is usually much better because it
breaks at the drop of a hat, and so you can isolate and debug it
easily, or with moderate testing.
If you prefer fragile code, that's up to you. I prefer a bit more
robustness.
Thinking before computing is unachievable? I cannot agree with that.
Now who's thinking in black and white? No, the imperfection of people's
thought will not inevitably lead to manifestations of thoughtless code, but
rather to manifestations of code written by a less than perfect thinker.
any relevance. How a bug gets into your code is far less importantFrom a code production point of view, this is not a distinction with
Provided they don't get in my way, sure.
[...] But that means dropping the "to the
greatest degree possible" bit. The greatest degree possible is "don't write
the program", which is a good indication of where an extreme will take you.
Your words:
See above.
Who is the fundamentalist here?
Tonio said:I have to read characters from stdin and save them in a string. The
problem is that I don't know how much characters will be read.
In other words they are a redundant and unnecessary reexpression of the
algorithm
Old Wolf said:The problem is that Paul Hsieh thinks "redundant" means "useless".
In fact, the English word "redundant" means exactly that, in the
minds of many people.
.... snip 180 lines of code ...pete said:/* BEGIN line_to_string.c */
Well, this still has the potential for cut and paste errors unless you
macrofy the whole line.
If you don't macrofy, then you risk error no matter what.
So let us take a more serious approach compare macros which prevent any
mismatch errors:
#define scaredOfCPlusPlus(var,count) var = malloc(count*sizeof *var)
#define newThing(type,count) (type *) malloc (count * sizeof (type))
So you can say var = newThing(char *, 512), and if the type is wrong,
the compiler tells you.
The scaredOfCPlusPlus(,) macro works fine, but doesn't look familliar,
And, of course, the real difference is that the first compiles straight
in C++, and the second is just an error.
I have found that in general the C++ optimizers and warnings are better
for the C++ mode of my compilers than the C mode.
Richard said:Those many people are just as wrong as Paul, then.
CBFalconer said:... snip 180 lines of code ...
I think the heart code of ggets is somewhat simpler. See:
<http://cbfalconer.home.att.net/download/>
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.