Recent Posts
Free Subdomains
Want a pastebin.com sub-domain for your community?
learn more...
What is pastebin?
Pastebin is a website that hosts all your text & code on dedicated servers for easy sharing.
learn more...
Learn a little bit about the new Pastebin.com on our help page. hide message
By Anonymous on the 16th of Apr 2009 07:02:42 PM Download | Raw | Embed | Report
  1. /* Problem: Inefficient and confusing */
  2. int foo(int bar)
  3. {
  4.         int return_value = 0;
  5.         int doing_okay = 1;
  6.         doing_okay = do_something( bar );
  7.         if (doing_okay)
  8.         {
  9.                 doing_okay = init_stuff();
  10.         }
  11.         if (doing_okay)
  12.         {
  13.                 doing_okay = prepare_stuff();
  14.         }
  15.         if (doing_okay)
  16.         {
  17.                 return_value = do_the_thing( bar );
  18.         }
  19.         return return_value;
  20. }
  21.  
  22. /* Problem: Getting murdered by PHB's for using goto */
  23. int foo(int bar)
  24. {
  25.         if (!do_something( bar )) {
  26.                 goto error;
  27.         }
  28.         if (!init_stuff( bar )) {
  29.                 goto error;
  30.         }
  31.         if (!prepare_stuff( bar )) {
  32.                 goto error;
  33.         }
  34.         return do_the_thing( bar );
  35. error:
  36.         return 0;
  37. }
  38.  
  39. /* Problem: Too many nested blocks, horrible */
  40. int foo(int bar)
  41. {
  42.         int return_value = 0;
  43.         if (do_something( bar )) {
  44.                 if (init_stuff( bar )) {
  45.                         if (prepare_stuff( bar )) {
  46.                                 return_value = do_the_thing( bar );
  47.                          }
  48.                 }
  49.         }
  50.         return return_value;
  51. }
  52.  
  53. /* Problem: Too awesome */
  54. int foo(int bar)
  55. {
  56.         return
  57.         do_something(bar) &&
  58.         init_stuff(bar) &&
  59.         prepare_stuff(bar) &&
  60.         do_the_thing(bar);
  61. }
Submit a correction or amendment below. [ previous version ] | [ difference ] | Make A New Post
To highlight particular lines, prefix each line with @@
Syntax highlighting:
Post expiration:
Post exposure:
Name / Title:
Email: