Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Learning C

Reply
Thread Tools

Learning C

 
 
Nick Keighley
Guest
Posts: n/a
 
      03-11-2006
Richard G. Riley wrote:
> "Chris"posted the following on 2006-03-10:
> > Richard G. Riley wrote:
> >> "Nick"posted the following on 2006-03-10:


> >>> I thought you were implying Linux was better because the *debugger* was

> >
> >> There is no "the debugger" : although gdb is prevalent in Linux -
> >> albeit with several front ends.


"debugger" / "debuggers" whatever. I've used ddd.


> >>> better. I've never stepped through an existing application (that wasn't
> >>> broken)
> >>> with a debugger. If you say it's a good way to learn C, who am I to
> >>> argue.


I stress that I talking about "stepping through an application". I have
*no*
objection to examining existing code. One way to learn is to look at
good
examples (and sometimes at bad).


> >> I said its one way to get used to the structure and flow of
> >> applications which is what he wants. Also, I do think a debugger can
> >> give real insight into how C works in the real world : results of
> >> operators there for you to see with no overhead of printfs which some
> >> favor.

> >
> > The printf's are portable. The printf's work without manual
> >intervention.

>
> No they dont : you have to insert them in the code.


yes, but you don't have to keep on inserting them. Debuggers are
generally manual.


>But thats being petty.


I beg to differ.

> Its rare that I find someone wanting their printfs to be
> portable in a system process or a an X gui or a Win 32 winproc : they
> dont work. Home grown or system supplied logging libraries possibly :
> but can you really analyse them at run time? I cant : I like to step
> through and see the flow of the app to get a feel for how the systems
> heart is beating.


ok I'm not saying you are wrong. I'm just pointing out that not
everyone
works and learns the way you do. I don't single step debuggers to
examine other people's applications


> > The printfs work without having to understand an additional tool.
> >
> >>> But it *still* sounds bizzare to me
> >>
> >> What does?


using a debugger to examine existing applications


> >> Are we talking about the same thing? Do you doubt that
> >> watching other, well written apps work is beneficial to a newbie?


*examining* existing applications and other examples, yes.
*stepping* existing applications and other examples, no.


> >> It
> >> seems fairly clear to me that it can only help. Its how the entire
> >> Open SW system works : people learning by doing and picking up on
> >> other peoples work.


right. BUT NOT IN A DEBUGGER


> > You've conflated "learning by doing and picking up on> other peoples work"
> > with "watching ... apps work" and that with stepping through an application
> > using a debugger. I think that's misleading.

>
> Really? Seems pretty straightforward to me and also how close on 100% of
> Universities teach coding at some stage or other :


really? *all* universities encourage the use of stepping?
Do you have statistics?

Could you go back and *read* what I and other posters have actually
been saying?


> adding modules to existing systems.


yes! absoloutly!


> Maybe I'm a bit slow today but I'm not seeing the
> subtleties of the point you are making here :


well you don't "add to an existing module" by using a debugger.


> the user is looking for
> a way to learn how to structure applications and build them himself.


yes yes


> I fail to see how analysing existing, successful apps can be anything
> other than beneficial. It doesnt take away the donkey work of learning
> the lanugage basics, but it can make text book "science" much more
> accessible and "real". I cant imagine becoming a programmer without
> such practice, guidance and "practical training". Its the same in all
> walks of life.


I think I'll give up here. My point wasn't that important. Just trying
to
make the point that different people do thinks in different ways. Linux

is not the only platform. Not everyone uses debuggers the way you do
(some people only use them when they suspect a compiler error). A
newbie should be aware there are different ways to do things and not
lock themselves into a particular approach too early.

Maybe I'll even get my debugger out and step through a program
sometime to see if it brings me any insights. Maybe you should try
a "debugger free day" and try and see what you have to do to manage
without. Try reasoning about the program. Consider invariants and
post/pre conditions. Try adding asserts etc.

no way is the One True Way


> "A desk is a dangerous place from which to view the world" - LeCarre.


"there is nothing as practical as a good theory" Lewin


--
Nick Keighley

 
Reply With Quote
 
 
 
 
Richard G. Riley
Guest
Posts: n/a
 
      03-11-2006
"Nick"posted the following on 2006-03-11:

> Richard G. Riley wrote:
>> "Chris"posted the following on 2006-03-10:
>> > Richard G. Riley wrote:
>> >> "Nick"posted the following on 2006-03-10:

>
>> >>> I thought you were implying Linux was better because the *debugger* was
>> >
>> >> There is no "the debugger" : although gdb is prevalent in Linux -
>> >> albeit with several front ends.

>
> "debugger" / "debuggers" whatever. I've used ddd.


ddd is a front end to gdb.

>
>
>> >>> better. I've never stepped through an existing application (that wasn't
>> >>> broken)
>> >>> with a debugger. If you say it's a good way to learn C, who am I to
>> >>> argue.

>
> I stress that I talking about "stepping through an application". I have
> *no*
> objection to examining existing code. One way to learn is to look at
> good
> examples (and sometimes at bad).
>


And how can stepping through an app be bad? Were you never put onto a
new project with a code base of several hundred thousand lines of code
and told to isolate some relatively bugs to get you familiar with the
code base?

>
>> >> I said its one way to get used to the structure and flow of
>> >> applications which is what he wants. Also, I do think a debugger can
>> >> give real insight into how C works in the real world : results of
>> >> operators there for you to see with no overhead of printfs which some
>> >> favor.
>> >
>> > The printf's are portable. The printf's work without manual
>> >intervention.

>>
>> No they dont : you have to insert them in the code.

>
> yes, but you don't have to keep on inserting them. Debuggers are
> generally manual.
>
>
>>But thats being petty.

>
> I beg to differ.


I meant me pointing out they are useless in most server based apps or
message driven GUI apps.

>
>> Its rare that I find someone wanting their printfs to be
>> portable in a system process or a an X gui or a Win 32 winproc : they
>> dont work. Home grown or system supplied logging libraries possibly :
>> but can you really analyse them at run time? I cant : I like to step
>> through and see the flow of the app to get a feel for how the systems
>> heart is beating.

>
> ok I'm not saying you are wrong. I'm just pointing out that not
> everyone
> works and learns the way you do. I don't single step debuggers to
> examine other people's applications
>


Thats fine Nick : I dont expect you too - but you seem to have strong
reasons for making a point against it whereas I see *only* benefits.

>
>> > The printfs work without having to understand an additional tool.
>> >
>> >>> But it *still* sounds bizzare to me
>> >>
>> >> What does?

>
> using a debugger to examine existing applications
>


We wont get into the ****ing contest of who has worked on more
apps/platforms etc but I find it a good teaching tool to get people up
to speed with an app and its internal data structures : modify on the
fly, symbol tables etc. Cant do that with a print out or printfs.

>
>> >> Are we talking about the same thing? Do you doubt that
>> >> watching other, well written apps work is beneficial to a newbie?

>
> *examining* existing applications and other examples, yes.
> *stepping* existing applications and other examples, no.
>


for me "examining" is "stepping" : but obviously with some
strategically placed break points and a few retunr to callers etc

>
>> >> It
>> >> seems fairly clear to me that it can only help. Its how the entire
>> >> Open SW system works : people learning by doing and picking up on
>> >> other peoples work.

>
> right. BUT NOT IN A DEBUGGER
>


Really : in a debugger. Do you really advocate printfs over a debugger
in a huge code base? How do you map data values to their equivalent
constants? To me it sounds incredible. If you hadnt mentioned ddd I
would wonder if we are talking about the same thing.

>
>> > You've conflated "learning by doing and picking up on> other peoples work"
>> > with "watching ... apps work" and that with stepping through an application
>> > using a debugger. I think that's misleading.

>>
>> Really? Seems pretty straightforward to me and also how close on 100% of
>> Universities teach coding at some stage or other :

>
> really? *all* universities encourage the use of stepping?
> Do you have statistics?


Maybe stepping is the key word here : it does not mean every line. It
means strategically placed break points and data analysis at those
points. It is an art.

>
> Could you go back and *read* what I and other posters have actually
> been saying?
>


I did. Some people seem to think that a debugger is just for finding
bugs : it is not. It is also useful for examining runtime trends. Far
more useful than hard to decipher printfs, especially in a non console mode.

>
>> adding modules to existing systems.

>
> yes! absoloutly!
>
>
>> Maybe I'm a bit slow today but I'm not seeing the
>> subtleties of the point you are making here :

>
> well you don't "add to an existing module" by using a debugger.
>


Of course you do. You use it to examine the data flow between the
system and your module.

>
>> the user is looking for
>> a way to learn how to structure applications and build them himself.

>
> yes yes
>
>
>> I fail to see how analysing existing, successful apps can be anything
>> other than beneficial. It doesnt take away the donkey work of learning
>> the lanugage basics, but it can make text book "science" much more
>> accessible and "real". I cant imagine becoming a programmer without
>> such practice, guidance and "practical training". Its the same in all
>> walks of life.

>
> I think I'll give up here. My point wasn't that important. Just trying
> to
> make the point that different people do thinks in different ways. Linux
>
> is not the only platform. Not everyone uses debuggers the way you do


Nobody said it was : you came flying in with that. The OP had
expressed an intrest in Linux and the fact that it comes with free
industry strength compilers and debuggers as well as hundreds of rock
solid C apps complete with build packages makes it a good bet for
someone to learn how to structure and analyse an application in
C. Windows can not compete with that IMO.

> (some people only use them when they suspect a compiler error). A


If there is a compile error, you wont be using a debugger.

> newbie should be aware there are different ways to do things and not
> lock themselves into a particular approach too early.
>


A newbie needs to examine other peoples stuff : especially when
adding/fixing bugs. Approaches vary, but it can never hurt to get down
and dirty to be sure.

A newbie certainly shouldnt dedicate his life to printf()'s : they
simply do not work in a lot of environments, are inflexible, and only
show the data that you WANT to see, not the data you SHOULD see. This
is where a debuggers "locals" view etc comes in. You see alllocal
data. Not what someone thinks they need to see.

> Maybe I'll even get my debugger out and step through a program
> sometime to see if it brings me any insights. Maybe you should try
> a "debugger free day" and try and see what you have to do to manage
> without. Try reasoning about the program. Consider invariants and
> post/pre conditions. Try adding asserts etc.


If you recall I did mention that a home brew logging system is
prefential to printf : I have nothing against them and have
implemented many with various backend report generators to examine the
data. A debugger isnt the only tool : and I never said it was. What it
can do is allow you to see the flow of an application while watching
live data, allow you to modify that data and to examine and ensure
data typing is consistant from skillful use of register/pointer/memory
examinations : it is why they exist.

>
> no way is the One True Way
>


And no where did I say it was. The whole crux here is you doubting
that stepping an existing app can help a user understand it : after
many, many and varied projects on various platforms in various
languages I find it incredulous how you could doubt this would be
beneficial. In order to even put in these printfs() you need some
understanding of whats going : that does not come from a print out all
the time. It does not some from a func spec which is not always
there. It does not come from holistic overview : it comes from
stepping through and examining what is going on. From finding out when
and why certain modules are called. From knowing what that little bit
of bit fiddling results in, from forcing a function call at runtime in
order to test a different calling parameter. The list goes on. Of
course none of this is "the only way" : but its a good way and one
thats been used a lot for years.

Do you need a debugger for a ten line string rversal func? Maybe not :
but I'll tell you a little secret, I'd still use one to test it
rigorously before handing it in to a system for an integration
test. Total extra effort? About 5 minutes.


I realise that there is a core here who seem to think a debugger is
almost evil : I sometimes question if they have used a real
debugger on a real system in the real world where programmers are
cycled on and off projects and people want to optimise their "up to
speed" figures. I realise that according to some posters some projects
get by without a debugger : I've never had the pleasure of such a
project/system.

>
>> "A desk is a dangerous place from which to view the world" - LeCarre.

>
> "there is nothing as practical as a good theory" Lewin
>
>



--
"A desk is a dangerous place from which to view the world" - LeCarre.
 
Reply With Quote
 
 
 
 
Nick Keighley
Guest
Posts: n/a
 
      03-11-2006
Richard G. Riley wrote:
> "Nick"posted the following on 2006-03-11:
> > Richard G. Riley wrote:
> >> "Chris"posted the following on 2006-03-10:
> >> > Richard G. Riley wrote:
> >> >> "Nick"posted the following on 2006-03-10:


> >> >>> I thought you were implying Linux was better because the *debugger* was
> >> >
> >> >> There is no "the debugger" : although gdb is prevalent in Linux -
> >> >> albeit with several front ends.

> >
> > "debugger" / "debuggers" whatever. I've used ddd.

>
> ddd is a front end to gdb.


I know


> >> >>> better. I've never stepped through an existing application (that wasn't
> >> >>> broken)
> >> >>> with a debugger. If you say it's a good way to learn C, who am I to
> >> >>> argue.

> >
> > I stress that I talking about "stepping through an application". I have
> > *no*
> > objection to examining existing code. One way to learn is to look at
> > good
> > examples (and sometimes at bad).

>
> And how can stepping through an app be bad? Were you never put onto a
> new project with a code base of several hundred thousand lines of code
> and told to isolate some relatively bugs to get you familiar with the
> code base?


about a year ago I was put on 750 kloc application. I had no previous
experience with the application. And limited experience with the
programming language. I did not step through the code with a debugger.

> >> >> I said its one way to get used to the structure and flow of
> >> >> applications which is what he wants. Also, I do think a debugger can
> >> >> give real insight into how C works in the real world : results of
> >> >> operators there for you to see with no overhead of printfs which some
> >> >> favor.
> >> >
> >> > The printf's are portable. The printf's work without manual
> >> >intervention.
> >>
> >> No they dont : you have to insert them in the code.

> >
> > yes, but you don't have to keep on inserting them. Debuggers are
> > generally manual.


<snip>

> I meant me pointing out they are useless in most server based apps or
> message driven GUI apps.


there are alternatives to printf(). I usually use some sort of logger.
For both
servers and GUIs. That 750kloc application has both.


> >> Its rare that I find someone wanting their printfs to be
> >> portable in a system process or a an X gui or a Win 32 winproc : they
> >> dont work. Home grown or system supplied logging libraries possibly :
> >> but can you really analyse them at run time? I cant : I like to step
> >> through and see the flow of the app to get a feel for how the systems
> >> heart is beating.

> >
> > ok I'm not saying you are wrong. I'm just pointing out that not
> > everyone
> > works and learns the way you do. I don't single step debuggers to
> > examine other people's applications

>
> Thats fine Nick : I dont expect you too - but you seem to have strong
> reasons for making a point against it whereas I see *only* benefits.


ok, we disagree. What's wrong with *reading* the code. UML? Source
browsers?


> >> > The printfs work without having to understand an additional tool.
> >> >
> >> >>> But it *still* sounds bizzare to me
> >> >>
> >> >> What does?

> >
> > using a debugger to examine existing applications

>
> We wont get into the ****ing contest of who has worked on more
> apps/platforms etc but I find it a good teaching tool to get people up
> to speed with an app and its internal data structures : modify on the
> fly, symbol tables etc. Cant do that with a print out or printfs.


I have *never* had any desire to do these things. Find the bug. Fix
the bug. Why would you want to modify things on-the-fly?!


> >> >> Are we talking about the same thing? Do you doubt that
> >> >> watching other, well written apps work is beneficial to a newbie?

> >
> > *examining* existing applications and other examples, yes.
> > *stepping* existing applications and other examples, no.

>
> for me "examining" is "stepping" : but obviously with some
> strategically placed break points and a few retunr to callers etc


"examine", to me, means to study the source code. A good source
browser can be handy.


> >> >> It
> >> >> seems fairly clear to me that it can only help. Its how the entire
> >> >> Open SW system works : people learning by doing and picking up on
> >> >> other peoples work.

> >
> > right. BUT NOT IN A DEBUGGER

>
> Really : in a debugger. Do you really advocate printfs over a debugger
> in a huge code base?





> How do you map data values to their equivalent
> constants? To me it sounds incredible. If you hadnt mentioned ddd I
> would wonder if we are talking about the same thing.


some constants get dumped as numbers. Some enums are already wrappered
so as to be able to decode themselves (ok I admit this is C++, ...its
only a
*little bit* of a move to the Dark Side. I can stop any time I want).

> >> > You've conflated "learning by doing and picking up on> other peoples work"
> >> > with "watching ... apps work" and that with stepping through an application
> >> > using a debugger. I think that's misleading.
> >>
> >> Really? Seems pretty straightforward to me and also how close on 100% of
> >> Universities teach coding at some stage or other :

> >
> > really? *all* universities encourage the use of stepping?
> > Do you have statistics?

>
> Maybe stepping is the key word here : it does not mean every line. It
> means strategically placed break points and data analysis at those
> points. It is an art.


and *all* universities teach it? Its a long time since I was at
university.

Yorkshire Man 2:
"Symbolic debuggers! You were lucky we 'ad t'punch t' cards with ar
teeth!"

> > Could you go back and *read* what I and other posters have actually
> > been saying?

>
> I did. Some people seem to think that a debugger is just for finding
> bugs : it is not. It is also useful for examining runtime trends. Far
> more useful than hard to decipher printfs, especially in a non console mode.


but you have to know where to put the breaks. And that means you must
at
least partially understand the application. To do that I'd read the
code...

> >> adding modules to existing systems.

> >
> > yes! absoloutly!
> >
> >> Maybe I'm a bit slow today but I'm not seeing the
> >> subtleties of the point you are making here :

> >
> > well you don't "add to an existing module" by using a debugger

>
> Of course you do. You use it to examine the data flow between the
> system and your module.


well I add to an existing module with a Text Editor. I'm not being
funny
here we *really* seem to be missing each others point.

I REALLY don't use a debugger to add code to an existing module.

> >> the user is looking for
> >> a way to learn how to structure applications and build them himself.

> >
> > yes yes
> >
> >> I fail to see how analysing existing, successful apps can be anything
> >> other than beneficial. It doesnt take away the donkey work of learning
> >> the lanugage basics, but it can make text book "science" much more
> >> accessible and "real". I cant imagine becoming a programmer without
> >> such practice, guidance and "practical training". Its the same in all
> >> walks of life.

> >
> > I think I'll give up here. My point wasn't that important. Just trying
> > to
> > make the point that different people do thinks in different ways. Linux
> >
> > is not the only platform. Not everyone uses debuggers the way you do

>
> Nobody said it was : you came flying in with that.


riight

> The OP had
> expressed an intrest in Linux and the fact that it comes with free
> industry strength compilers and debuggers as well as hundreds of rock
> solid C apps complete with build packages makes it a good bet for
> someone to learn how to structure and analyse an application in
> C. Windows can not compete with that IMO.


it's a perfectly good development platform though. Look Linux is ok.
Windows is ok. But two posters had encouraged the OP to move to
Linux. I'm not sure its such an open and shut decsision. You can
write crap non-portable code on Linux as well.

> > (some people only use them when they suspect a compiler error). A

>
> If there is a compile error, you wont be using a debugger.


well compiler bugs are about as rare as hens teeth. But why not? The
debugger would show you that the program flow or calculation results
did not follow the source code. All my tools are broken if the source
code does not represent what the machine is doing.

To be honest I can't remember the last time I had a bug caused by a
compiler error

> > newbie should be aware there are different ways to do things and not
> > lock themselves into a particular approach too early.

>
> A newbie needs to examine other peoples stuff : especially when
> adding/fixing bugs. Approaches vary, but it can never hurt to get down
> and dirty to be sure.
>
> A newbie certainly shouldnt dedicate his life to printf()'s : they
> simply do not work in a lot of environments, are inflexible, and only
> show the data that you WANT to see, not the data you SHOULD see. This
> is where a debuggers "locals" view etc comes in. You see alllocal
> data. Not what someone thinks they need to see.
>
> > Maybe I'll even get my debugger out and step through a program
> > sometime to see if it brings me any insights. Maybe you should try
> > a "debugger free day" and try and see what you have to do to manage
> > without. Try reasoning about the program. Consider invariants and
> > post/pre conditions. Try adding asserts etc.

>
> If you recall I did mention that a home brew logging system is
> prefential to printf :


where did the words "homebrew logging system" appear in the paragraph
above? I did write a fairly blunt paragraph here. And then thought
better of it.
Do you know what an invarient is? Design by contract?


>I have nothing against them and have
> implemented many with various backend report generators to examine the
> data.


good!

> A debugger isnt the only tool : and I never said it was. What it
> can do is allow you to see the flow of an application while watching
> live data, allow you to modify that data


never felt the need. Not since compilers got fast enough to run during
the day.

> and to examine and ensure
> data typing is consistant from skillful use of register/pointer/memory
> examinations : it is why they exist.


you examine registers? On a deeply embedded system, ok. But a server?

> > no way is the One True Way
> >

>
> And no where did I say it was. The whole crux here is you doubting
> that stepping an existing app can help a user understand it : after
> many, many and varied projects on various platforms in various
> languages I find it incredulous how you could doubt this would be
> beneficial. In order to even put in these printfs() you need some
> understanding of whats going : that does not come from a print out all
> the time. It does not some from a func spec which is not always
> there. It does not come from holistic overview : it comes from
> stepping through and examining what is going on. From finding out when
> and why certain modules are called. From knowing what that little bit
> of bit fiddling results in, from forcing a function call at runtime in
> order to test a different calling parameter. The list goes on. Of
> course none of this is "the only way" : but its a good way and one
> thats been used a lot for years.


I'd say the same went (in spades) for stepping. You've got to know
where
to step. There's source code, case tools, source browsers, source code.
I've even resorted to grep to find callers of functions.

> Do you need a debugger for a ten line string rversal func? Maybe not :
> but I'll tell you a little secret, I'd still use one to test it
> rigorously before handing it in to a system for an integration
> test. Total extra effort? About 5 minutes.


I'd write unit test. Also five minutes work and more likely to give
proper
coverage.

> I realise that there is a core here who seem to think a debugger is
> almost evil : I sometimes question if they have used a real
> debugger on a real system in the real world where programmers are
> cycled on and off projects and people want to optimise their "up to
> speed" figures.


normally I don't get into what I work on, but yes I do work on projects

where people get cycled on and off. I'm one of the cycled. It's a real
system. In the real world. Real people pay real money for the
facilities
it provides. And there is a requirement for more performance.

I'm not accusing you of it, but sometimes people seem to spend way
too much time hunched over a debugger when a bit of thought might
save them some time.

> I realise that according to some posters some projects
> get by without a debugger : I've never had the pleasure of such a
> project/system.
>
> >> "A desk is a dangerous place from which to view the world" - LeCarre.

> >
> > "there is nothing as practical as a good theory" Lewin



--
Nick Keighley

 
Reply With Quote
 
Richard G. Riley
Guest
Posts: n/a
 
      03-11-2006
On 2006-03-11, Nick Keighley <> wrote:
> Richard G. Riley wrote:
>> "Nick"posted the following on 2006-03-11:
>> > Richard G. Riley wrote:
>> >> "Chris"posted the following on 2006-03-10:
>> >> > Richard G. Riley wrote:
>> >> >> "Nick"posted the following on 2006-03-10:

>
>> >> >>> I thought you were implying Linux was better because the *debugger* was
>> >> >
>> >> >> There is no "the debugger" : although gdb is prevalent in Linux -
>> >> >> albeit with several front ends.
>> >
>> > "debugger" / "debuggers" whatever. I've used ddd.

>>
>> ddd is a front end to gdb.

>
> I know
>
>
>> >> >>> better. I've never stepped through an existing application (that wasn't
>> >> >>> broken)
>> >> >>> with a debugger. If you say it's a good way to learn C, who am I to
>> >> >>> argue.
>> >
>> > I stress that I talking about "stepping through an application". I have
>> > *no*
>> > objection to examining existing code. One way to learn is to look at
>> > good
>> > examples (and sometimes at bad).

>>
>> And how can stepping through an app be bad? Were you never put onto a
>> new project with a code base of several hundred thousand lines of code
>> and told to isolate some relatively bugs to get you familiar with the
>> code base?

>
> about a year ago I was put on 750 kloc application. I had no previous
> experience with the application. And limited experience with the
> programming language. I did not step through the code with a

debugger.

Your choice. I would have. Especially when I modified the code. But
again you are offering no evidence to suggest that stepping through an
app is "crazy" or "bizarre" as you originally claimed.

>
>> >> >> I said its one way to get used to the structure and flow of
>> >> >> applications which is what he wants. Also, I do think a debugger can
>> >> >> give real insight into how C works in the real world : results of
>> >> >> operators there for you to see with no overhead of printfs which some
>> >> >> favor.
>> >> >
>> >> > The printf's are portable. The printf's work without manual
>> >> >intervention.
>> >>
>> >> No they dont : you have to insert them in the code.
>> >
>> > yes, but you don't have to keep on inserting them. Debuggers are
>> > generally manual.

>
><snip>
>
>> I meant me pointing out they are useless in most server based apps or
>> message driven GUI apps.

>
> there are alternatives to printf(). I usually use some sort of logger.
> For both
> servers and GUIs. That 750kloc application has both.


Fine. But often loggers affect the app. And again, you only see what
you are told you can see.. : a debugger lets you see what you want to
see when you want to see it. Being able to see the data greatly
simplifies understanding an application and I cant expect anyone to
dispute that. But someone will ... :-;

>
>
>> >> Its rare that I find someone wanting their printfs to be
>> >> portable in a system process or a an X gui or a Win 32 winproc : they
>> >> dont work. Home grown or system supplied logging libraries possibly :
>> >> but can you really analyse them at run time? I cant : I like to step
>> >> through and see the flow of the app to get a feel for how the systems
>> >> heart is beating.
>> >
>> > ok I'm not saying you are wrong. I'm just pointing out that not
>> > everyone
>> > works and learns the way you do. I don't single step debuggers to
>> > examine other people's applications

>>
>> Thats fine Nick : I dont expect you too - but you seem to have strong
>> reasons for making a point against it whereas I see *only* benefits.

>
> ok, we disagree. What's wrong with *reading* the code. UML? Source
> browsers?


Because not all code is readable? Because not all code can be properly
deciphered from reading? Because you dont know what data is coming up
from those functions 40 deep? Becuase its plagues with missplaced
casts?

You dont know what branch conditions are going to be taken based on HW
port values? There are numerous reasons.


>
>
>> >> > The printfs work without having to understand an additional tool.
>> >> >
>> >> >>> But it *still* sounds bizzare to me
>> >> >>
>> >> >> What does?
>> >
>> > using a debugger to examine existing applications

>>
>> We wont get into the ****ing contest of who has worked on more
>> apps/platforms etc but I find it a good teaching tool to get people up
>> to speed with an app and its internal data structures : modify on the
>> fly, symbol tables etc. Cant do that with a print out or printfs.

>
> I have *never* had any desire to do these things. Find the bug. Fix
> the bug. Why would you want to modify things on-the-fly?!
>


Modify data to test or force a state. Its a basic of debugger use : you can
force your hand to avoid having to wait for a certain random data
suite to trigger the bug.

e.g someone says I'm getting a divide by zero somewhere near func().

go to func in debugger, force a zero into the divisor and see why the
checks arent stopping it. Simple example.


>
>> >> >> Are we talking about the same thing? Do you doubt that
>> >> >> watching other, well written apps work is beneficial to a newbie?
>> >
>> > *examining* existing applications and other examples, yes.
>> > *stepping* existing applications and other examples, no.

>>
>> for me "examining" is "stepping" : but obviously with some
>> strategically placed break points and a few retunr to callers etc

>
> "examine", to me, means to study the source code. A good source
> browser can be handy.
>


A good debugger is that too.

>
>> >> >> It
>> >> >> seems fairly clear to me that it can only help. Its how the entire
>> >> >> Open SW system works : people learning by doing and picking up on
>> >> >> other peoples work.
>> >
>> > right. BUT NOT IN A DEBUGGER

>>
>> Really : in a debugger. Do you really advocate printfs over a debugger
>> in a huge code base?

>
>
>
>
>> How do you map data values to their equivalent
>> constants? To me it sounds incredible. If you hadnt mentioned ddd I
>> would wonder if we are talking about the same thing.

>
> some constants get dumped as numbers. Some enums are already wrappered
> so as to be able to decode themselves (ok I admit this is C++, ...its
> only a
> *little bit* of a move to the Dark Side. I can stop any time I want).
>


I'm not good at remembering what 0xefecda means. I prefer something in
the debugger like "WM_GETFOCUS" or some such.

>> >> > You've conflated "learning by doing and picking up on> other peoples work"
>> >> > with "watching ... apps work" and that with stepping through an application
>> >> > using a debugger. I think that's misleading.
>> >>
>> >> Really? Seems pretty straightforward to me and also how close on 100% of
>> >> Universities teach coding at some stage or other :
>> >
>> > really? *all* universities encourage the use of stepping?
>> > Do you have statistics?

>>
>> Maybe stepping is the key word here : it does not mean every line. It
>> means strategically placed break points and data analysis at those
>> points. It is an art.

>
> and *all* universities teach it? Its a long time since I was at
> university.
>


me too.

> Yorkshire Man 2:
> "Symbolic debuggers! You were lucky we 'ad t'punch t' cards with ar
> teeth!"
>




>> > Could you go back and *read* what I and other posters have actually
>> > been saying?

>>
>> I did. Some people seem to think that a debugger is just for finding
>> bugs : it is not. It is also useful for examining runtime trends. Far
>> more useful than hard to decipher printfs, especially in a non console mode.

>
> but you have to know where to put the breaks. And that means you must
> at
> least partially understand the application. To do that I'd read the
> code...


So do I: of course. But i also analyse the flow at the same time : a
debugger does let you read the code you know :-;

>
>> >> adding modules to existing systems.
>> >
>> > yes! absoloutly!
>> >
>> >> Maybe I'm a bit slow today but I'm not seeing the
>> >> subtleties of the point you are making here :
>> >
>> > well you don't "add to an existing module" by using a debugger

>>
>> Of course you do. You use it to examine the data flow between the
>> system and your module.

>
> well I add to an existing module with a Text Editor. I'm not being
> funny
> here we *really* seem to be missing each others point.
>


No you dont. You use a text editor to create the symbolic equivalent
which is then compiled & linked into the bigger app. The debugger can then be
used to force data between your interfaces and the legacy very easily
for the purposes of quick integration testing. Yes, there are other
ways too.

> I REALLY don't use a debugger to add code to an existing module.
>


No. Nor do I. I use it, frequently, to monitor the addition. No one
here is suggesting the debugger is a compiler & linker & editor. It is
for me part of the process. Not for all, but we're heading back down
that well covered track again

>> >> the user is looking for
>> >> a way to learn how to structure applications and build them himself.
>> >
>> > yes yes
>> >
>> >> I fail to see how analysing existing, successful apps can be anything
>> >> other than beneficial. It doesnt take away the donkey work of learning
>> >> the lanugage basics, but it can make text book "science" much more
>> >> accessible and "real". I cant imagine becoming a programmer without
>> >> such practice, guidance and "practical training". Its the same in all
>> >> walks of life.
>> >
>> > I think I'll give up here. My point wasn't that important. Just trying
>> > to
>> > make the point that different people do thinks in different ways. Linux
>> >
>> > is not the only platform. Not everyone uses debuggers the way you do

>>
>> Nobody said it was : you came flying in with that.

>
> riight


You did. Look at the thread. The OP mentioned Linux : I said it was a
good idea for what he wanted to do : you came in with "hold on hold on
lets not start an OS war here".

>
>> The OP had
>> expressed an intrest in Linux and the fact that it comes with free
>> industry strength compilers and debuggers as well as hundreds of rock
>> solid C apps complete with build packages makes it a good bet for
>> someone to learn how to structure and analyse an application in
>> C. Windows can not compete with that IMO.

>
> it's a perfectly good development platform though. Look Linux is ok.
> Windows is ok. But two posters had encouraged the OP to move to
> Linux. I'm not sure its such an open and shut decsision. You can
> write crap non-portable code on Linux as well.


But you dont have the facilities to support his learning as well IMO :
remember me mentioning the thousands of apps with source code? No one
is saying Linux is "better", but I would say its better for someone
wanting to get into C programming big time : everything is part of the
base install. For Free. And documented.

>
>> > (some people only use them when they suspect a compiler error). A

>>
>> If there is a compile error, you wont be using a debugger.

>
> well compiler bugs are about as rare as hens teeth. But why not? The
> debugger would show you that the program flow or calculation results
> did not follow the source code. All my tools are broken if the source
> code does not represent what the machine is doing.
>
> To be honest I can't remember the last time I had a bug caused by a
> compiler error


Different things. I meant compilation error : sorry.

>
>> > newbie should be aware there are different ways to do things and not
>> > lock themselves into a particular approach too early.

>>
>> A newbie needs to examine other peoples stuff : especially when
>> adding/fixing bugs. Approaches vary, but it can never hurt to get down
>> and dirty to be sure.
>>
>> A newbie certainly shouldnt dedicate his life to printf()'s : they
>> simply do not work in a lot of environments, are inflexible, and only
>> show the data that you WANT to see, not the data you SHOULD see. This
>> is where a debuggers "locals" view etc comes in. You see alllocal
>> data. Not what someone thinks they need to see.
>>
>> > Maybe I'll even get my debugger out and step through a program
>> > sometime to see if it brings me any insights. Maybe you should try
>> > a "debugger free day" and try and see what you have to do to manage
>> > without. Try reasoning about the program. Consider invariants and
>> > post/pre conditions. Try adding asserts etc.

>>
>> If you recall I did mention that a home brew logging system is
>> prefential to printf :

>
> where did the words "homebrew logging system" appear in the paragraph
> above? I did write a fairly blunt paragraph here. And then thought
> better of it.
> Do you know what an invarient is? Design by contract?
>


I used those words. Its when you wrap whatever underlying logging system is
convenient to you in a fairly generic calling interface : so you could
log to files, text consoles, window systems whatever without changing
the calling code.

>
>>I have nothing against them and have
>> implemented many with various backend report generators to examine the
>> data.

>
> good!
>
>> A debugger isnt the only tool : and I never said it was. What it
>> can do is allow you to see the flow of an application while watching
>> live data, allow you to modify that data

>
> never felt the need. Not since compilers got fast enough to run during
> the day.
>


I really dont understand this. What has that got to do with a debugger?

>> and to examine and ensure
>> data typing is consistant from skillful use of register/pointer/memory
>> examinations : it is why they exist.

>
> you examine registers? On a deeply embedded system, ok. But a
>> server?


I also mentioned memory and pointers. And yes I do. Very useful in
debugging big C systems.

>
>> > no way is the One True Way
>> >

>>
>> And no where did I say it was. The whole crux here is you doubting
>> that stepping an existing app can help a user understand it : after
>> many, many and varied projects on various platforms in various
>> languages I find it incredulous how you could doubt this would be
>> beneficial. In order to even put in these printfs() you need some
>> understanding of whats going : that does not come from a print out all
>> the time. It does not some from a func spec which is not always
>> there. It does not come from holistic overview : it comes from
>> stepping through and examining what is going on. From finding out when
>> and why certain modules are called. From knowing what that little bit
>> of bit fiddling results in, from forcing a function call at runtime in
>> order to test a different calling parameter. The list goes on. Of
>> course none of this is "the only way" : but its a good way and one
>> thats been used a lot for years.

>
> I'd say the same went (in spades) for stepping. You've got to know
> where
> to step. There's source code, case tools, source browsers, source code.
> I've even resorted to grep to find callers of functions.
>


grep is ok : if I dont have a decent IDE I use something like emacs
tags. I have used grep in about 15 years

>> Do you need a debugger for a ten line string rversal func? Maybe not :
>> but I'll tell you a little secret, I'd still use one to test it
>> rigorously before handing it in to a system for an integration
>> test. Total extra effort? About 5 minutes.

>
> I'd write unit test. Also five minutes work and more likely to give
> proper
> coverage.
>
>> I realise that there is a core here who seem to think a debugger is
>> almost evil : I sometimes question if they have used a real
>> debugger on a real system in the real world where programmers are
>> cycled on and off projects and people want to optimise their "up to
>> speed" figures.

>
> normally I don't get into what I work on, but yes I do work on projects
>
> where people get cycled on and off. I'm one of the cycled. It's a real
> system. In the real world. Real people pay real money for the
> facilities
> it provides. And there is a requirement for more performance.
>
> I'm not accusing you of it, but sometimes people seem to spend way
> too much time hunched over a debugger when a bit of thought might
> save them some time.


No doubt. And equally the opposite applies : in my experience more so.

>
>> I realise that according to some posters some projects
>> get by without a debugger : I've never had the pleasure of such a
>> project/system.
>>
>> >> "A desk is a dangerous place from which to view the world" - LeCarre.
>> >
>> > "there is nothing as practical as a good theory" Lewin

>
>

 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      03-11-2006
"Nick Keighley" <> writes:
> Richard G. Riley wrote:
>> "Nick"posted the following on 2006-03-11:
>> > Richard G. Riley wrote:
>> >> "Chris"posted the following on 2006-03-10:
>> >> > Richard G. Riley wrote:
>> >> >> "Nick"posted the following on 2006-03-10:

>
>> >> >>> I thought you were implying Linux was better because the
>> >> >>> *debugger* was
>> >> >
>> >> >> There is no "the debugger" : although gdb is prevalent in Linux -
>> >> >> albeit with several front ends.
>> >
>> > "debugger" / "debuggers" whatever. I've used ddd.

>>
>> ddd is a front end to gdb.

>
> I know
>
>> >> >>> better. I've never stepped through an existing application
>> >> >>> (that wasn't broken) with a debugger. If you say it's a good
>> >> >>> way to learn C, who am I to argue.
>> >
>> > I stress that I talking about "stepping through an application". I have
>> > *no*
>> > objection to examining existing code. One way to learn is to look at
>> > good
>> > examples (and sometimes at bad).

>>
>> And how can stepping through an app be bad? Were you never put onto a
>> new project with a code base of several hundred thousand lines of code
>> and told to isolate some relatively bugs to get you familiar with the
>> code base?

>
> about a year ago I was put on 750 kloc application. I had no previous
> experience with the application. And limited experience with the
> programming language. I did not step through the code with a debugger.

[...]

If I might summarize:

Richard G. Riley really likes debuggers. Not everyone else likes them
as much as Richard does.

I believe that covers all the relevant points.

Next?

--
Keith Thompson (The_Other_Keith) kst- <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
 
Reply With Quote
 
Richard G. Riley
Guest
Posts: n/a
 
      03-11-2006
On 2006-03-11, Keith Thompson <kst-> wrote:
>
> If I might summarize:
>
> Richard G. Riley really likes debuggers. Not everyone else likes them
> as much as Richard does.
>
> I believe that covers all the relevant points.
>
> Next?
>


Very droll.

But not at all what the crux of this is about : what its about is a
one way of working which can dramatically speed up ones familiarity
with a system. I find it terrifying that there seems to be a fair
number of programmers here who think a debugger is "only for finding bugs"
: it is a limited and naive view.

Inserting printfs, asserts and so forth is time consuming, messes up
the code, limits one to what the programmer wanted you to see at
"write time", and is a colossal source of heisenbugs. Unless you're
perfect that is : which some here have indeed claimed to be.

And for using such a tool to be called "bizarre" is bizarre in
itself. Yes, yes, I know what Kernighan said : good on him.

The entire thread started with discussing how a new programmer could
familiarise himself with bulding & architecting apps : I'm afraid that
"look at the source code" simply isnt a credible answer. One learns by
doing and examining a running system compiled with debug is one of the
most productive tools in the trainers arsenal.

Next?
 
Reply With Quote
 
Mark McIntyre
Guest
Posts: n/a
 
      03-12-2006
On 11 Mar 2006 23:19:50 GMT, in comp.lang.c , "Richard G. Riley"
<> wrote:

>with a system. I find it terrifying that there seems to be a fair
>number of programmers here who think a debugger is "only for finding bugs"
>: it is a limited and naive view.


is this thread still going, or has my newsprovider regurgitated it?
Either way, i find it terrifying that someone thinks a debugger is for
programme analysis and testing. Yike.
Mark McIntyre
--
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan

----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
 
Reply With Quote
 
CBFalconer
Guest
Posts: n/a
 
      03-12-2006
Keith Thompson wrote:
>

.... snip ...
>
> If I might summarize:
>
> Richard G. Riley really likes debuggers. Not everyone else likes
> them as much as Richard does.
>
> I believe that covers all the relevant points.


Which buggers?

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
More details at: <http://cfaj.freeshell.org/google/>
Also see <http://www.safalra.com/special/googlegroupsreply/>


 
Reply With Quote
 
Ian Collins
Guest
Posts: n/a
 
      03-12-2006
Richard G. Riley wrote:
> On 2006-03-11, Keith Thompson <kst-> wrote:
>
>>If I might summarize:
>>
>>Richard G. Riley really likes debuggers. Not everyone else likes them
>>as much as Richard does.
>>
>>I believe that covers all the relevant points.
>>
>>Next?
>>

>
>
> Very droll.
>
> But not at all what the crux of this is about : what its about is a
> one way of working which can dramatically speed up ones familiarity
> with a system. I find it terrifying that there seems to be a fair
> number of programmers here who think a debugger is "only for finding bugs"
> : it is a limited and naive view.
>

There is the middle ground, read the code first and step tough bits you
can't sus out in the debugger. A decent source browser (one that gives
you callers and callees) is a better tool for the job, it gives you an
overview of the code, rather than the details of one part of it.

Using a debugger as the main tool for familiarising one's self with a
large body of code is a bit like using a microscope to read a book.

--
Ian Collins.
 
Reply With Quote
 
Nick Keighley
Guest
Posts: n/a
 
      03-12-2006
Richard G. Riley wrote:
> On 2006-03-11, Nick Keighley <> wrote:
> > Richard G. Riley wrote:
> >> "Nick"posted the following on 2006-03-11:
> >> > Richard G. Riley wrote:
> >> >> "Chris"posted the following on 2006-03-10:
> >> >> > Richard G. Riley wrote:
> >> >> >> "Nick"posted the following on 2006-03-10:


[ a long debate partly about using a debugger to analyse existing,
working
applications. Richard G. Riley thinks it's a good idea. I (Nick
Keighley) don't]

ok. This is *way* off topic. It has gone on too long. And the post has
grown
to gigantic proportions. I'm *really* going to stop now (I think I said
that
before...).

We are both probably frustratrated that the other doesn't seem to
understand our perefectly reasonable point of view. And everyone else
on
clc is probably even more frustrated that we both keep banging on.

What I do find odd is that we have drawn opposite conclusions for the
same
reason. Neither of us likes doing things manually that can be automated

(sign of a good programmer). So Richard objects to using printf() (or
custom
logger) because it is manual, error prone and may disturb the program,
and prefers using a debugger to achieve the same end. I object to the
use
of a debugger ***for exactly the same reasons*** !

<snip>

> >> I find [a debugger] a good teaching tool to get people up
> >> to speed with an app and its internal data structures : modify on the
> >> fly, symbol tables etc. Cant do that with a print out or printfs.

> >
> > I have *never* had any desire to do these things. Find the bug. Fix
> > the bug. Why would you want to modify things on-the-fly?!

>
> Modify data to test or force a state. Its a basic of debugger use : you can
> force your hand to avoid having to wait for a certain random data
> suite to trigger the bug.
>
> e.g someone says I'm getting a divide by zero somewhere near func().
>
> go to func in debugger, force a zero into the divisor and see why the
> checks arent stopping it. Simple example.


no. Put an assert() in. A modified variable is just for today. An
approriate
assert() lasts forever. Next year when someone casts doubt on the same
function, you simply look at the func() source code and say "nope,
can't
be a divide by zero because there's an assert() to check for that". Fix
it
once, never touch it again.

<snip>

> >> >> I fail to see how analysing existing, successful apps can be anything
> >> >> other than beneficial. It doesnt take away the donkey work of learning
> >> >> the lanugage basics, but it can make text book "science" much more
> >> >> accessible and "real". I cant imagine becoming a programmer without
> >> >> such practice, guidance and "practical training". Its the same in all
> >> >> walks of life.
> >> >
> >> > I think I'll give up here. My point wasn't that important. Just trying
> >> > to make the point that different people do thinks in different ways. Linux
> >> > is not the only platform. Not everyone uses debuggers the way you do
> >>
> >> Nobody said it was : you came flying in with that.

> >
> > riight

>
> You did. Look at the thread. The OP mentioned Linux : I said it was a
> good idea for what he wanted to do : you came in with "hold on hold on
> lets not start an OS war here".


a debugger war is much more fun...

<snip>

> >> > Maybe I'll even get my debugger out and step through a program
> >> > sometime to see if it brings me any insights. Maybe you should try
> >> > a "debugger free day" and try and see what you have to do to manage
> >> > without. Try reasoning about the program. Consider invariants and
> >> > post/pre conditions. Try adding asserts etc.
> >>
> >> If you recall I did mention that a home brew logging system is
> >> prefential to printf :

> >
> > where did the words "homebrew logging system" appear in the paragraph
> > above? I did write a fairly blunt paragraph here. And then thought
> > better of it. Do you know what an invarient is? Design by contract?

>
> I used those words. Its when you wrap whatever underlying logging system is
> convenient to you in a fairly generic calling interface : so you could
> log to files, text consoles, window systems whatever without changing
> the calling code.


I note you didn't say if you knew what "Design by Contract" meant.

<snip>

> >> A debugger isnt the only tool : and I never said it was. What it
> >> can do is allow you to see the flow of an application while watching
> >> live data, allow you to modify that data

> >
> > never felt the need. Not since compilers got fast enough to run during
> > the day.

>
> I really dont understand this. What has that got to do with a debugger?


I've modified variables using the debugger (the "debugger" actually had

toggle switches...) when the run time of the compiler was significant.
If it
took hours to recompile your code then machine code patches and
register
hacking was acceptable. It is no longer necessary (well, sometimes).

<snip>

> >> and to examine and ensure
> >> data typing is consistant from skillful use of register/pointer/memory
> >> examinations : it is why they exist.

> >
> > you examine registers? On a deeply embedded system, ok. But a
> >> server?

>
> I also mentioned memory and pointers. And yes I do. Very useful in
> debugging big C systems.


wow. Culture Shockville. To my shame I couldn't even tell you what
registers
my platform has without STFWing. Ok that's a project for today.

<snip>

> >> The whole crux here is you doubting
> >> that stepping an existing app can help a user understand it : after
> >> many, many and varied projects on various platforms in various
> >> languages I find it incredulous how you could doubt this would be
> >> beneficial. In order to even put in these printfs() you need some
> >> understanding of whats going :


<snip>

> > I'd say the same went (in spades) for stepping. You've got to know
> > where
> > to step. There's source code, case tools, source browsers, source code.
> > I've even resorted to grep to find callers of functions.

>
> grep is ok : if I dont have a decent IDE I use something like emacs
> tags. I have used grep in about 15 years


ok it's a tool of desparation. You * never* use grep?!

<snip>


--
Nick Keighley

Testing can show the presense of bugs, but not their absence.
-- Dijkstra

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[I'm learning C]: Learning to use ucontext Andrey Popp C Programming 5 01-31-2012 01:05 AM
Learning C and Learning Make/Configure/Building/Linking Hal Vaughan C Programming 7 03-21-2006 05:07 PM
e-learning, (collaborative learning environment) collinm Java 1 09-08-2005 09:52 PM
Learning about SMS technology... VM Wireless Networking 2 07-02-2004 02:36 PM
learning VHDL Vilvox VHDL 5 07-20-2003 08:59 AM



Advertisments