Thread: Now that I'm used to C++, printf() >>>>>> cout >> endl;

  1. #16
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    You see, when it comes to debugging, people will start talking and talking.
    Really? About what specifically?

    However, as usually, the actual good info they spread is just a 30% of the whole talking.
    I don't know if I can agree with you. I think you have to write many different kinds of programs to experiment with a variety of debugging techniques and in order to use all of the debugger's features. You probably are not going to use everything all the time. If someone mentions a specific feature, though, it's worth looking into instead of pretending it doesn't exist. If I acted like that, then I would be ignoring people who teach me things.

  2. #17
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,694
    Quote Originally Posted by whiteflags View Post
    Really? About what specifically?
    Yes really. Undefined.

    Quote Originally Posted by whiteflags View Post
    I don't know if I can agree with you. I think you have to write many different kinds of programs to experiment with a variety of debugging techniques and in order to use all of the debugger's features. You probably are not going to use everything all the time. If someone mentions a specific feature, though, it's worth looking into instead of pretending it doesn't exist. If I acted like that, then I would be ignoring people who teach me things.
    You missed the point. But anyway, let's not get off topic.
    // If you are having a burning desire to find out what I meant pm me.
    Code - functions and small libraries I use


    It’s 2014 and I still use printf() for debugging.


    "Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson

  3. #18
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    Why a PM? Explain to us why you -- who admits not understanding debuggers very well -- speak publicly that "when it comes to debugging, people will start talking and talking. However, as usually, the actual good info they spread is just a 30% of the whole talking" (sic)?

    I'm also curious as to who has ever told you that it is a good idea to debug a program with print statements. Or why do you think it is a good idea to spread that concept to beginners to the language when you yourself don't understand debuggers.

    Let's talk...
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  4. #19
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    There are probably better ways to do this, but this was the gist of our conversation. It has nothing to do with debugging, per se:
    You missed the point. But anyway, let's not get off topic.
    // If you are having a burning desire to find out what I meant pm me.
    What?
    When people talk, in general, they tend not to be laconic (with the meaning that Greek people say it, not something bad).
    I mean, that usually people, have two say one or two things (thus two sentences max), but they tend to say about 5-6.
    Oh, so it's just a general complaint about brevity. That's one way of looking at it I guess. I would say particularly with programming problems you have to say a lot to communicate effectively. Personally, I try to be concise, but more often than not, a situation is complex enough that I need to lay groundwork in order to be understood.
    I see your point. I believe that the ideal thing to express something is with the minimum number of words needed. In other words, say the minimum number of words and give the maximum amount of understanding. That's what laconic really means. Ancient Spartans (not all Ancient Greeks!!) were the leaders of the laconic way of speaking. The word laconic comes from their inhabitant.

  5. #20
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    Kind of funny since printf statements are a verbose, not laconic, approach to debugging.

    Hypocritical reasoning is another Greek invention.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  6. #21
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,694
    Quote Originally Posted by Mario F. View Post
    Kind of funny since printf statements are a verbose, not laconic, approach to debugging.
    This is relevant. I want just the value of a variable at the i-th loop. printf seems a laconic solution.
    Quote Originally Posted by Mario F. View Post
    Hypocritical reasoning is another Greek invention.
    One of the numerous.
    Are you saying that I am lying?
    Code - functions and small libraries I use


    It’s 2014 and I still use printf() for debugging.


    "Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson

  7. #22
    Make Fortran great again
    Join Date
    Sep 2009
    Posts
    1,413
    Seems like you guys are talking about different kinds of debugging, i.e. segfaults/memory problems vs. output. Like missing some code in a function that handles a custom data structure vs. missing a plus sign in an equation. I frequently use print statements, in whatever language, because my problems almost always have to do with equations and the resulting output since I'm rarely implementing data structures or allocating memory on my own.

  8. #23
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,694
    Memory problems frequently come from wrongly maths.
    Code - functions and small libraries I use


    It’s 2014 and I still use printf() for debugging.


    "Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson

  9. #24
    Make Fortran great again
    Join Date
    Sep 2009
    Posts
    1,413
    Quote Originally Posted by std10093 View Post
    Memory problems frequently come from wrongly maths.
    Then I don't understand your desire to use print statements. If we're talking about memory problems, debugger all the way.

    My main lines of work include PLC programming and CAD-related programming nowadays. In the case of PLC programming, at least with Allen-Bradley, debugging involves reviewing the rungs of whole routines to see what caused an error anyway. You could say their software has a built-in debugger since it directs you to the rung that caused the fault. In the case of CAD-related programming, if the result isn't in the form of what I expected, I used the wrong function. If it's not in the right proportions, I screwed up an equation.

  10. #25
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,694
    Maybe you are right. I am not comfortable enough yet with the gdb.
    However, printing always worked for me until now. Maybe it won't in the future. I remember that I was using gdb for some memory problem, but could not locate the source of the problem, without using printings. bdg said to me where and which variable causes the boom and some other info.
    Code - functions and small libraries I use


    It’s 2014 and I still use printf() for debugging.


    "Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson

  11. #26
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    Quote Originally Posted by Epy View Post
    Seems like you guys are talking about different kinds of debugging, i.e. segfaults/memory problems vs. output.
    We are talking of debugging in general.

    Tracing code execution through print statements essentially amount to a poor man dynamic analysis, which is merely an aspect of debugging. Naturally we won't hear anyone refusing print statements as a debugging technique, exactly because... it is a debugging technique. But what is being discussed here (and the OP should be read again for proper context) is the idea that debugging can be done through tracing.

    There's little that can be said that we don't know already about the complications of tracing. We all do it, even when coding outside the console. But we do it sparingly and within the context of dynamic analysis. But for the benefit of the OP, I'll list here some of the problems with tracing, and that can be easily solved with the help of a proper debugging tool (like GDB, not valgrind), but not only (see below for a better alternative to tracing that doesn't involve a debugger):


    • Print statements are awkward to write, often because they tend to require full formatting in order to gain visibility outside the program normal output. I suspect that even a seasoned C/C++ developer tends to spend time writing and correcting format in order to obtain a proper debugging output. For this reason, seems counterproductive to waste time writing and correcting debug code, when I should be writing and correcting program code.
    • Debugging is a cyclic activity. We tend to have to revisit old code after having introduced new code. As is the case with tracing, we want to get rid of all those extraneous print statements as soon as possible. But we will eventually need to rewrite them again when some future code affects the runtime of already debugged code and forces us to maintain that code. As you can probably guess, MutantJohn, you will end up rewriting a lot of print statements if this is your only debugging technique. Seems a terrible way to spend your time, when you think that ultimately your goal is to write a working program in a timely fashion.
    • As is often the case when I trace, I end up having to maintain my tracing code. To avoid the previous problem, I tend to leave my tracing code alive and not delete it. I comment it, or just leave it running. But this produces another problem: I end up having to maintain that code. I need to organize it, correct it when future code is introduced, or completely rewrite it. This means that my tracing code becomes de facto code, sometimes, ironically, it too requiring debugging. Now, on what code do you prefer to be spending your time?


    Tracing is an interesting quick-and-dirty debugging technique. But it should only be practiced in the context of dynamic code analysis. That is, when you are required to inspect output under several input conditions. But even then, it comes at a cost. The "quick" moniker isn't as obvious as you may think, since a proper debugger will offer you with memory inspection tools that surpass most of what you can do with print statements:


    • Watch variables values and much more at runtime
    • Alter variables at runtime and witness the effects
    • Break code execution based on many factors (when a variable has a certain value, when its value falls within a range, even after a variable has changed X amount of times).
    • Step over, step into and step back(!) in code.


    With more "recent" program techniques, tracing has even lost whatever little charm it had left. The day you start learning about Unit Testing and experiment with Test-Driven Development (TDD), assuming you adopt these programming methodologies, you'll realize they completely replace the need for dynamic code analysis as you know it. In fact, even if you end up not adopting Agile Development techniques, you may end up incorporating Unit Testing as an important part of your programming activity, even if not following to the letter the principles of TDD. Many programmers do this.

    It may be that debug print statements will always end up finding a place in your code. I know they have a place on mine (and many others in here). But they are rare, they are not used to replace a debugger, and -- at least in my case -- they will often display my lazy self in a most unproductive way.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  12. #27
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,694
    Mario said:
    Hypocritical reasoning is another Greek invention.
    Quote Originally Posted by std10093 View Post
    One of the numerous.
    Are you saying that I am lying?
    You forgot to answer? Please read the whole answers of others.......
    Code - functions and small libraries I use


    It’s 2014 and I still use printf() for debugging.


    "Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson

  13. #28
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    Quote Originally Posted by std10093 View Post
    Are you saying that I am lying?
    Yes.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  14. #29
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,694
    Ancient Greeks did invented many many things. But people's ability to be wrong or correct is not a Greek product.

    Now that I'm used to C++, printf() &gt;&gt;&gt;&gt;&gt;&gt; cout &gt;&gt; endl;-paris_tuileries_garden_facepalm_statue-jpg
    Code - functions and small libraries I use


    It’s 2014 and I still use printf() for debugging.


    "Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson

  15. #30
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,694
    I feel very upset (yes I know that some days are passed from this) about the fact that someone claims that I am lying.

    Claims are claims and I respect the right for everyone to assume things. Assumptions are ok, but they are not facts. For example, Mario made the assumption that I am lying and of course he is wrong.

    But my target is not to argue with him. As a matter of fact, Mario is actually what he writes below his name (but he has a typo, since one letter is wrong). Of course this is an opinion, my opinion, so it may not be a fact. However, in my mind, this is surely fact, based on what I have seemed him saying in the General-discussions (either to me, or to other members).

    What I am interested in, is all the other, to whom I want to make clear that I did not lie!

    I do not want this to get way off topic so I am putting a period here. However, pm are welcome.
    Code - functions and small libraries I use


    It’s 2014 and I still use printf() for debugging.


    "Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. cout code, endl, and \n help?
    By ZezXion in forum C++ Programming
    Replies: 5
    Last Post: 11-15-2012, 06:16 PM
  2. printf to cout
    By crzy in forum C++ Programming
    Replies: 9
    Last Post: 04-28-2008, 03:05 PM
  3. cout << oct << -12 << endl; ?
    By manav in forum C++ Programming
    Replies: 1
    Last Post: 04-16-2008, 03:39 AM
  4. cout << SunTradingLLC << "is looking for C++ Software Developers" << endl;
    By sun trading in forum Projects and Job Recruitment
    Replies: 1
    Last Post: 04-02-2008, 11:48 AM
  5. printf/cout
    By Ivan! in forum C++ Programming
    Replies: 4
    Last Post: 03-02-2003, 03:23 PM