C: Nested Ifs or Gotos

后端 未结 5 2243
温柔的废话
温柔的废话 2021-02-15 03:45

What is the best way to manage resources for a C program. Should I use a nested if structure or should I use goto statements?

I am aware there is a lot

5条回答
  •  北荒
    北荒 (楼主)
    2021-02-15 04:31

    No doubt about it Dijkstra was a formidable personality in the programming world. His Goto Considered Harmful paper was way overblown. Yes GoTo may be used indiscriminately and can be harmfull but many think an outright ban on GoTo is not warranted. Knuth provided a very well reasoned rebuttal to Dijkstra in: Structured Programming with GO TOs

    Read Knuth's paper, you will find that your GoTo pattern is one of the good uses for GoTo.

    BTW, Dijkstra is very quotable for a number of other things too. How about:

    • Object-oriented programming is an exceptionally bad idea which could only have originated in California.

    Dijkstra was a great mathematician and made huge contributions to computer science. However, I don't think he had to deal with, or was interested in, the day to day type stuff that 99.99 percent of our programs do.

    Use GoTo only with reason and structure. Use them rarely. But do use them.

提交回复
热议问题