<?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>Peaceful Programmer &#187; tips</title>
	<atom:link href="http://blog.raymondberg.com/archives/category/software/tips/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.raymondberg.com</link>
	<description>A Blog that Walks the Fine Line Between Usefulness and Acrobats</description>
	<lastBuildDate>Tue, 24 Jan 2012 03:18:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Elementary Java: main() and constructors</title>
		<link>http://blog.raymondberg.com/archives/180</link>
		<comments>http://blog.raymondberg.com/archives/180#comments</comments>
		<pubDate>Thu, 04 Mar 2010 03:38:42 +0000</pubDate>
		<dc:creator>rwb</dc:creator>
				<category><![CDATA[academia]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[software]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[comedy]]></category>
		<category><![CDATA[constructor]]></category>
		<category><![CDATA[difference]]></category>
		<category><![CDATA[elliptical]]></category>
		<category><![CDATA[galaxy]]></category>
		<category><![CDATA[god]]></category>
		<category><![CDATA[hilarious]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[joke]]></category>
		<category><![CDATA[learning java]]></category>
		<category><![CDATA[main]]></category>
		<category><![CDATA[spiral]]></category>
		<category><![CDATA[theology]]></category>
		<category><![CDATA[understanding java]]></category>
		<category><![CDATA[universe]]></category>

		<guid isPermaLink="false">http://blog.raymondberg.com/?p=180</guid>
		<description><![CDATA[I can't believe I wrote an entire blog post just to get to tell that joke.]]></description>
			<content:encoded><![CDATA[<p>This is one of those seemingly simple concepts that never really gets elaborated. Usually a student learning Java for the first time is told. &#8220;Write the following:&#8221;<br />
<code>public class Person<br />
{<br />
	public static void main(String[] args)<br />
	{<br />
		System.out.println("Hello World!");<br />
	}<br />
}</code><br />
&#8220;Don&#8217;t ask why, just do it.&#8221; Because of that, I&#8217;ve heard this question more than a few times in the last couple years.<br />
<span id="more-180"></span></p>
<h4>The main()</h4>
<p>The simple definition/purpose of the &#8216;main()&#8217; method? It&#8217;s the starting point for every single Java application you&#8217;ll ever write, and this one and only main() makes up the entire life of the program. Once main() starts you&#8217;re program is running, and once it exits then your program dies. That&#8217;s all it does, really.</p>
<p>I&#8217;ll give you some background on the details here, hopefully to reduce the &#8216;magic&#8217;. In the &#8220;public static void&#8221; part the &#8220;public&#8221; is the signature that is required as a main() must be accessible to all interested invokers, &#8216;static&#8217; signifies this method is always run in an identical environment with no worry about conflicting instances (read more on static elsewhere), and &#8216;void&#8217; designates that there is no return type from the method. The args variable, or whatever you choose to name it, is the array of command line inputs that you specified beyond the name of the Java class. Easy, right?</p>
<h4>The Constructor</h4>
<p>Constructors are an entirely different beast: an object that is created in a runtime is created by explicit or implicit call to that object&#8217;s constructor, essentially establishing the working space for that object. You can have many different constructors, too, but only one can be called for each object that you create. The most common place you see this is in the &#8220;new Person()&#8221; call where the &#8216;new&#8217; keyword indicates a new instance of this event, as created in the constructor call &#8216;Person()&#8217;. I know this is getting crazy, but just look at the following example.<br />
<code><br />
public class Galaxy<br />
{<br />
	public boolean isSpiral;<br />
	public boolean hasLife;<br />
	public Galaxy()<br />
	{<br />
		isSpiral = (Math.random() > 0.5); // 50-50 chance of being spiral<br />
		hasLife= (Math.random() > 0.99999999); // tiny chance of supporting life<br />
	}<br />
	public Galaxy(boolean isSpiralp)<br />
	{<br />
		isSpiral = isSpiralp;  //Specified before creation, guaranteed to be what is requested<br />
	}<br />
	public Galaxy(boolean isSpiralp, boolean hasLifep)<br />
	{<br />
		this(isSpiralp); //Call other constructor<br />
		hasLife = hasLifep; //set life<br />
	}<br />
}<br />
class Universe<br />
{<br />
	public static void main(String[] args)<br />
	{<br />
		Galaxy sagittariusDwarf = new Galaxy(false);<br />
		Galaxy milkyWay = new Galaxy(true,true);<br />
		Galaxy peacefulProgrammer = new Galaxy();<br />
		milkyWay = peacefulProgrammer;<br />
	}<br />
}<br />
</code></p>
<p>In this example Galaxy cannot be started by itself, some other program with a main() method (if it&#8217;s an application) must actually create the object through the constructor. In this case, we find an example in the Universe class. The Universe &#8216;starts up&#8217;, creates a few galaxies (overwrites some lesser galaxies), and then flickers out and dies. I know it&#8217;s sad; pay attention! </p>
<p>The Galaxy object isn&#8217;t limited to being used only in the Universe class, but it&#8217;s just what we used here.  Anything, in theory, could instantiate this galaxy object. I&#8217;ve met few girls with Eyes that seemed to instantiate a couple of Galaxy objects, but that&#8217;s another blog post.</p>
<h4>Self-referential, complicating monkey-wrench.</h4>
<p>Some situations call for main and constructor methods, and the constructor could be created inside the runtime. The reason for this is often that the object itself may be created within another program, or it could be something that stands alone. In the case of the universe example, it&#8217;s a theology question. If Universe is a class that can be independent of any other class and can suffice by it&#8217;s internal definition (a.k.a the programmer is an atheist), then you can just run Universe to create it&#8217;s own instance.</p>
<p><code>public class Universe<br />
{<br />
	public static final int TOTAL_ATOMS_POWER_OF_TEN = 81;<br />
	public static final boolean IS_STRING_THEORY_LEGITIMATE = false;<br />
	public Sphere core;<br />
	public void Universe()<br />
	{<br />
		core = new Sphere(1,1);<br />
		for(int i = 0; i < TOTAL_ATOMS_POWER_OF_TEN; i++)<br />
		{<br />
			core.increaseDensity(10.0);<br />
		}<br />
	}<br />
	public void bang()<br />
	{<br />
		//code to cause bang<br />
	}<br />
	public static void main(String args)<br />
	{<br />
		Universe everything = new Universe();<br />
		everything.bang();<br />
	}<br />
}</code></p>
<p>Now suppose the programmer isn't an atheist, then we've got a bit of a problem. We need somebody driving this crazy bus we call life; which will work out totally fine. In fact, not only can we create God, but we can make sure that he's got enough power to create more than one universe. Mix the following class into the Java file for the above and add water:<br />
<code>class God<br />
{<br />
	public static final POWER_REQD_PER_UNIVERSE = 42;<br />
	private int power;<br />
	Vector<Universe> multiverse;<br />
	public God()<br />
	{<br />
		multiverse = new Vector<Universe> multiverse;<br />
		power = POWER_REQD_PER_UNIVERSE;<br />
	}<br />
	public void createUniverse()<br />
	{<br />
		power += POWER_REQD_PER_UNIVERSE;<br />
		Universe temp = new Universe();<br />
		temp.bang();<br />
		multiverse.add(temp);<br />
	}<br />
	public void getHaircut()<br />
	{<br />
		//code to get haircut<br />
	)<br />
	public static void main(String[] args)<br />
	{<br />
		God me = new God();<br />
		me.addUniverse();<br />
		me.addUniverse();<br />
		me.getHaircut();<br />
	}<br />
}</code></p>
<p>The best thing about designing the original universe to allow for versatile, constructor-based invocation is that we didn't have to change the Universe object to allow for God to create a Universe. In this way we create Universe to be God-agnostic. </p>
<p>I can't believe I wrote an entire blog post just to get to tell that joke.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.raymondberg.com/archives/180/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Draw as well as you Program (and Vice-Versa)</title>
		<link>http://blog.raymondberg.com/archives/78</link>
		<comments>http://blog.raymondberg.com/archives/78#comments</comments>
		<pubDate>Tue, 13 Jan 2009 01:01:50 +0000</pubDate>
		<dc:creator>rwb</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[software]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[diagram]]></category>
		<category><![CDATA[modeling]]></category>
		<category><![CDATA[object oriented]]></category>
		<category><![CDATA[objects]]></category>
		<category><![CDATA[oop]]></category>

		<guid isPermaLink="false">http://blog.rwberg.org/?p=78</guid>
		<description><![CDATA[I was recently visited by a friend who is also an IT professional. Some time during the visit, I casually made the recommendation that programmers should take a drafting course. I was a bit surprised to receive a contradictory opinion, but it was well received and has forced me to further justify my position in [...]]]></description>
			<content:encoded><![CDATA[<p>I was recently visited by a friend who is also an <a href="http://media.techtarget.com/digitalguide/images/Misc/helpdeskDave.jpg" target="_blank">IT professional</a>. Some time during the visit, I casually made the recommendation that programmers should take a drafting course. I was a bit surprised to receive a contradictory opinion, but it was well received and has forced me to further justify my position in my own mind.</p>
<p>My case is rather simple; <span id="more-78"></span>programmers are trained to think in primarily object oriented environments, especially in recent years. Most, if not all, have had some formal training in object oriented modeling using UML or de facto standards in structure design (database or other). This is not coincidence. The reason for this trend is that objects can easily, and often must, be modeled for clarity in design and maintenance. But what isn&#8217;t obvious is how those models are generated.</p>
<p>Somewhere in our brain we can start to solve problems and make concrete these relatively abstract relationships with a certain degree of ease.  Not everyone can do it, but most people can draw a diagram of a workflow or an object model. It may be slow but it can be done by most functioning individuals; the key to success is practicing this method.</p>
<p>The trick to being a good modeler is a lot like being a good programmer: process, practice, and perception. You recognize relationships and patterns between past and present problems that allow for streamlining; this is the process. As you do more to practice this process then it can become easier as you have more cases to study and experience to pull from. But the mere act of this problem solving takes a certain flair for the spatial. The perception of the problem and, more importantly, the solution deals entirely with the multidimensional aspects of relationships.</p>
<p>So that brings us to the thesis: training the mind to recognize shapes and objects in their elemental forms will allow for a much easier command when high level design is required. Logically, the drawing tools used by architects and others to define 3-dimensional objects in 2-dimensional space would lend themselves to programmers who deal with multidimensional objects, relationships, and even data. Eventually our goal is the same: get that complex object into an understandable 2-dimensional model. At least until we get the <a href="http://news.cnet.com/2100-1041-6242143.html" target="_blank">3-dimensional hologram projectors</a> in the conference room.</p>
<p>To use a personal example, just today I was given a rather daunting task: design a class representation of elements in the TCP/IP stack and a driver that can use those classes to examine network traffic. In addition, this task is part one of three and the code generated should be usable as a larger part of an elementary <a href="http://en.wikipedia.org/wiki/Intrusion-detection_system" target="_blank">IDS</a> capable of handling Snort signature rules.</p>
<p>So what did I do? I reached for the notebook and drafting pencil and started sketching out an object model that would best represent the solution with plans for expansion into the second and third phase of the product.  It was elementary, but because I&#8217;ve done it before and because of some spatial techniques picked up in Art and Drafting classes, I was able to create a logical model that represented the first picture of the solution.</p>
<p>Of course my solution may not be ready for a text book just yet, but the original draft gives me a lot to work with. Eventually I can redistribute the objects to be a well balanced diagram. I honestly think that this skill is one of the most important ones in the programmer&#8217;s tool belt, and one of the best for limiting scope and thinning the <a href="http://en.wikipedia.org/wiki/Fear,_uncertainty_and_doubt" target="_self">FUD fog</a>.</p>
<p><strong>Ps</strong>. Part of my research shows a potential correlation to this concept between drawing maps and success in early programming courses (<a href="http://eprints.usq.edu.au/2256/" target="_blank">Do map drawing styles of programmers predict success&#8230;</a>). It doesn&#8217;t have any particularly conclusive results, but it does tickle the brain a bit. Doesn&#8217;t it?</p>
<p>Let me know whose side of the argument you&#8217;re on. Am I adding unneccessary recommendations to a field already taxed with educational scope creep?</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.raymondberg.com/archives/78/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tip: Make Comments Monospaced in Notepad++</title>
		<link>http://blog.raymondberg.com/archives/35</link>
		<comments>http://blog.raymondberg.com/archives/35#comments</comments>
		<pubDate>Thu, 24 Jul 2008 13:33:00 +0000</pubDate>
		<dc:creator>rwb</dc:creator>
				<category><![CDATA[software]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[applications]]></category>
		<category><![CDATA[customize]]></category>
		<category><![CDATA[notepad++]]></category>

		<guid isPermaLink="false">http://blog.rwberg.org/?p=35</guid>
		<description><![CDATA[I love coding in text editors because I don&#8217;t have to think about all the extra stuff. That&#8217;s not to say that I don&#8217;t love code completion and auto-generation tools, but it&#8217;s nice to sit down with just just you, a cup of hot apple cider, and ASCII. There&#8217;s no better tool for this than [...]]]></description>
			<content:encoded><![CDATA[<p>I love coding in text editors because I don&#8217;t have to think about all the extra stuff. That&#8217;s not to say that I don&#8217;t love code completion and auto-generation tools, but it&#8217;s nice to sit down with just just you, a cup of hot apple cider, and ASCII. There&#8217;s no better tool for this than Notepad++, in my opinion.</p>
<p>It boast an expansive built in syntax-higlighting library and great tools for automating some of your frequented commands. But a major problem, aside from the inability to do multi-line regex stuff, is the way comments are set up. I found out that I love the fact that it shrinks them, but I hate that it uses a non-monospaced font. But you can fix it, and fast.</p>
<p>First open up your %APP_DATA%/Notepad++/stylers.xml file in Notepad++. The APP_DATA variable usually points to your &#8216;Documents and Settings/youruser/Application Data&#8217; folder, but I could be wrong. Then do a find and replace to find &#8220;Comic Sans MS&#8221; and replace it with &#8220;&#8221;. That&#8217;s right, nothing.  Save and restart Notepad++ and you are ready to rock.</p>
<p>Thanks to Nathan for pointing this out to me. I&#8217;m fairly confident that he doesn&#8217;t even know I have a website. The only place I don&#8217;t talk about it, annoyingly, is at work. <img src='http://blog.raymondberg.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.raymondberg.com/archives/35/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

