Is this the most pointless code ever, or am I missing something?

This is a discussion on Is this the most pointless code ever, or am I missing something? within the C++ Programming forums, part of the General Programming Boards category; While the loop is useless persay, it can be used for other tasks. Hence it is valid I believe. If ...

  1. #16
    I am me, who else?
    Join Date
    Oct 2002
    Posts
    250
    While the loop is useless persay, it can be used for other tasks. Hence it is valid I believe. If the OP never uses it ever, still they learned that it can be used for something, so if nothing else, it was a good learning experience.

  2. #17
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,510
    The question was not if it was valid. The question was what it could be used for. Yes, it can be used for all the things already mentioned. However... all of them would be frown upon. I particularly abhor the idea of using it as an initial construct for a loop to be designed later. I'd better place a very obvious comment to make it very clear that loop is temporary. But then, if I did the comment, why would I need the loop? Right?

    If we are going to enter this kind of debate ... We might as well stop advising people not to use gets(), for instance. Because, really, "It's valid".
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    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.

  3. #18
    I am me, who else?
    Join Date
    Oct 2002
    Posts
    250
    Well I would say that its not as bad as gets() or system("Pause"), it could have use, the aforementioned commands have other things that are just not right with them. They could lead to potentially bad things. I couldn't see that as more than a possible waste of 2 lines. True, you could abuse it to the extreme, but then why bother at all?

    Its not "just" valid, gets() and other bad things like void main, are "valid" but not really usable in the same sense. It really is not a harmful thing. There are different levels of bad, this is probably on the same level as ocassionally slipping in a if( true) for no reason.

  4. #19
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >We might as well stop advising people not to use gets(), for instance. Because, really, "It's valid".
    That's an awful connection. We advise people not to use gets because it's inherently dangerous. That's not quite the same thing as extra code that serves no purpose but causes no harm.

    >However... all of them would be frown upon.
    Really. While I might not be the pinnacle of programming perfection, would you frown on this use? Be careful with absolute statements, I make a hobby of ripping them to shreds.
    My best code is written with the delete key.

  5. #20
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,510
    I didn't mean with my statement to diminish you in any way, Prelude. Simply I'm trying to stress that we seem to be suggesting the do-while loop has its uses by suggesting a use we normally frown upon. It also seems to me like clutching for straws.

    The irony of it all, is that the only good example people can give for a good use to it is macros. That loop exists to help define a macro. But the loop itself has a purpose that has nothing to do with what a do-while is supposed to be. It's an hack, it's an ugly hack, and it's an unecessary hack on a programming language that has no need for macros defined like that.

    We are trying to give the OP an example of an use that we know very well is considered bad code.

    That's all.

    EDIT: Btw, I love your website and have been studying your trees with a lot of interest. I have a thing for trees... Thanks a lot for having put it up. But... Prelude... I'm going to replace those macros
    Last edited by Mario F.; 07-06-2006 at 07:18 PM.
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    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
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >We are trying to give the OP an example of an use that we know very well is considered bad code.
    And I'm trying to get you to see that the concept "bad code" is often subjective. In terms of practicality, if you take a purist's view, the restrictions will probably keep you from writing anything substantial. Also, "bad code" depends on your current perspective. While macros are frowned upon in C++, in C it's not so cut and dry. Finally, "bad code" is in the eye of the beholder unless there's solid proof that it's bad. For example, gets is provably bad, but a pointless loop is not. If your only argument is equivalent to "I don't like it", you have no case.

    >But... Prelude... I'm going to replace those macros
    They're there for a reason. I typically don't make arbitrary choices when it comes to my code. Especially if those choices could be considered bad style.
    My best code is written with the delete key.

  7. #22
    pwns nooblars
    Join Date
    Oct 2005
    Location
    Portland, Or
    Posts
    1,094
    I have had stuff like this in my code that I forgot to remove, it used to have a evaluation, but I needed to test just one interation so I set it to false. Same with commented out code, I have a couple lines here and there in a lot of my projects that there is a line or 2 commented out, since I didn't want to delete it in case I needed (debug purposes usually) it.

  8. #23
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    I used such a thing in PHP once to simulate gotos. (It was rather ugly error handling code.)

    I don't think that there is any good use for it in modern C++. C, yes, but not C++.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Enforcing Machine Code Restrictions?
    By SMurf in forum Tech Board
    Replies: 21
    Last Post: 03-30-2009, 07:34 AM
  2. Errors including <windows.h>
    By jw232 in forum Windows Programming
    Replies: 4
    Last Post: 07-29-2008, 01:29 PM
  3. Avoiding Global variables
    By csonx_p in forum Windows Programming
    Replies: 32
    Last Post: 05-19-2008, 12:17 AM
  4. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  5. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21