<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wikidot="http://www.wikidot.com/rss-namespace">

	<channel>
		<title>Comments for page &quot;A case for unstructured programming&quot;</title>
		<link>http://250bpm.com/forum/t-1283596/a-case-for-unstructured-programming</link>
		<description>Posts in the discussion thread &quot;A case for unstructured programming&quot;</description>
				<copyright></copyright>
		<lastBuildDate>Sat, 01 Aug 2015 21:46:53 +0000</lastBuildDate>
		
					<item>
				<guid>http://250bpm.com/forum/t-1283596#post-2350060</guid>
				<title>(no title)</title>
				<link>http://250bpm.com/forum/t-1283596/a-case-for-unstructured-programming#post-2350060</link>
				<description></description>
				<pubDate>Sat, 01 Aug 2015 17:13:26 +0000</pubDate>
				<wikidot:authorName>martin_sustrik</wikidot:authorName>				<wikidot:authorUserId>939</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>Indentation fixed.</p> <p>As for the question, I would use goto. It's much more readble than do/break/while(0) construct.</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://250bpm.com/forum/t-1283596#post-2350058</guid>
				<title>(no title)</title>
				<link>http://250bpm.com/forum/t-1283596/a-case-for-unstructured-programming#post-2350058</link>
				<description></description>
				<pubDate>Sat, 01 Aug 2015 17:11:13 +0000</pubDate>
				<wikidot:authorName>martin_sustrik</wikidot:authorName>				<wikidot:authorUserId>939</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>Most of serious C code uses goto for error handling. I wouldn't worry much about being seen as a heretic by C++/Java people. Just tell them to check the C best practice.</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://250bpm.com/forum/t-1283596#post-2350055</guid>
				<title>(no title)</title>
				<link>http://250bpm.com/forum/t-1283596/a-case-for-unstructured-programming#post-2350055</link>
				<description></description>
				<pubDate>Sat, 01 Aug 2015 17:05:10 +0000</pubDate>
				<wikidot:authorName>Ian</wikidot:authorName>								<content:encoded>
					<![CDATA[
						 <p>In particular I often have code that looks like this:</p> <div class="code"> <pre> <code>if (obviously_no_result(request)) return null; calculation = check_something(request); if (calculation_shows_no_result(calculation)) return null; if (more_expensive_check_shows_no_result(calculation)) return null; full_calculation = expensive_full_check(request, calculation); if (!full_calculation) return null; result = get_result_structure(request, full_calculation); notify_hooks(result); return result;</code> </pre></div> <p>i.e. the fact that additional calculations are needed between ifs means that else-if cannot be used, and the performance hit of putting all calculations up front is unacceptable when most calls will (intentionally) fail.</p> <p>I've used this style for 20 years for efficiency and clarity. It is much more clear than 'only return once' style code. When I wrote a textbook with an example using this style it garnered a bad Amazon review from someone who complained it showed I was a terrible programmer, because I didn't follow 'best practice' as taught in their Java course. Not that I'm bitter, or anything&#8230;</p> <p>The complaint is that, if I need to do something for every failure (like adding a log, say), it is easy to forget a place to add it. I'm increasingly thinking that goto is actually a pretty good solution, and labels are a form of documentation. Though my need to be seen as non heretical probably stops me from using it in anger:</p> <div class="code"> <pre> <code>if (obviously_no_result(request)) goto no_result; calculation = check_something(request); if (calculation_shows_no_result(calculation)) goto no_result; if (more_expensive_check_shows_no_result(calculation)) goto no_result; full_calculation = expensive_full_check(request, calculation); if (!full_calculation) goto no_result; valid_result: result = get_result_structure(request, full_calculation); notify_hooks(result); return result; no_result: notify_error_hooks(request); return null;</code> </pre></div> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://250bpm.com/forum/t-1283596#post-2343787</guid>
				<title>(no title)</title>
				<link>http://250bpm.com/forum/t-1283596/a-case-for-unstructured-programming#post-2343787</link>
				<description></description>
				<pubDate>Thu, 23 Jul 2015 23:30:22 +0000</pubDate>
				<wikidot:authorName>Tim Janik</wikidot:authorName>								<content:encoded>
					<![CDATA[
						 <p>Sorry about the broken formatting, I didn't realize the indentation will collapse and I can't edit the post now. INDENT(1) is your friend&#8230; ;-)</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://250bpm.com/forum/t-1283596#post-2343786</guid>
				<title>(no title)</title>
				<link>http://250bpm.com/forum/t-1283596/a-case-for-unstructured-programming#post-2343786</link>
				<description></description>
				<pubDate>Thu, 23 Jul 2015 23:27:14 +0000</pubDate>
				<wikidot:authorName>Tim Janik</wikidot:authorName>								<content:encoded>
					<![CDATA[
						 <p>if do_stuff*() require a lot of surrounding context so cannot easily be factored out into a seperate function, would you advocate for using break over nested if()s?</p> <div class="code"> <pre> <code>void foo(void) { setup_do_stuff_context(); do { if(condition1()) { do_stuff1(); break; } if(condition2()) { do_stuff2(); break; } if(condition3()) { do_stuff3(); break; } do_stuff4(); } while (0); teardown_do_stuff_context(); }</code> </pre></div> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://250bpm.com/forum/t-1283596#post-2340555</guid>
				<title>(no title)</title>
				<link>http://250bpm.com/forum/t-1283596/a-case-for-unstructured-programming#post-2340555</link>
				<description></description>
				<pubDate>Sat, 18 Jul 2015 13:16:15 +0000</pubDate>
				<wikidot:authorName>martin_sustrik</wikidot:authorName>				<wikidot:authorUserId>939</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>Yeah, I often do the same.</p> <p>However, more often flattening the structure is harder to achieve and one must actually think and experiment with moving pieces around.</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://250bpm.com/forum/t-1283596#post-2340536</guid>
				<title>(no title)</title>
				<link>http://250bpm.com/forum/t-1283596/a-case-for-unstructured-programming#post-2340536</link>
				<description></description>
				<pubDate>Sat, 18 Jul 2015 12:29:29 +0000</pubDate>
				<wikidot:authorName>Brian Oxley</wikidot:authorName>								<content:encoded>
					<![CDATA[
						 <p>Beautiful reference!</p> <p>I often use early return as illustrated following the principal of avoiding deep nesting. One of my favorite refactorings is adding return to a the first branch and removing the matching else with an outdent of its block.</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://250bpm.com/forum/t-1283596#post-2340458</guid>
				<title>(no title)</title>
				<link>http://250bpm.com/forum/t-1283596/a-case-for-unstructured-programming#post-2340458</link>
				<description></description>
				<pubDate>Sat, 18 Jul 2015 07:58:40 +0000</pubDate>
				<wikidot:authorName>martin_sustrik</wikidot:authorName>				<wikidot:authorUserId>939</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>I've showed the simplest possible example. If you look at real-world examples you'll find out that lot of stuff out there cannot be nicified in this way.</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://250bpm.com/forum/t-1283596#post-2340455</guid>
				<title>(no title)</title>
				<link>http://250bpm.com/forum/t-1283596/a-case-for-unstructured-programming#post-2340455</link>
				<description></description>
				<pubDate>Sat, 18 Jul 2015 07:52:15 +0000</pubDate>
				<wikidot:authorName>catwell</wikidot:authorName>								<content:encoded>
					<![CDATA[
						 <p>Well, the way you presented your &quot;ugly&quot; code is a bit convoluted. You would probably write it like this:</p> <div class="code"> <pre> <code>void foo(void) { if (condition1()) do_stuff1(); else if (condition2()) do_stuff2(); else if (condition3()) do_stuff3(); else do_stuff4(); }</code> </pre></div> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://250bpm.com/forum/t-1283596#post-2340449</guid>
				<title>(no title)</title>
				<link>http://250bpm.com/forum/t-1283596/a-case-for-unstructured-programming#post-2340449</link>
				<description></description>
				<pubDate>Sat, 18 Jul 2015 07:40:59 +0000</pubDate>
				<wikidot:authorName>Mikhail Gusarov</wikidot:authorName>								<content:encoded>
					<![CDATA[
						 <p>One of the codebases I had been working on pushed this style even further:</p> <div class="code"> <pre> <code>void foo(void) { if (condition1()) DO_RETURN(do_stuff1()); if (condition2()) DO_RETURN(do_stuff2()); do_stuff3(); }</code> </pre></div> 
				 	]]>
				</content:encoded>							</item>
				</channel>
</rss>