<?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:blogger='http://schemas.google.com/blogger/2008' 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-831108661073114437</id><updated>2024-10-06T22:07:10.641-07:00</updated><category term="best programming practices"/><title type='text'>best kept secrets</title><subtitle type='html'>&lt;a href=&quot;http://feeds.feedburner.com/bestkeptsecretsrss&quot;&gt;Subscribe via RSS&lt;/a&gt;</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://bestkeptsecrects.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/831108661073114437/posts/default'/><link rel='alternate' type='text/html' href='http://bestkeptsecrects.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Rachel Albert</name><uri>http://www.blogger.com/profile/13165743738870327222</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>9</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-831108661073114437.post-5479620355992855818</id><published>2014-11-02T23:11:00.000-08:00</published><updated>2014-11-02T23:12:04.422-08:00</updated><title type='text'>Where have I been?</title><content type='html'>&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 13.63636302948px; line-height: 23.7999992370605px;&quot;&gt;I haven&#39;t been updating this blog for a while and there&#39;s a good reason – I&#39;m actually getting a chance to practice what I preach and write my own code from scratch! This fall I decided to move more towards computer graphics, and I&#39;m taking CS294-26: Computational Photography and Image Processing. You can check out my portfolio here: &lt;a href=&quot;http://www.rachelalbert.com/image_processing.html&quot;&gt;www.rachelalbert.com/image_processing.html&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 13.63636302948px; line-height: 23.7999992370605px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 13.63636302948px;&quot;&gt;&lt;span style=&quot;line-height: 23.7999992370605px;&quot;&gt;I am still very interested in finding out more about programming best practices, and in the spring I plan to volunteer with &lt;a href=&quot;http://software-carpentry.org/&quot; target=&quot;_blank&quot;&gt;Software Carpentry&lt;/a&gt;, an organization specifically created for the purpose of helping researchers write better code.&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 13.63636302948px;&quot;&gt;&lt;span style=&quot;line-height: 23.7999992370605px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 13.63636302948px;&quot;&gt;&lt;span style=&quot;line-height: 23.7999992370605px;&quot;&gt;This fall I also had the opportunity to volunteer for the Biophysics department and teach a one-month &lt;a href=&quot;http://python-biophysics-2014.wikispaces.com/&quot; target=&quot;_blank&quot;&gt;Introduction to Python class&lt;/a&gt;. It was a blast! I learned so much about all the different ways people think and how to account for those differences and communicate clearly about code. I also had the unique opportunity to experience 30 people sitting in a room together using pandas data frames for the first time! The class helped me appreciate how valuable is the experience of the Software Carpentry group! No matter how much you try to think ahead, someone will almost always interpret the material differently. Teaching helps you to get out of your own head and into the minds of others, and it clarifies your thoughts and assumptions. I highly recommend it!&lt;/span&gt;&lt;/span&gt;</content><link rel='replies' type='application/atom+xml' href='http://bestkeptsecrects.blogspot.com/feeds/5479620355992855818/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://bestkeptsecrects.blogspot.com/2014/11/where-have-i-been.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/831108661073114437/posts/default/5479620355992855818'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/831108661073114437/posts/default/5479620355992855818'/><link rel='alternate' type='text/html' href='http://bestkeptsecrects.blogspot.com/2014/11/where-have-i-been.html' title='Where have I been?'/><author><name>Rachel Albert</name><uri>http://www.blogger.com/profile/13165743738870327222</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-831108661073114437.post-3602872323592142950</id><published>2014-08-11T15:54:00.004-07:00</published><updated>2014-08-11T15:55:06.731-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="best programming practices"/><title type='text'>How to write multi-purpose code</title><content type='html'>&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;
I often make the claim that writing good clean code saves you time, and one big source of savings is the ability to reuse code. But how is this different from reusing messy, poorly written code? How can you write your code in such a way that it becomes easy to repurpose?&lt;/span&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;Writing multi-purpose code requires thoughtfulness. Typically when you first start writing a script, you are just focused on getting the computer to produce the desired output (like a stimulus on the screen or a chart in an analysis). You fiddle with the code until it does what you want, and then you stop. But wait! At this point it&#39;s likely that the code &lt;i&gt;only&lt;/i&gt; does what you want, and getting it to do anything else would be a serious challenge. Instead of just focusing on the output, consider going a little further and incorporating some of the following seven principles to help make your code more reusable in the future.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;&lt;b&gt;1) Break up the problem&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px;&quot;&gt;&lt;span style=&quot;line-height: 23.799999237060547px;&quot;&gt;When writing code for an experiment, often&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;there are&lt;/span&gt;&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;many steps that need to be completed to produce the final output. Segregating the code into each of these component steps will help you figure out which steps are unique to this experiment and which steps are more generally useful. If you segregate the code into its component parts (using functions or subscripts,&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;for example&lt;/span&gt;&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;), it will be easier to pull out sections of code for modularizing or repurposing later.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;&lt;b&gt;2) Use clear variable names&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px;&quot;&gt;&lt;span style=&quot;line-height: 23.799999237060547px;&quot;&gt;This may seem obvious, but using descriptive variable names is an important part of writing code that is easy to understand and reuse. There is a strong tendency when writing code to want to use short, simple variable names like &#39;a&#39; for &#39;aperture&#39;. This can be ok if the variable is within small, self-contained bits of code like functions. In research, however, it&#39;s often the case that variables get called in multiple disparate contexts throughout a very long script and it&#39;s also common for researchers to return to their code after months of absence. In those cases it&#39;s important to use longer variable names that clearly communicate what they represent.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px;&quot;&gt;&lt;span style=&quot;line-height: 23.799999237060547px;&quot;&gt;&lt;b&gt;3) Avoid &quot;magic numbers&quot;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px;&quot;&gt;&lt;span style=&quot;line-height: 23.799999237060547px;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px;&quot;&gt;&lt;span style=&quot;line-height: 23.799999237060547px;&quot;&gt;Magic numbers are values that are hard-coded into the way the code works. Unlike variables, which are clearly defined and easily changed, magic numbers are baked into the structure of the code. For example, a researcher might code the number of loops to be &#39;8&#39;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;(e.g., &lt;/span&gt;&lt;span style=&quot;color: #222222; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;for i = 1:8&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;&amp;nbsp;because they &quot;know&quot; that there will always be 8 items to iterate through. Or they might perform a slicing operation by selecting specific items (e.g., &lt;/span&gt;&lt;span style=&quot;color: #222222; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;list[251:252]&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;) because they &quot;know&quot; they will always want those particular items out of that list. But if you repurpose the code these assumptions may change, and it can be painfully difficult to find and change all the magic numbers in the code later on. It&#39;s often very simple to make variables for the values in question, and if you also clearly define the variables with descriptive names it&#39;s easier to check your work and modify the code later on.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px;&quot;&gt;&lt;span style=&quot;line-height: 23.799999237060547px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px;&quot;&gt;&lt;span style=&quot;line-height: 23.799999237060547px;&quot;&gt;&lt;b&gt;4) Use asserts liberally&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px;&quot;&gt;&lt;span style=&quot;line-height: 23.799999237060547px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px;&quot;&gt;&lt;span style=&quot;line-height: 23.799999237060547px;&quot;&gt;Speaking of assumptions, I often find that scientists make a lot of assumptions about the input for their experimental code (probably because they are usually the only one using it). For example, a researcher might assume that a particular input value is always divisible by two, or always greater than zero, or less than the maximum size of the list. Usually these sorts of assumptions are not even acknowledged, or when they are acknowledged it is through the use of comments. Unfortunately it is a sad fact of programming that comments will almost always become outdated at some point, and nobody ever reads them anyhow. The point is: when in doubt, use an assert.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px;&quot;&gt;&lt;span style=&quot;line-height: 23.799999237060547px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px;&quot;&gt;&lt;span style=&quot;line-height: 23.799999237060547px;&quot;&gt;Here is an example in Python (and Matlab&#39;s syntax is very similar):&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: #222222; font-family: Courier New, Courier, monospace; font-size: 14px;&quot;&gt;&lt;span style=&quot;line-height: 23.799999237060547px;&quot;&gt;a = 25&lt;/span&gt;&lt;/span&gt;&amp;nbsp;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: #222222; font-family: Courier New, Courier, monospace; font-size: 14px;&quot;&gt;&lt;span style=&quot;line-height: 23.799999237060547px;&quot;&gt;b = 50&lt;/span&gt;&lt;/span&gt;&amp;nbsp;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: #222222; font-family: Courier New, Courier, monospace; font-size: 14px;&quot;&gt;&lt;span style=&quot;line-height: 23.799999237060547px;&quot;&gt;assert b/a &amp;gt; 1, &quot;b must be greater than a&quot;&lt;/span&gt;&lt;/span&gt;&lt;/blockquote&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px;&quot;&gt;&lt;span style=&quot;line-height: 23.799999237060547px;&quot;&gt;In this example we want to assume that &#39;b/a&#39; is greater than one (for some other purpose later on in the code) so we write an assert that explicitly states the requirements that need to be satisfied. If &#39;b&#39; is greater than &#39;a&#39; then all goes well and the program continues. However, it&#39;s possible that we&#39;ve changed &#39;b&#39; and didn&#39;t realize it, perhaps because we re-wrote the code for a new experiment. Now &#39;b&#39; is no longer greater than &#39;a&#39; and we get the error message &#39;b must be greater than a&#39;. Without the assert it&#39;s conceivable that we wouldn&#39;t have noticed our error and we could have gotten some weird output value as a result. Depending on how sure we are of what the output value &lt;i&gt;should&lt;/i&gt;&amp;nbsp;be, we may or may not catch this error. Even if we did catch the error (for example if it caused a fatal problem later on in the code), the assert allows us to pinpoint the location of the error for faster debugging. This explicit method of programming makes reusing your code safer and easier.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px;&quot;&gt;&lt;span style=&quot;line-height: 23.799999237060547px;&quot;&gt;5) Don&#39;t duplicate code&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px;&quot;&gt;&lt;span style=&quot;line-height: 23.799999237060547px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px;&quot;&gt;&lt;span style=&quot;line-height: 23.799999237060547px;&quot;&gt;One major impediment to reusing code is the time it takes to edit the code for its new purpose. To minimize the cost of reusing your code later, try to avoid duplicating code. If you find yourself wanting to repeat several lines of code with minor changes, consider making those changes into variables (i.e. a list of values) then iterating through the values using a loop. On the other hand, if you find you are copying blocks of code from one file to another with minor changes, consider turning the code into a function that you can call in both files.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px;&quot;&gt;&lt;span style=&quot;line-height: 23.799999237060547px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px;&quot;&gt;&lt;span style=&quot;line-height: 23.799999237060547px;&quot;&gt;&lt;b&gt;6) Code defensively&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px;&quot;&gt;&lt;span style=&quot;line-height: 23.799999237060547px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px;&quot;&gt;&lt;span style=&quot;line-height: 23.799999237060547px;&quot;&gt;If you really want to write multi-use code, it&#39;s important to make your code as robust as possible to different inputs. You can think of this like &quot;defensive coding&quot;, where you try to anticipate how your code might break and address those situations ahead of time. You have to consider edge cases such as dividing by zero, inputs that are the wrong size or shape, or inputs which call values that are out of bounds. This is a skill that requires practice, creativity, and experience with actually breaking&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 13.63636302947998px; line-height: 23.799999237060547px;&quot;&gt;code&lt;/span&gt;&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;. For example, it&#39;s a classic mistake to define variables using different units (e.g. centimeters and meters) and then either make a mistake in the conversion process or even forget to make the conversion at all. To anticipate this type of error, you might decide to define all your variables using only meters, or perhaps even write (and test!) a short function to do the conversion for you.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px;&quot;&gt;&lt;span style=&quot;line-height: 23.799999237060547px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px;&quot;&gt;&lt;span style=&quot;line-height: 23.799999237060547px;&quot;&gt;&lt;b&gt;7) Clean up the code after the deadline&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px;&quot;&gt;&lt;span style=&quot;line-height: 23.799999237060547px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px;&quot;&gt;&lt;span style=&quot;line-height: 23.799999237060547px;&quot;&gt;Things tend to get a bit hairy around deadlines, and often times code quality suffers. If you think there&#39;s any chance you might reuse your messy last-minute code, clean it up immediately after the deadline. It&#39;s much faster and simpler to do this sooner rather than later so you don&#39;t forget how the code works.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;Learning how to incorporate these principles in your code may take extra time and effort at first, but with practice you can develop good habits that will continue to pay off in the future. Breaking up the problem, avoiding &quot;magic numbers&quot;, and using clear variable names will save you time if you refactor or reuse your code later. Even if you don&#39;t reuse the code, asserts, minimal code duplication, and defensive coding will reduce your chance of errors now.&lt;/span&gt;</content><link rel='replies' type='application/atom+xml' href='http://bestkeptsecrects.blogspot.com/feeds/3602872323592142950/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://bestkeptsecrects.blogspot.com/2014/08/how-to-write-multi-purpose-code.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/831108661073114437/posts/default/3602872323592142950'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/831108661073114437/posts/default/3602872323592142950'/><link rel='alternate' type='text/html' href='http://bestkeptsecrects.blogspot.com/2014/08/how-to-write-multi-purpose-code.html' title='How to write multi-purpose code'/><author><name>Rachel Albert</name><uri>http://www.blogger.com/profile/13165743738870327222</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-831108661073114437.post-8427764284046374906</id><published>2014-07-30T20:41:00.004-07:00</published><updated>2014-08-28T19:27:40.575-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="best programming practices"/><title type='text'>What can source control do for you? (Part 2)</title><content type='html'>&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;In &lt;/span&gt;&lt;a href=&quot;http://bestkeptsecrects.blogspot.com/2014/07/what-can-source-control-do-for-you-part.html&quot; style=&quot;font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot; target=&quot;_blank&quot;&gt;Part 1&lt;/a&gt;,&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt; I covered the basic mechanics of git and listed a few ways in which source control can be helpful. I mentioned easy recovery of lost files and previous versions, tracing the source of errors while debugging, and keeping a record of your accomplishments.&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;In this post I&#39;ll further explore the reasons you should use source control, then I&#39;ll briefly go over git branching and sharing code using github.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;&lt;b&gt;Is source control really worth the effort?&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;&lt;br class=&quot;Apple-interchange-newline&quot; /&gt;If you&#39;ve spent much time in a research environment, you have probably discovered the benefits of keeping a good lab notebook. Lab notebooks remind you of what you did and what you plan to do, and they also keep track of your justification for those decisions. They help you remember important details both during data collection and when it comes time to publish. It takes just a little extra time every day to keep your lab notebook thorough and up to date, and&amp;nbsp;&lt;i&gt;most&lt;/i&gt;&amp;nbsp;of the time you don&#39;t really need it to remember what you did. But once in a while, when you really need to remember something important, that notebook is priceless.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;Source control is like a lab notebook, but for code. Initially it may seem like an annoying time sink to keep track of all your changes, but if you make source control a consistent part of your workflow it will eventually prove its worth many times over.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px;&quot;&gt;&lt;span style=&quot;line-height: 23.799999237060547px;&quot;&gt;However, despite these many apparent benefits, most researchers do not use source control. They may see it as a tool to use only occasionally when they have to, or as something that would be nice if they had time. Or, even worse, they are convinced that they don&#39;t really need source control and that their current methods work just fine.&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px;&quot;&gt;&lt;span style=&quot;line-height: 23.799999237060547px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 13.63636302947998px; line-height: 23.799999237060547px;&quot;&gt;If these viewpoints seem reasonable to you, consider this: you&#39;re probably already using source control, but poorly! For example... Do you have lots of old commented code hanging around in your files &quot;just in case&quot;? Do you have multiple versions of many files (e.g.&amp;nbsp;&lt;/span&gt;&lt;i style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;script.txt&lt;/i&gt;&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;,&amp;nbsp;&lt;/span&gt;&lt;i style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 13.63636302947998px; line-height: 23.799999237060547px;&quot;&gt;script2.txt&lt;/i&gt;&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 13.63636302947998px; line-height: 23.799999237060547px;&quot;&gt;,&amp;nbsp;&lt;/span&gt;&lt;i style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;script_OLD.txt&lt;/i&gt;&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;,&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 13.63636302947998px; line-height: 23.799999237060547px;&quot;&gt;and&lt;/span&gt;&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;i style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 13.63636302947998px; line-height: 23.799999237060547px;&quot;&gt;final_script.txt&lt;/i&gt;&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;&amp;nbsp;all in the same directory? Do you use the &quot;Date Modified&quot; metadata to check if you&#39;ve recently made any changes to a file? These haphazard methods of source control are equivalent to using dozens of scribbled notes on pieces of paper scattered around your desk as a lab notebook. It&#39;s crazy, it&#39;s horribly inefficient, and it&#39;s asking for trouble! Well-designed tools for source control (like git) are like structured lab notebooks; they are worth your time and effort.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px;&quot;&gt;&lt;span style=&quot;line-height: 23.799999237060547px;&quot;&gt;&lt;b&gt;Exploring variations with branching and merging&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px;&quot;&gt;&lt;span style=&quot;line-height: 23.799999237060547px;&quot;&gt;OK, back to learning git. In addition to the basic function of tracking changes, git also has a more advanced feature called branching. This works exactly as it sounds – it makes a duplicate branch at a particular point in history, and subsequent changes to both branches cause them to diverge. The command to create a new branch is simply:&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: #222222; font-family: Courier New, Courier, monospace; font-size: 14px;&quot;&gt;&lt;span style=&quot;line-height: 23.799999237060547px;&quot;&gt;$ git branch NEW_BRANCH_NAME&lt;/span&gt;&lt;/span&gt;&lt;/blockquote&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px;&quot;&gt;&lt;span style=&quot;line-height: 23.799999237060547px;&quot;&gt;To switch branches, use the command:&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: #222222; font-family: Courier New, Courier, monospace; font-size: 14px;&quot;&gt;&lt;span style=&quot;line-height: 23.799999237060547px;&quot;&gt;$ git checkout BRANCH_NAME&lt;/span&gt;&lt;/span&gt;&lt;/blockquote&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px;&quot;&gt;&lt;span style=&quot;line-height: 23.799999237060547px;&quot;&gt;(Note that your changes must be either committed or stashed to switch branches.) This seems pretty straightforward, right? In fact, we might envision the branch structure to be something like a phylogenetic tree.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px;&quot;&gt;&lt;span style=&quot;line-height: 23.799999237060547px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;http://upload.wikimedia.org/wikipedia/commons/thumb/7/70/Phylogenetic_tree.svg/450px-Phylogenetic_tree.svg.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://upload.wikimedia.org/wikipedia/commons/thumb/7/70/Phylogenetic_tree.svg/450px-Phylogenetic_tree.svg.png&quot; height=&quot;216&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px;&quot;&gt;&lt;span style=&quot;line-height: 23.799999237060547px;&quot;&gt;However, there is also a way to recombine branches, called &lt;a href=&quot;http://git-scm.com/book/en/Git-Branching-Basic-Branching-and-Merging&quot; target=&quot;_blank&quot;&gt;merging&lt;/a&gt;. Merging will start at the common ancestor of two branches and apply all the changes that were made for both branches&amp;nbsp;in order, resulting in a final merged branch that shares all the traits of both of its parents.&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px;&quot;&gt;&lt;span style=&quot;line-height: 23.799999237060547px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px;&quot;&gt;&lt;span style=&quot;line-height: 23.799999237060547px;&quot;&gt;To merge two branches, first checkout the branch that you want to contain the merged changes (you are merging onto this branch), then merge:&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: #222222; font-size: 14px;&quot;&gt;&lt;span style=&quot;font-family: Courier New, Courier, monospace; line-height: 23.799999237060547px;&quot;&gt;$ git checkout MERGE_BRANCH_NAME&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #222222; font-size: 14px;&quot;&gt;&lt;span style=&quot;font-family: Courier New, Courier, monospace; line-height: 23.799999237060547px;&quot;&gt;$&lt;/span&gt;&lt;/span&gt;&amp;nbsp;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: #222222; font-size: 14px;&quot;&gt;&lt;span style=&quot;font-family: Courier New, Courier, monospace; line-height: 23.799999237060547px;&quot;&gt;git merge OTHER_BRANCH_NAME&lt;/span&gt;&lt;/span&gt;&lt;/blockquote&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px;&quot;&gt;&lt;span style=&quot;line-height: 23.799999237060547px;&quot;&gt;Now OTHER_BRANCH has remained unchanged, but MERGE_BRANCH contains all the combined edits from both branches.&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;If there are any conflicts (i.e., the exact same code was edited differently in the two branches), you will instead see a merge conflict error, along with a list of files containing conflicts. In each file, the conflict will be highlighted to show the most recent version of the code from each branch. You may resolve the merge conflict by deleting the version you do not want to keep (along with the highlight text of course!) and saving and committing your changes.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;So really, the code doesn&#39;t look like a typical phylogenetic tree at all. There can be plenty of transfer back and forth between branches, and the result probably looks a lot more like primordial soup instead. If your code looked like this, I bet you&#39;d be pretty happy to have git automatically keeping track of it for you.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgl0V4RoRGUYaC9FeZkspy4iitEhOQWUt85n0WD8rr9LssKhWCTsoSQrai0a6u4UH9AvD-EjDnyE7cJcMSPvvlU-TuB6oOKm700mV-q23a_tSiJQyl5rpEW_ObLjEuclFp0Jo1Dn8jAcWE/s1600/ford+doolittle+tree.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgl0V4RoRGUYaC9FeZkspy4iitEhOQWUt85n0WD8rr9LssKhWCTsoSQrai0a6u4UH9AvD-EjDnyE7cJcMSPvvlU-TuB6oOKm700mV-q23a_tSiJQyl5rpEW_ObLjEuclFp0Jo1Dn8jAcWE/s1600/ford+doolittle+tree.jpg&quot; height=&quot;240&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px;&quot;&gt;&lt;span style=&quot;line-height: 23.799999237060547px;&quot;&gt;&lt;b&gt;How to use branching and merging in research&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;Why are branching and merging useful? Consider this example: let&#39;s say you have one branch of experiment code that works and which you&#39;re currently using in an experiment. But say you also have a new variation of this experiment that you plan to run in the future. You can make a new branch from your current experiment code and start making lots of big changes for the new experiment. It&#39;s easy to switch between branches, so you can use both variations on the same computer as needed.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px;&quot;&gt;&lt;span style=&quot;line-height: 23.799999237060547px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px;&quot;&gt;&lt;span style=&quot;line-height: 23.799999237060547px;&quot;&gt;But now let&#39;s imagine that while running your current experiment you find a bug and fix it. And while you&#39;re at it, maybe you make some other subtle changes like saving an extra variable on each trial or changing the stimulus duration. If you were manually keeping track of these changes, you would have to immediately make the corresponding edits in your new branch. You might forget, or make a mistake, or you might even have to make the edits multiple times if you have multiple branch variations. This method is tedious and error-prone. With merging you can just merge your current working branch onto your experimental branch, and git will automatically take care of the changes and let you know if there are any conflicts.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px;&quot;&gt;&lt;span style=&quot;line-height: 23.799999237060547px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px;&quot;&gt;&lt;span style=&quot;line-height: 23.799999237060547px;&quot;&gt;&lt;b&gt;Collaborating across computers and people&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px;&quot;&gt;&lt;span style=&quot;line-height: 23.799999237060547px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px;&quot;&gt;&lt;span style=&quot;line-height: 23.799999237060547px;&quot;&gt;So far we&#39;ve only covered using git on your local computer, but it&#39;s also possible to share code via an external code repository on github. Github has a list of &lt;a href=&quot;https://help.github.com/categories/54/articles&quot; target=&quot;_blank&quot;&gt;resources and tutorials&lt;/a&gt; for how to use its site, so I won&#39;t get too much into the details here. The main difference is the push and pull commands. Pushing means sending your committed changes to a central version of the code on github, and p&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;ulling downloads changes that someone else has committed and pushed. This is useful for two or more people who are writing and editing shared code simultaneously, and it&#39;s also useful for a single researcher who makes edits to experimental code from multiple computers.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px;&quot;&gt;&lt;span style=&quot;line-height: 23.799999237060547px;&quot;&gt;To recap – source control has lots of uses! It helps individual researchers keep track of what they&#39;ve done and troubleshoot errors and bugs, it makes experimentation painless and error-free, and it also allows researchers to merge changes across computers and easily collaborate with others. What can source control do for you? As it turns out, quite a bit!&lt;/span&gt;&lt;/span&gt;</content><link rel='replies' type='application/atom+xml' href='http://bestkeptsecrects.blogspot.com/feeds/8427764284046374906/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://bestkeptsecrects.blogspot.com/2014/07/what-can-source-control-do-for-you-part_30.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/831108661073114437/posts/default/8427764284046374906'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/831108661073114437/posts/default/8427764284046374906'/><link rel='alternate' type='text/html' href='http://bestkeptsecrects.blogspot.com/2014/07/what-can-source-control-do-for-you-part_30.html' title='What can source control do for you? (Part 2)'/><author><name>Rachel Albert</name><uri>http://www.blogger.com/profile/13165743738870327222</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgl0V4RoRGUYaC9FeZkspy4iitEhOQWUt85n0WD8rr9LssKhWCTsoSQrai0a6u4UH9AvD-EjDnyE7cJcMSPvvlU-TuB6oOKm700mV-q23a_tSiJQyl5rpEW_ObLjEuclFp0Jo1Dn8jAcWE/s72-c/ford+doolittle+tree.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-831108661073114437.post-4678397653190118961</id><published>2014-07-21T21:49:00.002-07:00</published><updated>2014-08-28T19:28:32.867-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="best programming practices"/><title type='text'>What can source control do for you? (Part 1)</title><content type='html'>&lt;i style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 13.63636302947998px; line-height: 23.799999237060547px;&quot;&gt;Programmers often have strong feelings about source control, so&amp;nbsp;&lt;/i&gt;&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;&lt;i&gt;I&#39;d like to preface this post with a disclaimer: the entirety of my programming experience has been in an academic research setting, and my opinions and examples in this series on best programming practices are likely to reflect that experience. I hope that nonetheless someone can benefit from what I have learned.&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;/span&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;What is source control? And more importantly, why should you care?&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;Source control (also known as revision control, or version control) is a way to keep track of files: what changes were made, who made them, and when they were made. But source control can be much more than that – it can also provide a systematic way for you to experiment with files and share them with others. In this post I&#39;ll go over the basics of using one type of source control (git) and talk a little about how researchers in particular can benefit from source control.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;Git, SVN, and Mercurial are three programs which are commonly used for source control in the tech world right now. I&#39;m going to restrict my post to &lt;a href=&quot;http://en.wikipedia.org/wiki/Git_(software)&quot; target=&quot;_blank&quot;&gt;git&lt;/a&gt; because it&#39;s what I know and use. To me, the best thing about git is that it has a really shallow learning curve at the beginning, but it&#39;s also capable of some very complicated maneuvers if you take the time to learn more. Not only is it free and open source, it&#39;s also a useful thing to learn since many companies and professional programmers use it. I like git a lot, and I hope you will, too!&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;&lt;b&gt;Installation&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;Anyway, speaking of that shallow learning curve, git is mercifully easy to install. If you are using a package manager, you can install git using a command such as&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #222222;&quot;&gt;&lt;span style=&quot;font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;sudo brew install git&lt;/span&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&amp;nbsp;for Mac, or,&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;apt-get install git-core&lt;/span&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&amp;nbsp;for Linux. (If the words &quot;package manager&quot; and/or &quot;command line&quot; are unfamiliar to you, you&#39;ll probably want to check out my earlier post on &lt;a href=&quot;http://bestkeptsecrects.blogspot.com/2014/07/how-to-learn-programming-from-scratch.html&quot; target=&quot;_blank&quot;&gt;how to learn programming from scratch&lt;/a&gt;.) If you want something even easier (and probably more up to date, actually), you can download a package&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;http://git-scm.com/downloads&quot; style=&quot;font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;&amp;nbsp;that will install git for you automagically&lt;/span&gt;&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;As an aside, there is also a GUI (Graphical User Interface, or basically an &quot;App&quot;) available through &lt;a href=&quot;https://github.com/&quot; target=&quot;_blank&quot;&gt;github&lt;/a&gt;. As with many other things programming related, there are pros and cons to both the CLI (Command Line Interface) and the GUI. Which one you decide to use is really up to you, dependent on your background and needs, with one caveat: there is more support for the CLI, since that&#39;s what most people use. If at some point you search the internet for help with git,&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 13.63636302947998px; line-height: 23.799999237060547px;&quot;&gt;you&#39;ll probably find that there are a lot more people who can help you find the right command than can help you find the right menu button.&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;I haven&#39;t used the GUI very much myself, but based on my limited experience I would suggest using the command line interface instead if you can because it&#39;s a useful thing to learn.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;After you install git, take a few minutes to customize your git environment. If you haven&#39;t already, follow the instructions in my&amp;nbsp;&lt;a href=&quot;http://bestkeptsecrects.blogspot.com/2014/07/how-to-learn-programming-from-scratch.html&quot; target=&quot;_blank&quot;&gt;previous post&lt;/a&gt;&amp;nbsp;on how to change your default command line text editor. Trust me on this – you do&amp;nbsp;&lt;i&gt;not&lt;/i&gt;&amp;nbsp;want to use vi. You can also add your name and email address, especially if you intend to use github to share your code. To change your git config settings, replace the example name and email in the two commands below with your name and email (include the quotation marks in your command, but not the dollar signs):&lt;/span&gt;&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: #222222; font-family: Courier New, Courier, monospace;&quot;&gt;&lt;span style=&quot;font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;$ git config --global user.name &quot;Jane Doe&quot;&lt;/span&gt;&lt;/span&gt;&amp;nbsp;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: #222222; font-family: Courier New, Courier, monospace;&quot;&gt;&lt;span style=&quot;font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;$ git config --global user.email janedoe@example.com&lt;/span&gt;&lt;/span&gt;&lt;/blockquote&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;Another nice customization is adding color to your git environment, which makes git output much easier to read. To do this, type:&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: #222222; font-family: Courier New, Courier, monospace;&quot;&gt;&lt;span style=&quot;font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;$ git config --global color.ui auto&lt;/span&gt;&lt;/span&gt;&lt;/blockquote&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;To find out more about git configuration, you can also check out the documentation on the &lt;a href=&quot;http://git-scm.com/book/en/Getting-Started-First-Time-Git-Setup&quot; target=&quot;_blank&quot;&gt;git website&lt;/a&gt;.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;&lt;b&gt;How to create a repository&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;Ok, now that you have git installed, let&#39;s do an example. Suppose you are given someone else&#39;s code and you are told to modify it in some way. Since you don&#39;t really know how this code works yet, it would be nice to keep track of the original state of the code when it was given to you. If (when) you have to debug the code in the future, you can look back and try to see what changed between your current version and the original working version you started with.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;So let&#39;s create a git repository: open up the &lt;a href=&quot;http://bestkeptsecrects.blogspot.com/2014/07/how-to-learn-programming-from-scratch.html&quot; target=&quot;_blank&quot;&gt;command line&lt;/a&gt; and use the &quot;cd&quot; command to change your current directory to where the new code is located.&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;For example, if your new code is in Documents &amp;gt; programming &amp;gt; mycode, you type:&lt;/span&gt;&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: #222222; font-family: Courier New, Courier, monospace;&quot;&gt;&lt;span style=&quot;font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;$ cd ~/Documents/programming/mycode&lt;/span&gt;&lt;/span&gt;&lt;/blockquote&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;Now, to create a repository we simply type:&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: #222222; font-family: Courier New, Courier, monospace;&quot;&gt;&lt;span style=&quot;font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;$ git init&lt;/span&gt;&lt;/span&gt;&lt;/blockquote&gt;
&lt;span style=&quot;color: #222222;&quot;&gt;&lt;span style=&quot;font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;The next step is to add all the files you want to track to your git repository. If you want specific files (for example, &lt;/span&gt;&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;file1.txt&lt;/span&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt; and &lt;/span&gt;&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;file2.txt&lt;/span&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;) you can type in the names of each of the files manually, separated by spaces like this:&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: #222222; font-family: Courier New, Courier, monospace;&quot;&gt;&lt;span style=&quot;font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;$ git add file1.txt file2.txt&lt;/span&gt;&lt;/span&gt;&lt;/blockquote&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;If instead you just want to add all the files in that folder, you can just type:&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: #222222; font-family: Courier New, Courier, monospace;&quot;&gt;&lt;span style=&quot;font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;$ git add *&lt;/span&gt;&lt;/span&gt;&lt;/blockquote&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;(The * notation is actually from something called &lt;a href=&quot;http://en.wikipedia.org/wiki/Regular_expression&quot; target=&quot;_blank&quot;&gt;regular expressions&lt;/a&gt;, which is incredibly useful, but I don&#39;t have time to talk about it here.)&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;Finally, the last step is to save this current state of the code in memory. To do this, we &quot;commit&quot; the files that we just added. A commit is like a save point that we can access later if needed. When you commit code to memory, you should also add a commit message describing what changes you made since the last commit. &lt;i&gt;Commit messages are the most important and most useful aspect of source control.&lt;/i&gt;&amp;nbsp;If you fail to write thorough and informative commit messages, at some point you&#39;ll be forced to dig through your code to try to figure out what you did and why, and you probably won&#39;t save any time compared to not using source control at all.&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;color: #222222;&quot;&gt;&lt;span style=&quot;font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Useful commit messages include a verbal description of the specific problems that were fixed. For example, &lt;/span&gt;&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&quot;Fixed bugs, updated parameters&quot;&lt;/span&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt; is &lt;/span&gt;&lt;i style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;not&lt;/i&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&amp;nbsp;a useful commit message. Instead, the message should be much more specific, like this:&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: #222222; font-family: Courier New, Courier, monospace;&quot;&gt;&lt;span style=&quot;font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;&quot;Fixed off-by-one error in file 2,&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #222222; font-family: Courier New, Courier, monospace;&quot;&gt;&lt;span style=&quot;font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;added escape key to for-loop in file 1,&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #222222; font-family: Courier New, Courier, monospace;&quot;&gt;&lt;span style=&quot;font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;changed initial conditions from 3 to 2 to improve performance.&quot;&lt;/span&gt;&lt;/span&gt;&lt;/blockquote&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;Remember, your most important collaborator is your future self! If you write a thorough commit message now, you&#39;ll thank yourself later.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;Ok, let&#39;s commit this code. It&#39;s as simple as:&lt;/span&gt;&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: #222222; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;$ git commit&lt;/span&gt;&lt;/span&gt;&lt;/blockquote&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;After you type this command you&#39;ll be presented with the commit file in your default command line text editor. At the bottom of the file is a bunch of text telling you which files were changed and what the changes were, line-by-line. At the top of the file there is a blank section where you can type your commit message&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;. You might write something like &quot;First commit, initial state of the code&quot;, then save and exit.&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;That&#39;s it! Git is now keeping track of all your changes from now on.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;&lt;b&gt;Viewing your tracked changes&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;So how do we access this tracking information? First, let&#39;s make sure everything is working correctly. To check the status of your git repository, type the command:&lt;/span&gt;&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: #222222; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;$ git status&lt;/span&gt;&lt;/span&gt;&lt;/blockquote&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;You should get an output that says something like &quot;nothing to commit, working directory clean&quot;. Now let&#39;s edit one of the files that we added earlier and see what happens. For example, make a small change to file1.txt, save the file, and then call git status again. You should see something like this:&lt;/span&gt;&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;span style=&quot;color: #222222; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;Changes not staged for commit:&lt;/span&gt;&lt;span style=&quot;color: #222222; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;(use &quot;git add &amp;lt;file&amp;gt;...&quot; to update what will be commited)&lt;/span&gt;&lt;span style=&quot;color: #222222; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;(use &quot;git checkout -- &amp;lt;file&amp;gt;...&quot; to discard changes in working directory)&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: #222222; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;modified: file1.txt&lt;/span&gt;&lt;/span&gt;&lt;/blockquote&gt;
&lt;span style=&quot;color: #222222; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;no changes added to commit (use &quot;git add&quot; and/or &quot;git commit -a&quot;)&lt;/span&gt;&lt;/span&gt;&lt;/blockquote&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;This tells us that since the last time we committed, changes have only been made in a single file, file1.txt. To find out what was changed, we can type:&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: #222222;&quot;&gt;&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;$ git diff&lt;/span&gt;&lt;/span&gt;&lt;/blockquote&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;We will see some text showing the name of the file and a few lines before and after the spot that was changed. The change itself will be highlighted with plus signs (+) where text was added, and minus signs (-) where text was deleted. (By the way, any time the output for git is longer than a page, you&#39;ll see a colon (:) at the bottom of the terminal window instead of the usual dollar sign ($). To scroll, use the up and down arrows. To quit and return to the command line, press the q key.)&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;Ok, let&#39;s try one more thing. What if we wanted to look at the difference between the current state of the code and an even older version of the code from an earlier commit? For our current example we first need to have more than one commit. Go ahead and commit your changes to file1.txt, including a commit message that describes what you changed.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;Next, we need to choose the older commit we want to compare against. To view older commits, we use this command:&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: #222222;&quot;&gt;&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;$ git log&lt;/span&gt;&lt;/span&gt;&lt;/blockquote&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;You&#39;ll see a list of two commits, each followed by a hash (this is basically a code that allows you to uniquely identify that commit). You should also see your name and email (since you made the commits), the date and time of the commit, and the commit message. Highlight and copy the hash of the initial commit we made earlier, then return to the command line and type the following command (replace HASHCODE with the hash that you just copied):&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;color: #222222;&quot;&gt;&lt;span style=&quot;font-family: Courier New, Courier, monospace; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;$ git diff HASHCODE&lt;/span&gt;&lt;/span&gt;&lt;/blockquote&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 13.63636302947998px; line-height: 23.799999237060547px;&quot;&gt;Voila! You can now view all the changes since that first commit.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 13.63636302947998px; line-height: 23.799999237060547px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;b&gt;&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;How can source control help me?&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;Now that you understand the basics of how git works, let&#39;s talk a little about what it can do. Even for an individual, git can be very useful. There are many practical benefits, like easy recovery for accidental code and file deletion, and the ability to quickly and easily roll back code to a previous state. (In my next post I&#39;ll also talk about branching, which allows you to quickly and easily switch between variations of your code.)&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;Additionally, I&#39;ve already mentioned that git can be helpful for finding the source of errors when debugging. This is particularly useful if you make notes in your commit messages of which commits have been tested and confirmed to be working. If the code stops working later on, you know that it must be something you did between now and your most recent working commit, so there are fewer edits to sift through to find the error.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;Finally, one more benefit of tracking changes with git is that you have a record of what you&#39;ve accomplished over time. Commit logs show how your time was spent and describe in detail exactly how you solved the challenging problems you faced along the way. If you spend a lot of time working on your code alone and without recognition, as many researchers do, using git can be really encouraging!&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;color: #222222; font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;&lt;b&gt;Stay tuned for &lt;a href=&quot;http://bestkeptsecrects.blogspot.com/2014/07/what-can-source-control-do-for-you-part_30.html&quot; target=&quot;_blank&quot;&gt;part 2: merging and sharing code&lt;/a&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://bestkeptsecrects.blogspot.com/feeds/4678397653190118961/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://bestkeptsecrects.blogspot.com/2014/07/what-can-source-control-do-for-you-part.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/831108661073114437/posts/default/4678397653190118961'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/831108661073114437/posts/default/4678397653190118961'/><link rel='alternate' type='text/html' href='http://bestkeptsecrects.blogspot.com/2014/07/what-can-source-control-do-for-you-part.html' title='What can source control do for you? (Part 1)'/><author><name>Rachel Albert</name><uri>http://www.blogger.com/profile/13165743738870327222</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-831108661073114437.post-3121641720656911433</id><published>2014-07-14T16:18:00.000-07:00</published><updated>2014-07-16T15:20:26.764-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="best programming practices"/><title type='text'>Why you should write good code</title><content type='html'>&lt;div style=&quot;color: #222222; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;
&lt;div style=&quot;font-family: &#39;Open Sans&#39;, &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;I have seen a lot of bad code. Disorganized, repetitive, poorly-commented, inefficient bad code. And I&#39;ll admit – I have written some bad code, too. As a researcher I understand that the incentives on how to spend your time often run counter to your best intentions, and that sometimes bad code is unavoidable.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Open Sans&#39;, &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Open Sans&#39;, &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;But I am confident that most of the time writing good code is not only possible, it&#39;s also well worth the effort. Clean, well-written, well-maintained code actually saves you time, reduces errors, and makes it easier to share your code with other people.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Open Sans&#39;, &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Open Sans&#39;, &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;But perhaps you think this doesn&#39;t apply to you... perhaps you really don&#39;t have time to write good code, or your shoddy code at least isn&#39;t hurting anyone?&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Perhaps. But perhaps not.&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;In this post&lt;/span&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&amp;nbsp;I&#39;ll examine four common excuses (ahem, reasons) that I&#39;ve heard for why programmers write bad code, and by the end I hope you&#39;ll agree that in fact you really can&#39;t afford&amp;nbsp;&lt;i&gt;not&lt;/i&gt;&amp;nbsp;to write good code.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Open Sans&#39;, &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Open Sans&#39;, &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;b&gt;Reason #1: &quot;I don&#39;t have time&quot;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Open Sans&#39;, &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div style=&quot;font-family: Times;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Not having enough time is by far the most common reason I hear for not writing good code. And it&#39;s true – good code often demands a higher initial cost of time and effort. But this kind of thinking is very short-sighted; in the long term, poorly written code will actually weigh you down like a load of bricks.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Times;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Poorly-written code often runs slower, which costs anywhere from a few seconds to a few minutes every time you run your program. It&#39;s also more difficult to read and understand, which means more time debugging when (not if!) things go wrong. Hastily written code usually only works for a specific case and must be manually tweaked for every variation. This kind of rigid structure is very difficult to modify and repurpose. And finally, returning to your code after an absence is almost always confusing and frustrating, and discourages you from reusing your code in the future. To summarize:&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Times;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; font-family: Times; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhzJF098s4CYBwN60W2xl7WjhwK4t2d78dU1S-k_qit6VOOZl6gqZjulrvfVh-FZDiiEwxM72jFwuQgnJn4bzW8sWdGbZf1bmEFGrrAbdo8MFZNNmQMvHyCvFhrzJfuMX3yCXLBa0k_myk/s1600/CostofBadCode_small.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhzJF098s4CYBwN60W2xl7WjhwK4t2d78dU1S-k_qit6VOOZl6gqZjulrvfVh-FZDiiEwxM72jFwuQgnJn4bzW8sWdGbZf1bmEFGrrAbdo8MFZNNmQMvHyCvFhrzJfuMX3yCXLBa0k_myk/s1600/CostofBadCode_small.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Times;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Times;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;b&gt;Reason #2: &quot;My code may be messy, but it works just fine&quot;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Times;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Times;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;When I hear this reason I wonder whether this person has ever seen another person&#39;s code. S&lt;/span&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;oftware bugs are so ubiquitous they have even been found in&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;http://www.pcworld.com/article/205318/11_infamous_software_bugs.html&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot; target=&quot;_blank&quot;&gt;NASA&#39;s space explorations, Intel&#39;s pentium chips, and United States missiles and military aircraft&lt;/a&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;. Even for well-written code, it&#39;s almost certain that if the code is long enough it has at least one bug in it.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Times;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Times;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;How confident are you that your messy, hastily written code, which only&amp;nbsp;&lt;i&gt;you&lt;/i&gt;&amp;nbsp;have reviewed and tested, has no bugs? How many programs have you ever written in a hurry? What are the odds that there are no bugs in&amp;nbsp;&lt;i&gt;any&lt;/i&gt;&amp;nbsp;of them? Pretty slim, I&#39;m guessing.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Times;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Times;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Writing good code not only helps prevent mistakes in the first place, it also makes it easier to find the mistakes later.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Times;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Times;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;b&gt;Reason #3: &quot;I&#39;m only going to use this code once&quot;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Times;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Times;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;OK, I will partially concede that this is a reasonable excuse for not writing great code. But stop and consider for a moment how often this is really true. How often do you return to that code you said you would only use once? Even if you don&#39;t use the entire script or function verbatim, how often do you copy sections of code to use elsewhere?&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Times;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Times;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Is there a better alternative to writing single-use code and cannibalizing it? Perhaps you could write a smaller, cleaner, more abstract function, and turn that single-use code into multi-use code.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Times;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Times;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;b&gt;Reason #4: &quot;I&#39;m the only one who ever uses my code&quot;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Times;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Times;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;While you may be the only one using your code now, it&#39;s worth considering whether anyone else might inherit your code in the future. If you are part of an organization or group, what are the chances that some poor soul will take over your project one day and have to sift through your incomprehensible code? This has happened to me, and let me tell you – it sucks!&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;And even if you really are the only one using your code, I hope you&#39;ll agree that&amp;nbsp;&lt;i&gt;you&lt;/i&gt;&amp;nbsp;are actually pretty important. As I mentioned in reasons 1 and 2, writing good code saves&amp;nbsp;you&amp;nbsp;time and reduces the number of errors&amp;nbsp;you&amp;nbsp;make. After all, &lt;a href=&quot;http://berkeleysciencereview.com/reproducible-collaborative-data-science/&quot; target=&quot;_blank&quot;&gt;&quot;Your most important collaborator is your future self.&quot;&lt;/a&gt;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;And hey – if your code is clean and easy to use, maybe you won&#39;t be the only one using it for very long. Developing good programming habits opens up doors to collaboration and contribution to larger projects in the future.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Times;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;So, is it worth it to write good code? If you consider the time saved, errors prevented, code reused, and opportunities for collaboration, the benefits seem to greatly outweigh the initial costs. I hope this post inspires you to improve your code habits! If you&#39;re looking for more information on how to write better code, I&#39;ll be writing a series on best programming practices that&#39;s geared toward young researchers. Stay tuned!&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://bestkeptsecrects.blogspot.com/feeds/3121641720656911433/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://bestkeptsecrects.blogspot.com/2014/07/why-you-should-write-good-code.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/831108661073114437/posts/default/3121641720656911433'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/831108661073114437/posts/default/3121641720656911433'/><link rel='alternate' type='text/html' href='http://bestkeptsecrects.blogspot.com/2014/07/why-you-should-write-good-code.html' title='Why &lt;em&gt;you&lt;/em&gt; should write good code'/><author><name>Rachel Albert</name><uri>http://www.blogger.com/profile/13165743738870327222</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhzJF098s4CYBwN60W2xl7WjhwK4t2d78dU1S-k_qit6VOOZl6gqZjulrvfVh-FZDiiEwxM72jFwuQgnJn4bzW8sWdGbZf1bmEFGrrAbdo8MFZNNmQMvHyCvFhrzJfuMX3yCXLBa0k_myk/s72-c/CostofBadCode_small.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-831108661073114437.post-7087538415180151387</id><published>2014-07-06T15:23:00.000-07:00</published><updated>2014-07-18T19:23:58.827-07:00</updated><title type='text'>How to learn programming from scratch</title><content type='html'>&lt;div class=&quot;p2&quot; style=&quot;color: #222222; font-family: &#39;Open Sans&#39;, &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 23.799999237060547px; margin-bottom: 0.825em;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;In many ways programming is one of the most easily accessible skills you can learn. There is no formal education required to get started, and there is a vast ocean of resources available for free on the internet. In fact, many professional programmers are self-taught.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;At the same time, if you&#39;ve never done any kind of programming before it can be really intimidating at first. How do you know where to start or who to ask when you have questions? Not that long ago, you just had to tinker around with code trying to figure out how it worked on your own. Now there are many tutorials and forums specifically geared toward people with zero programming experience.&lt;/span&gt;&lt;br /&gt;
&lt;b style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/b&gt;
&lt;b style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Choosing a language&lt;/b&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;So where do you start? First you need to figure out what language you want to learn. There&#39;s a good chance that eventually you&#39;ll want to learn more than one language, but just stick with one for now. The language you choose really depends on what your goal is for learning to program. In the table below I list a few example languages for different purposes. If you don&#39;t have a particular goal I recommend starting with something easy like HTML or Python.&lt;/span&gt;&lt;/div&gt;
&lt;div align=&quot;center&quot;&gt;
&lt;table border=&quot;2&quot; bordercolor=&quot;#000000&quot; cellpadding=&quot;10&quot; cellspacing=&quot;0&quot; style=&quot;background-color: #d3fbe5; border-collapse: collapse; text-align: center;&quot;&gt;&lt;caption style=&quot;padding-bottom: 4px;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Example Programming Languages&lt;/span&gt;&lt;/b&gt;&lt;/caption&gt;&lt;tbody&gt;
&lt;tr style=&quot;background-color: #009944; color: white; padding-bottom: 4px; padding-top: 5px;&quot;&gt;&lt;th&gt;&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Front End (web stuff)&lt;/span&gt;&lt;/div&gt;
&lt;/th&gt;&lt;/tr&gt;
&lt;tr class=&quot;alt&quot;&gt;&lt;td&gt;&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;HTML, CSS, PHP, Javascript, Ruby on Rails&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;background-color: #009944; color: white; padding-bottom: 4px; padding-top: 5px;&quot;&gt;&lt;th&gt;&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Back End (server stuff)&lt;/span&gt;&lt;/div&gt;
&lt;/th&gt;&lt;/tr&gt;
&lt;tr class=&quot;alt&quot;&gt;&lt;td&gt;&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Python, C, C++, C#, Scala, Java, Ruby on Rails&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;background-color: #009944; color: white; padding-bottom: 4px; padding-top: 5px;&quot;&gt;&lt;th&gt;&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Phone Apps&lt;/span&gt;&lt;/div&gt;
&lt;/th&gt;&lt;/tr&gt;
&lt;tr class=&quot;alt&quot;&gt;&lt;td&gt;&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Objective C / Cocoa (iPhone), Java (Android)&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;background-color: #009944; color: white; padding-bottom: 4px; padding-top: 5px;&quot;&gt;&lt;th&gt;&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Databases&lt;/span&gt;&lt;/div&gt;
&lt;/th&gt;&lt;/tr&gt;
&lt;tr class=&quot;alt&quot;&gt;&lt;td&gt;&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;SQL (pronounced &quot;sequel&quot;), PostgreSQL&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr style=&quot;background-color: #009944; color: white; padding-bottom: 4px; padding-top: 5px;&quot;&gt;&lt;th&gt;&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Research&lt;/span&gt;&lt;/div&gt;
&lt;/th&gt;&lt;/tr&gt;
&lt;tr class=&quot;alt&quot;&gt;&lt;td&gt;&lt;div style=&quot;margin: 0px;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;MATLAB, R, Python&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;div style=&quot;color: #222222; font-family: &#39;Open Sans&#39;, &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Once you&#39;ve picked a language you&#39;ll probably want to jump right in with the installation and online tutorials – but wait! There&#39;s one important step that will make your life much easier. You should learn a little about the command line.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #222222; font-family: &#39;Open Sans&#39;, &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;color: #222222; font-family: &#39;Open Sans&#39;, &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;The command line&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;color: #222222; font-family: &#39;Open Sans&#39;, &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #222222; font-family: &#39;Open Sans&#39;, &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;The command line is a text-only interface to your computer. Not only do you use it to install and update things, you can also use it to navigate around your computer (including to hidden files and folders), and to automatically rename, copy, move, and delete large batches of files (there are also many other cool things that it can do which I won&#39;t cover here).&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #222222; font-family: &#39;Open Sans&#39;, &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #222222; font-family: &#39;Open Sans&#39;, &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;On UNIX operating systems (i.e. Mac and Linux) the command line is accessible through applications called Terminal (for Mac) and Konsole (for Linux). The default &quot;language&quot; (called a shell) is &lt;/span&gt;&lt;a href=&quot;http://en.wikipedia.org/wiki/Bash_(Unix_shell)&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Bash&lt;/a&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;. (Windows is something different entirely, I don&#39;t know much about that, sorry!)&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #222222; font-family: &#39;Open Sans&#39;, &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #222222; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;
&lt;div style=&quot;font-family: &#39;Open Sans&#39;, &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;It may seem like a pain to add this extra step, but I promise it will be worth it later on. Unfortunately I&#39;ve found that many great programming resources on the internet assume that you already know how to do basic things on the command line, so not knowing about it can be a huge barrier for someone just starting out. I suggest these two tutorials: &lt;/span&gt;&lt;a href=&quot;http://vic.gedris.org/Manual-ShellIntro/1.2/ShellIntro.pdf&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;An Introduction to the Linux Command Shell for Beginners&lt;/a&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt; by Victor Gedris, and &lt;/span&gt;&lt;a href=&quot;http://linuxcommand.org/lc3_learning_the_shell.php&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Learning the Shell&lt;/a&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt; by William E. Shotts, Jr. They are both very short and clearly written, and will give you a solid foundation for navigating the command line.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Open Sans&#39;, &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: &#39;Open Sans&#39;, &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;EDIT: I realized belatedly that I neglected to include an optional but important step here – setting your default command line text editor. Once in a while you may want to edit a file using the command line (such as hidden files or git commit messages), and unfortunately the default text editor for UNIX systems is something called &lt;a href=&quot;http://en.wikipedia.org/wiki/Vi&quot; target=&quot;_blank&quot;&gt;vi&lt;/a&gt;. Vi is really obtuse and I do not recommend it. (Honestly, why should you have to google how to save and exit in your default text editor? That&#39;s the opposite of user-friendly.) Instead, I recommend a simple editor called &lt;a href=&quot;http://www.howtogeek.com/howto/42980/the-beginners-guide-to-nano-the-linux-command-line-text-editor/&quot; target=&quot;_blank&quot;&gt;nano&lt;/a&gt;. To change your default editor, follow these steps:&lt;/span&gt;&lt;/div&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;1. Open the command line (see above) and type the command:&amp;nbsp;&lt;/span&gt;&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;open ~/.profile&lt;/span&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/blockquote&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; (this will open the hidden profile file in your default text editor)&lt;/span&gt;&amp;nbsp;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;2. At the bottom of the file, add this line:&amp;nbsp;&lt;/span&gt;&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;export EDITOR=nano&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Open Sans&#39;, &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/blockquote&gt;
&lt;span style=&quot;font-family: &#39;Open Sans&#39;, &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif;&quot;&gt;&amp;nbsp; &amp;nbsp; and then save and close the file&amp;nbsp;&lt;/span&gt;&amp;nbsp;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;font-family: &#39;Open Sans&#39;, &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Open Sans&#39;, &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif;&quot;&gt;3. Repeat steps 1 and 2 above, but this time replace &lt;/span&gt;&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;.profile&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Open Sans&#39;, &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif;&quot;&gt; with &lt;/span&gt;&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;.bashrc&lt;/span&gt;&amp;nbsp;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Open Sans&#39;, &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif;&quot;&gt;4. In the command line, type these two commands:&amp;nbsp;&lt;/span&gt;&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;source ~/.profile&lt;/span&gt;&amp;nbsp;&lt;/blockquote&gt;
&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;blockquote class=&quot;tr_bq&quot;&gt;
&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;source ~/.bashrc&lt;/span&gt;&lt;/blockquote&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;5. Enjoy using nano&lt;/span&gt;&lt;/blockquote&gt;
&lt;/div&gt;
&lt;div style=&quot;color: #222222; font-family: &#39;Open Sans&#39;, &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #222222; font-family: &#39;Open Sans&#39;, &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Installation&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;color: #222222; font-family: &#39;Open Sans&#39;, &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;color: #222222; font-family: &#39;Open Sans&#39;, &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Next step: installation! This part is actually pretty simple, and it&#39;s different for every language, so I recommend that you just search for the language you want to learn and follow their instructions. The only side note I will add is that there are things called &lt;/span&gt;&lt;a href=&quot;http://en.wikipedia.org/wiki/Package_management_system&quot; style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;package managers&lt;/a&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt; which make installation and updates easier by packaging together all the other dependencies your program needs to run. You&#39;re not required to have a package manager to install a language, but they can sometimes save you a lot of time.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;color: #222222; font-family: &#39;Open Sans&#39;, &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;b&gt;Tutorials&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;
Whenever you&#39;re just starting out in a new programming language it&#39;s a good idea to take a tour, familiarize yourself with the syntax of the language, and learn about some of it&#39;s basic features. This is the kind of information that a tutorial provides. Programming tutorials are very diverse; each one assumes a particular level of experience between &quot;I&#39;ve never typed a command before&quot; and &quot;I already know five languages, what&#39;s special about this one?&quot; It&#39;s important to find one that meets you on your level.&lt;br /&gt;
&lt;br /&gt;
There are many, many tutorials available for free on the internet for just about every language you might want to learn. Here are just a few that begin at a very basic level.&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://learnpythonthehardway.org/book/ex0.html&quot; target=&quot;_blank&quot;&gt;Learn Python The Hard Way&lt;/a&gt;&lt;br /&gt;
The thing I like most about this tutorial is that it starts off very simple and each step is very incremental so you don&#39;t get lost along the way. I also like that it tackles some difficult concepts, like debugging, object oriented programming, and inheritance. Essentially, this tutorial doesn&#39;t just try to teach you how to program, it also tries to teach you how to think like a programmer. (The tutorial is free online, and there are also videos and other extra materials available for purchase.)&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://www.codecademy.com/&quot; target=&quot;_blank&quot;&gt;Codecademy&lt;/a&gt;&lt;br /&gt;
The best part about Codecademy is the way it makes programming fun and interesting by giving you useful, realistic projects. Each lesson is accompanied by a tiny fully functional project or game that helps you practice what you just learned. For example, the very first project for Python is a tip calculator – what a creative way to teach basic number operations! Codecademy tutorials are available for HTML/CSS, Javascript, jQuery, Python, Ruby, PHP, and APIs.&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;https://www.khanacademy.org/computing/cs/programming&quot; target=&quot;_blank&quot;&gt;Khan Academy&lt;/a&gt;&lt;br /&gt;
If you&#39;re interested in free self-guided learning online, Khan Academy is one of the best resources available (maybe THE best?). The founder, Salman Khan, gave a nice&amp;nbsp;&lt;a href=&quot;http://www.ted.com/talks/salman_khan_let_s_use_video_to_reinvent_education&quot; target=&quot;_blank&quot;&gt;TED talk&lt;/a&gt; in 2011 about the origins of the site. A couple years ago they added a complete Javascript tutorial, and it looks amazing! The highlight of Khan Academy is the free videos, which are easy to follow and much more engaging than reading a book or tutorial online. Since they are in Javascript, the lessons are also much more visual and interactive. Finally, I want to point out my favorite part of the Khan Academy tutorial – at the very end there is a section on &lt;a href=&quot;https://www.khanacademy.org/computing/cs/programming/good-practices/v/the-power-of-the-docs&quot; target=&quot;_blank&quot;&gt;Becoming a Better Programmer&lt;/a&gt;! I think it&#39;s important for tutorials (like this blog, even) to recognize that they won&#39;t be able to cover everything, and to point people towards good principles and other helpful resources they can turn to when they get stuck.&lt;br /&gt;
&lt;br /&gt;
(A short note about text editors: many tutorials will suggest that you use the default plain text editor on your system, e.g. Notepad or Textedit. That&#39;s fine, but there are certainly better programs out there. By far the best one I have used is &lt;a href=&quot;http://www.sublimetext.com/&quot; target=&quot;_blank&quot;&gt;Sublime&lt;/a&gt;. Serious programmers also use editor &quot;languages&quot; which allow quick navigation and editing through keyboard shortcuts. The two most popular are &lt;a href=&quot;http://en.wikipedia.org/wiki/Editor_war&quot; target=&quot;_blank&quot;&gt;Emacs and Vim&lt;/a&gt;. But really, just stick with Sublime, it&#39;s awesome.)&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Next step: make something!&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
The one piece of advice pretty much every programmer will give you is that programming is a skill that you learn by doing. Once you have the basics, the next step is to make something real that works. It&#39;s even better if you can think of something you might use in your everyday life. If you don&#39;t have any ideas, there are lots of great suggestions online. For example, here are two project lists: one for &lt;a href=&quot;http://www.codeconquest.com/programming-projects/ideas-for-programming-projects/&quot; target=&quot;_blank&quot;&gt;front end&lt;/a&gt; programming, and one for &lt;a href=&quot;https://github.com/karan/Projects&quot; target=&quot;_blank&quot;&gt;back end&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;How to find help&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
When you get stuck (and you will!) there are several good places to ask for help. First, programming languages usually have a help function that brings up a short written explanation of each command, often with examples of how to use it. Use google to find out how to access the help function for your language.&lt;br /&gt;
&lt;br /&gt;
Second, if you&#39;re still stuck, search for your problem online. Try to include some key words, like the name of the language, the function, and the error you&#39;re getting if there is one. It also sometimes helps to type your query as a question (like &quot;how do I add two numbers in python?&quot;) or even paste your error into the search box directly. Chances are someone else has faced this problem before and some other nice person has kindly taken the time to answer their question. If you don&#39;t find the answer right away, keep looking and maybe try changing your search terms. Like everything else, it takes practice to search for the right question, too.&lt;br /&gt;
&lt;br /&gt;
If you still can&#39;t find your answer, you can post a question on a support forum like &lt;a href=&quot;http://stackoverflow.com/&quot; target=&quot;_blank&quot;&gt;StackOverflow&lt;/a&gt;. A word of caution for beginners: it&#39;s sometimes hard to express your question in a way that other people can understand and help you. Just as there are good people on the internet there are also rude and obnoxious people as well. Be patient with the strangers giving you free advice, and if they seem frustrated with you try to understand why. At the same time, don&#39;t take it personally if they&#39;re rude!&lt;br /&gt;
&lt;br /&gt;
Lastly, if you&#39;re learning a particular library within a language there are often community support forums and email listserves for users of that library. These smaller communities are often friendlier and more responsive to questions, and sometimes you&#39;ll even get a reply from the original author of the library themselves.&lt;br /&gt;
&lt;br /&gt;
There are many more topics regarding learning to program which I didn&#39;t cover here, so feel free to comment if you think I missed something or have a suggestion. Thanks for reading!&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://bestkeptsecrects.blogspot.com/feeds/7087538415180151387/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://bestkeptsecrects.blogspot.com/2014/07/how-to-learn-programming-from-scratch.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/831108661073114437/posts/default/7087538415180151387'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/831108661073114437/posts/default/7087538415180151387'/><link rel='alternate' type='text/html' href='http://bestkeptsecrects.blogspot.com/2014/07/how-to-learn-programming-from-scratch.html' title='How to learn programming from scratch'/><author><name>Rachel Albert</name><uri>http://www.blogger.com/profile/13165743738870327222</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-831108661073114437.post-8076697875601205401</id><published>2014-06-26T23:11:00.001-07:00</published><updated>2014-06-26T23:34:17.609-07:00</updated><title type='text'>MATLAB or Python?</title><content type='html'>&lt;div class=&quot;p1&quot; style=&quot;color: #222222; font-family: &#39;Open Sans&#39;, &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 23.799999237060547px; margin-bottom: 0.825em;&quot;&gt;
If you’re new to research or looking to expand your skill set, you might be asking yourself “Should I learn Python?” I think the answer to this question is usually a resounding “Yes.”&lt;/div&gt;
&lt;div class=&quot;p2&quot; style=&quot;color: #222222; font-family: &#39;Open Sans&#39;, &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 23.799999237060547px; margin-bottom: 0.825em;&quot;&gt;
Here are 6 reasons you may want to consider learning this up-and-coming language:&lt;/div&gt;
&lt;div class=&quot;p2&quot; style=&quot;color: #222222; font-family: &#39;Open Sans&#39;, &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 23.799999237060547px; margin-bottom: 0.825em;&quot;&gt;
&lt;strong style=&quot;font-style: inherit; line-height: 1.7;&quot;&gt;0) Python is open source&lt;/strong&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot; style=&quot;color: #222222; font-family: &#39;Open Sans&#39;, &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 23.799999237060547px; margin-bottom: 0.825em;&quot;&gt;
This means it’s freely available and can be modified and built upon by anyone. Open source software works like this: programmers from lots of different backgrounds contribute code, which is then reviewed and edited by other programmers and eventually approved and packaged into the&amp;nbsp;&lt;a data-mce-href=&quot;https://www.python.org/&quot; href=&quot;https://www.python.org/&quot; style=&quot;color: #1b8be0; font-style: inherit; font-weight: inherit; line-height: 1.7; text-decoration: none;&quot; target=&quot;_blank&quot;&gt;Python&lt;/a&gt;&amp;nbsp;language.&lt;/div&gt;
&lt;div class=&quot;p1&quot; style=&quot;color: #222222; font-family: &#39;Open Sans&#39;, &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 23.799999237060547px; margin-bottom: 0.825em;&quot;&gt;
Using open source software for research has many benefits. In the same way that&amp;nbsp;&lt;a data-mce-href=&quot;http://en.wikipedia.org/wiki/Open_access_journal&quot; href=&quot;http://en.wikipedia.org/wiki/Open_access_journal&quot; style=&quot;color: #1b8be0; font-style: inherit; font-weight: inherit; line-height: 1.7; text-decoration: none;&quot; target=&quot;_blank&quot;&gt;open access journals&lt;/a&gt;&amp;nbsp;make published scientific papers available to everyone, open source software makes it easier for people to benefit from and contribute to scientific code. The fact that open source software is free eliminates the need for pesky and expensive institutional licenses and creates the potential for contributors who are not affiliated with a university to make tools that researchers can use.&amp;nbsp;&lt;/div&gt;
&lt;div class=&quot;p1&quot; style=&quot;color: #222222; font-family: &#39;Open Sans&#39;, &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 23.799999237060547px; margin-bottom: 0.825em;&quot;&gt;
&lt;strong style=&quot;font-style: inherit; line-height: 1.7;&quot;&gt;1) Python libraries adapt quickly&lt;/strong&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot; style=&quot;color: #222222; font-family: &#39;Open Sans&#39;, &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 23.799999237060547px; margin-bottom: 0.825em;&quot;&gt;
In addition to the core of the language there are also a large number of extensions called “libraries”. Libraries are similar to MATLAB’s Toolboxes except there are many more of them, they tend to be much smaller and more specific, and they are usually distributed independently. Python libraries develop very organically - someone realizes the need for a certain feature for their project, they write the code and make it available for anyone to download. Users then submit bug reports, suggest features, and sometimes contribute to the project directly.&amp;nbsp;&lt;/div&gt;
&lt;div class=&quot;p1&quot; style=&quot;color: #222222; font-family: &#39;Open Sans&#39;, &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 23.799999237060547px; margin-bottom: 0.825em;&quot;&gt;
As more Python tools have become available for scientific research, more researchers have started using python, and the quality and diversity of the tools is increasing. This decentralized model allows researchers to start using new features in a matter of weeks (instead of years) and it encourages specialized research communities to work together on developing tools for new scientific endeavors.&lt;/div&gt;
&lt;div class=&quot;p1&quot; style=&quot;color: #222222; font-family: &#39;Open Sans&#39;, &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 23.799999237060547px; margin-bottom: 0.825em;&quot;&gt;
&lt;strong style=&quot;font-style: inherit; line-height: 1.7;&quot;&gt;2) Numpy, Scipy, and Matplotlib have most of what you need&lt;/strong&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot; style=&quot;color: #222222; font-family: &#39;Open Sans&#39;, &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 23.799999237060547px; margin-bottom: 0.825em;&quot;&gt;
These three libraries form the backbone of Python for researchers.&amp;nbsp;&lt;/div&gt;
&lt;ul class=&quot;ul1&quot; style=&quot;color: #222222; font-family: &#39;Open Sans&#39;, &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 23.799999237060547px; list-style: square; margin: 0px 0px 0.825em 2.5em; padding: 0px;&quot;&gt;
&lt;li class=&quot;li1&quot; style=&quot;font-style: inherit; font-weight: inherit; line-height: 1.7;&quot;&gt;&lt;a data-mce-href=&quot;http://www.numpy.org/&quot; href=&quot;http://www.numpy.org/&quot; style=&quot;color: #1b8be0; font-style: inherit; font-weight: inherit; line-height: 1.7; text-decoration: none;&quot; target=&quot;_blank&quot;&gt;Numpy&lt;/a&gt;&amp;nbsp;allows you to do all sorts of mathematical operations and data restructuring.&amp;nbsp;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;font-style: inherit; font-weight: inherit; line-height: 1.7;&quot;&gt;&lt;a data-mce-href=&quot;http://www.scipy.org/&quot; href=&quot;http://www.scipy.org/&quot; style=&quot;color: #1b8be0; font-style: inherit; font-weight: inherit; line-height: 1.7; text-decoration: none;&quot; target=&quot;_blank&quot;&gt;Scipy&lt;/a&gt;&amp;nbsp;does pretty much everything else: importing and exporting data (including to and from MATLAB), statistical functions, matrix operations, FFT’s and other signal processing, linear algebra, image processing, and a large number of other specialized mathematical and scientific features.&amp;nbsp;&lt;/li&gt;
&lt;li class=&quot;li1&quot; style=&quot;font-style: inherit; font-weight: inherit; line-height: 1.7;&quot;&gt;&lt;a data-mce-href=&quot;http://matplotlib.org/&quot; href=&quot;http://matplotlib.org/&quot; style=&quot;color: #1b8be0; font-style: inherit; font-weight: inherit; line-height: 1.7; text-decoration: none;&quot; target=&quot;_blank&quot;&gt;Matplotlib&lt;/a&gt;&amp;nbsp;is a flexible library for creating research-style plots similar to those in MATLAB. The library has a very wide range in terms of functionality (i.e. types of plots), and is sometimes easier to customize than MATLAB. (However, I am not a big fan of either MATLAB or Matplotlib in terms of style. I’m still waiting for a plotting library that doesn’t require me to use Adobe Illustrator for my final posters and presentations.)&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&quot;p1&quot; style=&quot;color: #222222; font-family: &#39;Open Sans&#39;, &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 23.799999237060547px; margin-bottom: 0.825em;&quot;&gt;
That being said, pretty much anything you would want to do with basic MATLAB you can do with Numpy, Scipy, and Matplotlib.&lt;/div&gt;
&lt;div class=&quot;p1&quot; style=&quot;color: #222222; font-family: &#39;Open Sans&#39;, &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 23.799999237060547px; margin-bottom: 0.825em;&quot;&gt;
&lt;strong style=&quot;font-style: inherit; line-height: 1.7;&quot;&gt;3) Pandas is an amazing time saver&lt;/strong&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot; style=&quot;color: #222222; font-family: &#39;Open Sans&#39;, &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 23.799999237060547px; margin-bottom: 0.825em;&quot;&gt;
The number one reason I recommend Python is the&amp;nbsp;&lt;a data-mce-href=&quot;http://pandas.pydata.org/&quot; href=&quot;http://pandas.pydata.org/&quot; style=&quot;color: #1b8be0; font-style: inherit; font-weight: inherit; line-height: 1.7; text-decoration: none;&quot; target=&quot;_blank&quot;&gt;Pandas&lt;/a&gt;&amp;nbsp;library. Pandas is a tool for manipulating and analyzing data. It uses a structure called a data frame (copied from R), which allows you to sort, filter, and group your data. Pandas is seamlessly integrated with Numpy, Scipy, and Matplotlib. This means you can easily run statistical tests on your data in various groupings and with various filters. Pandas also has a number of tools for dealing with missing data and time series data which are particularly suited to many research purposes.&lt;/div&gt;
&lt;div class=&quot;p1&quot; style=&quot;margin-bottom: 0.825em;&quot;&gt;
&lt;div style=&quot;color: #222222; font-family: &#39;Open Sans&#39;, &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;
The Pandas workflow is really much simpler and more efficient than anything I&#39;ve seen or done in MATLAB. Here is an example:&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;color: #222222; font-family: &#39;Open Sans&#39;, &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;
Raw data may be imported from a .mat file like this&lt;/div&gt;
&lt;blockquote class=&quot;tr_bq&quot; style=&quot;color: #222222; font-family: &#39;Open Sans&#39;, &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;
import scipy.io&lt;br /&gt;
import pandas&amp;nbsp;&lt;/blockquote&gt;
&lt;blockquote class=&quot;tr_bq&quot; style=&quot;color: #222222; font-family: &#39;Open Sans&#39;, &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;
mat = scipy.io.loadmat( &#39;file.mat&#39; )&lt;br /&gt;
df = pandas.DataFrame( mat[ &#39;saved_variable_name&#39; ] )&lt;/blockquote&gt;
&lt;/div&gt;
&lt;div class=&quot;p1&quot; style=&quot;margin-bottom: 0.825em;&quot;&gt;
&lt;div style=&quot;color: #222222; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;
&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;The imported ma&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Open Sans&#39;, &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif;&quot;&gt;trix is organized as a data frame. The next step is to rename the columns. This is as easy as&lt;/span&gt;&lt;/div&gt;
&lt;blockquote class=&quot;tr_bq&quot; style=&quot;color: #222222; font-family: &#39;Open Sans&#39;, &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;
df.columns =&amp;nbsp;[&#39;trial&#39;, &#39;stim_value&#39;, &#39;response&#39;,&amp;nbsp;&#39;etc&#39;]&lt;/blockquote&gt;
&lt;div style=&quot;color: #222222; font-family: &#39;Open Sans&#39;, &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;
Now it&#39;s no longer necessary to remember which columns are which variables, and the likelihood of thoughtless errors later in the analysis is greatly reduced. Let&#39;s say we only want to look at the data where the stimulus value is positive. We simply say&lt;/div&gt;
&lt;blockquote class=&quot;tr_bq&quot; style=&quot;color: #222222; font-family: &#39;Open Sans&#39;, &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;
df_filtered = df[ df[&#39;stim_value&#39;] &amp;gt; 0 ]&lt;/blockquote&gt;
&lt;div style=&quot;color: #222222; font-family: &#39;Open Sans&#39;, &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;
You can then analyze the data something like this&lt;/div&gt;
&lt;blockquote class=&quot;tr_bq&quot; style=&quot;color: #222222; font-family: &#39;Open Sans&#39;, &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;
df_sum = df_filtered.sum()&lt;/blockquote&gt;
&lt;div style=&quot;color: #222222; font-family: &#39;Open Sans&#39;, &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;
And finally, we can plot the data as a bar graph with&lt;/div&gt;
&lt;blockquote class=&quot;tr_bq&quot; style=&quot;color: #222222; font-family: &#39;Open Sans&#39;, &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;
df_sum.plot( type=&#39;bar&#39; )&lt;/blockquote&gt;
&lt;div style=&quot;color: #222222; font-family: &#39;Open Sans&#39;, &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;
That&#39;s it! Pandas is really easy to use, and it&#39;s by far my first choice for data analysis. It&#39;s also a good place to start if you want to begin using Python in your research. Often data analysis is separate from the hardware and proprietary software demands of the experiment itself, and researchers tend to code up the analysis on their own and only share the output with their collaborators, thus alleviating some of the costs of switching to a new language (more about that below). You can also check out this&amp;nbsp;&lt;a href=&quot;http://pandas.pydata.org/pandas-docs/stable/10min.html&quot; target=&quot;_blank&quot;&gt;10 minute introduction to Pandas&lt;/a&gt;.&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;p1&quot; style=&quot;color: #222222; font-family: &#39;Open Sans&#39;, &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 23.799999237060547px; margin-bottom: 0.825em;&quot;&gt;
&lt;strong style=&quot;font-style: inherit; line-height: 1.7;&quot;&gt;4) IPython Notebook makes writing and sharing code easy&lt;/strong&gt;&lt;/div&gt;
&lt;div class=&quot;p2&quot; style=&quot;color: #222222; font-family: &#39;Open Sans&#39;, &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 23.799999237060547px; margin-bottom: 0.825em;&quot;&gt;
&lt;a href=&quot;http://ipython.org/&quot; target=&quot;_blank&quot;&gt;IPython&lt;/a&gt; is an interactive command shell (like MATLAB&#39;s command window) that allows you to import libraries and data into a temporary workspace. &lt;a href=&quot;http://ipython.org/notebook.html&quot; target=&quot;_blank&quot;&gt;IPython Notebook&lt;/a&gt;&amp;nbsp;is a huge and beautiful extension on this idea of interactive computing. The Notebook is a rich text web interface for IPython, which means it runs in the browser (e.g. Firefox). It allows you to create annotated code snippets, including inline plots and mathematical formulas with LaTex support. Some people have even created&amp;nbsp;&lt;a href=&quot;http://jakevdp.github.io/blog/2013/05/07/migrating-from-octopress-to-pelican/&quot; target=&quot;_blank&quot;&gt;blogs using IPython Notebook&lt;/a&gt;. I can&#39;t really do it justice, so if you want more information check out &lt;a href=&quot;http://nbviewer.ipython.org/github/jvns/pandas-cookbook/blob/master/cookbook/A%20quick%20tour%20of%20IPython%20Notebook.ipynb&quot; target=&quot;_blank&quot;&gt;these&lt;/a&gt; &lt;a href=&quot;http://nbviewer.ipython.org/github/nborwankar/LearnDataScience/blob/master/notebooks/Z0.%20A%20quick%20tour%20of%20the%20IPython%20notebook.ipynb&quot; target=&quot;_blank&quot;&gt;links&lt;/a&gt;!&lt;/div&gt;
&lt;div class=&quot;p2&quot; style=&quot;color: #222222; font-family: &#39;Open Sans&#39;, &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 23.799999237060547px; margin-bottom: 0.825em;&quot;&gt;
&lt;strong style=&quot;font-style: inherit; line-height: 1.7;&quot;&gt;5) Transferable skills&lt;/strong&gt;&lt;/div&gt;
&lt;div class=&quot;p1&quot; style=&quot;color: #222222; font-family: &#39;Open Sans&#39;, &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 23.799999237060547px; margin-bottom: 0.825em;&quot;&gt;
Lastly, in the event you are considering a career outside of academia, any transferable skills you can develop while doing research are incredibly valuable. Python is widely used in industry, from tiny startups to major companies like Google and Dropbox. Learning it might be your ticket to a new career.&lt;/div&gt;
&lt;div class=&quot;p2&quot; style=&quot;color: #222222; font-family: &#39;Open Sans&#39;, &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 23.799999237060547px; margin-bottom: 0.825em;&quot;&gt;
&lt;br style=&quot;font-style: inherit; font-weight: inherit; line-height: 1.7;&quot; /&gt;
Of course, there are some costs to switching. In many fields MATLAB is still the predominant language, making it difficult to use Python when collaborating with others. Additionally, there is the issue of legacy code. Some MATLAB toolboxes and packages (for example Psychtoolbox and MrVista) have yet to be completely replicated in Python (although that is changing - check out&amp;nbsp;&lt;a href=&quot;http://www.psychopy.org/&quot; target=&quot;_blank&quot;&gt;Psychopy&lt;/a&gt; and &lt;a href=&quot;http://web.stanford.edu/~mwaskom/software/lyman/&quot; target=&quot;_blank&quot;&gt;Lyman&lt;/a&gt;). A tougher challenge, however, is the legacy code passed down from researcher to researcher in individual labs. Having to use and maintain legacy lab code often forces new researchers to learn MATLAB whether they want to or not. Yet, even with the larger initial cost of learning two languages, I would still argue that learning Python saves you time in the long-term.&lt;/div&gt;
&lt;div class=&quot;p2&quot; style=&quot;margin-bottom: 0.825em;&quot;&gt;
&lt;div style=&quot;color: #222222; font-family: &#39;Open Sans&#39;, &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;
&lt;br style=&quot;font-style: inherit; font-weight: inherit; line-height: 1.7;&quot; /&gt;&lt;/div&gt;
&lt;div style=&quot;color: #222222; font-family: &#39;Open Sans&#39;, &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;
Need even more reasons to learn Python? Here are two other blog posts extolling Python&#39;s virtues from an entirely different perspective:&lt;/div&gt;
&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style=&quot;color: #222222; font-family: &#39;Open Sans&#39;, &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;&lt;a href=&quot;http://ajminich.com/2013/06/22/9-reasons-to-switch-from-matlab-to-python/&quot;&gt;http://ajminich.com/2013/06/22/9-reasons-to-switch-from-matlab-to-python/&lt;/a&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;color: #222222; font-family: &#39;Open Sans&#39;, &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 23.799999237060547px;&quot;&gt;&lt;a href=&quot;http://metarabbit.wordpress.com/2013/10/18/why-python-is-better-than-matlab-for-scientific-software/&quot;&gt;http://metarabbit.wordpress.com/2013/10/18/why-python-is-better-than-matlab-for-scientific-software/&lt;/a&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;div class=&quot;p1&quot; style=&quot;color: #222222; line-height: 23.799999237060547px; margin-bottom: 0.825em;&quot;&gt;
&lt;div style=&quot;font-family: &#39;Open Sans&#39;, &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif; font-size: 14px;&quot;&gt;
Convinced, but don&#39;t know where to begin? Here are some resources for learning Python from the beginning and for switching from MATLAB.&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;You can download Python and all of its major scientific libraries for free through &lt;a href=&quot;https://www.enthought.com/products/canopy/academic/&quot; target=&quot;_blank&quot;&gt;Enthought&lt;/a&gt;. Other libraries can be downloaded directly from their respective websites or through a software package manager such as&amp;nbsp;&lt;a href=&quot;http://brew.sh/&quot; target=&quot;_blank&quot;&gt;homebrew&lt;/a&gt; or &lt;a href=&quot;https://pypi.python.org/pypi/pip&quot; target=&quot;_blank&quot;&gt;pip&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;A great tutorial for switching from MATLAB to Python may be found &lt;a href=&quot;http://wiki.scipy.org/NumPy_for_Matlab_Users&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Two excellent introductory Python tutorials: &lt;a href=&quot;http://scipy-lectures.github.io/intro/intro.html#the-interactive-workflow-ipython-and-a-text-editor&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;, and &lt;a href=&quot;http://www.learnpython.org/&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;To learn more, I recommend reading through the documentation for various libraries you might use and following along with the exercises on your own computer (for example, here is the &lt;a href=&quot;http://pandas.pydata.org/pandas-docs/stable/dsintro.html&quot; target=&quot;_blank&quot;&gt;Pandas documentation&lt;/a&gt;).&lt;/li&gt;
&lt;/ul&gt;
&lt;br /&gt;
Happy coding!&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://bestkeptsecrects.blogspot.com/feeds/8076697875601205401/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://bestkeptsecrects.blogspot.com/2014/06/matlab-or-python.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/831108661073114437/posts/default/8076697875601205401'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/831108661073114437/posts/default/8076697875601205401'/><link rel='alternate' type='text/html' href='http://bestkeptsecrects.blogspot.com/2014/06/matlab-or-python.html' title='MATLAB or Python?'/><author><name>Rachel Albert</name><uri>http://www.blogger.com/profile/13165743738870327222</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-831108661073114437.post-4868731323339221072</id><published>2011-10-12T08:36:00.000-07:00</published><updated>2011-10-12T08:38:40.247-07:00</updated><title type='text'>Review: Vehicles by Valentino Braitenberg</title><content type='html'>&lt;b&gt;Vehicles: Experiments in Synthetic Psychology&lt;/b&gt; by Valentino Braitenberg&lt;br /&gt;
Cambridge, MA: The MIT Press, 1996, x + 152 pp., $16.23, ISBN 0-262-52112-1&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;I first heard about Vehicles from the recommended reading list of Dr. Brian Wandell, Principal Investigator of the VISTA Lab at Stanford University in Menlo Park, CA. It is an excellent read that creatively challenged the way I approach studying the brain, and I highly recommend it.&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
The simple premise of &lt;i&gt;Vehicles&lt;/i&gt; is beautifully encapsulated in the first chapter entitled &quot;Let the Problem of the Mind Dissolve in Your Mind&quot; and that is exactly what author Valentino Braitenberg helps the reader do. The first eighty-five pages are devoted to building a very abstract model of a mind, and the subsequent fifty pages take this model apart and examine how it relates directly to what we know about the biology of the brain. &lt;br /&gt;
&lt;br /&gt;
The model consists of fourteen &quot;vehicles&quot; possessing increasingly more complex hardware. Through an incredibly intuitive and believable progression, Braitenberg works upward from a simple sensor attached to a motor to 
tiny animated machines with very human-like behavior. Although their internal workings are simple to understand, the final vehicles perform surprisingly complex actions indicating memory, foresight, and free will.&lt;br /&gt;
&lt;br /&gt;
This part of the book is manageable even for someone with no background in science, yet is thought-provoking enough to inspire the imagination of even the most seasoned neurobiologist. It is, in a word, beautiful.&lt;br /&gt;
&lt;br /&gt;
Following this seductive creation of a human-like mind out of simple circuits are fifty pages of biological notes. The biological explanations are a bit dense and technical and often inconclusive.&lt;br /&gt;
&lt;br /&gt;
One of the recurring themes in this section is the lack of sufficient information to determine the validity of the &lt;i&gt;Vehicles&lt;/i&gt; model. While direct biological evidence for the simpler circuits is easy to find, the more advanced circuitry is still largely hypothetical given our current understanding of the brain.&lt;br /&gt;
&lt;br /&gt;
While this is definitely a disappointing ending, it is still possible to appreciate the primary message of the book: synthesis is vastly easier than analysis. For all our difficulty in figuring out the inner workings of the brain, the human mind may turn out to be simpler than we imagine.&lt;br /&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://bestkeptsecrects.blogspot.com/feeds/4868731323339221072/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://bestkeptsecrects.blogspot.com/2011/10/review-vehicles-by-valentino.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/831108661073114437/posts/default/4868731323339221072'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/831108661073114437/posts/default/4868731323339221072'/><link rel='alternate' type='text/html' href='http://bestkeptsecrects.blogspot.com/2011/10/review-vehicles-by-valentino.html' title='Review: Vehicles by Valentino Braitenberg'/><author><name>Rachel Albert</name><uri>http://www.blogger.com/profile/13165743738870327222</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-831108661073114437.post-7812291849494126040</id><published>2011-10-12T07:48:00.000-07:00</published><updated>2011-10-12T07:48:01.708-07:00</updated><title type='text'>Review: The Mind Within the Net by Manfred Spitzer</title><content type='html'>&lt;b&gt;The Mind Within the Net: Models of Learning, Thinking, and Acting&lt;/b&gt; by Manfred Spitzer&lt;br /&gt;
Cambridge, MA: The MIT Press, 2000, xiv + 359 pp., $29.00, ISBN 0-262-19406-6&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;The Mind Within the Net&lt;/i&gt;&lt;i&gt; was recommended to me by Professor Paul Kieffaber at the College of William &amp;amp; Mary in Virginia. The book provides an excellent review of neural networks and their applications that is both accessible and surprisingly thorough; I highly recommend it.&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
In &lt;i&gt;The Mind Within the Net&lt;/i&gt;, German psychiatrist Manfred Spitzer guides the budding neuroscientist from the basic workings of a single neuron to an intuitive sense for the emergent properties of whole networks. Spitzer takes care to provide crucial background information at each step and each new concept emerges organically out of the previous sections. Yet despite its accessibility the book smoothly tackles many formidable concepts in neuroscience, including:&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;mechanisms for selective attention &lt;/li&gt;
&lt;li&gt;declarative and working memory&lt;/li&gt;
&lt;li&gt;information storage in complex networks &lt;/li&gt;
&lt;li&gt;the development of language&lt;/li&gt;
&lt;/ul&gt;
The result is a lucid explanation of how structure relates to function at every level of the brain.&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;/div&gt;
&lt;ul&gt;
&lt;/ul&gt;
The first half of the book is designed to help the reader build a tool-kit of different types of basic network structures that can be combined to produce more complex brain functions. In addition to explaining the biological mechanism for each network, the book is peppered liberally with visual illustrations and examples from research.&amp;nbsp; &lt;br /&gt;
&lt;br /&gt;
The tool-kit contains four basic types of networks:&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;Hebbian Learning (Long-Term Potentiation)&lt;/li&gt;
&lt;li&gt;Kohonen networks (center-surround organization)&lt;/li&gt;
&lt;li&gt;Hopfield networks (attractor states) &lt;/li&gt;
&lt;li&gt;Elman networks (recurrent states)&lt;/li&gt;
&lt;/ul&gt;
Along the way Spitzer also takes time to demonstrate data generalization, type formation, and the importance of noise within the system. He uses these concepts and the network structures above as a solid foundation for the second half of the book, in which he explores applications of neural nets in understanding brain dysfunction.&lt;br /&gt;
&lt;br /&gt;
The applications section covers a number of neurological disorders that have been the subject of significant study in recent years: schizophrenia, autism, learning disabilities, phantom limbs, Alzheimer&#39;s disease, and depression. In each case Spitzer examines how small changes in the parameters of normal networks can lead to large qualitative changes in the network&#39;s function as a whole.&lt;br /&gt;
&lt;br /&gt;
Although the examples Spitzer provides are not intended as definitive etiologies of these diseases, they do give the reader a sense for for how network level disorders manifest and how they are studied.&lt;br /&gt;
&lt;br /&gt;
By working both forward (creating networks that mimic biological structures) and backward (deducing network structure from DSM-IV symptoms) Spitzer successfully argues that neural networks are an integral tool in our quest to better understand the brain.</content><link rel='replies' type='application/atom+xml' href='http://bestkeptsecrects.blogspot.com/feeds/7812291849494126040/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://bestkeptsecrects.blogspot.com/2011/10/review-mind-within-net-by-manfred.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/831108661073114437/posts/default/7812291849494126040'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/831108661073114437/posts/default/7812291849494126040'/><link rel='alternate' type='text/html' href='http://bestkeptsecrects.blogspot.com/2011/10/review-mind-within-net-by-manfred.html' title='Review: The Mind Within the Net by Manfred Spitzer'/><author><name>Rachel Albert</name><uri>http://www.blogger.com/profile/13165743738870327222</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>