tag:blogger.com,1999:blog-83283319719991311012024-02-20T23:08:44.561-08:00Confessions of a Coffee WenchAnonymoushttp://www.blogger.com/profile/14838141359688200161noreply@blogger.comBlogger4125tag:blogger.com,1999:blog-8328331971999131101.post-22647100613822354592013-07-03T21:06:00.001-07:002013-07-03T21:06:21.721-07:00"So...funny story..." First off, it has been a while, and I should apologize for that. Writing in a format that doesn't offend is tricky, and conveying anything with importance is even moreso. On top of that, my personal life has gotten in the way, which actually leads to this post: a hopefully enjoyable deviation from attempting to teach things about programming.<br /><br /> Today's story comes to you courtesy of my first-ever programming job, from now four years ago. I was a sophomore in college, and had experience at a basic level with pointers and creating linked-lists in C++. I was given a unique opportunity to program a software-defined radio (from here on known as a "SDR", basically, a very expensive WiFi card). Doing so required implementing a <a href="http://en.wikipedia.org/wiki/Network_Driver_Interface_Specification">Windows NDIS driver</a>, which as you can probably guess meant I was a little over my head, and there was a bit of a learning curve associated with it.<br /><br /> SDR's serve to help reduce the cost of R&D for a new protocol. Developers have a choice: build unique hardware from the ground-up, plug in some code, and hope that everything works easy-peasy, or use one of these things, which have high initial cost, but are purpose-built for allowing any stack of code to run. They handle their own ADC/DAC, and just need a "front-end" (and antenna) to transmit on a given spectrum. For our purposes, I was transmitting a modified 802.11b protocol, so I had to use the 2.4GHz spectrum.<br /><br /> Again: I was a noobie. Readers might be quick to point out "wait, you're still pretty young". Yes, but I have experience now, and have learned from my mistakes. Such as this one.<br /><br /> Seeing as the aforementioned 802.11b protocol was one of our team's own creation (focusing on cooperative networking, in case anyone is curious), this meant a lot of on-the-fly decisions about implementation. Design wasn't really a factor -- I could make linked lists, I tried to separate my code blocks as best I could, but my functions were embarrassingly long. That's neither here nor there, but probably would have helped with debugging (see: <a href="http://cgordini.blogspot.com/2013/05/a-different-kind-of-lego.html">previous post</a>).<br /><br /> Onto the subject of mistakes and bugs: when you are running an executable within a command prompt, and it segfaults, it exits "gracefully" -- alerting the user with a printed message to the screen, and killing the process, restoring control of that prompt to the user.<br />
<br />
Seeing as this driver was being developed, learned about, and decided upon simultaneously, there were numerous times where I would have a null dereference. For those unaware, that's where you dereference a pointer, attempting to access a member of whatever object that pointer was pointing to, but the pointer was NULL to begin with, therefore accessing memory you shouldn't, and the computer yells at you -- AKA a "segfault".<br /><br /> What do you think a computer does when a null dereference/segfault occurs in kernel-mode code, stuff that is supposed to be super-efficient and super-careful and super-accurate?<br /><br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td><a href="http://fc05.deviantart.net/fs71/i/2011/264/7/f/blue_screen_of_sadness_by_potasiyam-d49xeht.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img alt="Source: http://potasiyam.deviantart.com/art/Blue-screen-of-sadness-258539681?q=gallery%3Apotasiyam&qo=1" border="0" height="250" src="http://fc05.deviantart.net/fs71/i/2011/264/7/f/blue_screen_of_sadness_by_potasiyam-d49xeht.jpg" title="" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="font-size: 13px;">Bad Things happen.<br /></td></tr>
</tbody></table>
In the TRANSMIT stage of our protocol, this was an inconvenience. That means one computer is down, while I reboot, recover as much of the logs as possible (only towards the end of the job did I get adept at using WinDBG + kernel-mode debugging in XP), and try to figure out which printf() call was showing something that it shouldn't.<br />
<br />
In the RECEIVE stage, it's an entirely different beast. My (malformed) packet has just taken down every SDR-equipped computer in the lab (aside from the source node). One null dereference, one segfault, and my lab is painted blue.<br /><br />
<div style="text-align: center;">
<b>Honestly, it looked cool as hell.</b></div>
<br />Segfaults are bad, mkay?<br /><br />
<br />
<span style="font-size: xx-small;">1) Oh, and if you have a really, really bad day, the blue-screen might be a hint that you've just corrupted your Windows install. I had to teach myself how to use Clonezilla to have a backup partition to easily restore from, very shortly after such experiences.</span><br />
<br />
<br /><span style="font-size: xx-small;">2) When we got these SDRs, we had to have three parts: the SDR, a chip to support the front-end, and the front-end itself. These cost about $4000, total, per SDR setup. As another horror story, the instant we took two of them out of the box they came in, we heard pops and could smell a bit of smoke. A fuse blew, instantaneously. Fortunately, between a $0.10 fuse from Digikey, and someone who was way more adept at PCB reading, voltage-drop measurements, and soldering than I, we salvaged those things.</span>Anonymoushttp://www.blogger.com/profile/14838141359688200161noreply@blogger.com0tag:blogger.com,1999:blog-8328331971999131101.post-38751976433223377512013-05-15T19:43:00.000-07:002013-05-15T19:47:06.721-07:00A Different Kind Of Lego<br />
I'm going to talk a bit about Object Oriented Programming, and why it's a great tool for you to use to <i>solve a problem</i>.<br />
<br />
It is far from the <i>only</i> tool, and there are plenty of circumstances where it isn't appropriate. You'll notice this is a theme in programming. Sometimes, a decent OOP hierarchy is just Too. Damn. Slow. The "Introduction to Data Structures and Algorithms" class at my university is an example of this -- I designed ALL of my projects with SOME semblance of "objects" (I can't call it OOP and look myself in the mirror) -- and the speed of my program took a noticable hit. That class was speed-based, so my grade took a hit as well.<br />
<br />
I'm a very big fan of the following mantra:<br />
<br />
<b> "Make it work, make it pretty, make it fast."</b><br />
<br />
The last two, as mentioned above, are fairly interchangable, based on the needs of the program. And your program is <i>useless</i> without the first. Functionality above all, but there's no need making things harder on yourself when you do the eventual code restructuring for (pretty | speed), which is where the subject of this post comes in.<br />
<br />
Let's talk about abstraction. CS (and CE, lets be honest -- I'll cover it in a bit) is all about abstraction. People throw around the "pillars of OOP", and a common "weed out the ones who didn't pay attention in CS 102" interview question is "Explain (inheiritance | polymorphism | encapsulation)" (Source: I was asked it, and the interviewer was surprised that I had an immediate answer. I was surprised other canidates did not).<br />
<br />
I would argue that an understanding of what abstraction /is/, and why we use it, is fundamental for a good programmer.<br />
<br />
See, abstraction lets you modularize your code. Think of it as (*gasp*) turning your code into a Lego model. Each component of your code is an individual Brick. If you're anything like me, you've had those Bricks for 10, 15 years, and your little brother chewed on some of them, making them not click in as well; making the model not be built easily or successfully. Some are even (ick) MegaBloks. Every once in a while you find a K'nex. <br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="http://i.imgur.com/F1eSZkH.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="240" src="http://i.imgur.com/F1eSZkH.png" width="320" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">OOP.</td></tr>
</tbody></table>
Such is your code when designed in a decent OOP manner. Each object is a Brick. They click together REALLY nicely -- in fact the only reason they exist at all is to click together with each other. Private/public properties exist to force things to click only in certain manners -- if you're using superglue instead of the studs of a Brick, you are Doing It Wrong.<br />
<br />
Every once in a while you get a chewed-upon Brick, or a MegaBlok, or a K'Nex. OOP allows you to say "this isn't the end of the world, I'll just get a new Brick," and be on your merry way.<br />
<br />
Or you could have no modularity, no abstraction whatsoever to your code. You have a superglued conglomerate mess, and if you have a bug (hint, you do. You might not know it yet, but you do.) then it will be HELLA difficult to detect (see: Knowing You're a Tool), and even worse, HELLA difficult to fix. See, you have to bash open your scale-model of the Statue of Liberty with a hammer, pull out the broken section, patch together a fix with ducktape and prayer (we call this a "hack" and they're frowned upon. Hacking the Matrix is cool. Hacking your codebase is not.), throw it in there, and superglue it all up together again.<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="http://i.imgur.com/O9zWfRo.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="240" src="http://i.imgur.com/O9zWfRo.jpg" width="320" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Not OOP.</td></tr>
</tbody></table>
Everything in CS/CE has abstraction. Consider: transistors->logic gates->combinational/sequential circuits->basic mathematical circuits (timers, combinators, ALU's, etc)->....->processor. That's CE for you, and the idea is you can make something VERY complicated VERY elegantly out of VERY tiny components.<br />
<br />
CS is no different, and that elegance, alongside knowing how to apply it, is more key than I feel is being taught. Industry thrives on it. Especially in projects that are being simultaneously developed by non-trivially large teams. I talked about <a href="http://cgordini.blogspot.com/2013/05/git-101.html">Revision Control</a> before. Well, consider: what do you think is easier, 10 programmers all working on the same 4 files that collectively do something very large and complicated, or each programmer "owning" their own task, and related sets of files. You trade off a small number of files, but who cares? If you throw a 1.5 KLOC file at me, my eyes will glaze over anyway. Which do you think Git plays nicer with (if you know how to merge nicely, this is admittedly a non-issue)?<br />
<br />
Each programmer owns* their own Brick. They can click into their team, and have it pulled out and replaced if need be, when it's discovered you are trying to use a MegaBlok when the team really needs a Lego.<br />
<br />
It works, and it's pretty. It might not be the fastest, but that's okay. I'll willingly make that trade, and so will <i>every part of industry I've experienced to date</i>.<br />
<br />
That's not even getting into the discussions of the benefits of "code contracts" and RAII (Though I intend to). This is purely based on "look how easy it is to <a href="https://en.wikipedia.org/wiki/Code_refactoring">refactor</a> your code and find/fix bugs".<br />
<br />
And here's a little secret: even the code I wrote that was supposed to be blazing fast (the NDIS driver) had abstraction, had some semblance of object-orientedness.<br />
<br />
<i>So for the love of all that is holy, please stop saying "I have the following, and it works for 7 out of 12 test cases, but I can't find the bug..." and show me a 200 line function that has seven or eight STL containers all being indexed into simultaneously. I will want to strangle you.</i><br />
<br />
-----------<br />
<br />
*The concept of ownership is under some debate from senior developers. If you "own" some code, and that code is <i>wrong</i>, should you really own it? Or should they take it away from you?<br /><br /><b>For Friday: (Introduction to) Introduction to Object Oriented Programming Week, Part 2</b>Anonymoushttp://www.blogger.com/profile/14838141359688200161noreply@blogger.com0tag:blogger.com,1999:blog-8328331971999131101.post-73802671200215423622013-05-11T00:27:00.000-07:002014-01-17T13:32:44.379-08:00Git 101<br />
<div style="font-size: small; margin-bottom: 5px; margin-top: 5px; padding: 0px;">
<span style="font-family: Verdana, sans-serif;">A couple sections of the internet that I've been on have been like "What's Git, and why should I care?" This is a repost of my answer to that.<br /><br />It doesn't really follow my preferred format for my blog, as it is a <i>tutorial</i> instead of a <i>dialogue</i>, but that's alright. My overall goal is the sharing of information, so share I shall.</span></div>
<div style="font-size: small; margin-bottom: 5px; margin-top: 5px; padding: 0px;">
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<hr style="margin-bottom: 0px;" />
<br />
<div style="font-size: small; margin-bottom: 5px; margin-top: 5px; padding: 0px;">
<span style="font-family: Verdana, sans-serif;">Git is <strong>revision control</strong>. That means if you mess up, rather than having to remember what your old code looked like and did, you can just <strong>revert</strong> back to a previous state.<br /><br />Here's something fairly important to note:</span></div>
<div style="font-size: small; margin-bottom: 5px; margin-top: 5px; padding: 0px;">
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="float: left; margin-right: 1em; text-align: left;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi8IPDGW1_sEzIjITueR7eLKVht8jg8bHURHEgcAKjDLF3tkQKFXfxaKrXG8Gj_kxz2K87tNTZRS2Wzy2lDHOFEvHHZrikISgll_uK_e4RpRwuqhQiRa7vzowg4HhChceFZcpOHVJRZrs0/s1600/Screen+shot+2013-05-10+at+7.30.48+PM.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><span style="font-family: Verdana, sans-serif;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi8IPDGW1_sEzIjITueR7eLKVht8jg8bHURHEgcAKjDLF3tkQKFXfxaKrXG8Gj_kxz2K87tNTZRS2Wzy2lDHOFEvHHZrikISgll_uK_e4RpRwuqhQiRa7vzowg4HhChceFZcpOHVJRZrs0/s400/Screen+shot+2013-05-10+at+7.30.48+PM.jpg" height="225" width="400" /></span></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><div style="font-size: small; margin-bottom: 5px; margin-top: 5px; padding: 0px; text-align: start;">
<b><span style="font-family: Verdana, sans-serif; font-size: x-small;">This is NOT Revision Control. This is a disaster. I know this because I did it this way, once upon a time.</span></b><br />
<b><span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span></b></div>
</td></tr>
</tbody></table>
<div style="margin-bottom: 5px; margin-top: 5px; padding: 0px;">
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<div style="font-size: small; margin-bottom: 5px; margin-top: 5px; padding: 0px;">
<span style="font-family: Verdana, sans-serif;">Git allows for <strong>remote hosting</strong> on sites like Bitbucket, Github, and even Google Code. That way, you can <strong>pull</strong> your code down from a remote location on computers, edit it, and <strong>push</strong> it back up. It's essentially a <em>cloud</em> of data storage, like Dropbox, but smarter for code.</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiNv3o5xS7Pweeu3Vzc2lXp8aokuJemDu_pNDQ3YIMaNTR3Yn-sE6-HokyX7dW-L5RKryzxQN0GHvo0J6hn7W87yNqGvaNztzlRODtU2SUTuLrL1B-yxAlhNZUm31VEFP23sGAoxmrstTQ/s1600/Screen+shot+2013-05-10+at+7.33.26+PM.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiNv3o5xS7Pweeu3Vzc2lXp8aokuJemDu_pNDQ3YIMaNTR3Yn-sE6-HokyX7dW-L5RKryzxQN0GHvo0J6hn7W87yNqGvaNztzlRODtU2SUTuLrL1B-yxAlhNZUm31VEFP23sGAoxmrstTQ/s1600/Screen+shot+2013-05-10+at+7.33.26+PM.jpg" height="255" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="float: left; margin-right: 1em;"><tbody>
<tr><td class="tr-caption" style="font-size: 13px; text-align: center;"><div class="separator" style="clear: both; text-align: left;">
<b><span style="font-family: Verdana, sans-serif; font-size: x-small;">This IS Revision Control. It is noticeably easier to navigate, and in general, use.</span></b></div>
<div class="separator" style="clear: both;">
</div>
</td></tr>
</tbody></table>
</td></tr>
</tbody></table>
</div>
<div style="font-size: small; margin-bottom: 5px; margin-top: 5px; padding: 0px;">
</div>
<hr style="margin-bottom: 0px;" />
<br />
<div style="font-size: small; margin-bottom: 5px; margin-top: 5px; padding: 0px;">
<span style="font-family: Verdana, sans-serif;"><strong>~</strong><strong>~THE BASICS~</strong><strong>~</strong></span></div>
<div style="font-size: small; margin-bottom: 5px; margin-top: 5px; padding: 0px;">
<span style="font-family: Verdana, sans-serif;">If in Windows: Download Git Bash, because I like me a command prompt, and it teaches you what's going on a bit better.<br />If in Linux or OS X: There are handy-dandy installers for integrating Git commands, such as "sudo apt-get install git" if I recall correctly.</span></div>
<div style="font-size: small; margin-bottom: 5px; margin-top: 5px; padding: 0px;">
<span style="font-family: Verdana, sans-serif;">Cool, we now have a Command Prompt for Git. It uses Unix-based commands, like "ls" and "cd" and "mkdir" and the like, so you'll notice the Windows Git Bash shell is really a cygwin shell. Not a coincidence.</span></div>
<div style="font-size: small; margin-bottom: 5px; margin-top: 5px; padding: 0px;">
<span style="font-family: Verdana, sans-serif;"><strong>~</strong><strong>~LINK TO REMOTE REPOSITORIES~</strong><strong>~</strong></span></div>
<div style="font-size: small; margin-bottom: 5px; margin-top: 5px; padding: 0px;">
<span style="font-family: Verdana, sans-serif;">So now, let's assume you have some code that you want to start a revision control system on.</span></div>
<div style="font-size: small; margin-bottom: 5px; margin-top: 5px; padding: 0px;">
<span style="font-family: Verdana, sans-serif;">We'll call it hello_world.cpp, in a folder called SENIOR_DESIGN_PROJECT.</span></div>
<div style="font-size: small; margin-bottom: 5px; margin-top: 5px; padding: 0px;">
<span style="font-family: Verdana, sans-serif;">On your remote hosting site (Bitbucket has unlimited free repositories, or folders-of-code, and Github has something similar for students IIRC), you can click the big MAKE NEW REPOSITORY button, and it will create a new empty remote repository.</span></div>
<div style="font-size: small; margin-bottom: 5px; margin-top: 5px; padding: 0px;">
<span style="font-family: Verdana, sans-serif;">THEN.</span></div>
<div style="font-size: small; margin-bottom: 5px; margin-top: 5px; padding: 0px;">
<span style="font-family: Verdana, sans-serif;">You can run a command (in your respective Terminal, be it Terminal in Linux/OSX, or Git Bash in Windows) on your code folder, as prompted by the $ symbol:</span></div>
<pre style="border-bottom-left-radius: 5px; border-bottom-right-radius: 5px; border-top-left-radius: 5px; border-top-right-radius: 5px; border: 1px solid rgb(237, 237, 237); margin: 10px; padding: 0px 0px 0px 10px; position: relative;"><code style="border-left-color: rgb(237, 237, 237); border-left-style: solid; border-left-width: 1px; display: block; margin-left: 20px; overflow: auto; padding-left: 10px;"><span style="font-family: Verdana, sans-serif;"> $ git init
</span></code></pre>
<div style="font-size: small; margin-bottom: 5px; margin-top: 5px; padding: 0px;">
<span style="font-family: Verdana, sans-serif;">to initialize that folder to be compatible with Git. You'll have to do this once per project.</span></div>
<div style="font-size: small; margin-bottom: 5px; margin-top: 5px; padding: 0px;">
<span style="font-family: Verdana, sans-serif;">Next up, link that folder to your remote repository by telling it where EXACTLY to push things back up to the cloud (as discussed earlier).</span></div>
<pre style="border-bottom-left-radius: 5px; border-bottom-right-radius: 5px; border-top-left-radius: 5px; border-top-right-radius: 5px; border: 1px solid rgb(237, 237, 237); margin: 10px; padding: 0px 0px 0px 10px; position: relative;"><code style="border-left-color: rgb(237, 237, 237); border-left-style: solid; border-left-width: 1px; display: block; margin-left: 20px; overflow: auto; padding-left: 10px;"><span style="font-family: Verdana, sans-serif;"> $ git remote add origin http://some.github.repository/SENIOR_DESIGN_PROJ.git
</span></code></pre>
<div style="font-size: small; margin-bottom: 5px; margin-top: 5px; padding: 0px;">
<span style="font-family: Verdana, sans-serif;">What this says is "this local codebase is linked to a remote codebase, which we'll call 'origin', found on this git repository at this address."</span></div>
<div style="font-size: small; margin-bottom: 5px; margin-top: 5px; padding: 0px;">
<span style="font-family: Verdana, sans-serif;">Follow it up with:</span></div>
<pre style="border-bottom-left-radius: 5px; border-bottom-right-radius: 5px; border-top-left-radius: 5px; border-top-right-radius: 5px; border: 1px solid rgb(237, 237, 237); margin: 10px; padding: 0px 0px 0px 10px; position: relative;"><code style="border-left-color: rgb(237, 237, 237); border-left-style: solid; border-left-width: 1px; display: block; margin-left: 20px; overflow: auto; padding-left: 10px;"><span style="font-family: Verdana, sans-serif;">$ git add .
$ git commit -m "Initial Commit."
$ git push -u origin master
</span></code></pre>
<div style="font-size: small; margin-bottom: 5px; margin-top: 5px; padding: 0px;">
<span style="font-family: Verdana, sans-serif;">to say "push anything, and all future things, to the Master branch". For simplicity's sake, we'll only care about the Master branch.</span></div>
<div style="font-size: small; margin-bottom: 5px; margin-top: 5px; padding: 0px;">
<span style="font-family: Verdana, sans-serif;"><strong>~</strong><strong>~WHAT DID I JUST DO~</strong><strong>~</strong></span></div>
<div style="font-size: small; margin-bottom: 5px; margin-top: 5px; padding: 0px;">
<span style="font-family: Verdana, sans-serif;">Let's run through the commands you just used one by one real quick.</span></div>
<pre style="border-bottom-left-radius: 5px; border-bottom-right-radius: 5px; border-top-left-radius: 5px; border-top-right-radius: 5px; border: 1px solid rgb(237, 237, 237); margin: 10px; padding: 0px 0px 0px 10px; position: relative;"><code style="border-left-color: rgb(237, 237, 237); border-left-style: solid; border-left-width: 1px; display: block; margin-left: 20px; overflow: auto; padding-left: 10px;"><span style="font-family: Verdana, sans-serif;"> $ git add .
</span></code></pre>
<div style="font-size: small; margin-bottom: 5px; margin-top: 5px; padding: 0px;">
<span style="font-family: Verdana, sans-serif;">Adds all NEW/CHANGED files (i.e. hello_world.cpp in this case) to a pending STAGING area.</span></div>
<pre style="border-bottom-left-radius: 5px; border-bottom-right-radius: 5px; border-top-left-radius: 5px; border-top-right-radius: 5px; border: 1px solid rgb(237, 237, 237); margin: 10px; padding: 0px 0px 0px 10px; position: relative;"><code style="border-left-color: rgb(237, 237, 237); border-left-style: solid; border-left-width: 1px; display: block; margin-left: 20px; overflow: auto; padding-left: 10px;"><span style="font-family: Verdana, sans-serif;"> $ git commit -m "message"
</span></code></pre>
<div style="font-size: small; margin-bottom: 5px; margin-top: 5px; padding: 0px;">
<span style="font-family: Verdana, sans-serif;">Commits that staging area, locking it down as some kind of feature or bugfix or whatever MESSAGE is. This is known as a "commit".</span></div>
<pre style="border-bottom-left-radius: 5px; border-bottom-right-radius: 5px; border-top-left-radius: 5px; border-top-right-radius: 5px; border: 1px solid rgb(237, 237, 237); margin: 10px; padding: 0px 0px 0px 10px; position: relative;"><code style="border-left-color: rgb(237, 237, 237); border-left-style: solid; border-left-width: 1px; display: block; margin-left: 20px; overflow: auto; padding-left: 10px;"><span style="font-family: Verdana, sans-serif;"> $ git push
</span></code></pre>
<div style="font-size: small; margin-bottom: 5px; margin-top: 5px; padding: 0px;">
<span style="font-family: Verdana, sans-serif;">Actually pushes this code up to your remote repo. Notice I purposely left out all the extra flags -- you only really need those for your FIRST ever push for this project!</span></div>
<div style="font-size: small; margin-bottom: 5px; margin-top: 5px; padding: 0px;">
<span style="font-family: Verdana, sans-serif;">You can see what files have been last changed between commits with</span></div>
<pre style="border-bottom-left-radius: 5px; border-bottom-right-radius: 5px; border-top-left-radius: 5px; border-top-right-radius: 5px; border: 1px solid rgb(237, 237, 237); margin: 10px; padding: 0px 0px 0px 10px; position: relative;"><code style="border-left-color: rgb(237, 237, 237); border-left-style: solid; border-left-width: 1px; display: block; margin-left: 20px; overflow: auto; padding-left: 10px;"><span style="font-family: Verdana, sans-serif;"> $ git status
</span></code></pre>
<div style="font-size: small; margin-bottom: 5px; margin-top: 5px; padding: 0px;">
<span style="font-family: Verdana, sans-serif;">And pull down changes from other users/computers with</span></div>
<pre style="border-bottom-left-radius: 5px; border-bottom-right-radius: 5px; border-top-left-radius: 5px; border-top-right-radius: 5px; border: 1px solid rgb(237, 237, 237); margin: 10px; padding: 0px 0px 0px 10px; position: relative;"><code style="border-left-color: rgb(237, 237, 237); border-left-style: solid; border-left-width: 1px; display: block; margin-left: 20px; overflow: auto; padding-left: 10px;"><span style="font-family: Verdana, sans-serif;"> $ git pull
</span></code></pre>
<div style="font-size: small; margin-bottom: 5px; margin-top: 5px; padding: 0px;">
<strong><span style="font-family: Verdana, sans-serif;">Now let's consider a different computer.</span></strong></div>
<div style="font-size: small; margin-bottom: 5px; margin-top: 5px; padding: 0px;">
<span style="font-family: Verdana, sans-serif;">On a different computer (we'll call it C2), if you run:</span></div>
<pre style="border-bottom-left-radius: 5px; border-bottom-right-radius: 5px; border-top-left-radius: 5px; border-top-right-radius: 5px; border: 1px solid rgb(237, 237, 237); margin: 10px; padding: 0px 0px 0px 10px; position: relative;"><code style="border-left-color: rgb(237, 237, 237); border-left-style: solid; border-left-width: 1px; display: block; margin-left: 20px; overflow: auto; padding-left: 10px;"><span style="font-family: Verdana, sans-serif;"> $ git clone http://some.github.repository/SENIOR_DESIGN_PROJ.git
</span></code></pre>
<div style="font-size: small; margin-bottom: 5px; margin-top: 5px; padding: 0px;">
<span style="font-family: Verdana, sans-serif;">You'll be prompted for your password, then your computer will go off and grab the most recent code and store it in a folder called SENIOR_DESIGN_PROJ.</span></div>
<div style="font-size: small; margin-bottom: 5px; margin-top: 5px; padding: 0px;">
<span style="font-family: Verdana, sans-serif;">You make some changes to the source code. Fix a bug, whatever.</span></div>
<div style="font-size: small; margin-bottom: 5px; margin-top: 5px; padding: 0px;">
<span style="font-family: Verdana, sans-serif;">SO:</span></div>
<pre style="border-bottom-left-radius: 5px; border-bottom-right-radius: 5px; border-top-left-radius: 5px; border-top-right-radius: 5px; border: 1px solid rgb(237, 237, 237); margin: 10px; padding: 0px 0px 0px 10px; position: relative;"><code style="border-left-color: rgb(237, 237, 237); border-left-style: solid; border-left-width: 1px; display: block; margin-left: 20px; overflow: auto; padding-left: 10px;"><span style="font-family: Verdana, sans-serif;"> $ git add .
$ git commit -m "I fixed that stupid memory leak."
$ git push
</span></code></pre>
<div style="font-size: small; margin-bottom: 5px; margin-top: 5px; padding: 0px;">
<span style="font-family: Verdana, sans-serif;">And back on C1:</span></div>
<pre style="border-bottom-left-radius: 5px; border-bottom-right-radius: 5px; border-top-left-radius: 5px; border-top-right-radius: 5px; border: 1px solid rgb(237, 237, 237); margin: 10px; padding: 0px 0px 0px 10px; position: relative;"><code style="border-left-color: rgb(237, 237, 237); border-left-style: solid; border-left-width: 1px; display: block; margin-left: 20px; overflow: auto; padding-left: 10px;"><span style="font-family: Verdana, sans-serif;"> $ git pull
</span></code></pre>
<div style="font-size: small; margin-bottom: 5px; margin-top: 5px; padding: 0px;">
<span style="font-family: Verdana, sans-serif;">Congrats, you just pulled back down the bugfix that you wrote on a entirely different computer! This is how teams are able to work on a codebase simultaneously -- they all commit and merge it all into branches. In our case, we, again, only care about the Master branch.</span></div>
<div style="font-size: small; margin-bottom: 5px; margin-top: 5px; padding: 0px;">
<span style="font-family: Verdana, sans-serif;"><strong>~</strong><strong>~I DONE GOOFED~</strong><strong>~</strong></span></div>
<div style="font-size: small; margin-bottom: 5px; margin-top: 5px; padding: 0px;">
<span style="font-family: Verdana, sans-serif;">Or, you make some changes, decide these were bad changes, and you want to roll back:</span></div>
<pre style="border-bottom-left-radius: 5px; border-bottom-right-radius: 5px; border-top-left-radius: 5px; border-top-right-radius: 5px; border: 1px solid rgb(237, 237, 237); margin: 10px; padding: 0px 0px 0px 10px; position: relative;"><code style="border-left-color: rgb(237, 237, 237); border-left-style: solid; border-left-width: 1px; display: block; margin-left: 20px; overflow: auto; padding-left: 10px;"><span style="font-family: Verdana, sans-serif;"> $ git checkout <filename>
</span></code></pre>
<div style="font-size: small; margin-bottom: 5px; margin-top: 5px; padding: 0px;">
<span style="font-family: Verdana, sans-serif;">resets a single file by removing it from the Staging area.</span></div>
<pre style="border-bottom-left-radius: 5px; border-bottom-right-radius: 5px; border-top-left-radius: 5px; border-top-right-radius: 5px; border: 1px solid rgb(237, 237, 237); margin: 10px; padding: 0px 0px 0px 10px; position: relative;"><code style="border-left-color: rgb(237, 237, 237); border-left-style: solid; border-left-width: 1px; display: block; margin-left: 20px; overflow: auto; padding-left: 10px;"><span style="font-family: Verdana, sans-serif;"> $ git reset HEAD --hard
</span></code></pre>
<div style="font-size: small; margin-bottom: 5px; margin-top: 5px; padding: 0px;">
<span style="font-family: Verdana, sans-serif;">resets your entire codebase to the previous commit.</span></div>
<pre style="border-bottom-left-radius: 5px; border-bottom-right-radius: 5px; border-top-left-radius: 5px; border-top-right-radius: 5px; border: 1px solid rgb(237, 237, 237); margin: 10px; padding: 0px 0px 0px 10px; position: relative;"><code style="border-left-color: rgb(237, 237, 237); border-left-style: solid; border-left-width: 1px; display: block; margin-left: 20px; overflow: auto; padding-left: 10px;"><span style="font-family: Verdana, sans-serif;"> $ git checkout commit-number
</span></code></pre>
<div style="font-size: small; margin-bottom: 5px; margin-top: 5px; padding: 0px;">
<span style="font-family: Verdana, sans-serif;">resets your entire codebase to an arbitrary commit-number (IIRC). This is VERY handy if you mess up your code base, but an earlier version worked.</span></div>
<hr style="font-size: small; margin-bottom: 0px;" />
<div style="font-size: small; margin-bottom: 5px; margin-top: 5px; padding: 0px;">
<span style="font-family: Verdana, sans-serif;"><strong>TL;DR</strong><br />Set up git repo on a project folder:</span></div>
<pre style="border-bottom-left-radius: 5px; border-bottom-right-radius: 5px; border-top-left-radius: 5px; border-top-right-radius: 5px; border: 1px solid rgb(237, 237, 237); margin: 10px; padding: 0px 0px 0px 10px; position: relative;"><code style="border-left-color: rgb(237, 237, 237); border-left-style: solid; border-left-width: 1px; display: block; margin-left: 20px; overflow: auto; padding-left: 10px;"><span style="font-family: Verdana, sans-serif;"> $ git init
</span></code></pre>
<div style="font-size: small; margin-bottom: 5px; margin-top: 5px; padding: 0px;">
<span style="font-family: Verdana, sans-serif;">Set up a link to a remote repo:</span></div>
<pre style="border-bottom-left-radius: 5px; border-bottom-right-radius: 5px; border-top-left-radius: 5px; border-top-right-radius: 5px; border: 1px solid rgb(237, 237, 237); margin: 10px; padding: 0px 0px 0px 10px; position: relative;"><code style="border-left-color: rgb(237, 237, 237); border-left-style: solid; border-left-width: 1px; display: block; margin-left: 20px; overflow: auto; padding-left: 10px;"><span style="font-family: Verdana, sans-serif;"> $ git remote add origin http://blahblahblah
</span></code></pre>
<div style="font-size: small; margin-bottom: 5px; margin-top: 5px; padding: 0px;">
<span style="font-family: Verdana, sans-serif;">Do an initial commit and push:</span></div>
<pre style="border-bottom-left-radius: 5px; border-bottom-right-radius: 5px; border-top-left-radius: 5px; border-top-right-radius: 5px; border: 1px solid rgb(237, 237, 237); margin: 10px; padding: 0px 0px 0px 10px; position: relative;"><code style="border-left-color: rgb(237, 237, 237); border-left-style: solid; border-left-width: 1px; display: block; margin-left: 20px; overflow: auto; padding-left: 10px;"><span style="font-family: Verdana, sans-serif;"> $ git add .
$ git commit -m "Initial commit"
$ git push -u origin master
</span></code></pre>
<div style="font-size: small; margin-bottom: 5px; margin-top: 5px; padding: 0px;">
<span style="font-family: Verdana, sans-serif;">Make some changes, see what they were:</span></div>
<pre style="border-bottom-left-radius: 5px; border-bottom-right-radius: 5px; border-top-left-radius: 5px; border-top-right-radius: 5px; border: 1px solid rgb(237, 237, 237); margin: 10px; padding: 0px 0px 0px 10px; position: relative;"><code style="border-left-color: rgb(237, 237, 237); border-left-style: solid; border-left-width: 1px; display: block; margin-left: 20px; overflow: auto; padding-left: 10px;"><span style="font-family: Verdana, sans-serif;"> $ git status
</span></code></pre>
<div style="font-size: small; margin-bottom: 5px; margin-top: 5px; padding: 0px;">
<span style="font-family: Verdana, sans-serif;">Pull to make sure you didn't have conflicting changes stashed in the remote repository (i.e. a team member fixed it while you were working on it, and you don't want to mess up their fix, you should just reset your own and use theirs)</span></div>
<pre style="border-bottom-left-radius: 5px; border-bottom-right-radius: 5px; border-top-left-radius: 5px; border-top-right-radius: 5px; border: 1px solid rgb(237, 237, 237); margin: 10px; padding: 0px 0px 0px 10px; position: relative;"><code style="border-left-color: rgb(237, 237, 237); border-left-style: solid; border-left-width: 1px; display: block; margin-left: 20px; overflow: auto; padding-left: 10px;"><span style="font-family: Verdana, sans-serif;"> $ git pull
$ git checkout hello_world_teammate_revised.cpp
</span></code></pre>
<div style="font-size: small; margin-bottom: 5px; margin-top: 5px; padding: 0px;">
<span style="font-family: Verdana, sans-serif;">Make some better changes, and push them back up:</span></div>
<pre style="border-bottom-left-radius: 5px; border-bottom-right-radius: 5px; border-top-left-radius: 5px; border-top-right-radius: 5px; border: 1px solid rgb(237, 237, 237); margin: 10px; padding: 0px 0px 0px 10px; position: relative;"><code style="border-left-color: rgb(237, 237, 237); border-left-style: solid; border-left-width: 1px; display: block; margin-left: 20px; overflow: auto; padding-left: 10px;"><span style="font-family: Verdana, sans-serif;"> $ git add .
$ git commit -m "I fixed teammates bug!"
$ git push
</span></code></pre>
<div style="font-size: small; margin-bottom: 5px; margin-top: 5px; padding: 0px;">
<strong><span style="font-family: Verdana, sans-serif;">That's basically the basics! With this you can store all your code remotely, navigate the remote location to find commit numbers, roll back code as need be (either single files, or ENTIRE groups of files to previously working commits), and work on a project with a team!</span></strong><br />
<strong><span style="font-family: Verdana, sans-serif;"><br /></span></strong><strong><span style="font-family: Verdana, sans-serif;">Next Week: <a href="http://cgordini.blogspot.com/2013/05/a-different-kind-of-lego.html">(Introduction to) Introduction to Object Oriented Programming Week, </a></span></strong><strong><span style="font-family: Verdana, sans-serif;"><a href="http://cgordini.blogspot.com/2013/05/a-different-kind-of-lego.html">Part 1: A Different Kind Of Lego</a></span></strong></div>
Anonymoushttp://www.blogger.com/profile/14838141359688200161noreply@blogger.com0tag:blogger.com,1999:blog-8328331971999131101.post-84299645192064288022013-05-10T08:32:00.000-07:002013-05-11T00:28:42.484-07:00Beginnings I am an interesting enigma in the world of CS. That's Computer Science, not Counter-Strike, though I'm game for a round if you are (Source, not 1.6. Sorry, old-school gamers...and new-school, I guess, with GO being out now. Way to alienate right away, self.)<br />
<br />
I have been programming "professionally" for four years now, without actually having a true, contracted, full-time position. Only in the summers (that's not entirely true, my first programming job I elected to do concurrently with school). Many of my peers only have one internship under their belt, then they go into a full-time job. Maybe even two. I've done C-based NDIS driver-development, web development on the ASP.NET MVC platform, and most recently going on two summers worth of C# MVP development. That's a lot of internship, hence the title of this blog. It's also a lot of school, as I am going for two degrees -- both Computer Science, AND Computer Engineering. Hence the driver-dev, and being an enigma.<br />
<br />
There are no shortages of blogs out there that will tell you why your thought patterns are wrong. I'm actually quite a fan of them, which I'll get into why in just a moment (seems odd, right?). Even though I'm an old-as-dirt intern, I feel I can learn a lot (which is appropriate. I may be as old as dirt, but I am still just an intern). A lot of blogs I've been reading are from senior developers (and when I say senior, I mean <i>senior</i>, as in <i>worked for Microsoft for so long that they left to start their own company</i>) and they tend to know what they're doing. They're really good to learn from. I feel I can be good to learn from too -- I am not so presumptuous to say "your methodology is flawed" (or at least, I hope I'm not), but I do feel I can bring something to the table: a unique look from someone who has experienced both quite a bit of college, and quite a bit of industry, and can help bridge the gap between them.<br />
<br />
I will make an effort to update this fairly often -- it will serve as a good exercise of commitment for me, and hopefully a pleasant distraction from elements of my life, as hobbies are intended to do. Perhaps two or three times a week, that seems like a reasonable goal.<br />
<br />
As for now: hello, Internet. Let's see how this goes.<br />
<br />
<b>Next: <a href="http://cgordini.blogspot.com/2013/05/git-101.html">Git101</a></b>Anonymoushttp://www.blogger.com/profile/14838141359688200161noreply@blogger.com0Ann Arbor, MI, USA42.2808256 -83.74303780000002542.1868316 -83.904399300000023 42.3748196 -83.581676300000026