<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-7573455095858650997</id><updated>2012-02-16T12:05:06.189-07:00</updated><category term='C++'/><category term='Life'/><category term='development practices'/><category term='Scheme Lisp Programming Macros'/><category term='Schme Lisp Exceptions Macros Generators'/><category term='bash gnuplot'/><category term='Android development'/><category term='guidelines competency'/><category term='recursion induction programming'/><category term='college'/><category term='unit-testing'/><category term='Masters'/><category term='C/C++ strongly typed Go'/><category term='Go Cross Compiling'/><category term='School'/><title type='text'>Real World Academia</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://evanfarrer.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7573455095858650997/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://evanfarrer.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Evan</name><uri>http://www.blogger.com/profile/03848709590438147138</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_Pxmu7QQVgkk/SrI9CTHifyI/AAAAAAAAAE8/evZ3klxp4YM/S220/evan.jpeg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>16</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-7573455095858650997.post-4171647750283179328</id><published>2011-12-20T23:23:00.002-07:00</published><updated>2011-12-20T23:24:21.284-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Android development'/><title type='text'>Android development on Ubuntu 11.10 Oneiric</title><content type='html'>I decided to play around with Android development but I had a hard time finding good instructions on how to set up the Android development environment on Ubuntu 11.10. With a little trial and error I've figured it out. I'm posting my notes in hopes that they will be useful to me in the future and possibly to others also. The aren't a complete step-by-step guide and they assume you're comfortable with the Linux command line, but hopefully they'll be useful.&lt;br /&gt;
&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;Download and untar/gzip the Android SDK&lt;/li&gt;
&lt;li&gt;Install the JRE&lt;/li&gt;
&lt;ol&gt;
&lt;li&gt;sudo apt-get install icedtea6-plugin openjdk-6-jre&amp;nbsp;openjdk-6-jdk&amp;nbsp;ia32-libs&lt;/li&gt;
&lt;/ol&gt;
&lt;li&gt;Install ant&lt;/li&gt;
&lt;ol&gt;
&lt;li&gt;sudo apt-get install ant&lt;/li&gt;
&lt;/ol&gt;
&lt;li&gt;Set your JAVA_HOME and CLASSPATH&lt;/li&gt;
&lt;ol&gt;
&lt;li&gt;export JAVA_HOME=/usr/lib/jvm/java-6-openjdk&lt;/li&gt;
&lt;li&gt;export CLASSPATH=/usr/lib/jvm/java-6-openjdk/lib&lt;/li&gt;
&lt;/ol&gt;
&lt;li&gt;Update the build tools&lt;/li&gt;
&lt;ol&gt;
&lt;li&gt;cd android*;&amp;nbsp;./tools/android update sdk --no-ui&lt;/li&gt;
&lt;/ol&gt;
&lt;li&gt;Download eclipse (Helios release) (Note the one in the Ubuntu repositories doesn't seem to work)&lt;/li&gt;
&lt;ol&gt;
&lt;li&gt;google-chrome www.eclipse.org/downloads/&lt;/li&gt;
&lt;/ol&gt;
&lt;li&gt;Untar eclipse&lt;/li&gt;
&lt;ol&gt;
&lt;li&gt;tar -xvf ./eclipse*.tar.gz&lt;/li&gt;
&lt;/ol&gt;
&lt;li&gt;Install the eclipse Android plugin&lt;/li&gt;
&lt;ol&gt;
&lt;li&gt;eclipse : Help -&amp;gt; Install New Software ...&lt;/li&gt;
&lt;li&gt;enter: "Android Plugin"&lt;/li&gt;
&lt;li&gt;enter: "https://dl-ssl.google.com/android/eclipse/"&lt;/li&gt;
&lt;li&gt;Select 'Developer Tools'&lt;/li&gt;
&lt;li&gt;Click "Next"&lt;/li&gt;
&lt;/ol&gt;
&lt;li&gt;Restart eclipse&lt;/li&gt;
&lt;li&gt;Select the Android SDK&lt;/li&gt;
&lt;/ol&gt;
&lt;div&gt;
At this point you should have the Android SDK and eclipse installed and configured for Android development.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Here are some notes on doing Android development if you prefer to live on the command line instead of living in eclipse.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;ol&gt;
&lt;li&gt;Create and Android Emulator&lt;/li&gt;
&lt;ol&gt;
&lt;li&gt;cd android*; ./tools/android -&amp;gt; Tools -&amp;gt; Manage AVDs&lt;/li&gt;
&lt;/ol&gt;
&lt;li&gt;Start the Android Emulator&lt;/li&gt;
&lt;ol&gt;
&lt;li&gt;cd android*; ./tools/emulator -avd &lt;emulator_name&gt;&lt;/emulator_name&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;li&gt;Create a new Android project&lt;/li&gt;
&lt;ol&gt;
&lt;li&gt;cd android*;&amp;nbsp;/tools/android create project&amp;nbsp;--target android-14&amp;nbsp;--name HelloAndroid&amp;nbsp;--path ../HelloAndroid.git&amp;nbsp;--activity HelloAndroidActivity&amp;nbsp;--package com.mydomain.helloandroid&lt;/li&gt;
&lt;/ol&gt;
&lt;li&gt;Compile your project&lt;/li&gt;
&lt;ol&gt;
&lt;li&gt;cd ../HelloAndroid.git; ant debug&lt;/li&gt;
&lt;/ol&gt;
&lt;li&gt;Push your project onto your running Android emulator&lt;/li&gt;
&lt;ol&gt;
&lt;li&gt;ant debug install&lt;/li&gt;
&lt;/ol&gt;
&lt;/ol&gt;
&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7573455095858650997-4171647750283179328?l=evanfarrer.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://evanfarrer.blogspot.com/feeds/4171647750283179328/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://evanfarrer.blogspot.com/2011/12/android-development-on-ubuntu-1110.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7573455095858650997/posts/default/4171647750283179328'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7573455095858650997/posts/default/4171647750283179328'/><link rel='alternate' type='text/html' href='http://evanfarrer.blogspot.com/2011/12/android-development-on-ubuntu-1110.html' title='Android development on Ubuntu 11.10 Oneiric'/><author><name>Evan</name><uri>http://www.blogger.com/profile/03848709590438147138</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_Pxmu7QQVgkk/SrI9CTHifyI/AAAAAAAAAE8/evZ3klxp4YM/S220/evan.jpeg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7573455095858650997.post-887225766882898490</id><published>2011-08-23T22:48:00.000-06:00</published><updated>2011-08-23T22:48:11.224-06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='college'/><title type='text'>Why you should get a college degree</title><content type='html'>&lt;span class="Apple-style-span" style="font-size: large;"&gt;Introduction&lt;/span&gt;&lt;br /&gt;
I've been thinking about why it's important to get a college degree for many years and have finally decided to write down why I think it's important. I've heard many arguments over the years both for and against college. I'll try and address those arguments here. I should point out that my arguments may only apply to those going into a technical field (Computer Science, Electrical Engineering, Mechanical Engineering), but many of the arguments may apply to non-technical fields.&amp;nbsp; Since I don't fully understand these fields, nor do I fully understand the college experience for non-technical degrees, I am likely not qualified to discuss the related benefits or costs.&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-size: large;"&gt;Background&lt;/span&gt;&lt;br /&gt;
Since many of my arguments will be based on empirical evidence, I believe my personal background is relevant. My career goals have been to be a Software Engineer. Computer Programming has been a long hobby and passion of mine. I started working as a Computer Programmer before I started college. Since I was working in my desired field, I didn't think that&amp;nbsp;college&amp;nbsp;would be that important. &amp;nbsp;I did, however, decide to get my bachelors degree as career insurance in case I later needed or wanted to change careers. At the time, I didn't think there would be much educational benefit (I felt I already had many of the skills and knowledge that I would need for my career), but it seemed like a good idea. Many of the advanced CS courses I took showed me that I did have a lot to learn from college and I continue to use the knowledge I gained from my undergraduate studies at work.&lt;br /&gt;
&lt;br /&gt;
A few years after getting my bachelors degree, I decided to go back to get my Masters Degree. Graduate school was more of a hobby than a career advancement strategy. I enjoyed reading papers and learning new things, and I wanted to get experience doing academic research and writing academic papers on my research. Just like with my Bachelors degree, I've been pleasantly&amp;nbsp;surprised&amp;nbsp;at how much I've learned while getting my Masters Degree. I've now graduated, and since my school work is done, I have had a lot of time to review my schooling and to think of the costs and benefits of my undergraduate and graduate work.&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="font-size: large;"&gt;Addressing&amp;nbsp;the Myths&lt;/span&gt;&lt;br /&gt;
Over the years I have heard repeated many arguments against college which I simply don't believe are valid. Here are the common myths that I've heard along with my counter argument.&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &lt;b&gt;1. A degree is just a piece of paper&lt;/b&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; This is simply not true. A degree is a certification from an educational institution that you have&amp;nbsp;successfully&amp;nbsp;completed an academic program. A degree is intangible, a diploma is tangible and is typically a piece of high quality paper.&lt;br /&gt;
&lt;br /&gt;
&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;b&gt;2. A diploma is just a piece of paper&lt;/b&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&amp;nbsp; &amp;nbsp; This is true, but the diploma is not really the goal of going to college. The diploma is a token that represents something of greater value. The diploma is nothing more than a certificate to show you have a degree. The concept of a token that represents something of value is not only limited to college diplomas. Cash, paychecks, car and house titles are all just pieces of paper, but their value is much greater than the cost of the paper that they're printed on. There is also a greater probability that you will be able to obtain the later pieces of paper such as cash, titles, paychecks if you have first obtained the first piece of paper a diploma.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&amp;nbsp; &amp;nbsp; &lt;b&gt;3. Just because you have a degree doesn't mean you're smart.&lt;/b&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; This is certainly true. I have met and interviewed many degreed Software Engineers who managed to make it through college without retaining much of what they studied. Many of these unqualified Software Engineers were even able to pass their classes with good grades. So, I completely agree that the process of getting a degree will not guarantee competence. I have also met and interviewed non-degreed Software Engineers who were also incompetent and unqualified. So if a degree does not guarantee competence then why bother getting a degree? The answer is that a degree can help you become more competent, and therefore, a degreed individual is much more likely to be competent. &amp;nbsp;My experience in talking and interviewing Software Engineers leads me to believe that there are a higher percentage of degreed Software&amp;nbsp;Engineering&amp;nbsp;that are competent than there are non-degreed Software Engineers that are competent. Just like safe driving habits won't guarantee you won't die in an auto accident a degree won't guarantee you'll be competent, but both will increase the likelihood of safety and competency respectively.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&amp;nbsp; &amp;nbsp; 4. I don't have a degree, and I'm smarter than those that do.&lt;/b&gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; This is entirely possible. As I mentioned before, I've met non-degreed Software Engineers who surpassed the average degreed counterparts in ability and competency. I do, however, think that this scenario is rare and unlikely. Of the non-degreed Software Engineers that I've known and interviewed, I have observed that there are many more who had an&amp;nbsp;exaggerated&amp;nbsp;perception of their abilities then those who's abilities we're above the average degreed Software Engineer. The idea that there are a lot non-degreed Software Engineers who erroneously think they are extra competent should not come as a surprise to those that are familiar with &lt;a href="http://en.wikipedia.org/wiki/Illusory_superiority"&gt;illusory superiority&lt;/a&gt;&amp;nbsp;where people tend to overestimate their abilities or the &lt;a href="http://en.wikipedia.org/wiki/Dunning%E2%80%93Kruger_effect"&gt;Dunning-Kruger effect&lt;/a&gt;&amp;nbsp;where the least competent tend to overestimate their abilities the most. If college degrees do in fact increase competency, then it would be expected that non-degreed individuals would not only be less competent, but would also not have the knowledge required to grasp the depth of their incompetence.&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &lt;b&gt;5. College is a waste of money. &amp;nbsp;They don't teach anything that you can't learn on your own.&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&amp;nbsp; &amp;nbsp; &lt;/b&gt;While I agree that college doesn't teach you anything that you can't learn on your own. I do not think that it is a waste of money. I believe that college provides several benefits over self learning. Namely:&lt;br /&gt;
&lt;blockquote&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;b&gt;A. Access to experts.&lt;/b&gt; Many of my classes were taught by professors who were considered experts in their fields. They kept up to date on the latest research and technology and shared that with their students. I remember discussing with a professor at the University of Utah an idea that I had for a research project for my Masters Thesis. He not only was able to quickly point out that my research topic had already been fully explored about 10 years earlier (a fact that I was not able to discover on my own despite several internet searches), he was also able to point me to that research. If I didn't have access to this professor, I would have spent a lot of time gaining knowledge that could have been gained in much less time by reading a&amp;nbsp;handful&amp;nbsp;of academic papers. This professor helped me to focus my research on areas that had not already been extensively explored.&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;b&gt;B.&amp;nbsp;Immediate&amp;nbsp;feedback.&lt;/b&gt; More that once I've done an assignment, taken a test, or participated in a class lecture thinking that I fully understood a subject, only to find out the next week when the graded work was returned that I didn't. If you study on your own you may likewise misunderstand a topic, but you may not get the feedback that you need.&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;b&gt;C. A well rounded&amp;nbsp;curriculum.&lt;/b&gt;&amp;nbsp;Both my Masters and Bachelors degrees surprised me at not only the depth of learning that I received but also the breadth. I think it would be possible (although much more difficult) for me to&lt;b&gt;&amp;nbsp;&lt;/b&gt;learn those topics on my own, but I'm less confident I would have known that some of those topics even existed or that they were important. I didn't know what I didn't know. It is impossible to study a topic that you don't know exists. A good example of this is big-O notation. Many un-degreed Computer Scientists have never heard of big-O notation or have shallow or incorrect understanding of what it is. In my job we use it all the time, if you don't know what it is you'll be left behind in the conversation or you'll require us to stop work and teach you about the topic (at work we pay you to be effective, we don't want to pay you to get an education). It's not a terribly difficult topic, but you won't learn it if you don't know it exists, and it's easy to get confused about what it really means. A good degree in Computer Science will guarantee the exposure to the topic and a good professor will give ample feedback to ensure a proper understanding.&lt;br /&gt;
&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; D. Access to equipment and technologies.&lt;/b&gt;&amp;nbsp;Somethings you just can't learn (adequately) from books. You need to get you hands dirty and work with it. Many of these equipment and technologies are out of the price range for many people. Colleges can provide access to these technologies at a cheaper cost than if you purchased all the technologies on your own.&lt;/blockquote&gt;&lt;b&gt;&lt;br /&gt;
&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&amp;nbsp; &amp;nbsp; 6. But if you did learn it all on your own and you are competent why don't employers just interview you so you can prove that you're qualified? &lt;/b&gt;They could but interviewing is expensive. I believe the right way to interview for a technical position is to have your most qualified employees ask candidates technical questions. This process is likely to result in hiring a qualified candidate. First of all, your most qualified employees are also likely your highest paid employees, so you're paying them a lot of money to interview. They are also likely to be overworked as they can perform the most tasks (hence the most qualified) and if they weren't overworked you wouldn't be hiring. &amp;nbsp; If you interview every candidate you will spend a lot of money paying your existing employees to interview and it is likely that your employees will get tired of interviewing and they may leave for another job where they can do real work and not perform job interviews. Because interviewing is expensive you must be selective with who you interview, so it makes sense to only interview those candidates that are most likely to be qualified. In my experience degrees individuals are most likely to be qualified and so it may make good business sense to toss the resumes of the candidates that don't have degrees. An obvious exception to this rule is if you simply do not have enough candidates, in which case, you may end up interviewing all candidates, but you should start with those who are most likely to be qualified first.&lt;br /&gt;
&lt;b&gt;&amp;nbsp; &amp;nbsp;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&amp;nbsp; &amp;nbsp; 7. What about professors who live in their ivory towers and know nothing about the real world?&lt;/b&gt;&amp;nbsp; This is a common criticism about professors, and one that I've probably uttered a time or two. Such professors do exist, but I've found that often what they teach isn't applicable to today's real world problems but it often becomes applicable in the future. I remember learning about closures while working on my Bachelors degree. At the time I didn't think I'd ever use them as C/C++ Java ruled the industry. Since then Perl, Python, Ruby, JavaScript, Google Go have all become more predominant and all support closures. Even C++ recently added support for lambdas which in C++ are close to full grown closures. Had I ignored this topic, I would have had a more difficult time learning these languages and taking advantage of the power of closures. Additionally many of the students that are complaining about ivory tower professor do not have any real experience in the "real world" either. They are college students, who haven't spent a lot of time working in the "real wold," and, therefore, likely unqualified to determine what knowledge will have real world significance.&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;
&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;div style="display: inline !important;"&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-size: large;"&gt;Conclusion&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
While I don't think&amp;nbsp;college&amp;nbsp;is perfect, I do believe the vast majority of people&amp;nbsp;entering&amp;nbsp;technical fields would greatly benefit from obtaining a college degree. I've talked to many who don't have degrees who feel that they aren't useful, but very few who have earned a technical degree who question the benefit. If there are additional&amp;nbsp;augments against earning a college degree in a technical field that I haven't addressed, I would love to hear them.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7573455095858650997-887225766882898490?l=evanfarrer.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://evanfarrer.blogspot.com/feeds/887225766882898490/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://evanfarrer.blogspot.com/2011/08/why-you-should-get-college-degree.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7573455095858650997/posts/default/887225766882898490'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7573455095858650997/posts/default/887225766882898490'/><link rel='alternate' type='text/html' href='http://evanfarrer.blogspot.com/2011/08/why-you-should-get-college-degree.html' title='Why you should get a college degree'/><author><name>Evan</name><uri>http://www.blogger.com/profile/03848709590438147138</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_Pxmu7QQVgkk/SrI9CTHifyI/AAAAAAAAAE8/evZ3klxp4YM/S220/evan.jpeg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7573455095858650997.post-6133095105355779993</id><published>2011-07-14T15:31:00.000-06:00</published><updated>2011-07-14T15:31:02.674-06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='bash gnuplot'/><title type='text'>Using gnuplot to make simple line graphs.</title><content type='html'>Gnu plot is an amazing tool. It's great for generating quick plots from bash. I've had my programs generate statistical data and then thrown it into gnuplot so I can better understand how my program is behaving. Unfortunately every time I use it I end up having to go back to the web to relearn the basic syntax of creating a line graph. I'm going to try and save myself some time by documenting the basic usage here.&lt;br /&gt;
&lt;br /&gt;
To draw a simple line graph first place the points to draw in a separate file in this case named "gnuplot.data"&lt;br /&gt;
&lt;script src="https://gist.github.com/1083443.js?file=gnuplot.data"&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;br /&gt;
Now create the gnuplot script:&lt;br /&gt;
&lt;script src="https://gist.github.com/1083451.js?file=gistfile1.txt"&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;br /&gt;
The pause line at the end keeps the gnuplot from flashing the graph and then immediately exiting. When you execute gnuplot you'll see the following:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-hXAkiCtGzGc/Th9dDiZgIHI/AAAAAAAAAJo/Y32lxXjKp2g/s1600/gnuplot.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="233" src="http://3.bp.blogspot.com/-hXAkiCtGzGc/Th9dDiZgIHI/AAAAAAAAAJo/Y32lxXjKp2g/s320/gnuplot.png" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
There is a ton more you can do with gnuplot like generate png files, create different types of graphs, but I've found that as a simple programming tool this gets me 90% there. For more information checkout the&amp;nbsp;&lt;a href="http://www.gnuplot.info/"&gt;gnuplot homepage&lt;/a&gt;. &amp;nbsp;Happy plotting&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7573455095858650997-6133095105355779993?l=evanfarrer.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://evanfarrer.blogspot.com/feeds/6133095105355779993/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://evanfarrer.blogspot.com/2011/07/using-gnuplot-to-make-simple-line.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7573455095858650997/posts/default/6133095105355779993'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7573455095858650997/posts/default/6133095105355779993'/><link rel='alternate' type='text/html' href='http://evanfarrer.blogspot.com/2011/07/using-gnuplot-to-make-simple-line.html' title='Using gnuplot to make simple line graphs.'/><author><name>Evan</name><uri>http://www.blogger.com/profile/03848709590438147138</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_Pxmu7QQVgkk/SrI9CTHifyI/AAAAAAAAAE8/evZ3klxp4YM/S220/evan.jpeg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/-hXAkiCtGzGc/Th9dDiZgIHI/AAAAAAAAAJo/Y32lxXjKp2g/s72-c/gnuplot.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7573455095858650997.post-1862467957464286556</id><published>2011-06-08T21:44:00.000-06:00</published><updated>2011-06-08T21:44:18.387-06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='unit-testing'/><category scheme='http://www.blogger.com/atom/ns#' term='development practices'/><title type='text'>Test Second Development</title><content type='html'>Let me start off by stating that I'm a big fan of test-first development. I think that a (the?) major benefit of writing unit-tests is the fact that the first person to use a new API is the developer herself/himself. By first writing tests against the API before it has written you increase the likely hood of creating a unable, testable and bug free code. Test-first development is valuable even if you &lt;b&gt;never&lt;/b&gt;&amp;nbsp;ran any of the unit-tests that you wrote. The purpose of this post is not to&amp;nbsp;extol&amp;nbsp;the virtues of test-first development but to share a scenario where I feel it may be &amp;nbsp;better to not write the unit-tests right away.&lt;br /&gt;
&lt;br /&gt;
Several weeks ago I started to work on a simple command line utility. Nothing fancy but just something to scratch an itch that I've had for a while. I had a vague idea of what I wanted it to do but hadn't quite worked out all of the details. Additionally I wasn't sure how the utility would involve. Finally I was writing the utility in Google Go, which I have done a bit of development but I certainly haven't played with it long enough to fully think in the language. In short I simply didn't know what I was doing and I knew it would be some time before I fully understood the problem I was trying to solve. I started to write the code and neglected to start by writing unit-tests. After some time of hacking on the utility I finally got to the point where I had a working prototype and I finally understood the problem. At that point I reviewed the code of my program and I realized that I had (not&amp;nbsp;surprisingly) got the architecture of the program wrong. I figured out the right architecture of the program and started on the refactor. During the refactor the majority of the original code and internal API's was radically changed. If I had written any unit-tests they would have been discarded as the code and API's they would have tested simply did not exist in the refactored program. I could have preserved end-to-end tests but not any unit-tests. During the refactor I wrote unit-tests and I now have a program that has good unit-test coverage. I'll call this development process "Test Second Development". I'd like to propose the following criteria for when test-second development &lt;b&gt;may&lt;/b&gt;&amp;nbsp;be appropriate.&lt;br /&gt;
&lt;br /&gt;
&lt;ol&gt;&lt;li&gt;You don't understand the program you are writing.&lt;/li&gt;
&lt;li&gt;You don't understand the language you are writing the program in.&lt;/li&gt;
&lt;li&gt;You will have the luxury of refactoring the program once you understand it, and before it "ships".&lt;/li&gt;
&lt;li&gt;You're&amp;nbsp;disciplined&amp;nbsp;enough to write unit-tests when you do your rewrite/refactor.&lt;/li&gt;
&lt;/ol&gt;&lt;div&gt;In other words I think it may be OK to delay writing unit-test when you are writing a true *prototype.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;My thoughts on test-second development are still&amp;nbsp;immature&amp;nbsp;and evolving, but I thought I'd jot them down for future reference. In my case I don't think that I would have gained any benefit to using test-first development and I can definitely see how test-first development would have slowed down the discovery process.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;* If you are writing code for your job and anyone else will know about your project, then I really doubt you will ever write a prototype. As soon as someone sees or hears about your project they'll want to ship it. I once worked for a company that shipped a simple utility that I had written to aid in testing my code. I only found out that they had shipped it after my manager came and talked with me about the utility and told me that I needed to pretty up the GUI. When I told him that it was a testing utility and was never meant to be shipped he told me that since it was shipped we'd have to support it. I started prettying up the GUI and started on a new testing utility. The new testing utility had a big banner across the front stating that it was for internal testing only. I later learned that calling testing tools something like "The&amp;nbsp;enema tester" was a good strategy for ensuring that internal testing tools never got shipped.&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7573455095858650997-1862467957464286556?l=evanfarrer.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://evanfarrer.blogspot.com/feeds/1862467957464286556/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://evanfarrer.blogspot.com/2011/06/test-second-development.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7573455095858650997/posts/default/1862467957464286556'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7573455095858650997/posts/default/1862467957464286556'/><link rel='alternate' type='text/html' href='http://evanfarrer.blogspot.com/2011/06/test-second-development.html' title='Test Second Development'/><author><name>Evan</name><uri>http://www.blogger.com/profile/03848709590438147138</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_Pxmu7QQVgkk/SrI9CTHifyI/AAAAAAAAAE8/evZ3klxp4YM/S220/evan.jpeg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7573455095858650997.post-2623084260030078860</id><published>2011-04-23T21:23:00.000-06:00</published><updated>2011-04-23T21:23:26.763-06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Go Cross Compiling'/><title type='text'>Cross Compiling Google Go Code</title><content type='html'>This is more of a note to self, so I can look up this information in the future as needed. Google Go makes it really easy to cross-compile. Here is how you an compile your Go project for another architecture. The first step is to compile the cross compiling compilers (I can't believe I just typed that). So lets checkout the source code for the go compiler.&lt;br /&gt;
&lt;pre class="brush: bash"&gt;hg clone -r release https://go.googlecode.com/hg/ go&lt;/pre&gt;&lt;br /&gt;
Now to compile the Go compiler for the architecture of your machine, simply cd into the go/src directory and run the all.bash script&lt;br /&gt;
&lt;pre class="brush: bash"&gt;cd go/src; ./all.bash&lt;/pre&gt;If you want to create compilers for a different architecture you set the GOARCH environment variable and then run the make.bash script.&lt;br /&gt;
&lt;pre class="brush: bash"&gt;GOARCH=arm ./make.bash&lt;/pre&gt;&lt;pre class="brush: bash"&gt;GOARCH=386 ./make.bash&lt;/pre&gt;&lt;pre class="brush: bash"&gt;GOARCH=amd64 ./make.bash&lt;/pre&gt;&lt;br /&gt;
The all.bash script compiles the compiler and runs the unit tests, the make.bash script just compiles the compilers.&lt;br /&gt;
&lt;br /&gt;
This will create separate compilers, linkers and assemblers for each of the three architectures. Because each compiler, linker and assembler have a different name you can have support all architectures simultaneously. &lt;br /&gt;
&lt;br /&gt;
Once you have the Go compilers compiled you can now compile your project for different architectures by creating a Go Makefile and setting the GOARCH environment variable before typing make.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush: bash"&gt;GOARCH=arm make&lt;/pre&gt;&lt;pre class="brush: bash"&gt;GOARCH=386 make&lt;/pre&gt;&lt;pre class="brush: bash"&gt;GOARCH=amd64 make&lt;/pre&gt;&lt;br /&gt;
That's it! You can now cross compile your Go code. More information on the Go compilers, creating a Go Makefile and getting started with Go can be found &lt;a href="http://golang.org/cmd/"&gt;here&lt;/a&gt;, &lt;a href="http://golang.org/doc/code.html"&gt;here&lt;/a&gt;, and &lt;a href="http://golang.org/doc/install.html"&gt;here&lt;/a&gt; respectively. Happy Hacking!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7573455095858650997-2623084260030078860?l=evanfarrer.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://evanfarrer.blogspot.com/feeds/2623084260030078860/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://evanfarrer.blogspot.com/2011/04/cross-compiling-google-go-code.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7573455095858650997/posts/default/2623084260030078860'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7573455095858650997/posts/default/2623084260030078860'/><link rel='alternate' type='text/html' href='http://evanfarrer.blogspot.com/2011/04/cross-compiling-google-go-code.html' title='Cross Compiling Google Go Code'/><author><name>Evan</name><uri>http://www.blogger.com/profile/03848709590438147138</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_Pxmu7QQVgkk/SrI9CTHifyI/AAAAAAAAAE8/evZ3klxp4YM/S220/evan.jpeg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7573455095858650997.post-1966324366304607960</id><published>2011-04-22T21:17:00.000-06:00</published><updated>2011-04-22T21:17:54.378-06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='School'/><category scheme='http://www.blogger.com/atom/ns#' term='Life'/><category scheme='http://www.blogger.com/atom/ns#' term='Masters'/><title type='text'>I'm back</title><content type='html'>Last year I decided that it was time to finish up my Masters degree. I recognized that in order to finish in a timely manner I would need to forgo all hobbies for a while and so this blog has been on hold. I'm now done, or at least I'm at the stage where I'm waiting for the final announcement that I'm done and so I'm now returning to normal life. After having dropped out more than a year ago I'm finding that it's taking some time to get adjusted to normal non-academic life. I'm also slowly starting to remember all the non-homework activities that I used to participate in. I wonder how long it will be before I become as busy as I was before.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7573455095858650997-1966324366304607960?l=evanfarrer.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://evanfarrer.blogspot.com/feeds/1966324366304607960/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://evanfarrer.blogspot.com/2011/04/im-back.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7573455095858650997/posts/default/1966324366304607960'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7573455095858650997/posts/default/1966324366304607960'/><link rel='alternate' type='text/html' href='http://evanfarrer.blogspot.com/2011/04/im-back.html' title='I&apos;m back'/><author><name>Evan</name><uri>http://www.blogger.com/profile/03848709590438147138</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_Pxmu7QQVgkk/SrI9CTHifyI/AAAAAAAAAE8/evZ3klxp4YM/S220/evan.jpeg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7573455095858650997.post-5212920017261302439</id><published>2010-03-16T22:41:00.000-06:00</published><updated>2010-03-16T22:41:22.116-06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='guidelines competency'/><title type='text'>Developer Etiquette</title><content type='html'>I created a list of etiquette guidelines for Software Engineers. &amp;nbsp;These etiquette guidelines are not for social interactions, but are instead for writing code. &amp;nbsp;Like most etiquette guidelines these are designed to minimize the discomfort for others. &amp;nbsp;So here they are.&lt;br /&gt;
&lt;br /&gt;
Before committing I will:&lt;br /&gt;
&lt;br /&gt;
&lt;ol&gt;&lt;li&gt;Review the patch.&lt;/li&gt;
&lt;li&gt;Review the list of files that are not being committed, but have been modified or are new.&lt;/li&gt;
&lt;li&gt;Compile the code.&lt;/li&gt;
&lt;li&gt;Run any affected unit-tests.&lt;/li&gt;
&lt;li&gt;Test the code to make sure it does not break core functionality.&lt;/li&gt;
&lt;/ol&gt;The reason behind #1 is simple. &amp;nbsp;It's very easy to accidentally commit code that's not ready, or that contains printf debug code. &amp;nbsp;It's quite obnoxious to have your terminal sprayed with hundreds of "XXX Hey I'm executing function foo()." &amp;nbsp;By following guideline number #1 you will rarely accidentally commit half-baked code. &amp;nbsp;The git add --patch command makes this really easy.&lt;br /&gt;
&lt;br /&gt;
Guideline #2 saves you from forgetting to commit some critical patch, or more commonly forgetting to add a new file to the repository. &amp;nbsp;I've found that most of the time when code compiles on the developer's computer but not anyone else's, it's because they forgot to add a file. &amp;nbsp;The git status command helps here.&lt;br /&gt;
&lt;br /&gt;
Guideline #3 is simple. &amp;nbsp;Committing code that doesn't compile turns a O(1) problem into a O(n) where n is the number of developers on your team. &amp;nbsp;Don't ever check in code that doesn't compile.&lt;br /&gt;
&lt;br /&gt;
Guideline #4 ensures that you don't accidentally break the unit-tests. &amp;nbsp;It is much easier to fix bugs earlier rather than later. &amp;nbsp;So if you break the tests it's better to find out before you commit.&lt;br /&gt;
&lt;br /&gt;
Guideline #5 is similar to #4 but assumes that not all of your code is covered by unit-tests. &amp;nbsp;Even if you test every line of code with unit-tests, your unit-tests won't tell you that you just made your GUI look like puke. &amp;nbsp;So run the code and make sure nothing broke.&lt;br /&gt;
&lt;br /&gt;
If you follow these guidelines you can still write horribly broken code and be a terrible developer, but at least you won't prevent your co-workers from being competent.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7573455095858650997-5212920017261302439?l=evanfarrer.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://evanfarrer.blogspot.com/feeds/5212920017261302439/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://evanfarrer.blogspot.com/2010/03/developer-etiquette.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7573455095858650997/posts/default/5212920017261302439'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7573455095858650997/posts/default/5212920017261302439'/><link rel='alternate' type='text/html' href='http://evanfarrer.blogspot.com/2010/03/developer-etiquette.html' title='Developer Etiquette'/><author><name>Evan</name><uri>http://www.blogger.com/profile/03848709590438147138</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_Pxmu7QQVgkk/SrI9CTHifyI/AAAAAAAAAE8/evZ3klxp4YM/S220/evan.jpeg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7573455095858650997.post-1190233514976848002</id><published>2010-01-20T22:42:00.001-07:00</published><updated>2010-02-22T21:07:34.269-07:00</updated><title type='text'>Easy to Use</title><content type='html'>I've noticed that when choosing a tool for software development one of the criteria that's often proposed is the tool should be "easy to use".  While I agree that ease of use should be a criteria for choosing a tool I've come to realize that I have a different opinion on what "easy to use" means than others.  When I say a tool is "easy to use" I mean it literally.  A tool that is easy to use should make it really easy for me to do what I want.  Here are some of the development tools that I use that I consider easy to use:&lt;br /&gt;
&lt;br /&gt;
&lt;ol&gt;&lt;li&gt;vim&lt;/li&gt;
&lt;li&gt;git&lt;/li&gt;
&lt;li&gt;The command line (bash)&lt;/li&gt;
&lt;/ol&gt;All three of these tools let me do my job as quickly and painlessly as possible. &amp;nbsp;If you asked others for a list of similar tools that are easy to use you may get the following:&lt;br /&gt;
&lt;br /&gt;
&lt;ol&gt;&lt;li&gt;notepad&lt;/li&gt;
&lt;li&gt;svn&lt;/li&gt;
&lt;li&gt;GUI's&lt;/li&gt;
&lt;/ol&gt;By my definition the above tools are not easier to use than my list (they don't allow me to do my job as quickly or painlessly) but they are easier to &lt;b&gt;learn&lt;/b&gt;. &amp;nbsp;I'm not sure if easy to learn and easy to use must be mutually exclusive but I can't think of any tools that I use frequently that have both qualities. &amp;nbsp;There is nothing wrong with choosing a tool that's easier to learn over one that's easier to use as long as you use the tool infrequently. &amp;nbsp;Investing years to fully learn vim is a waste of time if you only edit text files for a few minutes every month. &amp;nbsp;If your going to use a tool frequently over a long period of time then you should spend the time to learn the tool that's easy to use even if it isn't easy to learn.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7573455095858650997-1190233514976848002?l=evanfarrer.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://evanfarrer.blogspot.com/feeds/1190233514976848002/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://evanfarrer.blogspot.com/2010/01/easy-to-use.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7573455095858650997/posts/default/1190233514976848002'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7573455095858650997/posts/default/1190233514976848002'/><link rel='alternate' type='text/html' href='http://evanfarrer.blogspot.com/2010/01/easy-to-use.html' title='Easy to Use'/><author><name>Evan</name><uri>http://www.blogger.com/profile/03848709590438147138</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_Pxmu7QQVgkk/SrI9CTHifyI/AAAAAAAAAE8/evZ3klxp4YM/S220/evan.jpeg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7573455095858650997.post-6396049752569384790</id><published>2010-01-05T21:34:00.000-07:00</published><updated>2010-01-05T21:34:30.973-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='recursion induction programming'/><title type='text'>Recursion and Inductive Proofs</title><content type='html'>I've discovered that programmers frequently stumble when writing recursive algorithms.  There are some simple rules that programmers can steal from mathematics to make writing recursive algorithms easy.  I should point out that I'm only talking about writing recursive algorithms for interacting with recursive data-structures (lists, trees, etc.).  Let's get started by reviewing some basic steps for proving a statement holds for all natural numbers&amp;nbsp;&lt;i&gt;n&lt;/i&gt; using an inductive proof.&lt;br /&gt;
&lt;ol&gt;&lt;li&gt;Base case: &amp;nbsp;Show the statement holds for a value of &lt;i&gt;n&lt;/i&gt; (usually &lt;i&gt;n&lt;/i&gt;=1 or &lt;i&gt;n&lt;/i&gt;=0).&lt;/li&gt;
&lt;li&gt;Inductive step: &amp;nbsp;Assuming the statement holds for any value of &lt;i&gt;n&lt;/i&gt; then show it also holds for a value of &lt;i&gt;n&lt;/i&gt;+1&lt;/li&gt;
&lt;/ol&gt;Rule 2.5 would be to make sure that the inductive step reduces the problem space. &amp;nbsp;Using a base case of &lt;i&gt;n&lt;/i&gt;=0 and then and inductive step of &lt;i&gt;n&lt;/i&gt;-1 wouldn't be a valid proof because the inductive step does not really reduce the problem space (remember we're talking about natural numbers for this example). &amp;nbsp;So let's use an inductive proof to show that 0+1+2...&lt;i&gt;n&lt;/i&gt;=(&lt;i&gt;n&lt;/i&gt;(&lt;i&gt;n&lt;/i&gt;+1))/2.&lt;br /&gt;
&lt;br /&gt;
Base case: Show the statement holds for &lt;i&gt;n&lt;/i&gt;=0&lt;br /&gt;
&lt;pre class="brush: cpp"&gt;0=0(0+1)/2
&lt;/pre&gt;This equation clearly holds.&lt;br /&gt;
&lt;br /&gt;
Inductive step: &amp;nbsp;Assuming the statement holds for any value of &lt;i&gt;n&lt;/i&gt; then show it will also hold for &lt;i&gt;n&lt;/i&gt;+1.&lt;br /&gt;
&lt;pre class="brush: cpp"&gt;0+1+2...n+(n+1) = ((n+1)((n+1)+1)/2
&lt;/pre&gt;If we assume that the statement holds for &lt;i&gt;n&lt;/i&gt; then we can reduce the expression.&lt;br /&gt;
&lt;pre class="brush: cpp"&gt;(n(n+1))/2 + (n+1) = ((n+1)((n+1)+1)/2
&lt;/pre&gt;Using some basic algebra we can reduce both sides and discover that the inductive step holds.&lt;br /&gt;
&lt;br /&gt;
Now we can apply same (perhaps slightly tweaked) rules to writing a recursive algorithm for finding the length of a linked-list (a recursive data-structure).&lt;br /&gt;
&lt;br /&gt;
Let's start out with the function signature.&lt;br /&gt;
&lt;pre class="brush: cpp"&gt;int length(Node *node)
{
  // Do stuff here
}
&lt;/pre&gt;Base case: Write the algorithm for &lt;i&gt;n&lt;/i&gt;=0 (the linked-list with 0 nodes).&lt;br /&gt;
&lt;pre class="brush: cpp"&gt;int length(Node *node)
{
  if (NULL == node)
  {
    return 0;
  }
  // Do more stuff here
}
&lt;/pre&gt;Congratulations!  If you've make it this far you're above average.  You've solved the base case without dumping core.&lt;br /&gt;
&lt;br /&gt;
Now onto the inductive step:  Assume that your length function will work for lists of length &lt;i&gt;n&lt;/i&gt; now write code to make it work for lists of length &lt;i&gt;n&lt;/i&gt; + 1.&lt;br /&gt;
&lt;pre class="brush: cpp"&gt;int length(Node *node)
{
  if (NULL == node)
  {
    return 0;
  }
  else
  {
    return 1 + length(node-&gt;next);
  }
}
&lt;/pre&gt;Notice that if we assume that "length(...)" works for lists of length &lt;i&gt;n&lt;/i&gt; then for lists of length &lt;i&gt;n&lt;/i&gt; + 1 all we need to do is add 1 to the length.  You should also notice that we passed &lt;i&gt;node-&gt;next&lt;/i&gt; to the "length(...)" function not just &lt;i&gt;node&lt;/i&gt; because rule 2.5 states that the inductive step must reduce the problem space and just passing &lt;i&gt;node&lt;/i&gt; would not reduce the problem space.  Congratulations!  If you've make it this far you're now well above average.  Now not only will your algorithm not core dump, but it won't hang either.&lt;br /&gt;
&lt;br /&gt;
So let's review what we've done.  We've used the rules for inductive proofs to guide us in writing a recursive algorithm.  Does this mean we've proved that this algorithm is correct?  The answer is, not really or at least, not formally.  Even though we haven't proved this algorithm is correct we can be much more confident that it will work.  &lt;br /&gt;
&lt;br /&gt;
If we were to write unit-tests for this algorithm (which you should *always* do before writing the algorithm) we could use the rules of induction to guide our unit tests.  We could write a test for testing the base case and another test for testing the inductive case.&lt;br /&gt;
&lt;br /&gt;
Since math has been around longer than computers, it makes sense that we could borrow a few ideas from it to make our jobs easier.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7573455095858650997-6396049752569384790?l=evanfarrer.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://evanfarrer.blogspot.com/feeds/6396049752569384790/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://evanfarrer.blogspot.com/2010/01/recursion-and-inductive-proofs.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7573455095858650997/posts/default/6396049752569384790'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7573455095858650997/posts/default/6396049752569384790'/><link rel='alternate' type='text/html' href='http://evanfarrer.blogspot.com/2010/01/recursion-and-inductive-proofs.html' title='Recursion and Inductive Proofs'/><author><name>Evan</name><uri>http://www.blogger.com/profile/03848709590438147138</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_Pxmu7QQVgkk/SrI9CTHifyI/AAAAAAAAAE8/evZ3klxp4YM/S220/evan.jpeg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7573455095858650997.post-1427495995407663347</id><published>2009-11-27T22:27:00.000-07:00</published><updated>2009-11-27T22:27:21.771-07:00</updated><title type='text'>Google's Go trying to be too clever.</title><content type='html'>I've discovered a couple of cases where Google's Go is trying to be too clever.  There are two expressions who's behavior changes based upon what is done with evaluated results.  Lets look at a bit of code.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush: cpp"&gt;package main

import . "fmt"

// Define a simple struct
type foo struct {
        a int;
}

// Define an interface
type plus1 interface {
        add1() int;
}

func any(a interface{}) {
        v := a.(plus1).add1();
        Printf("%v\n", v);
}

func main() {
        f := foo{1};
        any(f);
}
&lt;/pre&gt;&lt;br /&gt;
So this code defines a simple struct "foo" with a single member a.  It defines a "plus1" interface that says that any struct that implements the interface must implement an add1 method that returns an int.  The main function instantiates a "foo" and passes it onto the any function.  Because "foo" doesn't implement the "plus1" interface the first expression in the function "any" will fail with a runtime exception.  the "a.(plus1)" is called a type assertion and it fails if the "a" doesn't implement the "plus1" interface.  Now we can switch this code so the type assertion won't assert by assigning the results of the type expression to some variables.  Consider the following:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush: cpp"&gt;package main

import . "fmt"

// Define a simple struct
type foo struct {
        a int;
}

// Define an interface
type plus1 interface {
        add1() int;
}

func any(a interface{}) {
        a1, ok := a.(plus1);
        if ok {
                v := a1.add1();
                Printf("%v\n", v);
        }
 }

func main() {
        f := foo{1};
        any(f);
}
&lt;/pre&gt;&lt;br /&gt;
The only difference in this code is that the type assertion will not assert but instead return two values (yes Go can return multiple values!).  The second value is of type bool which indicates whether the first value is "a" cast to "plus1".  If "a" isn't of type "plus1" then instead of asserting the type assertion will just return false for the second parameter.  While this is clever, it feels like assigning the return value to a variable magically alters the behavior of the expression.  I think this will just make the language too difficult to learn.  The second operation has to do with go-routines and I'll talk about it next time.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7573455095858650997-1427495995407663347?l=evanfarrer.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://evanfarrer.blogspot.com/feeds/1427495995407663347/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://evanfarrer.blogspot.com/2009/11/googles-go-trying-to-be-too-clever.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7573455095858650997/posts/default/1427495995407663347'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7573455095858650997/posts/default/1427495995407663347'/><link rel='alternate' type='text/html' href='http://evanfarrer.blogspot.com/2009/11/googles-go-trying-to-be-too-clever.html' title='Google&apos;s Go trying to be too clever.'/><author><name>Evan</name><uri>http://www.blogger.com/profile/03848709590438147138</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_Pxmu7QQVgkk/SrI9CTHifyI/AAAAAAAAAE8/evZ3klxp4YM/S220/evan.jpeg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7573455095858650997.post-1040815981450000630</id><published>2009-11-18T15:06:00.001-07:00</published><updated>2009-11-18T15:09:09.349-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='C/C++ strongly typed Go'/><title type='text'>Letting the compiler find the bugs</title><content type='html'>Lets start by looking at a bit of contrived C/C++ code.  See if you can spot the (hopefully obvious) bug.&lt;br /&gt;
&lt;pre class="brush: cpp"&gt;#include &amp;lt;stdio.h&amp;gt;

int main()
{
    float fieldLength = 120; // yards
    float fieldWidth  = 48.77; // meters
    float yardsInAMile = 1760; // yards per mile

    printf("You must run around the perimeter of an American football field %f times to run a marathon\n", 
            26.2 * (yardsInAMile / ((fieldLength * 2) + (fieldWidth * 2))));

    return 0;
}
&lt;/pre&gt;&lt;br /&gt;
It probably shouldn't take you too long to realize that in the above code I'm mixing units.  I'm adding yards to meters.  While bugs like this are obvious in trivial code they can be difficult to track down in more complex software.  What can we do to prevent bugs like this from creeping into code?  One solution is to use coding standards to reduce ambiguity.  For example you could decide to use metric units for all data in your project.  You could also use 'typedefs' and variable naming conventions to make errors even more obvious.  Consider the following:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush: cpp"&gt;#include &amp;lt;stdio.h&amp;gt;
typedef float yards;
typedef float meters;

int main()
{
    yards fieldLengthYards = 120; // yards
    meters fieldWidthMeters  = 48.77; // meters
    float yardsInAMile = 1760; // yards per mile

    printf("You must run around the perimeter of an American football field %f times to run a marathon\n", 
            26.2 * (yardsInAMile / ((fieldLengthYards * 2) + (fieldWidthMeters * 2))));

    return 0;
}
&lt;/pre&gt;&lt;br /&gt;
By including the units in the variable names and types it makes the programmers intentions clear.  It's also easier to spot bugs in code audits.  For even more safety you could define Meters and Yards classes that encapsulate the floats and prevent mixing of types.  The advantage of defining new types/classes is the compiler can now ensure that you don't mix types.  The disadvantage is that you'll end up writing a class for each type, with lots of overloaded operators.  Writing a class for every unit feels to burdensome for all but the most critical code (nukes, airplane firmware, surgery robots, etc.).  The problem with the above 'typedef' solution is that C/C++'s 'typedef' really only defines an alias for the type.  Both the type-checker and the compiler will treat 'meters' the exact same way it treats 'yards', we want the type-checker to treat 'meters' and 'yards' as distinct types and the compiler to treat them both as floats.  Google's new system language Go lets you do just that.  Lets reproduce the original bug in Google Go.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush: cpp"&gt;package main

import "fmt"

func main() {
    var fieldLength float = 120; // yards
    var fieldWidth  float = 48.77; // meters
    var yardsInAMile float = 1760; // yards per mile

    fmt.Printf("You must run around the perimeter of an American football field %f times to run a marathon\n", 
            26.2 * (yardsInAMile / ((fieldLength * 2) + (fieldWidth * 2))));
}
&lt;/pre&gt;&lt;br /&gt;
This has the same bug as the C/C++ code above.  The code should be readable to a C/C++ developer, the only really "weird" thing is that the type follows the variable name.  Now let's use Go's strong typing to let the compiler catch the bug for us.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush: cpp"&gt;package main

import "fmt"

type yards float
type meters float

func main() {
        var fieldLength yards = 120;
        var fieldWidth meters = 48.77;
        var yardsInAMile float = 1760; // yards per mile

        fmt.Printf("You must run around the perimeter of an American football field %f times to run a marathon\n",
                26.2*(yardsInAMile/((fieldLength*2)+(fieldWidth*2))));
}
&lt;/pre&gt;&lt;br /&gt;
Notice that all we did is define two new types 'yards' and 'meters' all which should act like 'floats', but should be treated differently by the type-checker.  When we compile we get the following error:&lt;br /&gt;
&lt;pre&gt;invalid operation: fieldLength * 2 + fieldWidth * 2 (type yards + meters)
&lt;/pre&gt;&lt;br /&gt;
The most important part of the error is at the end where it tells us we're trying to add 'yards' with 'meters'.  The type checker found the bug for us!  So how do we fix it?  We need some conversion routines.  So lets add some methods to the types and fix the bugs.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush: cpp"&gt;package main

import "fmt"

type yards float
type meters float
type miles float

func (m meters) toYards() yards { return yards(m * 1.0936133) }
func (y yards) toMiles() miles  { return miles(1760.0 / y) }

func main() {
        var fieldLength yards = 120;
        var fieldWidth meters = 48.77;

        fmt.Printf("You must run around the perimeter of an American football field %f times to run a marathon\n",
                26.2*((fieldLength*2)+(fieldWidth.toYards()*2)).toMiles());
}
&lt;/pre&gt;&lt;br /&gt;
With the corrected program we see that you only have to run around the field 133 times instead of 136.6 times!&lt;br /&gt;
&lt;br /&gt;
Go isn't the first nor the only programming language that allows you to encode units as types, but it's close enough to C/C++ for a good comparison.  So what's the runtime overhead of the change?  Well there are a couple of method calls (toYards(), toMiles()) where the original version did the conversions inline.  The error checking happens at compile time because Go is statically typed so there's no runtime performance hit.  Personally I'd much rather wait for my program to call a couple of functions than to run around an American football field 3.6 more times.&lt;br /&gt;
&lt;br /&gt;
By carefully using Go's (or any other language with a good type system) type system you can spend more time writing code and less time tracking down bugs.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7573455095858650997-1040815981450000630?l=evanfarrer.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://evanfarrer.blogspot.com/feeds/1040815981450000630/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://evanfarrer.blogspot.com/2009/11/letting-compiler-find-bugs.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7573455095858650997/posts/default/1040815981450000630'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7573455095858650997/posts/default/1040815981450000630'/><link rel='alternate' type='text/html' href='http://evanfarrer.blogspot.com/2009/11/letting-compiler-find-bugs.html' title='Letting the compiler find the bugs'/><author><name>Evan</name><uri>http://www.blogger.com/profile/03848709590438147138</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_Pxmu7QQVgkk/SrI9CTHifyI/AAAAAAAAAE8/evZ3klxp4YM/S220/evan.jpeg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7573455095858650997.post-3682024317610389622</id><published>2009-11-09T22:34:00.002-07:00</published><updated>2009-11-09T22:35:57.673-07:00</updated><title type='text'>More fun with C/C++</title><content type='html'>In order to write a program it's useful (but not necessary) to have an accurate mental model of how the language works, so you can mentally interpret your code before handing it off the compiler.  So if you're a C/C++ programmer take a look at the following code and see if you can correctly identify the output:&lt;br /&gt;
&lt;pre class="brush: cpp"&gt;#include &amp;lt;stdio.h&amp;gt;

int foo(int a, int b, int c, int d)
{
    if (a&gt;b)
    {
        return c;
    }
    else
    {
        return d;
    }
}

int main(int argc, char * argv[])
{
    int x = 2;
    int y = 1;

    printf("Result: %d\n", foo(x+=y, y+=x, x+=y, y+=x));

    return 0;
}
&lt;/pre&gt;In this case the output is non-deterministic.  While C/C++ specify what order arguments will be pushed onto the stack it doesn't specify what order they'll be evaluated in.  So there are several possibilities for the output.  This flexibility allows compiler writers to order the evaluation of operations in the most efficient way.  If you want to avoid confusing/broken code don't mutate variables in argument positions.  The person that ends up maintaining your code will thank you for it.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7573455095858650997-3682024317610389622?l=evanfarrer.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://evanfarrer.blogspot.com/feeds/3682024317610389622/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://evanfarrer.blogspot.com/2009/11/more-fun-with-cc.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7573455095858650997/posts/default/3682024317610389622'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7573455095858650997/posts/default/3682024317610389622'/><link rel='alternate' type='text/html' href='http://evanfarrer.blogspot.com/2009/11/more-fun-with-cc.html' title='More fun with C/C++'/><author><name>Evan</name><uri>http://www.blogger.com/profile/03848709590438147138</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_Pxmu7QQVgkk/SrI9CTHifyI/AAAAAAAAAE8/evZ3klxp4YM/S220/evan.jpeg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7573455095858650997.post-7858188922448635705</id><published>2009-10-21T22:33:00.008-06:00</published><updated>2009-10-22T21:13:45.772-06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='C++'/><title type='text'>Coding Challenge</title><content type='html'>Here is a little coding challenge.  Learning how to solve this probably won't make you a better programmer (it may make you worse) but it's fun anyway.  You are given a file named "helloworld.cxx" that contains the following code.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush: cpp"&gt;#include &amp;lt;stdio.h&amp;gt;
#include "muck.h"

int 
main(int argc, char **argv)
{
    printf("%s\n", "Hello World!");
}
&lt;/pre&gt;&lt;br /&gt;
You &lt;b&gt;can't&lt;/b&gt; edit this file!  Your job is to write the "muck.h" header file.  When you're done compile "helloworld.cxx" and run it and the output should be "Goodbye!" followed by a newline.  Nothing more nothing less.  Remember you can only modify "muck.h" and you must compile "helloworld.cxx" unmodified.  My &lt;a href="http://www.cs.utah.edu/~farrer/coding_challenge/muck.h"&gt;solution&lt;/a&gt; and it's &lt;a href="http://www.cs.utah.edu/~farrer/coding_challenge/Makefile"&gt;Makefile&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7573455095858650997-7858188922448635705?l=evanfarrer.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://evanfarrer.blogspot.com/feeds/7858188922448635705/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://evanfarrer.blogspot.com/2009/10/coding-challenge.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7573455095858650997/posts/default/7858188922448635705'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7573455095858650997/posts/default/7858188922448635705'/><link rel='alternate' type='text/html' href='http://evanfarrer.blogspot.com/2009/10/coding-challenge.html' title='Coding Challenge'/><author><name>Evan</name><uri>http://www.blogger.com/profile/03848709590438147138</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_Pxmu7QQVgkk/SrI9CTHifyI/AAAAAAAAAE8/evZ3klxp4YM/S220/evan.jpeg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7573455095858650997.post-2560417447338827889</id><published>2009-10-06T12:56:00.001-06:00</published><updated>2009-10-06T12:58:34.666-06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Schme Lisp Exceptions Macros Generators'/><title type='text'>The Essence of Scheme (part two)</title><content type='html'>This post is a continuation of &lt;a href="http://evanfarrer.blogspot.com/2009/09/essence-of-scheme.html"&gt;part one.&lt;/a&gt;  You probably want to read &lt;a href="http://evanfarrer.blogspot.com/2009/09/essence-of-scheme.html"&gt;that post&lt;/a&gt; first.  So in my previous post I walked you through a nifty little though experiment on why Scheme is so expressive, and why those pesky ('s and )'s are actually useful.  In this post I hope to provide some concrete examples of using Scheme's macros to do interesting things.  So lets start with a simple example.  The Scheme programming language (R5RS) doesn't have a built in "while" loop.  It does have a "do" loop which is kind of like a "for" loop but I don't think it gets used much.  Most Schemers use recursion instead.  Lets say you're just learning Scheme and recursion hurts your brain and you really really just want to use a "while" loop just this one time and you promise that you'll pay better attention when you CS professor talks about recursion.  It turns out it's quite easy to implement a "while" loop as a Scheme macro&lt;sup&gt;1&lt;/sup&gt;.&lt;br /&gt;
&lt;pre class="brush: cpp"&gt;;; A while loop
(define-syntax while
  (syntax-rules ()
    [(_ (cnd ...) body ...)
     (letrec ([tmp (lambda () (if (cnd ...) (begin body ... (tmp)) (void)))])
       (tmp))]))
&lt;/pre&gt;If you want to try it out here is a bit of code that uses the while loop to count from 10 down to 1.&lt;br /&gt;
&lt;pre class="brush: cpp"&gt;(define count 10)
(while (&gt; count 0)
       (printf "~a\n" count)
       (set! count (- count 1)))
&lt;/pre&gt;So in 10 lines of code you can define a "while" loop that works just like the "while" loops built into C/C++/Java/Python/Insert_Your_Favorite_Language_Here.&lt;br /&gt;
&lt;br /&gt;
So that doesn't seem to hard.  If C didn't have a built in "while" loop you could always create you're own with a C style macro as follows.&lt;br /&gt;
&lt;pre class="brush: cpp"&gt;#define WHILE(cond) for(;cond;)
&lt;/pre&gt;Lets try something more difficult.  Scheme also doesn't have a C/C++ "#include" directive.  So lets write our own.&lt;br /&gt;
&lt;pre class="brush: cpp"&gt;;; Define include
(define-syntax include
  (lambda (stx)
    (define (read-all port)
      (let ([exp (read port)])
        (if (eof-object? exp)
            '()
            (cons exp
                  (read-all port)))))
    (define read-file
      (lambda (fn ctx)
        (let ([port (open-input-file fn)])
          (begin0
            (datum-&gt;syntax ctx (read-all port))
            (close-input-port port)))))
    (syntax-case stx ()
      ((ctx filename)
       (with-syntax ([(exp ...) (read-file (syntax-&gt;datum #'filename) #'ctx)])
         #'(begin exp ...))))))
&lt;/pre&gt;Once you've defined this you can use it as follows.&lt;br /&gt;
&lt;pre class="brush: cpp"&gt;(include "extern.ss")
&lt;/pre&gt;Once you've defined the "include" macro any include expression will get evaluated at &lt;b&gt;compile&lt;/b&gt; time which opens up the included file reads in the text and injects it into the the source file at the location of the "include" call.  Spend a little time thinking about that.  A Scheme programmer can write code that gets evaluated at compile time and that code can open, close, and read from files.  So if Scheme's macro language allows you to read from files what else can it do?  It turns out anything that a Scheme program can do.  The above macro can read from files because any old PLT-Scheme program can read from files.  A Scheme macro is just a chunk of regular old Scheme code that gets executed at compile time.  If your Scheme allows you to open up a TCP/IP socket then you can write a macro to do this at compile time&lt;sup&gt;2&lt;/sup&gt;.  If your Scheme allows you to rotate images then you can do it at compile time.  If your Scheme allows you to play music then you can play music at compile time&lt;sup&gt;3&lt;/sup&gt;.  OK so lets look at some more examples.&lt;br /&gt;
&lt;pre class="brush: cpp"&gt;(define current-catch 
  (make-parameter 
   (lambda (exn) 
     (printf exn) 
     (exit 1))))

(define (throw exn)
  ((current-catch) exn))

(define-syntax try
  (syntax-rules (catch throw)
    [(_ body ... (catch exn cbody ...))
     (let/cc k
       (parameterize ([current-catch (lambda (exn) cbody ... (k (void)))])
         (begin body ...)))]))
&lt;/pre&gt;This chunk of code allows users to throw and catch exceptions using "try", "catch" and "throw"&lt;sup&gt;4&lt;/sup&gt;.  Scheme doesn't have a built in exception mechanism, but in 13 lines of code you can write your own.  The following code will use the above macro and functions.&lt;br /&gt;
&lt;pre class="brush: cpp"&gt;(try 
 (printf "Yes\n") 
 (throw "Error\n")
 (printf "No\n")
 (catch exn 
   (printf exn)))

&lt;/pre&gt;It will print "Yes" followed by "Error" the "No" will not be displayed because of the "Error" exception will be thrown.  OK lets look at one more.&lt;br /&gt;
&lt;pre class="brush: cpp"&gt;(define-syntax define-generator
  (lambda (stx)
    (syntax-case stx ()
      ((_ (name args ...) body ...)
       (with-syntax ([yield (datum-&gt;syntax #'name 'yield)])
         #'(define (name args ...)
             (define yield-k #f)
             (define return-k void)
             (define (yield retval)
               (let/cc k
                 (set! yield-k k)
                 (return-k retval)))
             (lambda ()
               (let/cc ret
                 (set! return-k ret)
                 (if yield-k
                     (yield-k '())
                     (begin
                       body ...
                       (set! yield-k (lambda (x) (void)))))))))))))
&lt;/pre&gt;This allow you to define Python style &lt;a href="http://www.python.org/dev/peps/pep-0255/"&gt;generators&lt;/a&gt;.  Here is a simple example that defines a "range" generator that will reuturn 0 he first time it's called and 1 the next.&lt;br /&gt;
&lt;pre class="brush: cpp"&gt;(define-generator (range init limit)
  (let loop ([i init])
    (yield i)
    (when (&lt; i limit)
      (loop (+ i 1)))))

(define foo (range 0 1))
(foo)
(foo)
&lt;/pre&gt;
I hope these examples give some insight at how expressive and malleable the Scheme programming language is.  There is one more issue I'd like to address.  If you're a Python programmer you may be thinking to yourself.  "Hey Python has loops, exceptions, generators and import which is kind of like #include.  If python has these built in then why should I use Scheme?"  That is a valid but slightly myopic question.  The point of Scheme's macro system is not to create another Python with funnier syntax.  The real point is that you the developer can extend and grow the language to meet your needs.  You may extend the language by adding features that are found in other programming languages, but you may also add features that don't exist in any language, and that don't have a name, and that may not be generally useful but really make the current program you're working on really really easy to write.  In Python, Perl and Java users have the power to create and extend libraries, in Scheme users have the power to create and extend languages&lt;sup&gt;5&lt;/sup&gt;.  Power to the people!&lt;br /&gt;
&lt;br /&gt;
[1] All examples tested in in PLT-Scheme 4.1.3.&lt;br /&gt;
[2] Implementing "http-include" is left as an exercise for the reader.&lt;br /&gt;
[3] Playing music at compile time is possible but not recommended by the author.&lt;br /&gt;
[4] Anyone want to try implementing exceptions in C?&lt;br /&gt;
[5] There is one major downside to learning Scheme.  Eventually you'll find yourself writing a program in C/C++/Python/Java and you'll realize that you could solve some problem really elegantly if you could just extend the language just a little bit.  Then you'll realize that you can't and you'll spend the next hour wishing you we're never enlightened.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7573455095858650997-2560417447338827889?l=evanfarrer.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://evanfarrer.blogspot.com/feeds/2560417447338827889/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://evanfarrer.blogspot.com/2009/10/essence-of-scheme-part-two.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7573455095858650997/posts/default/2560417447338827889'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7573455095858650997/posts/default/2560417447338827889'/><link rel='alternate' type='text/html' href='http://evanfarrer.blogspot.com/2009/10/essence-of-scheme-part-two.html' title='The Essence of Scheme (part two)'/><author><name>Evan</name><uri>http://www.blogger.com/profile/03848709590438147138</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_Pxmu7QQVgkk/SrI9CTHifyI/AAAAAAAAAE8/evZ3klxp4YM/S220/evan.jpeg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7573455095858650997.post-7116862203607971440</id><published>2009-09-28T14:25:00.000-06:00</published><updated>2009-09-28T14:25:16.622-06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Scheme Lisp Programming Macros'/><title type='text'>The Essence of Scheme</title><content type='html'>Note that throughout this post "Scheme" could be replaced with "Lisp" without changing it's meaning.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style="font-size: x-large;"&gt;My Introduction to Scheme&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
My first exposure to Scheme was in college at the University of Utah.  At that time they taught a Programming Languages course that was based on the book&amp;nbsp;&lt;a href="http://mitpress.mit.edu/sicp/"&gt;Structure and Interpretation of Computer Programs&lt;/a&gt;, and the&amp;nbsp;&lt;a href="http://www.plt-scheme.org/"&gt;Dr. Scheme&lt;/a&gt;&amp;nbsp;programming environment. &amp;nbsp;While I enjoyed the class I never understood why some people thought Scheme was so special. &amp;nbsp;In my defense the class really didn't teach us Scheme they just used a small subset of the language to teach us about programming language features such as exceptions, continuations, closures, loops, recursion, conditionals, first class functions etc. &amp;nbsp;It really was a great class, you learned about these features by writing and modifying interpreters that implemented these features. &amp;nbsp;The only problem is that many students including myself left that class thinking they knew Scheme, but we didn't. &amp;nbsp;I didn't get re-introduced&amp;nbsp;to Scheme again until a few years later when I was learning Perl. &amp;nbsp;I kept on learning about features of Perl that I really liked, and then I realized that all of these features were also in Scheme. &amp;nbsp;I decided that I needed to go back and tinker with &amp;nbsp;Scheme. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style="font-size: x-large;"&gt;Learning Scheme&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
I started learning Scheme by writing programs and reading a lot of blogs, and articles in an attempt to get my brain wrapped around the programming language. &amp;nbsp;Almost everyone talked about how powerful Scheme is, but it took me a long time before I really understood why Scheme is such an expressive language. &amp;nbsp;Because it takes a lot of work and study to reach Scheme enlightenment, many developers simply give up on the language, before they really understand it. &amp;nbsp;I don't know if it's possible to reach Scheme enlightenment, without all the hard work, but I hope this post will at least will give you a peek at why Scheme is so expressive, and why those that really learn it have a tendency to turn into&amp;nbsp;&lt;a href="http://www.google.com/search?q=smug+lisp+weenie"&gt;Smug Lisp Weenies&lt;/a&gt;. &amp;nbsp;In short this is the blog post that I wish I could have read when I was working towards Scheme enlightenment. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style="font-size: x-large;"&gt;A shortcut to Scheme enlightenment&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
Lets get started. &amp;nbsp;Consider the following snippet:&lt;br /&gt;
&lt;pre class="brush: cpp"&gt;(if val
  0
  1)
&lt;/pre&gt;&lt;br /&gt;
Now if you're an experienced programmer or a Schemer you were probably tempted to just glance at the above snippet and move on, but take a minute and really think about what you're looking at. &amp;nbsp;As a Schemer I can see three different interpretations of the snippet.&lt;br/&gt;&lt;br /&gt;
The most obvious interpretation of the above snippet is an 'if' expression.  The expressions condition is the 'val' value, the consequence is the integer '0' and the alternate is the integer '1'.&lt;br/&gt;&lt;br /&gt;
The second interpretation that I see is a linked-list&lt;sup&gt;1&lt;/sup&gt; of 4 elements. &amp;nbsp;The first elements in the list are the symbols&lt;sup&gt;2&lt;/sup&gt; 'if' and 'val' followed by the integers '0' and '1'.&lt;br/&gt;&lt;br /&gt;
The third interpretation is a tree data structure.  A linked-list can represent a tree structure by putting the first element in the list as the root and all other elements in the list as child notes of the root.  Because Scheme allows a linked-list to have another linked-list as an element arbitrary tree structures can be represented using linked-lists.  So the above snippet could also represent the following tree: &lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/_Pxmu7QQVgkk/Srmd9TtDybI/AAAAAAAAAFg/F52W8CFZI34/s1600-h/if.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://4.bp.blogspot.com/_Pxmu7QQVgkk/Srmd9TtDybI/AAAAAAAAAFg/F52W8CFZI34/s320/if.png" /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;/div&gt;This tree also happens to be the  &lt;a href="http://en.wikipedia.org/wiki/Abstract_syntax_tree"&gt;Abstract Syntax Tree&lt;/a&gt; for the previously mentioned 'if' expression. &amp;nbsp;At this point you may be wondering why this is important, and we'll get to that but for know just consider that every expression in Scheme is an expression, a linked-list and the AST for that expression.  Now lets explore the consequences of that fact.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style="font-size: x-large;"&gt;Scheme and linked-lists&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
Scheme is one of many dialects of Lisp.  The name List is short for "List Processing".  Although Lisp dialects do support other data-structures, they have very powerful constructs that make them an ideal language for processing linked-lists&lt;sup&gt;3&lt;/sup&gt;.  Because every Scheme expression is also a linked-list and Scheme is an ideal language for processing linked-lists we can conclude that Scheme is an ideal language for processing Scheme expressions&lt;sup&gt;4&lt;/sup&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style="font-size: x-large;"&gt;Compilers and AST&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
When you write a compiler for a language one of the first things you may do will be to build an AST for the tokenized and parsed text.  An AST is a simplified representation of the code that is in a format that is easily to manipulate. &amp;nbsp;When the code has been transformed to an AST it is easy for the compiler to perform optimizations, static analysis and transform complex language features into more basic language features.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style="font-size: x-large;"&gt;Bringing it all together&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
So we've discussed that all Scheme expressions are linked-lists and Scheme is a great language for manipulating linked-lists.  We've also discusses that all Scheme expressions are also the AST for that expression, and AST's are a great data-structure for compiler writers to do complex transformations.  It shouldn't be too hard to see that Scheme is an excellent language for performing complex transformations on Scheme expressions.  In fact Scheme allows you to easily extend the programming language in ways that are only reserved for language designers and compiler writers in other languages.  When I learn about some new programming language feature in Python that I wish was in C++, my only choices is to hope that the great C++ language design committee will include the feature in some future version of the C++ spec and that g++ will implement that feature quickly, and my distro will ship the updated version, and ...  If I want to use that same feature in Scheme, I can simply implement it and I don't need to ask the language design committee for permission, I don't need to modify the Scheme compiler/interpreter, I don't need to modify any Makefiles, I just implement the feature and start using it immediately! &amp;nbsp;That IMHO is &lt;b&gt;the&lt;/b&gt; feature that makes Scheme such a powerful tool! &amp;nbspIn my next post we'll look at some examples of how easy it is to &lt;a href="http://video.google.com/videoplay?docid=-8860158196198824415#"&gt;grow your own language&lt;/a&gt; with Scheme.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[1] I know that for this to be treated as a list in code it would need to be quoted, but if it was simply read in from a file with a 'read' call it would come in as a list.&lt;br /&gt;
[2] Scheme symbols are like read-only strings that can be efficiently compared for equality by simply comparing their pointers.  Symbols are often used like enums in C++.&lt;br /&gt;
[3] A proof of this statement is left as an exercise for the reader.&lt;br /&gt;
[4] Yep, you should prove this one too while you're at it.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7573455095858650997-7116862203607971440?l=evanfarrer.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://evanfarrer.blogspot.com/feeds/7116862203607971440/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://evanfarrer.blogspot.com/2009/09/essence-of-scheme.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7573455095858650997/posts/default/7116862203607971440'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7573455095858650997/posts/default/7116862203607971440'/><link rel='alternate' type='text/html' href='http://evanfarrer.blogspot.com/2009/09/essence-of-scheme.html' title='The Essence of Scheme'/><author><name>Evan</name><uri>http://www.blogger.com/profile/03848709590438147138</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_Pxmu7QQVgkk/SrI9CTHifyI/AAAAAAAAAE8/evZ3klxp4YM/S220/evan.jpeg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_Pxmu7QQVgkk/Srmd9TtDybI/AAAAAAAAAFg/F52W8CFZI34/s72-c/if.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7573455095858650997.post-5081898077154149178</id><published>2009-09-16T22:08:00.005-06:00</published><updated>2009-10-06T12:58:03.931-06:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='C++'/><title type='text'>A(nother) counter intuitive C++ (mis)feature</title><content type='html'>I've been using C++ for about 12 years now. &amp;nbsp;Which means I don't know if very well. &amp;nbsp;Early on in my C++ career I thought I had a good grasp of the language, but C++ is one of those languages that the more you learn the more you understand how hopeless it is to fully understand it. &amp;nbsp;Every month or so I'm confronted with some new corner case that I didn't know about. &amp;nbsp;Last months mis-feature had to due with overloading and overriding. &amp;nbsp;&lt;br /&gt;
Consider the following code:&lt;br /&gt;
&lt;pre class="brush: cpp"&gt;class Bar
{
    public:
        virtual void method(int a)
        {
            std::cout &lt;&lt; "Bar " &lt;&lt; a &lt;&lt; std::endl;
        }
};

class Baz : public Bar
{
    public:
        virtual void foo(std::string a)
        {
            std::cout &lt;&lt; "Baz " &lt;&lt; a &lt;&lt; std::endl;
        }
};
int main()
{
    int i = 9;
    std::string s = "9";

    Baz *b1 = new Baz();

    b1-&gt;method(i);
    b1-&gt;method(s);
}
&lt;/pre&gt;&lt;br /&gt;
If you compile this code (with g++) you'll get the following errors:&lt;br /&gt;
&lt;pre class="brush: cpp"&gt;error: invalid conversion from ‘int’ to ‘const char*’
error:   initializing argument 1 of ‘std::basic_string&lt;_CharT, _Traits, _Alloc&amp;gt;::basic_string(const _CharT*, const _Alloc&amp;) [with _CharT = char, _Traits = std::char_traits&lt;char&gt;, _Alloc = std::allocator&lt;char&gt;]’&lt;/char&gt;&lt;/char&gt;&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
This caught me by&amp;nbsp;surprise. &amp;nbsp;I had assumed that the compiler would match the method signatures &lt;b&gt;after&amp;nbsp;&lt;/b&gt;the method names were mangled, and thus method(std::string) would not hide method(int). &amp;nbsp;It turns out that methods are matched only by the name, and after the match has been found (in this case finding the method(std::string) the type checker validates the parameter types. &amp;nbsp;While I can understand this could make the compiler more efficient, it seem that by default the C++ compiler does the wrong (non-intuitive) thing.&lt;br /&gt;
&lt;br /&gt;
So how do you make the compiler do what you want?  You just need to add a "using" line right before Baz's method as follows:&lt;br /&gt;
&lt;pre class="brush: cpp"&gt;...
using Bar::method;
virtual void method(std::string a)
{
...
}
...
&lt;/pre&gt;&lt;br /&gt;
Of course you could have guessed that.  Right?&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7573455095858650997-5081898077154149178?l=evanfarrer.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://evanfarrer.blogspot.com/feeds/5081898077154149178/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://evanfarrer.blogspot.com/2009/09/another-counter-intuitive-c-misfeature.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7573455095858650997/posts/default/5081898077154149178'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7573455095858650997/posts/default/5081898077154149178'/><link rel='alternate' type='text/html' href='http://evanfarrer.blogspot.com/2009/09/another-counter-intuitive-c-misfeature.html' title='A(nother) counter intuitive C++ (mis)feature'/><author><name>Evan</name><uri>http://www.blogger.com/profile/03848709590438147138</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_Pxmu7QQVgkk/SrI9CTHifyI/AAAAAAAAAE8/evZ3klxp4YM/S220/evan.jpeg'/></author><thr:total>1</thr:total></entry></feed>
