<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: code-formatting people: I need your help</title>
	<atom:link href="http://blog.tplus1.com/index.php/2008/12/12/code-formatting-people-i-need-your-help/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.tplus1.com/index.php/2008/12/12/code-formatting-people-i-need-your-help/</link>
	<description>Programming, gardening, economics, life in Cleveland Heights</description>
	<lastBuildDate>Sat, 04 Feb 2012 03:03:50 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Marius Gedminas</title>
		<link>http://blog.tplus1.com/index.php/2008/12/12/code-formatting-people-i-need-your-help/comment-page-1/#comment-3446</link>
		<dc:creator>Marius Gedminas</dc:creator>
		<pubDate>Tue, 16 Dec 2008 20:34:09 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tplus1.com/?p=264#comment-3446</guid>
		<description>Here&#039;s how I would format these:&lt;br&gt;&lt;br&gt;&lt;pre&gt;&lt;br&gt;cat1, cat2, cat3, cat4, cat5 = [self.categories[x] for x in range(1, 6)]&lt;br&gt;&lt;/pre&gt;&lt;br&gt;&lt;br&gt;since it fits in 78 columns (duh!).  If it didn&#039;t, I&#039;d try&lt;br&gt;&lt;br&gt;&lt;pre&gt;&lt;br&gt;cat1, cat2, cat3, cat4, cat5 = [self.categories[x]&lt;br&gt;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;for x in range(1, 6)]&lt;br&gt;&lt;/pre&gt;&lt;br&gt;&lt;br&gt;and&lt;br&gt;&lt;br&gt;&lt;pre&gt;&lt;br&gt;cat1, cat2, cat3, cat4, cat5 = [&lt;br&gt;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;self.categories[x] for x in range(1, 6)]&lt;br&gt;&lt;/pre&gt;&lt;br&gt;&lt;br&gt;On to the second example.  I find those repeated &quot;1 if condition else None&quot;&lt;br&gt;expressions annoying; surely a helper can make them readable&lt;br&gt;&lt;br&gt;&lt;pre&gt;&lt;br&gt;def output_bool(self, x):&lt;br&gt;&#160;&#160;&#160;&#160;return 1 if x else None&lt;br&gt;&lt;/pre&gt;&lt;br&gt;&lt;br&gt;I&#039;d name that helper $outputformat_bool for whatever output format you&#039;re&lt;br&gt;producing.&lt;br&gt;&lt;br&gt;Next, I&#039;d be inclined to put every tuple element on a separate line, if at&lt;br&gt;least one of them is so large that it doesn&#039;t fit on a single line.&lt;br&gt;&lt;br&gt;&lt;pre&gt;&lt;br&gt;def my_send_methods(self, SendMethod, disabled=False):&lt;br&gt;&#160;&#160;&#160;&#160;return [(x.id,&lt;br&gt;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;x.display_name,&lt;br&gt;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;dict(selected=output_bool(x == self.preferred_send_method),&lt;br&gt;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;disabled=output_bool(disabled)),&lt;br&gt;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;) for x in SendMethod.constants.values()]&lt;br&gt;&lt;/pre&gt;&lt;br&gt;&lt;br&gt;For the third example, I see your argument, but I think the intimidation factor&lt;br&gt;of a single expression spanning 9 lines of code is worse than having people&lt;br&gt;explicitly make sure the expressions are independent:&lt;br&gt;&lt;br&gt;&lt;pre&gt;&lt;br&gt;employees = ([(0, &#039;None&#039;)] +&lt;br&gt;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;[(x.id, x.display_name,&lt;br&gt;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;dict(selected=output_bool(x.id == employee_id)))&lt;br&gt;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;for x in v2org.employees])&lt;br&gt;locations = [(x.id, x.display_name,&lt;br&gt;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;dict(selected=output_bool(x.id == location_id))&lt;br&gt;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;for x in v2org.locations]&lt;br&gt;statuses = [(x.id, x.display_name,&lt;br&gt;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;dict(selected=output_bool(x.id == status_id))&lt;br&gt;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;for x in model.ShiftStatus.select()]&lt;br&gt;return dict(htmlclass=&quot;advancedscheduling&quot;, v2org=v2org, name=name,&lt;br&gt;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;employees=employees, locations=locations, statuses=statuses)&lt;br&gt;&lt;/pre&gt;&lt;br&gt;&lt;br&gt;Although this particular example has enough regularities to want to extract&lt;br&gt;them into a helper&lt;br&gt;&lt;br&gt;&lt;pre&gt;&lt;br&gt;def item_list(items, selected_id):&lt;br&gt;&#160;&#160;&#160;&#160;return [(x.id, x.display_name,&lt;br&gt;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;dict(selected=output_bool(x.id == selected_id))&lt;br&gt;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;for x in items]&lt;br&gt;&lt;br&gt;employees = [(0, &#039;None&#039;)] + item_list(v2org.employees, employee_id)&lt;br&gt;locations = item_list(v2org.locations, location_id)&lt;br&gt;statuses = item_list(model.ShiftStatus.select(), status_id)&lt;br&gt;return dict(htmlclass=&quot;advancedscheduling&quot;, v2org=v2org, name=name,&lt;br&gt;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;employees=employees, locations=locations, statuses=statuses)&lt;br&gt;&lt;/pre&gt;&lt;br&gt;&lt;br&gt;HTH,</description>
		<content:encoded><![CDATA[<p>Here&#39;s how I would format these:</p>
<p><pre>&lt;br&gt;cat1, cat2, cat3, cat4, cat5 = [self.categories[x] for x in range(1, 6)]&lt;br&gt;</pre></p>
<p>since it fits in 78 columns (duh!).  If it didn&#39;t, I&#39;d try</p>
<p><pre>&lt;br&gt;cat1, cat2, cat3, cat4, cat5 = [self.categories[x]&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;for x in range(1, 6)]&lt;br&gt;</pre></p>
<p>and</p>
<p><pre>&lt;br&gt;cat1, cat2, cat3, cat4, cat5 = [&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;self.categories[x] for x in range(1, 6)]&lt;br&gt;</pre></p>
<p>On to the second example.  I find those repeated &#8220;1 if condition else None&#8221;<br />expressions annoying; surely a helper can make them readable</p>
<p><pre>&lt;br&gt;def output_bool(self, x):&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return 1 if x else None&lt;br&gt;</pre></p>
<p>I&#39;d name that helper $outputformat_bool for whatever output format you&#39;re<br />producing.</p>
<p>Next, I&#39;d be inclined to put every tuple element on a separate line, if at<br />least one of them is so large that it doesn&#39;t fit on a single line.</p>
<p><pre>&lt;br&gt;def my_send_methods(self, SendMethod, disabled=False):&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return [(x.id,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;x.display_name,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;dict(selected=output_bool(x == self.preferred_send_method),&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;disabled=output_bool(disabled)),&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;) for x in SendMethod.constants.values()]&lt;br&gt;</pre></p>
<p>For the third example, I see your argument, but I think the intimidation factor<br />of a single expression spanning 9 lines of code is worse than having people<br />explicitly make sure the expressions are independent:</p>
<p><pre>&lt;br&gt;employees = ([(0, &amp;#39;None&amp;#39;)] +&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[(x.id, x.display_name,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;dict(selected=output_bool(x.id == employee_id)))&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;for x in v2org.employees])&lt;br&gt;locations = [(x.id, x.display_name,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;dict(selected=output_bool(x.id == location_id))&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;for x in v2org.locations]&lt;br&gt;statuses = [(x.id, x.display_name,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;dict(selected=output_bool(x.id == status_id))&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;for x in model.ShiftStatus.select()]&lt;br&gt;return dict(htmlclass=&quot;advancedscheduling&quot;, v2org=v2org, name=name,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;employees=employees, locations=locations, statuses=statuses)&lt;br&gt;</pre></p>
<p>Although this particular example has enough regularities to want to extract<br />them into a helper</p>
<p><pre>&lt;br&gt;def item_list(items, selected_id):&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return [(x.id, x.display_name,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;dict(selected=output_bool(x.id == selected_id))&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;for x in items]&lt;br&gt;&lt;br&gt;employees = [(0, &amp;#39;None&amp;#39;)] + item_list(v2org.employees, employee_id)&lt;br&gt;locations = item_list(v2org.locations, location_id)&lt;br&gt;statuses = item_list(model.ShiftStatus.select(), status_id)&lt;br&gt;return dict(htmlclass=&quot;advancedscheduling&quot;, v2org=v2org, name=name,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;employees=employees, locations=locations, statuses=statuses)&lt;br&gt;</pre></p>
<p>HTH,</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matt Wilson</title>
		<link>http://blog.tplus1.com/index.php/2008/12/12/code-formatting-people-i-need-your-help/comment-page-1/#comment-3447</link>
		<dc:creator>Matt Wilson</dc:creator>
		<pubDate>Tue, 16 Dec 2008 19:55:15 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tplus1.com/?p=264#comment-3447</guid>
		<description>Marius, thanks for the feedback!</description>
		<content:encoded><![CDATA[<p>Marius, thanks for the feedback!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Marius Gedminas</title>
		<link>http://blog.tplus1.com/index.php/2008/12/12/code-formatting-people-i-need-your-help/comment-page-1/#comment-1350</link>
		<dc:creator>Marius Gedminas</dc:creator>
		<pubDate>Tue, 16 Dec 2008 15:34:09 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tplus1.com/?p=264#comment-1350</guid>
		<description>Here&#039;s how I would format these:&lt;br&gt;&lt;br&gt;&lt;pre&gt;&lt;br&gt;cat1, cat2, cat3, cat4, cat5 = [self.categories[x] for x in range(1, 6)]&lt;br&gt;&lt;/pre&gt;&lt;br&gt;&lt;br&gt;since it fits in 78 columns (duh!).  If it didn&#039;t, I&#039;d try&lt;br&gt;&lt;br&gt;&lt;pre&gt;&lt;br&gt;cat1, cat2, cat3, cat4, cat5 = [self.categories[x]&lt;br&gt;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;for x in range(1, 6)]&lt;br&gt;&lt;/pre&gt;&lt;br&gt;&lt;br&gt;and&lt;br&gt;&lt;br&gt;&lt;pre&gt;&lt;br&gt;cat1, cat2, cat3, cat4, cat5 = [&lt;br&gt;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;self.categories[x] for x in range(1, 6)]&lt;br&gt;&lt;/pre&gt;&lt;br&gt;&lt;br&gt;On to the second example.  I find those repeated &quot;1 if condition else None&quot;&lt;br&gt;expressions annoying; surely a helper can make them readable&lt;br&gt;&lt;br&gt;&lt;pre&gt;&lt;br&gt;def output_bool(self, x):&lt;br&gt;&#160;&#160;&#160;&#160;return 1 if x else None&lt;br&gt;&lt;/pre&gt;&lt;br&gt;&lt;br&gt;I&#039;d name that helper $outputformat_bool for whatever output format you&#039;re&lt;br&gt;producing.&lt;br&gt;&lt;br&gt;Next, I&#039;d be inclined to put every tuple element on a separate line, if at&lt;br&gt;least one of them is so large that it doesn&#039;t fit on a single line.&lt;br&gt;&lt;br&gt;&lt;pre&gt;&lt;br&gt;def my_send_methods(self, SendMethod, disabled=False):&lt;br&gt;&#160;&#160;&#160;&#160;return [(x.id,&lt;br&gt;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;x.display_name,&lt;br&gt;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;dict(selected=output_bool(x == self.preferred_send_method),&lt;br&gt;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;disabled=output_bool(disabled)),&lt;br&gt;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;) for x in SendMethod.constants.values()]&lt;br&gt;&lt;/pre&gt;&lt;br&gt;&lt;br&gt;For the third example, I see your argument, but I think the intimidation factor&lt;br&gt;of a single expression spanning 9 lines of code is worse than having people&lt;br&gt;explicitly make sure the expressions are independent:&lt;br&gt;&lt;br&gt;&lt;pre&gt;&lt;br&gt;employees = ([(0, &#039;None&#039;)] +&lt;br&gt;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;[(x.id, x.display_name,&lt;br&gt;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;dict(selected=output_bool(x.id == employee_id)))&lt;br&gt;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;for x in v2org.employees])&lt;br&gt;locations = [(x.id, x.display_name,&lt;br&gt;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;dict(selected=output_bool(x.id == location_id))&lt;br&gt;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;for x in v2org.locations]&lt;br&gt;statuses = [(x.id, x.display_name,&lt;br&gt;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;dict(selected=output_bool(x.id == status_id))&lt;br&gt;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;for x in model.ShiftStatus.select()]&lt;br&gt;return dict(htmlclass=&quot;advancedscheduling&quot;, v2org=v2org, name=name,&lt;br&gt;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;employees=employees, locations=locations, statuses=statuses)&lt;br&gt;&lt;/pre&gt;&lt;br&gt;&lt;br&gt;Although this particular example has enough regularities to want to extract&lt;br&gt;them into a helper&lt;br&gt;&lt;br&gt;&lt;pre&gt;&lt;br&gt;def item_list(items, selected_id):&lt;br&gt;&#160;&#160;&#160;&#160;return [(x.id, x.display_name,&lt;br&gt;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;dict(selected=output_bool(x.id == selected_id))&lt;br&gt;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;for x in items]&lt;br&gt;&lt;br&gt;employees = [(0, &#039;None&#039;)] + item_list(v2org.employees, employee_id)&lt;br&gt;locations = item_list(v2org.locations, location_id)&lt;br&gt;statuses = item_list(model.ShiftStatus.select(), status_id)&lt;br&gt;return dict(htmlclass=&quot;advancedscheduling&quot;, v2org=v2org, name=name,&lt;br&gt;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;employees=employees, locations=locations, statuses=statuses)&lt;br&gt;&lt;/pre&gt;&lt;br&gt;&lt;br&gt;HTH,</description>
		<content:encoded><![CDATA[<p>Here&#39;s how I would format these:</p>
<p>&lt;pre&gt;<br />cat1, cat2, cat3, cat4, cat5 = [self.categories[x] for x in range(1, 6)]<br />&lt;/pre&gt;</p>
<p>since it fits in 78 columns (duh!).  If it didn&#39;t, I&#39;d try</p>
<p>&lt;pre&gt;<br />cat1, cat2, cat3, cat4, cat5 = [self.categories[x]<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for x in range(1, 6)]<br />&lt;/pre&gt;</p>
<p>and</p>
<p>&lt;pre&gt;<br />cat1, cat2, cat3, cat4, cat5 = [<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.categories[x] for x in range(1, 6)]<br />&lt;/pre&gt;</p>
<p>On to the second example.  I find those repeated &#8220;1 if condition else None&#8221;<br />expressions annoying; surely a helper can make them readable</p>
<p>&lt;pre&gt;<br />def output_bool(self, x):<br />&nbsp;&nbsp;&nbsp;&nbsp;return 1 if x else None<br />&lt;/pre&gt;</p>
<p>I&#39;d name that helper $outputformat_bool for whatever output format you&#39;re<br />producing.</p>
<p>Next, I&#39;d be inclined to put every tuple element on a separate line, if at<br />least one of them is so large that it doesn&#39;t fit on a single line.</p>
<p>&lt;pre&gt;<br />def my_send_methods(self, SendMethod, disabled=False):<br />&nbsp;&nbsp;&nbsp;&nbsp;return [(x.id,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x.display_name,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dict(selected=output_bool(x == self.preferred_send_method),<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;disabled=output_bool(disabled)),<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;) for x in SendMethod.constants.values()]<br />&lt;/pre&gt;</p>
<p>For the third example, I see your argument, but I think the intimidation factor<br />of a single expression spanning 9 lines of code is worse than having people<br />explicitly make sure the expressions are independent:</p>
<p>&lt;pre&gt;<br />employees = ([(0, &#39;None&#39;)] +<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[(x.id, x.display_name,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dict(selected=output_bool(x.id == employee_id)))<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for x in v2org.employees])<br />locations = [(x.id, x.display_name,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dict(selected=output_bool(x.id == location_id))<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for x in v2org.locations]<br />statuses = [(x.id, x.display_name,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dict(selected=output_bool(x.id == status_id))<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for x in model.ShiftStatus.select()]<br />return dict(htmlclass=&#8221;advancedscheduling&#8221;, v2org=v2org, name=name,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;employees=employees, locations=locations, statuses=statuses)<br />&lt;/pre&gt;</p>
<p>Although this particular example has enough regularities to want to extract<br />them into a helper</p>
<p>&lt;pre&gt;<br />def item_list(items, selected_id):<br />&nbsp;&nbsp;&nbsp;&nbsp;return [(x.id, x.display_name,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dict(selected=output_bool(x.id == selected_id))<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for x in items]</p>
<p>employees = [(0, &#39;None&#39;)] + item_list(v2org.employees, employee_id)<br />locations = item_list(v2org.locations, location_id)<br />statuses = item_list(model.ShiftStatus.select(), status_id)<br />return dict(htmlclass=&#8221;advancedscheduling&#8221;, v2org=v2org, name=name,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;employees=employees, locations=locations, statuses=statuses)<br />&lt;/pre&gt;</p>
<p>HTH,</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matt Wilson</title>
		<link>http://blog.tplus1.com/index.php/2008/12/12/code-formatting-people-i-need-your-help/comment-page-1/#comment-1351</link>
		<dc:creator>Matt Wilson</dc:creator>
		<pubDate>Tue, 16 Dec 2008 14:55:15 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tplus1.com/?p=264#comment-1351</guid>
		<description>Marius, thanks for the feedback!</description>
		<content:encoded><![CDATA[<p>Marius, thanks for the feedback!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: nes</title>
		<link>http://blog.tplus1.com/index.php/2008/12/12/code-formatting-people-i-need-your-help/comment-page-1/#comment-1362</link>
		<dc:creator>nes</dc:creator>
		<pubDate>Mon, 15 Dec 2008 21:55:05 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tplus1.com/?p=264#comment-1362</guid>
		<description>&lt;pre&gt; &lt;code&gt;&lt;br&gt;The only real gripe I have with the non-standard bool values. If you must have a bool that can’t be used to do arithmetics create some kind of custom Matt bool:&lt;br&gt;&lt;br&gt;class mbool:&lt;br&gt;    def __init__(self,expr):&lt;br&gt;        self.val=bool(expr)&lt;br&gt;    def __nonzero__(self):&lt;br&gt;        return self.val&lt;br&gt;    def __bool__(self):&lt;br&gt;        return self.val&lt;br&gt;&lt;br&gt;then you can also extract the repeating part:&lt;br&gt;&lt;br&gt;def selected_lst(org_entity, select_id):&lt;br&gt;    return [(x.id, x.display_name, {&#039;selected&#039;:mbool(x.id == status_id)})&lt;br&gt;            for x in org_entity]&lt;br&gt;&lt;br&gt;Which allows you to say:&lt;br&gt;return dict(&lt;br&gt;    htmlclass=&quot;advancedscheduling&quot;,&lt;br&gt;    v2org=v2org,&lt;br&gt;    name=name,&lt;br&gt;    employees=[(0, &#039;None&#039;)] + selected_lst(v2org.employees,employee_id),&lt;br&gt;    locations=selected_lst(v2org.locations,location_id),&lt;br&gt;    statuses=selected_lst(model_ShiftStatus.select(),status_id),&lt;br&gt;)&lt;br&gt;&lt;br&gt;&lt;/code&gt; &lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>&lt;pre&gt; <code>&lt;br&gt;The only real gripe I have with the non-standard bool values. If you must have a bool that can’t be used to do arithmetics create some kind of custom Matt bool:&lt;br&gt;&lt;br&gt;class mbool:&lt;br&gt;&nbsp;&nbsp;&nbsp;&nbsp;def __init__(self,expr):&lt;br&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.val=bool(expr)&lt;br&gt;&nbsp;&nbsp;&nbsp;&nbsp;def __nonzero__(self):&lt;br&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return self.val&lt;br&gt;&nbsp;&nbsp;&nbsp;&nbsp;def __bool__(self):&lt;br&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return self.val&lt;br&gt;&lt;br&gt;then you can also extract the repeating part:&lt;br&gt;&lt;br&gt;def selected_lst(org_entity, select_id):&lt;br&gt;&nbsp;&nbsp;&nbsp;&nbsp;return [(x.id, x.display_name, {&amp;#39;selected&amp;#39;:mbool(x.id == status_id)})&lt;br&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for x in org_entity]&lt;br&gt;&lt;br&gt;Which allows you to say:&lt;br&gt;return dict(&lt;br&gt;&nbsp;&nbsp;&nbsp;&nbsp;htmlclass=&quot;advancedscheduling&quot;,&lt;br&gt;&nbsp;&nbsp;&nbsp;&nbsp;v2org=v2org,&lt;br&gt;&nbsp;&nbsp;&nbsp;&nbsp;name=name,&lt;br&gt;&nbsp;&nbsp;&nbsp;&nbsp;employees=[(0, &amp;#39;None&amp;#39;)] + selected_lst(v2org.employees,employee_id),&lt;br&gt;&nbsp;&nbsp;&nbsp;&nbsp;locations=selected_lst(v2org.locations,location_id),&lt;br&gt;&nbsp;&nbsp;&nbsp;&nbsp;statuses=selected_lst(model_ShiftStatus.select(),status_id),&lt;br&gt;)&lt;br&gt;&lt;br&gt;</code> &lt;/pre&gt;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matt Wilson</title>
		<link>http://blog.tplus1.com/index.php/2008/12/12/code-formatting-people-i-need-your-help/comment-page-1/#comment-1353</link>
		<dc:creator>Matt Wilson</dc:creator>
		<pubDate>Sat, 13 Dec 2008 17:31:04 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tplus1.com/?p=264#comment-1353</guid>
		<description>Thanks for the writeup.  I think maybe you can do preformatted text with the code tag, and then use lots of nbsp&#039;s to indent.&lt;br&gt;&lt;code&gt;&lt;br&gt;def f(a, b, c):&lt;br&gt; &#160;&#160;return a + b + c&lt;br&gt;&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>Thanks for the writeup.  I think maybe you can do preformatted text with the code tag, and then use lots of nbsp&#39;s to indent.<br /><code>&lt;br&gt;def f(a, b, c):&lt;br&gt; &amp;nbsp;&amp;nbsp;return a + b + c&lt;br&gt;</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matt Wilson</title>
		<link>http://blog.tplus1.com/index.php/2008/12/12/code-formatting-people-i-need-your-help/comment-page-1/#comment-1355</link>
		<dc:creator>Matt Wilson</dc:creator>
		<pubDate>Sat, 13 Dec 2008 17:29:26 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tplus1.com/?p=264#comment-1355</guid>
		<description>I&#039;m not against OOP, I just learned how to program in an environment without any OOP people around me, so I doesn&#039;t come naturally.  And I&#039;ve worked with some bad programmers that were also OOP fans, so I&#039;ve read a lot of really ugly OOP code.&lt;br&gt;&lt;br&gt;For example, I dislike having to hop up four or five or more parent classes to find the code that actually does what I want.  So maybe in reaction to that, I&#039;m too far on the opposite extreme, where I avoid any anything but low-level data types and literals.&lt;br&gt;&lt;br&gt;I write these posts in order to get feedback and hopefully improve.  Thanks for your comments.</description>
		<content:encoded><![CDATA[<p>I&#39;m not against OOP, I just learned how to program in an environment without any OOP people around me, so I doesn&#39;t come naturally.  And I&#39;ve worked with some bad programmers that were also OOP fans, so I&#39;ve read a lot of really ugly OOP code.</p>
<p>For example, I dislike having to hop up four or five or more parent classes to find the code that actually does what I want.  So maybe in reaction to that, I&#39;m too far on the opposite extreme, where I avoid any anything but low-level data types and literals.</p>
<p>I write these posts in order to get feedback and hopefully improve.  Thanks for your comments.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: simon</title>
		<link>http://blog.tplus1.com/index.php/2008/12/12/code-formatting-people-i-need-your-help/comment-page-1/#comment-1352</link>
		<dc:creator>simon</dc:creator>
		<pubDate>Sat, 13 Dec 2008 11:21:41 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tplus1.com/?p=264#comment-1352</guid>
		<description>Yuck, mangled my whitespace. I can&#039;t find any documentation on how to do preformatted text in Disqus comments, so here&#039;s my un-mangled version: &lt;a href=&quot;http://simonwillison.net/static/2008/code-formatting-example.txt&quot; rel=&quot;nofollow&quot;&gt;http://simonwillison.net/static/2008/code-forma...&lt;/a&gt;</description>
		<content:encoded><![CDATA[<p>Yuck, mangled my whitespace. I can&#39;t find any documentation on how to do preformatted text in Disqus comments, so here&#39;s my un-mangled version: <a href="http://simonwillison.net/static/2008/code-formatting-example.txt" rel="nofollow"></a><a href="http://simonwillison.net/static/2008/code-forma.." rel="nofollow">http://simonwillison.net/static/2008/code-forma..</a>.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: rgzdev</title>
		<link>http://blog.tplus1.com/index.php/2008/12/12/code-formatting-people-i-need-your-help/comment-page-1/#comment-1354</link>
		<dc:creator>rgzdev</dc:creator>
		<pubDate>Sat, 13 Dec 2008 10:03:23 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tplus1.com/?p=264#comment-1354</guid>
		<description>You are not a fan of OOP are you? A functional language like Erlang seems more apropiate for you, Python&#039;s parameter passing is not side effect free so your issue #2 doesn&#039;t apply much.&lt;br&gt;&lt;br&gt; Instead of returning tuples and dictionaries you should be returning class instances where the breaking down into separate lines is more natural. I for one can&#039;t understand why  selected and disabled aren&#039;t properties or methods of employee.&lt;br&gt;&lt;br&gt; This also makes the code more readable for collaborators, experience tells me highly functional programs tend to be terse on documentation. If you are programming in Python is probably because  you appreciate readability, so not only do I expect you to use intermediary variables, I even expect you to give them descriptive names so everybody knows what that value you just calculated is.&lt;br&gt;&lt;br&gt; I understand you have your style and respect it and given that most of your code is written to work like this its probably a bad idea to switch now, so I&#039;ll simply encourage you to follow the advises given by Gary and David about proper indentation.&lt;br&gt;&lt;br&gt; Nice post, cheers.</description>
		<content:encoded><![CDATA[<p>You are not a fan of OOP are you? A functional language like Erlang seems more apropiate for you, Python&#39;s parameter passing is not side effect free so your issue #2 doesn&#39;t apply much.</p>
<p> Instead of returning tuples and dictionaries you should be returning class instances where the breaking down into separate lines is more natural. I for one can&#39;t understand why  selected and disabled aren&#39;t properties or methods of employee.</p>
<p> This also makes the code more readable for collaborators, experience tells me highly functional programs tend to be terse on documentation. If you are programming in Python is probably because  you appreciate readability, so not only do I expect you to use intermediary variables, I even expect you to give them descriptive names so everybody knows what that value you just calculated is.</p>
<p> I understand you have your style and respect it and given that most of your code is written to work like this its probably a bad idea to switch now, so I&#39;ll simply encourage you to follow the advises given by Gary and David about proper indentation.</p>
<p> Nice post, cheers.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matt Wilson</title>
		<link>http://blog.tplus1.com/index.php/2008/12/12/code-formatting-people-i-need-your-help/comment-page-1/#comment-1359</link>
		<dc:creator>Matt Wilson</dc:creator>
		<pubDate>Fri, 12 Dec 2008 20:37:22 +0000</pubDate>
		<guid isPermaLink="false">http://blog.tplus1.com/?p=264#comment-1359</guid>
		<description>David,&lt;br&gt;&lt;br&gt;I flip-flop a lot on using backslashes vs opening a list on one line&lt;br&gt;and then putting the meat of the assignments on the next line.&lt;br&gt;&lt;br&gt;Thanks for the tip on conditional expressions.  I&#039;ll go back and see&lt;br&gt;if that approach works.  I prefer using None rather than False because&lt;br&gt;I&#039;m never going to misinterpret None as an integer.&lt;br&gt;&lt;br&gt;Thanks for the feedback.</description>
		<content:encoded><![CDATA[<p>David,</p>
<p>I flip-flop a lot on using backslashes vs opening a list on one line<br />and then putting the meat of the assignments on the next line.</p>
<p>Thanks for the tip on conditional expressions.  I&#39;ll go back and see<br />if that approach works.  I prefer using None rather than False because<br />I&#39;m never going to misinterpret None as an integer.</p>
<p>Thanks for the feedback.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

