<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>SciTools Blog &#187; astyle</title>
	<atom:link href="http://scitools.com/blog/tag/astyle/feed" rel="self" type="application/rss+xml" />
	<link>http://scitools.com/blog</link>
	<description>Maintain your Software</description>
	<lastBuildDate>Mon, 30 Jan 2012 19:15:21 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Code Refactoring</title>
		<link>http://scitools.com/blog/2010/04/code-refactoring.html</link>
		<comments>http://scitools.com/blog/2010/04/code-refactoring.html#comments</comments>
		<pubDate>Tue, 06 Apr 2010 04:10:28 +0000</pubDate>
		<dc:creator>KevinG</dc:creator>
				<category><![CDATA[Plugins]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Understand 2.5]]></category>
		<category><![CDATA[addons]]></category>
		<category><![CDATA[astyle]]></category>
		<category><![CDATA[complexity]]></category>
		<category><![CDATA[cyclomatic]]></category>
		<category><![CDATA[mccabe]]></category>
		<category><![CDATA[metics]]></category>

		<guid isPermaLink="false">http://scitools.com/blog/?p=642</guid>
		<description><![CDATA[Refactoring is a disciplined technique for restructuring an existing body of code, altering its internal structure without changing its external behavior. Its heart is a series of small behavior preserving transformations. Each transformation (called a &#8216;refactoring&#8217;) does little, but a sequence of transformations can produce a significant restructuring. Since each refactoring is small, it&#8217;s less [...]]]></description>
			<content:encoded><![CDATA[<blockquote><p>Refactoring is a disciplined technique for restructuring an existing body of code, altering its internal structure without changing its external behavior. Its heart is a series of small behavior preserving transformations. Each transformation (called a &#8216;refactoring&#8217;) does little, but a sequence of transformations can produce a significant restructuring. Since each refactoring is small, it&#8217;s less likely to go wrong. The system is also kept fully working after each small refactoring, reducing the chances that a system can get seriously broken during the restructuring.  &#8212; Martin Fowler  <a title="http://www.refactoring.com/" href="http://www.refactoring.com/">http://www.refactoring.com/</a></p></blockquote>
<p>In other words, refactoring is making your code cleaner, safer, and easier to use. Understand can be a very powerful tool in your re-factoring arsenal. Here are a few ways you can use Understand in your refactoring process.</p>
<p><span id="more-642"></span></p>
<h3>Quickly Identify References</h3>
<p>In the long <a href="http://www.refactoring.com/catalog/index.html" target="_blank">list of refactorings</a>, many of the suggested refactorings involve replacing one data type with another. In many cases that can involve changing the calls to that data type as well. Understand can instantly show you everywhere that that entity is used, called, referenced, modified or typed. Just right click on the entity, select View Information, and expand the references section.</p>
<p><a href="http://www.scitools.com/blog/wp-content/uploads/2010/04/image.png"><img style="display: inline; border-width: 0px;" title="image" src="http://www.scitools.com/blog/wp-content/uploads/2010/04/image_thumb.png" border="0" alt="image" width="284" height="205" /></a></p>
<h3>Identify Complex Functions</h3>
<p>Many overly-complex functions can be refactored into smaller, more maintainable units. Knowing the McCabe <a href="http://en.wikipedia.org/wiki/Cyclomatic_complexity" target="_blank">Cyclomatic complexity</a> can help you quickly identify functions and methods that are overly complicated and may be good candidates for refactoring. You can quickly find the complexity of every function in an Understand project by selecting Metrics –&gt; Export Metrics. If you’re just looking for a quick list of complex functions, this plugin will show you the most complex functions in your project.</p>
<p>Download it from our <a href="http://www.scitools.com/plugins/plugins.php" target="_blank">Plugin page</a> and you’ll see a list of the most complex functions in your project.</p>
<p><a href="http://www.scitools.com/blog/wp-content/uploads/2010/04/image1.png"><img style="display: inline; border-width: 0px;" title="image" src="http://www.scitools.com/blog/wp-content/uploads/2010/04/image_thumb1.png" border="0" alt="image" width="343" height="264" /></a></p>
<h3>Reformat your code</h3>
<p>If you have ugly code, you can beautify it quickly with the the tip reported in this entry:</p>
<p><a href="http://scitools.com/blog/2008/11/tip-beautify-your-code.html" target="_blank">Tip &#8211; Beautify your code</a></p>
<p>With one button press, turn a file that looks like this:</p>
<p><a href="http://www.scitools.com/blog/wp-content/uploads/2010/04/image2.png"><img style="display: inline; border-width: 0px;" title="image" src="http://www.scitools.com/blog/wp-content/uploads/2010/04/image_thumb2.png" border="0" alt="image" width="644" height="73" /></a></p>
<p>into this:</p>
<p><a href="http://www.scitools.com/blog/wp-content/uploads/2010/04/image3.png"><img style="display: inline; border-width: 0px;" title="image" src="http://www.scitools.com/blog/wp-content/uploads/2010/04/image_thumb3.png" border="0" alt="image" width="644" height="226" /></a></p>
<h3>Rename Entities</h3>
<p>Sometimes renaming an entity can go a long way towards making the code readable, perhaps a missed name class or method.</p>
<p>Download <a href="http://scitools.com/blog/wp-content/uploads/2010/04/rename.zip" target="_blank">rename.zip</a> for a user tool to quickly rename entities in Understand – it goes through the references and replaces each instance of the class or object with the new name.</p>
<p>Save the .pl script to your hard drive, and then in Understand under <em>Tools | User Tools| Configure</em> select Import to load the .ini file. Change the path to the location of the .pl file. Then to use it, right click on any entity in Understand and select User Tools | Replace. You&#8217;ll be prompted for the new text, and then all references to that entity will be renamed. You&#8217;ll want to reparse the changed files after each rename so that the database stays up to date (Ctrl+R by default).</p>
<p><a href="http://www.scitools.com/blog/wp-content/uploads/2010/04/image4.png"><img style="display: inline; border-width: 0px;" title="image" src="http://www.scitools.com/blog/wp-content/uploads/2010/04/image_thumb4.png" border="0" alt="image" width="499" height="114" /></a></p>
<h3>Follow Dependencies</h3>
<table border="0" cellspacing="0" cellpadding="2" width="600">
<tbody>
<tr>
<td width="300" valign="top">Understand’s new Dependency features can help you to quickly get a handle on what parts of the code are dependant on other parts of the code, letting you define what logical lines to divide your code into.<br />
<a href="http://www.scitools.com/features/dependencyBrowser.php">Dependency Browser</a><br />
<a href="http://www.scitools.com/features/dependenciesGraphs.php">Dependency Graphs</a><br />
<a href="http://www.scitools.com/features/exportDependencies.php">Exporting Dependencies</a></td>
<td width="39" valign="top"><a href="http://www.scitools.com/blog/wp-content/uploads/2010/04/image5.png"><img style="display: inline; border-width: 0px;" title="image" src="http://www.scitools.com/blog/wp-content/uploads/2010/04/image_thumb5.png" border="0" alt="image" width="255" height="275" /></a></td>
</tr>
</tbody>
</table>
]]></content:encoded>
			<wfw:commentRss>http://scitools.com/blog/2010/04/code-refactoring.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tip &#8211; Beautify your code</title>
		<link>http://scitools.com/blog/2008/11/tip-beautify-your-code.html</link>
		<comments>http://scitools.com/blog/2008/11/tip-beautify-your-code.html#comments</comments>
		<pubDate>Thu, 06 Nov 2008 20:49:32 +0000</pubDate>
		<dc:creator>KevinG</dc:creator>
				<category><![CDATA[Tips]]></category>
		<category><![CDATA[Understand 2.0]]></category>
		<category><![CDATA[astyle]]></category>
		<category><![CDATA[beautify]]></category>
		<category><![CDATA[user tools]]></category>

		<guid isPermaLink="false">http://scitools.com/blog/http:/scitools.com/blog/archives/2008/11/tip-beautify-your-code.html</guid>
		<description><![CDATA[Your code is beautiful, formatted to your liking and spaced just how you want it, but sometimes you have to work with other people’s code – yuck! If only there was something that would make it look like your code, instead of spaghetti. Artistic Style, or astyle as it is also known, is a great [...]]]></description>
			<content:encoded><![CDATA[<p>Your code is beautiful, formatted to your liking and spaced just how you want it, but sometimes you have to work with other people’s code – yuck! If only there was something that would make it look like your code, instead of spaghetti. <a href="http://astyle.sourceforge.net/" target="_blank">Artistic Style</a>, or astyle as it is also known, is a great open source application that does exactly that.</p>
<p>So you can quickly turn this:</p>
<p><a href="http://scitools.com/blog/wp-content/uploads/mt-old/WindowsLiveWriter/TipBeautifyyourcode_D95D/image_26.png"><img style="display: inline; border-width: 0px;" title="image" src="http://scitools.com/blog/wp-content/uploads/mt-old/WindowsLiveWriter/TipBeautifyyourcode_D95D/image_thumb_12.png" border="0" alt="image" width="748" height="84" /></a></p>
<p>Into this:</p>
<p><a href="http://scitools.com/blog/wp-content/uploads/mt-old/WindowsLiveWriter/TipBeautifyyourcode_D95D/image_28.png"><img style="display: inline; border-width: 0px;" title="image" src="http://scitools.com/blog/wp-content/uploads/mt-old/WindowsLiveWriter/TipBeautifyyourcode_D95D/image_thumb_13.png" border="0" alt="image" width="604" height="212" /></a></p>
<p>We plan on implementing astyle into the editor at some point in the future, but I’m not so patient, and I decided to use our plugin mechanism to do it now, and will show you how.</p>
<p><span id="more-376"></span></p>
<p>There are two ways to run astyle from inside Understand, as an Interactive Report plugin, or as a custom user tool. Either way, first you’ll need to install or build astyle you can <a href="http://sourceforge.net/project/showfiles.php?group_id=2319l" target="_blank">download it from here</a>.</p>
<h3>Interactive Report</h3>
<p>The Interactive report integrates directly with the file context menu in Understand. Download the plugin <a href="http://www.scitools.com/plugins/plugins/IReport/astyle.upl" target="_blank">from here</a>(right click and save as). To install it, just move the file to SciTools\conf\plugin\User\IReport\ and restart Understand.<br />
To run the plugin, right click on a File, select Interactive Reports and Beautify</p>
<p><a href="http://scitools.com/blog/wp-content/uploads/mt-old/WindowsLiveWriter/TipBeautifyyourcode_D95D/image_2.png"><img style="display: inline; border-width: 0px;" title="image" src="http://scitools.com/blog/wp-content/uploads/mt-old/WindowsLiveWriter/TipBeautifyyourcode_D95D/image_thumb.png" border="0" alt="image" width="260" height="83" /></a></p>
<p>At which point you’ll be presented with the options window:</p>
<p><a href="http://scitools.com/blog/wp-content/uploads/mt-old/WindowsLiveWriter/TipBeautifyyourcode_D95D/image_4.png"><img style="display: inline; border-width: 0px;" title="image" src="http://scitools.com/blog/wp-content/uploads/mt-old/WindowsLiveWriter/TipBeautifyyourcode_D95D/image_thumb_1.png" border="0" alt="image" width="288" height="211" /></a></p>
<p>The first field is pretty straight forward, just navigate to where the astyle executable is installed.</p>
<p>The rest of the dialog may seem overwhelming, but the tricky part is figuring out what your “style” is. Astyle has 5 predefined styles, and chances are that one of them will be pretty close to what you like.</p>
<p><a href="http://scitools.com/blog/wp-content/uploads/mt-old/WindowsLiveWriter/TipBeautifyyourcode_D95D/image_6.png"><img style="display: inline; border-width: 0px;" title="image" src="http://scitools.com/blog/wp-content/uploads/mt-old/WindowsLiveWriter/TipBeautifyyourcode_D95D/image_thumb_2.png" border="0" alt="image" width="323" height="51" /></a></p>
<p>Astyle’s <a href="http://astyle.sourceforge.net/astyle.html" target="_blank">documentation</a> goes into more detail about each of these styles, but here is a rough overview:</p>
<table border="1" cellspacing="0" cellpadding="0" width="699">
<tbody>
<tr>
<td width="233" align="center" valign="top"><strong>ANSI</strong></td>
<td width="233" align="center" valign="top"><strong>GNU</strong></td>
<td width="233" align="center" valign="top"><strong>KR</strong></td>
</tr>
<tr>
<td width="233" valign="top">ANSI style formatting and indenting. Brackets are broken, indentation is 4 spaces. Namespaces, classes, and switches are NOT indented.</td>
<td width="233" valign="top">GNU style formatting and indenting. Brackets are broken, blocks are indented, and indentation is 2 spaces. Namespaces, classes, and switches are NOT indented.</td>
<td width="233" valign="top">Kernighan &amp; Ritchie style formatting and indenting. Brackets are attached, indentation is 4 spaces. Namespaces, classes, and switches are NOT indented.</td>
</tr>
<tr>
<td width="233" valign="top">
<pre>namespace foospace
{
int Foo()
{
if (isBar)
{
bar();
return 1;
}
else
return 0;
}
}</pre>
</td>
<td width="233" valign="top">
<pre>namespace foospace
{
int Foo()
{
if (isBar)
{
bar();
return 1;
}
else
return 0;
}
}</pre>
</td>
<td width="233" valign="top">
<pre>namespace foospace {
int Foo() {
if (isBar) {
bar();
return 1;
} else
return 0;
}
}</pre>
</td>
</tr>
</tbody>
</table>
<table border="1" cellspacing="0" cellpadding="0" width="466">
<tbody>
<tr>
<td width="233" align="center" valign="top"><strong>Linux</strong></td>
<td width="233" align="center" valign="top"><strong>Java</strong></td>
</tr>
<tr>
<td width="233" valign="top">Linux style formatting and indenting. All brackets are Linux style, indentation is 8 spaces. Namespaces, classes, and switches are NOT indented.</td>
<td width="233" valign="top">Java style formatting and indenting. Brackets are attached, indentation is 4 spaces. Switches are NOT indented.</td>
</tr>
<tr>
<td width="233" valign="top">
<pre>namespace foospace
{
int Foo()
{
if (isBar) {
bar();
return 1;
} else
return 0;
}
}</pre>
</td>
<td width="233" valign="top">
<pre>class foospace {
int Foo() {
if (isBar) {
bar();
return 1;
} else
return 0;
}
}</pre>
</td>
</tr>
</tbody>
</table>
<p>If one of these appeals to you as is, just select it from the “Predefined Style” section. If you want to modify one, select it and the other options in the dialog will allow you to override the default settings for a style. For more details about what the command does, select “Display the help text” in the Action section:</p>
<p><a href="http://scitools.com/blog/wp-content/uploads/mt-old/WindowsLiveWriter/TipBeautifyyourcode_D95D/image_8.png"><img style="display: inline; border-width: 0px;" title="image" src="http://scitools.com/blog/wp-content/uploads/mt-old/WindowsLiveWriter/TipBeautifyyourcode_D95D/image_thumb_3.png" border="0" alt="image" width="162" height="103" /></a></p>
<p>When you are ready to run it, you can either preview the changes in a separate window, or apply them directly to the source code. Of course I would suggest previewing the changes until you figure out exactly what your style is. Note that if your project uses relative paths or named roots, only the preview will work right now since the file naming is different, but you can still copy and paste <img src='http://scitools.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<h3>User Tool</h3>
<p>If you already know what astyle command line options you want to use, you can setup a user tool  to quickly transform a file. Again, this only works for projects with absolute paths.</p>
<p>So here are the command line options I want to use with astyle:</p>
<p>astyle &#8211;style=ansi -t -B -w</p>
<p>To implement these as a user tool, I select Tools | User Tools | Configure</p>
<p>Then I create a new tool. I name it and provide the path to the astyle executable. Then I provide the parameters. The lipstick icon is optional <img src='http://scitools.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><a href="http://www.scitools.com/blog/wp-content/uploads/2010/04/screenshot.43.png"><img style="display: inline; border-width: 0px;" title="screenshot.43" src="http://www.scitools.com/blog/wp-content/uploads/2010/04/screenshot.43_thumb.png" border="0" alt="screenshot.43" width="343" height="241" /></a></p>
<p>I also decided to bind this to a keyboard shortcut (Ctrl Shift B). You can set the keyboard shortcuts in Tool | Options | Key Bindings.</p>
<p><a href="http://scitools.com/blog/wp-content/uploads/mt-old/WindowsLiveWriter/TipBeautifyyourcode_D95D/image_18.png"><img style="display: inline; border-width: 0px;" title="image" src="http://scitools.com/blog/wp-content/uploads/mt-old/WindowsLiveWriter/TipBeautifyyourcode_D95D/image_thumb_8.png" border="0" alt="image" width="535" height="97" /></a></p>
<p>Now if I run into an ugly file, I can just hit Ctrl Shift B, and bam, pretty code!</p>
]]></content:encoded>
			<wfw:commentRss>http://scitools.com/blog/2008/11/tip-beautify-your-code.html/feed</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>

