oscillator

  • Thread starter Bill Cunningham
  • Start date
R

Richard

Bill Cunningham said:
Other than the fact that your formula 'price-ma*ma/100' must be wrong, not
really (if we don't count the incorrect printf specifier, the allergy to
white space, and the failure to have a useful error message). Run the
following version of your code and see what happens:

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

double os(double price, double ma)
{
/* mha: note that ma / ma * 100 == 100 always */
printf("sanity check on the value computed:\n"
"price = %g, ma = %g\n"
"ma / ma * 100 = %g\n"
"price - ma / ma * 100 = %g\n",
price, ma, ma / ma * 100, price - ma / ma * 100);

return price - ma / ma * 100;
}

int main(int argc, char *argv[])
{
double price, ma; /* mha: moved to beginning of block for
pre-C99 compilers */
if (argc != 3) {
fprintf(stderr, "usage error: "
"price and 'ma' arguments needed\n");
exit(EXIT_FAILURE);
}
price = strtod(argv[1], NULL);
ma = strtod(argv[2], NULL);
printf("added sanity check on input:\n"
" price = %.2f, ma = %.2f\n", price, ma);

printf("%.2f\n", os(price, ma)); /* mha: was "%f.2" */
return 0;
}

I don't quite know what you're doing here but it does look interesting.

Bill

If you do not know what he is doing, how can it be interesting? Did you
compare your code and his? Can you give any idea what you think the
differences might be?
 
B

Bill Cunningham

If you do not know what he is doing, how can it be interesting? Did you
compare your code and his? Can you give any idea what you think the
differences might be?

I compiled the code and the results were the same as before my error was
corrected. The source was what I have trouble reading.

Bill
 
R

Richard

Bill Cunningham said:
I compiled the code and the results were the same as before my error was
corrected. The source was what I have trouble reading.

Bill

Err yes. But to understand the code you need to read the source. Come
back when you have tried to do just that.
 
N

Nick Keighley

    As to level of understanding, I don't profess to be a C expert or I
wouldn't need clc. As for the term "Troll" this is my understanding of it.

    From wikipedia there was an instance where a man pretended to be a woman
and so on and there was a big problem. On clc I doubt seriously that it is
possible to "troll". No one truely knows nor will ever expect to meet anyone
else here. That's common sense. And all we discuss is C. And nothing else.
How much damage can be possibly done.

read this http://catb.org/jargon/html/T/troll.html
 
B

Bill Cunningham

read this http://catb.org/jargon/html/T/troll.html

Ok Nick so the term Troll is used on usenet I can see. There is an easy
remedy to this. Myself if I thought someone didn't want to learn I would put
them in my killfile. There are several persons on usenet that I do not read
their posts because they are a waste of my time. I do not know who is behind
the keyboard if it is someone who doesn't want to learn I would killfile
them. Then again it may be someone with difficulties learning from texts and
learns easier by example. This is an individual descision.

Still the worst damage that I see can be done is someone is wasting my
time. I would killfile them. I would expect that from someone who is of the
opinion that I was wasting their time and for those who would want to help I
would be very greatful and work with them to my best ability.

Bill
 
R

Richard

Bill Cunningham said:
read this http://catb.org/jargon/html/T/troll.html

Ok Nick so the term Troll is used on usenet I can see. There is an easy
remedy to this. Myself if I thought someone didn't want to learn I would put
them in my killfile. There are several persons on usenet that I do not read
their posts because they are a waste of my time. I do not know who is behind
the keyboard if it is someone who doesn't want to learn I would killfile
them. Then again it may be someone with difficulties learning from texts and
learns easier by example. This is an individual descision.

Still the worst damage that I see can be done is someone is wasting my
time. I would killfile them. I would expect that from someone who is of the
opinion that I was wasting their time and for those who would want to help I
would be very greatful and work with them to my best ability.

Bill

The worst thing is that you're self absorbed with little desire to
learn. No one is wasting your time. You are wasting other people's time
by refusing to LEARN from what is being told to you.

My suggestion is that you give up. You have neither the work ethic nor
the talent to become a C programmer.

Possibly your talents lie in other directions. But they are most
certainly not in programming. I'm sorry, but that's the way it seems to
me. Stop wasting your and other peoples time. It's hopeless.
 
B

Bill Cunningham

The worst thing is that you're self absorbed with little desire to
learn. No one is wasting your time. You are wasting other people's time
by refusing to LEARN from what is being told to you.

My suggestion is that you give up. You have neither the work ethic nor
the talent to become a C programmer.

Possibly your talents lie in other directions. But they are most
certainly not in programming. I'm sorry, but that's the way it seems to
me. Stop wasting your and other peoples time. It's hopeless.

I hav received advice from your Richard and from others that seem to
conflict. For example indent. I was told to use indent and that it would
help me with style and I use it because it makes things easier to read as
well as show me readable style. You say don't use it and do things the hard
way. Whose advice I am going to follow ? Someone is going to think I am not
listening.

My decision is to use indent so people can read my text. I will also
read the produced code so that I might learn style. Indent adds alot of
whitespace. I don't like some of its style but helps complaints I get
concerning indentation.

Bill
 
B

Bill Cunningham

Stop wasting your and other peoples time. It's hopeless.

I don't believe in hopelessness. I do need hard work but I think it
lies in the direction of a one on one completent instructor in perhaps a
school setting. Most of the schools around teach C++. Maybe I'll find one
that teaches C.

Bill
 
B

Bill Cunningham

I went to WV university here locally and took prealgebra. I was bad at
it. I studied with a tutor and she had a difficult time with me. Like
Einstein I failed math, and I was getting tutoring because I like math but
just didn't have a head for it.

I got some books ranging from algebra to calculus. I sat down and
studied, studied and studied some more. I learned more myself than with a
tutor teaching me. I do forget and need to brush up on skills but the tutor
was going too fast for me. In my own time, a long time. I learned.

Bill
 
R

Richard

Bill Cunningham said:
I hav received advice from your Richard and from others that seem to
conflict. For example indent. I was told to use indent and that it would
help me with style and I use it because it makes things easier to read as
well as show me readable style. You say don't use it and do things the hard
way. Whose advice I am going to follow ? Someone is going to think I am not
listening.

Don't be such a dense fool. I explained WHY to do it yourself. So YOU
would understand the benefits of laying your code out and the importance
of doing just that. So we didn#t have to hear you whining about how
"brackets were still a bit confusing" for you. Do TRY and read what is
being told to you. I have lost all patience and I do no apologise for
being short in my replies.
My decision is to use indent so people can read my text. I will
also

Why not do it yourself for garps sake? Why use indent? Are you so stupid
that you can not see what harm you are doing your own development here?
read the produced code so that I might learn style. Indent adds alot of
whitespace. I don't like some of its style but helps complaints I get
concerning indentation.

I really can not believe what I am reading here. Stop. Go
back. Think. Indent is not MEANT to be used every 3 seconds to tidy your
code. A good programmer does it as he goes MANUALLY with the help of a
good context/language sensitive editor. STOP USING INDENT. Do NOT listen
to whoever told you to use it. DO IT YOURSELF. MANUALLY. LEARN WHY YOU
ARE DOING IT.
 
B

Bill Cunningham

[snip]
Why not do it yourself for garps sake? Why use indent? Are you so stupid
that you can not see what harm you are doing your own development here?


I really can not believe what I am reading here. Stop. Go
back. Think. Indent is not MEANT to be used every 3 seconds to tidy your
code. A good programmer does it as he goes MANUALLY with the help of a
good context/language sensitive editor. STOP USING INDENT. Do NOT listen
to whoever told you to use it. DO IT YOURSELF. MANUALLY. LEARN WHY YOU
ARE DOING IT.

I don't think the gripe from others is braces. It's white space in
sentences for example,

fp=fopen("file","wb"); /* typical for me I can read it */

People complain about text I write like above. So I am learning

fp = fopen ( "file", "wb" );

Which does look alittle better and is really no extra work. I seem to
compact things.

Bill
 
R

Richard

Bill Cunningham said:
[snip]
Why not do it yourself for garps sake? Why use indent? Are you so stupid
that you can not see what harm you are doing your own development here?


I really can not believe what I am reading here. Stop. Go
back. Think. Indent is not MEANT to be used every 3 seconds to tidy your
code. A good programmer does it as he goes MANUALLY with the help of a
good context/language sensitive editor. STOP USING INDENT. Do NOT listen
to whoever told you to use it. DO IT YOURSELF. MANUALLY. LEARN WHY YOU
ARE DOING IT.

I don't think the gripe from others is braces. It's white space in
sentences for example,

fp=fopen("file","wb"); /* typical for me I can read it */

People complain about text I write like above. So I am learning

fp = fopen ( "file", "wb" );

Which does look alittle better and is really no extra work. I seem to
compact things.

Bill

If anyone says that they are either more of a beginner than you or have
never programmed C in industry.

Do NOT leave white space like that.

The code should be

fp=fopen("file","wb");

The grip WAS about braces and multiple statements on one line. You would
know that if you READ what is being said to you.
 
R

Richard

I would argue for

fp = fopen("file", "wb");

There is no One Right Way to indent or space code. (Well, except that
whatever *I* do is automatically The Right Way. :) )

I have rarely seen excessive white space appreciated in c code
bases. Yes for indentation. No in other places. Is it the end of the
world? Of course not.

But in THIS situation with Bill appearing to try the patience of a rock,
I think stronger points need to be made about the layout people were
objecting to in his code snippets.
 
B

Ben Bacarisse

Richard said:
"Bill Cunningham" <[email protected]> writes:

If anyone says that they are either more of a beginner than you or have
never programmed C in industry.

Do NOT leave white space like that.

The code should be

fp=fopen("file","wb");

The grip WAS about braces and multiple statements on one line. You would
know that if you READ what is being said to you.

Step away from the keyboard. Take a moment...

You don't have to answer Bill, and laying down the law about spacing
will not help him or anyone else. Surely you allow, and even
encourage, space round operators and after a comma? Even if you don't,
insisting that there is only one way is bound to start a flame war!

In my experience people who are struggling with a programming language
often get the layout all wrong. They get it wrong, because that are
looking at a pile of symbols that conveys no meaning. Trying to get
good layout before understanding the code is like insisting that a
dyslexic learns to spell. As the understanding grows, the layout come
naturally because the symbols stop being arbitrary and start to mean
something at a deep level. You then often have to encourage a
conventional layout since students often like to invent their own, but
they will invent something logical to them that draws out the meaning
the symbols (and tokens) have stared to have.

I found that it does not work the other way round. "Natural"
programmers (and I think most people here have a flair for it) find
this very odd, since symbols mean so much to such people. But that is
just like a friend of mine who could spot a typo on a broadsheet after
scanning it for a few seconds. She simply could not understand that I
could not see my spelling mistakes even if stared at then for several
seconds.

Someone posted a loop like this recently:

while (condition) {
some code
};

and I'll bet most people here feel queasy just looking at that
semicolon. I do. It stands out a mile to me. Once it does to Bill,
he'll naturally indent his code.
 
K

Keith Thompson

Bill Cunningham said:
I went to WV university here locally and took prealgebra. I was bad at
it. I studied with a tutor and she had a difficult time with me. Like
Einstein I failed math, and I was getting tutoring because I like math but
just didn't have a head for it.

I got some books ranging from algebra to calculus. I sat down and
studied, studied and studied some more. I learned more myself than with a
tutor teaching me. I do forget and need to brush up on skills but the tutor
was going too fast for me. In my own time, a long time. I learned.

<OT>
That's interesting. For myself, and I suspect for most others,
there's a fairly strong positive correlation between liking something
and being good at it. It must be frustrating not to have a knack for
something you enjoy.
</OT>
 
K

Keith Thompson

Richard said:
Do NOT leave white space like that.

The code should be

fp=fopen("file","wb");

The grip WAS about braces and multiple statements on one line. You would
know that if you READ what is being said to you.

That wasn't the only gripe.

Bill, you should be aware that Richard's preference for whitespace (or
rather for a nearly complete lack of it) is unusual. Most C
programmers would strongly prefer the version Walter posted:

fp = fopen("file", "wb");

You should also be aware that Richard is a bit of a troll, though he's
managed to show some signs of sanity and helpfulness in this thread.

My own opinion:

Pick a layout that you like *and* that's consistent with general good
practice (i.e., what a lot of other programmers use). Try to lay out
your code in a consistent manner as you write it, using whatever
editor you're comfortable with. Pick a set of options to "indent"
that's consistent with your chosen style. Go ahead and run your code
through indent as often as you feel the need, but try to anticipate
what it's going to do by *understanding* just how the layout of the
code reflects its structure and meaning.

Eventually, as you get better at this, you'll hardly need to use
indent, because you'll format your code consistently without even
having to think about it. Or at least without having to think about
it too much.

It's sort of like driving a car. Once you've had some practice, you
don't think "lift foot from accelerator, move foot to left, lower foot
on brake, apply pressure", you just think "slow down".

Similarly, an experienced C programmer doesn't think "... put the '{'
at the end of the line, indent the following lines one level deeper to
the right, put the closing '}' on a line by itself aligned under the
corresponding keyword", he/she just thinks "write a compound
statement".

Spending a lot of time and mental effort concentrating on code layout
is a sign of a beginner. That's not a bad thing, it's something you
have to go through to gain experience. And it's not the most
important part of programming, so if a tool like indent helps you by
letting you concentrate on the meaning and structure of your program,
I don't think that's a bad thing.
 
N

Nick Keighley

I'm with you here. Why type it wrong then indent it? Why not do
it right in the first place?

If anyone says that they are either more of a beginner than you or have
never programmed C in industry.

Do NOT leave white space like that.

The code should be

    fp=fopen("file","wb");

The grip WAS about braces and multiple statements on one line. You would
know that if you READ what is being said to you

I think this just demonstrates that different people have different
opinons.
I find the compressed version hard to read (do you have a whitespace
shortage where you work?). For the record I am not a beginner and I
have
programmed C in industry.

I use ws like this

fp = fopen ("file", "wb");

I accept

fp = fopen("file", "wb");

stuff[*] like this

fp=fopen("file","wb");

I put though indent. AND complain about the layout.

But I also agree indentation is more important than
whitepace within a line.



[*] I thought of a couple of other words before I settled on "stuff"


--
Nick Keighley

"Almost every species in the universe has an irrational fear of the
dark.
But they're wrong- cos it's not irrational. It's Vashta Nerada."
The Doctor
 
R

Richard

Ben Bacarisse said:
Step away from the keyboard. Take a moment...

You don't have to answer Bill, and laying down the law about spacing
will not help him or anyone else. Surely you allow, and even
encourage, space round operators and after a comma? Even if you don't,
insisting that there is only one way is bound to start a flame war!

You are exaggerating the case. I pointed out earlier that its not the
end of the world.

I have however taught a lot of graduates into big code bases. I do know
what I am talking about. Excessive white space is never, ever the case
in C. In *any* of hundreds, of programs I have worked on.
In my experience people who are struggling with a programming language
often get the layout all wrong. They get it wrong, because that are
looking at a pile of symbols that conveys no meaning. Trying to get

*snip*


I know. This is why I want him to MANUALLY INDENT and NOT use indent.
 
R

Richard

Keith Thompson said:
That wasn't the only gripe.

Bill, you should be aware that Richard's preference for whitespace (or
rather for a nearly complete lack of it) is unusual. Most C
programmers would strongly prefer the version Walter posted:

fp = fopen("file", "wb");

You should also be aware that Richard is a bit of a troll, though he's
managed to show some signs of sanity and helpfulness in this thread.

I am not a troll. I just dont like your or Heathfields pompous
posturing.

btw I do not have a lot to argue with in the code line above.

The POINT is that Bill is NOT listening to what is said. And only a
clueless idiot would recommend he uses indent (the program) for his
layout. For him to understand scoping and *braces* (sigh!) he MUST learn
to indent the code himself. It really is that simple and no amount of
trying to obfuscate the thread with your views on trolling your perceive
me to do will change that. Opinionated? Yes. Entitled to be and
qualified to be? Yes. IMO of course.
 

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,777
Messages
2,569,604
Members
45,228
Latest member
MikeMichal

Latest Threads

Top