tag:blogger.com,1999:blog-20610586240889552522024-03-08T12:36:11.594-08:00Corey SunwoldAdventures in CodeCorey Sunwoldhttp://www.blogger.com/profile/03034494611188304767noreply@blogger.comBlogger7125tag:blogger.com,1999:blog-2061058624088955252.post-19255558431818759742013-02-19T21:47:00.000-08:002013-05-11T10:23:49.202-07:00Starting Is Easy<span style="font-family: Verdana, sans-serif;">Do you know what the best part of a project is? </span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">Its the beginning. In the beginning the project is bold, wonderful, exciting, challenging, intellectually stimulating. It's a new thing that barely exists except in your mind. You sit in your chair and you can see the whole complete picture buzzing along doing all the things you want it to do. Think of the users! Their lives will be made so much better by it! People will be impressed at this technological miracle you have birthed. </span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">This fantasy is made possible by a combination of energy and excitement brought on by a change to your status quo and the blind faith that what you make will be as wonderful in reality as it is in your head. </span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span><span style="font-family: Verdana, sans-serif;">You break open your trusty text editor, fire up a new repo, and file new project that idea right into existence. Now your idea has become a little more concrete and now instead of being purely in your head some of it is real and tangible. Sure there's not much there but its something you can point to as proof it is more than just an idea. It even has the name you've given it. </span><br />
<br />
<span style="font-family: Verdana, sans-serif;">Now a feeling of invincibility is sweeping over you. You think to yourself "I'm going to do this the right way. I'm not going to take all of those short cuts in the name of deadlines. I am going to make something that I am proud of."</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">And so you do...</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">Tests are written. Well designed interfaces and models are drawn up on your whiteboard. Levels of abstraction seem so clear and obvious. </span><br />
<br />
<span style="font-family: Verdana, sans-serif;">Now reality begins to creep into your project, and reality is a cruel mistress. She brings with her a cold, bright light that follows her illuminating every dark dirty corner of everything she touches. </span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">A test is failing.</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">Good! The tests are supposed to fail at first. A failing test is like a to-do. It tells you that you need to write some code to make that test pass, no problem. </span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span><span style="font-family: Verdana, sans-serif;">Ten minutes go by and you have made no progress. This is difficult. You think to yourself, "I have good momentum that I don't want to break. I'll come back to this." Your momentum seems unprecedented. You could easily graph the number of tests you need to get this working and see the rate at which you are making the tests pass and you will have this whole project done in record time. A genius you are! Everyone else are such lazy fools to not complete all of their projects at the rate you are finishing.</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span><span style="font-family: Verdana, sans-serif;">The next day comes, starry eyed and barely able to sleep because your mind is racing with thoughts and energy to pour into the project. But that test is still failing. </span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">Progress continues, but it doesn't seem to be at the rate it was yesterday. Yesterday you were invincible. Today suddenly frustration seems close at hand.</span><br />
<br />
<span style="font-family: Verdana, sans-serif;">Come to think of it that interface isn't going to work out like you hoped. </span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">And your models aren't as pure and well thought out as they seemed yesterday. You are violating some clear design principles but it would mean so much extra code to make them conform and work "the right way." If it wasn't enough, Super Awesome Framework you are using to build this with has some abstraction leakage and quirks that force you to write ugly work arounds.</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">Soon you are left questioning why you are working on this. The enthusiasm and intrigue towards the project are sapped. Problems with the interface keep coming up. There are use cases that no one seemed to think through that have the potential to clutter your interface just to get it working. </span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">After awhile, the deadline, real or imposed, is rearing its ugly head. </span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">This function is so simple and obvious, it must work right? Certainly you will save yourself some time by not writing tests against this obviously working code. After all, you're a genius remember? One of those 10x programmers? </span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">Shortcut after shortcut is taken. Ideals are traded for pragmatism. Technical debt is accrued and you are left wondering just how proud you really are of this creation. Is this something you want to point to and have people remember you by? Would you forever engrave your name into this? </span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">As reality takes its toll on the project, the weight and burden of the project on you personally begins to grow. It will cause you to constantly reevaluate what you are doing and how you are spending your time. Is it really worth it? Is it really worth all the time and energy you are putting into it? If you put it off for a week will it still be as important and worth a continued time investment?</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<br />
<span style="font-family: Verdana, sans-serif;">Will it ever be complete? </span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span><span style="font-family: Verdana, sans-serif;">The stakes of the project have the greatest impact on whether or not it will. If you are doing this for a business that is counting on increased customer satisfaction and/or improved revenue, that business will ensure that one way or another this project will be completed no matter how late it is. </span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span><span style="font-family: Verdana, sans-serif;">For personal projects it may never get this far. Was this an interesting academic exercise you wanted to show off on Github? Was this something you were trying to make for your own personal use, or were you making it with the intent that someone else could directly benefit? Is this something that you know quite well will most likely never see the face of a real user?</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">Of course everyone says to just start. Starting is the hard part right? Once you start the hard part is over isn't it? Not so Kimosabe.</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">Starting a project is easy. Starting just means showing up and taking one step. Finishing means taking thousands of steps, mile after mile, pounding the pavement until your feet are blistered, your body aches, and sweat drips from every pore in your skin. Starting is easy. Finishing can be the most difficult thing you've ever done.</span>Corey Sunwoldhttp://www.blogger.com/profile/03034494611188304767noreply@blogger.com0tag:blogger.com,1999:blog-2061058624088955252.post-51668182710808836162013-02-16T22:21:00.000-08:002013-03-10T18:35:14.428-07:00My Productivity Advice<!--[if gte mso 9]><xml>
<o:OfficeDocumentSettings>
<o:AllowPNG/>
</o:OfficeDocumentSettings>
</xml><![endif]-->
<!--[if gte mso 9]><xml>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<w:TrackMoves/>
<w:TrackFormatting/>
<w:PunctuationKerning/>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:DoNotPromoteQF/>
<w:LidThemeOther>EN-US</w:LidThemeOther>
<w:LidThemeAsian>JA</w:LidThemeAsian>
<w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript>
<w:Compatibility>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
<w:SplitPgBreakAndParaMark/>
<w:EnableOpenTypeKerning/>
<w:DontFlipMirrorIndents/>
<w:OverrideTableStyleHps/>
<w:UseFELayout/>
</w:Compatibility>
<m:mathPr>
<m:mathFont m:val="Cambria Math"/>
<m:brkBin m:val="before"/>
<m:brkBinSub m:val="--"/>
<m:smallFrac m:val="off"/>
<m:dispDef/>
<m:lMargin m:val="0"/>
<m:rMargin m:val="0"/>
<m:defJc m:val="centerGroup"/>
<m:wrapIndent m:val="1440"/>
<m:intLim m:val="subSup"/>
<m:naryLim m:val="undOvr"/>
</m:mathPr></w:WordDocument>
</xml><![endif]--><!--[if gte mso 9]><xml>
<w:LatentStyles DefLockedState="false" DefUnhideWhenUsed="true"
DefSemiHidden="true" DefQFormat="false" DefPriority="99"
LatentStyleCount="276">
<w:LsdException Locked="false" Priority="0" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Normal"/>
<w:LsdException Locked="false" Priority="9" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="heading 1"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 2"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 3"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 4"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 5"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 6"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 7"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 8"/>
<w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 9"/>
<w:LsdException Locked="false" Priority="39" Name="toc 1"/>
<w:LsdException Locked="false" Priority="39" Name="toc 2"/>
<w:LsdException Locked="false" Priority="39" Name="toc 3"/>
<w:LsdException Locked="false" Priority="39" Name="toc 4"/>
<w:LsdException Locked="false" Priority="39" Name="toc 5"/>
<w:LsdException Locked="false" Priority="39" Name="toc 6"/>
<w:LsdException Locked="false" Priority="39" Name="toc 7"/>
<w:LsdException Locked="false" Priority="39" Name="toc 8"/>
<w:LsdException Locked="false" Priority="39" Name="toc 9"/>
<w:LsdException Locked="false" Priority="35" QFormat="true" Name="caption"/>
<w:LsdException Locked="false" Priority="10" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Title"/>
<w:LsdException Locked="false" Priority="1" Name="Default Paragraph Font"/>
<w:LsdException Locked="false" Priority="11" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Subtitle"/>
<w:LsdException Locked="false" Priority="22" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Strong"/>
<w:LsdException Locked="false" Priority="20" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Emphasis"/>
<w:LsdException Locked="false" Priority="59" SemiHidden="false"
UnhideWhenUsed="false" Name="Table Grid"/>
<w:LsdException Locked="false" UnhideWhenUsed="false" Name="Placeholder Text"/>
<w:LsdException Locked="false" Priority="1" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="No Spacing"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 1"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 1"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 1"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 1"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 1"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 1"/>
<w:LsdException Locked="false" UnhideWhenUsed="false" Name="Revision"/>
<w:LsdException Locked="false" Priority="34" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="List Paragraph"/>
<w:LsdException Locked="false" Priority="29" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Quote"/>
<w:LsdException Locked="false" Priority="30" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Intense Quote"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 1"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 1"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 1"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 1"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 1"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 1"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 1"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 1"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 2"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 2"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 2"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 2"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 2"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 2"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 2"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 2"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 2"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 2"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 2"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 2"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 2"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 2"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 3"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 3"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 3"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 3"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 3"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 3"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 3"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 3"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 3"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 3"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 3"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 3"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 3"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 3"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 4"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 4"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 4"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 4"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 4"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 4"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 4"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 4"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 4"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 4"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 4"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 4"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 4"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 4"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 5"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 5"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 5"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 5"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 5"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 5"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 5"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 5"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 5"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 5"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 5"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 5"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 5"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 5"/>
<w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 6"/>
<w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 6"/>
<w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 6"/>
<w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 6"/>
<w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 6"/>
<w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 6"/>
<w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 6"/>
<w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 6"/>
<w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 6"/>
<w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 6"/>
<w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 6"/>
<w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 6"/>
<w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 6"/>
<w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 6"/>
<w:LsdException Locked="false" Priority="19" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Subtle Emphasis"/>
<w:LsdException Locked="false" Priority="21" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Intense Emphasis"/>
<w:LsdException Locked="false" Priority="31" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Subtle Reference"/>
<w:LsdException Locked="false" Priority="32" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Intense Reference"/>
<w:LsdException Locked="false" Priority="33" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Book Title"/>
<w:LsdException Locked="false" Priority="37" Name="Bibliography"/>
<w:LsdException Locked="false" Priority="39" QFormat="true" Name="TOC Heading"/>
</w:LatentStyles>
</xml><![endif]-->
<!--[if gte mso 10]>
<style>
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:"Table Normal";
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-parent:"";
mso-padding-alt:0in 5.4pt 0in 5.4pt;
mso-para-margin:0in;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:12.0pt;
font-family:Cambria;
mso-ascii-font-family:Cambria;
mso-ascii-theme-font:minor-latin;
mso-hansi-font-family:Cambria;
mso-hansi-theme-font:minor-latin;}
</style>
<![endif]-->
<!--StartFragment-->
<br />
<div class="MsoNormal">
<span style="font-family: Verdana, sans-serif;">Computers might
very well be both a blessing and curse to our society. The Internet has
improved communication thousands of times over and with continuous improvements
in speed and design it seems to be improving exponentially.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: Verdana, sans-serif;">That is for some
definition of improving. As a software engineer working with largely
network-based systems, I am right at the forefront for all of this. My day job
consists of building faster and more innovative ways to make you, the lowly
consumer, buy more stuff you don’t need.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: Verdana, sans-serif;">But since
something has to put food on the table, and I actually do enjoy it, I find
myself in front of a computer far more than eight hours a day typing, reading,
scrolling, and reading some more. I always have at least one web browser open,
ten chat windows, a code editor of some kind, and a terminal window. For all of
us desk jockeys toiling away at our networked computer screens, the siren’s
song of information is never more than a click away.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: Verdana, sans-serif;">Have you ever
thought about why you keep finding yourself wanting to check Facebook? Or why
you know you shouldn’t but you find clever ways to rationalize reading the
latest tweets in your feed? <a href="http://www.ft.com/cms/s/0/27514afc-5444-11e2-9d25-00144feab49a.html#axzz2L8LTXwHI" target="_blank">It’s all about dopamine</a>.
Whenever you go to check for some new information whether it be on Reddit,
Facebook, Twitter, Hacker News, or any of those other ugly time sucks your
brain releases a hit of dopamine as soon as you read something new. This is not
unlike chemically what <a href="http://www.macalester.edu/psychology/whathap/UBNRP/Dopamine/cocaine.html" target="_blank">happens in your brain when you take a hit of cocaine</a>.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: Verdana, sans-serif;">As you check more
of this information over and over you begin to crave more and more. It becomes
harder to focus on a given task for longer than a few minutes. If go to work,
maybe spend 10-20 minutes catching up news, the front page of Hacker News, and
your Facebook feed, then continue to check back in on these things over and
over throughout the day you may vary well find that you have easily spent up to
half or more of your entire working day on suckling from this fire hose of a
teat. <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: Verdana, sans-serif;">We know its
wrong, but yet we still do it, over and over, day after day. It’s a not
unwarranted joke that when Reddit goes down productivity among white collar
workers improves. <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: Verdana, sans-serif;">I’m here to say
there is a better way. I’m here to inform you life does not have to be like
this. I’m here to tell you that you can make a measurable improvement to your
happiness and quality of life by tackling this wretched demon. <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: Verdana, sans-serif;">Thankfully, the
alcoholics from before our time have given us some tips to rid ourselves of
this beast.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: Verdana, sans-serif;">The first step is
to admit you have a problem. I know I do. I am weak and powerless in front of
these rationalized dopamine dealing drug peddlers. <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: Verdana, sans-serif;">The second step
is to quit cold turkey. At this point you are probably skeptical of me. I was
you at one point. I understand your apprehension towards this idea. I challenge
you to try this just for two weeks. At the end of those two weeks you can go
about your business gorging on a backlog of tweets, likes, updates, and posts. <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: Verdana, sans-serif;">But before we go
further I’ll tackle some of your skepticism head on.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: Verdana, sans-serif;">But the Pomodoro
technique….<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Verdana, sans-serif;">No. This is not
well suited to tackling this problem. This is best suited for the manager
facing a barrage of emails, phone calls, and face to face interruptions that
prevent him or her from doing meaningful work in the day. Do not use the
Pomodoro technique as a rationalization to allow “just a little hit.”<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: Verdana, sans-serif;">I’ll just limit
myself to only check these things once or twice a day.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Verdana, sans-serif;">No you wont. You
must admit you are weak. Checking at all will do to your mind what Buddhists
describe as “stirring up the muddy water.” You need to let the dirt and debris
in your mind settle, and taking in any of this pointless information is going
to leave you just as bad and unfocused as when you were wasting half your day
doing it. Plus, from personal experience, you will relapse.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: Verdana, sans-serif;">But I will miss
out on all kinds of important information.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Verdana, sans-serif;">Doubtful. In
todays super connected day and age if you live in a city of any size and talk
to at least one person a day you will most likely be unable to miss current
world events. Someone will tell you about it, you will catch a glimpse of
something on a TV on in a restaurant, you will see the headline on a newspaper
as you pass by. All other information is just noise.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: Verdana, sans-serif;">I’ll assume at
this point you have given up your rationalization of the issue and have given
in to the idea that quitting cold turkey is the only way. I will now give you a
step-by-step process to help.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<div class="MsoListParagraphCxSpFirst" style="mso-list: l0 level1 lfo1; text-indent: -.25in;">
</div>
<ol>
<li><span style="font-family: Verdana, sans-serif; text-indent: -0.25in;">Turn off notifications on your phone for
all possible apps. Email, Facebook, Twitter, Foursquare, Farmville, all of it
goes. My only exception to this is that during my on-call shift I do
temporarily turn on work email notifications. Otherwise, no exceptions. While
you are at it, just uninstall everything except e-mail. People who matter will
call or text you. People who don’t matter will Facebook message you.</span></li>
<li><span style="font-family: Verdana, sans-serif; text-indent: -0.25in;">Turn off your TV. In fact, cancel your
cable subscription right now. Even if you take nothing else away from this blog
post cut the cord and don’t look back.</span></li>
<li><span style="font-family: Verdana, sans-serif;"><span style="text-indent: -0.25in;"><span style="font-size: 7pt;"> </span></span><span style="text-indent: -0.25in;">Limit your email. I recommend only
checking twice a day at most. Email is a necessary evil because it is so
ingrained in our day-to-day communication. The best you can do is keep Outlook,
iMail, or Gmail closed except for dedicated times during the day. While you are
at it, spend this time really reading what people are sending you instead of
just skimming it, and take more time to write thoughtful messages when you have
a need to respond to someone.</span></span></li>
<li><span style="font-family: Verdana, sans-serif; text-indent: -0.25in;">You will find yourself with huge amounts
of time you don’t know what to do with. Previously you would get bored for a
second and use that moment to check your email, or twitter, or whatever. You
will need a replacement activity or you will relapse.</span></li>
</ol>
<!--[if !supportLists]--><span style="font-family: Verdana, sans-serif;"><br /></span>
<br />
<div class="MsoListParagraphCxSpMiddle" style="margin-left: 1.0in; mso-add-space: auto; mso-list: l0 level2 lfo1; text-indent: -.25in;">
<!--[if !supportLists]--><span style="font-family: Verdana, sans-serif;"><span style="mso-bidi-font-family: "Helvetica Neue"; mso-fareast-font-family: "Helvetica Neue";">a.<span style="font-size: 7pt;"> </span></span><!--[endif]-->I too am a smartphone user, and I highly
recommend downloading the Amazon Kindle app, and putting together a reading
list of books. Anytime you find yourself with a few spare minutes you would
otherwise check the latest Reddit, read a few pages out of your current book.<o:p></o:p></span></div>
<div class="MsoListParagraphCxSpMiddle" style="margin-left: 1.0in; mso-add-space: auto; mso-list: l0 level2 lfo1; text-indent: -.25in;">
<!--[if !supportLists]--><span style="font-family: Verdana, sans-serif;"><span style="mso-bidi-font-family: "Helvetica Neue"; mso-fareast-font-family: "Helvetica Neue";">b.<span style="font-size: 7pt;"> </span></span><!--[endif]-->Take up meditation. I will leave this as
optional, but I highly recommend it. There is no real wrong way to do it, the
simplest is to sit somewhere comfortable, close your eyes, and focus on your
breathing. For beginners, its recommended that you count on the inhale of every
breathe from one to ten and restart at one any time you notice your mind
drifting onto something else. Eventually you start to embrace any moment of
silence because it gives you an opportunity to practice meditation however
briefly and stay more in the moment.<o:p></o:p></span></div>
<div class="MsoListParagraphCxSpMiddle" style="margin-left: 1.0in; mso-add-space: auto; mso-list: l0 level2 lfo1; text-indent: -.25in;">
<!--[if !supportLists]--><span style="font-family: Verdana, sans-serif;"><span style="mso-bidi-font-family: "Helvetica Neue"; mso-fareast-font-family: "Helvetica Neue";">c.<span style="font-size: 7pt;"> </span></span><!--[endif]-->Spend time with people. Talk to them in
person. Be they friends, family, coworkers, or strangers on the street. Real people
are way more interesting than self satisfied strangers online.<o:p></o:p></span></div>
<div class="MsoListParagraphCxSpMiddle" style="margin-left: 1.0in; mso-add-space: auto; mso-list: l0 level2 lfo1; text-indent: -.25in;">
<!--[if !supportLists]--><span style="font-family: Verdana, sans-serif;"><span style="mso-bidi-font-family: "Helvetica Neue"; mso-fareast-font-family: "Helvetica Neue";">d.<span style="font-size: 7pt;"> </span></span><!--[endif]-->At work, if you find yourself with small
periods of time where you don’t know what else to do and would otherwise check
out the latest unprofitablestartup.io on Hacker News, take initiative and think
for a second why you are in this state. Why do you not know what to do next?
Are you blocked by someone else? Go find them and figure out what needs to be
done to get them moving. Do you not have anything to work on? Check with your
manager. Is your manager or not around or do you not have one? Work on that
thing you talked about staying late and fixing a few weeks ago.<o:p></o:p></span></div>
<div class="MsoListParagraphCxSpMiddle" style="margin-left: 1.0in; mso-add-space: auto; mso-list: l0 level2 lfo1; text-indent: -.25in;">
<!--[if !supportLists]--><span style="font-family: Verdana, sans-serif;"><span style="mso-bidi-font-family: "Helvetica Neue"; mso-fareast-font-family: "Helvetica Neue";">e.<span style="font-size: 7pt;"> </span></span><!--[endif]-->For longer periods of time outside work,
filling this time hole becomes more challenging. Much like you have a list of
books you are reading, create a list of things you want to work on. This can be
as small and simple as a household chore you have put off, or it may be
learning a new language, writing a book, or writing a blog post about how much
better your life is now that you rid yourselves of those evil time suck
websites.<o:p></o:p></span></div>
<div class="MsoListParagraphCxSpLast">
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: Verdana, sans-serif;">After your two
weeks are up, take five minutes and reflect on how they have gone for you and
your state of mind. Have you been more productive at work? Have you done things
you don’t normally do? Have you finally gotten around to doing something you
have been putting off for a long time? At this point you should make a decision
whether or not to continue your self imposed exile from the online world or
return to your procrastinating ways. <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .25in;">
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: Verdana, sans-serif;">Here is my dirty
little secret. I’m not perfect. For the last five months I’ve been alternating
periods on and off the grid. I generally spend about three weeks off, than one
to three weeks on. Mostly this is just because I am weak and there is always
something that comes up that sucks me back in. Honestly I do find that during
my period of time offline I am happier, I am more productive, and my life is
generally improved. Eventually I hope to have the willpower to stay in my cold
turkey state indefinitely, but like an arctangent approaching an asymptote I
may forever more forward without ever fully reaching my goal. Better to try and
fail than to not try at all.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<!--EndFragment--><br />Corey Sunwoldhttp://www.blogger.com/profile/03034494611188304767noreply@blogger.com0tag:blogger.com,1999:blog-2061058624088955252.post-87707676324612414192011-07-22T21:00:00.000-07:002011-07-22T21:00:01.321-07:00Frustrations With Data Access on Android + Intro to OrmLiteWorking in the .Net world during the day and doing some Android development in my spare time has a tendency to bias my opinion against Java. Don't get me wrong, I'll take Java over C/C++/Objective-C any day, but the lack of lambdas and delegates can get frustrating when you are spoiled by .Net's recent trend towards functional programming. This really becomes noticeable at the data access layer of Android applications where the API's for interacting with the onboard SQLite database can best be described as adequate.<br />
<div><br />
</div><div>Thankfully API problems, unlike core system architecture problems, are easily overcome by open source software and your fellow developers experiencing the same problems as you. </div><div><br />
</div><div>After having just about enough inline SQL to drive me crazy I decided to investigate what Object Relational Mappers (ORM) are available for the Android OS. Since Android is based on its own implementation of the Java Virtual Machine there are a lot of Java applicable tools out there. </div><div><br />
</div><div>The first and most popular you may run across when looking around is Hibernate. Quite possibly one of the older and more popular open source ORM's available, it was originally built for larger Java applications than a simple Android app. </div><div><br />
</div><div>Another common one you will find is OrmLite. OrmLite is designed to be much more lightweight and smaller scale than Hibernate. This means that it does sacrifice some of the power that Hibernate has, but instead has simplicity and very small Jar files to add to your project.</div><div><br />
</div><div>Because of this I have arbitrarily started exploring OrmLite as my choice for Android development. Later on I may decide to go with Hibernate, but for now its OrmLite. </div><div><br />
</div><div>So lets say you have run into this same problem and have decided that you too are sick of endless Cursor manipulation and are ready to spend more time writing Android apps and less time praying that the <a href="http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html#rawQuery(java.lang.String, java.lang.String[])">rawQuery </a>statement you just wrote is valid SQL syntax.</div><div><ol><li>The first thing you need to do is add the Jar's to your project. Go to the <a href="http://ormlite.com/">OrmLite website</a> and download the ormlite-core and ormlite-android jar files. </li>
<li>Add these to your project. Assuming you are using Eclipse, right click on the project name and choose Properties. Then under Java Build Path->Libraries choose Add External JARs... and select the two Jar's that you just downloaded.</li>
<li>First you want to create the model class that you are going to be working with. OrmLite relies on Annotations to make sense of your class. Use the <a href="http://ormlite.com/javadoc/ormlite-core/com/j256/ormlite/table/DatabaseTable.html">@DatabaseTable</a> annotation to mark your class as a table, and the <a href="http://ormlite.com/javadoc/ormlite-core/com/j256/ormlite/field/DatabaseField.html">@DatabaseField</a> annotations to mark your properties as fields. Here is an example of a super simple data class. In it you can see that I set the id field to be the primary key for the table:<br />
<br />
<pre class="java" name="code">import com.j256.ormlite.table.DatabaseTable;
import com.j256.ormlite.field.DatabaseField;
@DatabaseTable(tableName="data")
public class Data {
@DatabaseField(id = true)
private long id;
@DatabaseField
private String value;
public Data() {
}
public Data(long id, String value) {
this.id = id;
this.value = value;
}
public long getId() {
return this.id;
}
public String getValue() {
return this.value;
}
}
</pre></li>
<li>Now you need to create your database helper class with the verbosely named <a href="http://ormlite.com/javadoc/ormlite-android/com/j256/ormlite/android/apptools/OrmLiteSqliteOpenHelper.html">OrmLiteSqliteOpenHelper</a>. If you have created <a href="http://developer.android.com/reference/android/database/sqlite/SQLiteOpenHelper.html">SqliteOpenHelper </a>classes before, this should feel very similar. Setup your constructor and override the onCreate and onUpgrade methods as you would a normal SqliteOpenHelper. One important note is that OrmLite relies on <a href="http://java.sun.com/blueprints/corej2eepatterns/Patterns/DataAccessObject.html">Data Access Objects</a> to act as an intermediary layer on top of your database. This is what abstracts away the details you didn't want to deal with when you decided to go the ORM route. Because of this, it is recommended to give yourself a public method that returns yourself a <a href="http://ormlite.com/javadoc/ormlite-core/com/j256/ormlite/dao/Dao.html">Dao </a>object specific to the type you are working with. The Dao is a generic class, where the first type is the type of the model you want to work with and the second type is the type of the property you marked as the id in your model. In my example I used a long for the id so I create a Dao<Data, Long>, but if you hadn't set an id property you should be able to use the Object type. Example class: <br />
<br />
<pre class="java" name="code">import com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper;
import com.j256.ormlite.dao.Dao;
import com.j256.ormlite.support.ConnectionSource;
import com.j256.ormlite.table.TableUtils;
public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
private static final String DATABASE_NAME = "test.db";
private static final int DATABASE_VERSION = 1;
private Dao<data, long=""> mDao;
public DatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
mDao = null;
}
@Override
public void onCreate(SQLiteDatabase db, ConnectionSource connectionSource) {
try {
TableUtils.createTable(connectionSource, Data.class);
} catch(SQLException e) {
Log.e(DatabaseHelper.class.getName(), "Can't create database.");
throw new RuntimeException(e);
}
}
@Override
public void onUpgrade(SQLiteDatabase db, ConnectionSource connectionSource, int oldVersion, int newVersion) {
try {
TableUtils.dropTable(connectionSource, Data.class, true);
onCreate(db, connectionSource);
} catch(SQLException e) {
Log.e(DatabaseHelper.class.getName(), "Can't drop databases.");
throw new RuntimeException(e);
}
}
public Dao<data, long=""> getDataDao() throws SQLException {
if (mDao == null) {
mDao = getDao(Data.class);
}
return mDao;
}
}
</data,></data,></pre></li>
<li>The easiest way to start using your <a href="http://ormlite.com/javadoc/ormlite-android/com/j256/ormlite/android/apptools/OrmLiteSqliteOpenHelper.html">DatabaseHelper </a>from your Activity is to create an <a href="http://ormlite.com/javadoc/ormlite-android/com/j256/ormlite/android/apptools/OrmLiteBaseActivity.html">OrmLiteBaseActivity</a>. This gives you a few added methods to simplify things for you. For example it gives you the getHelper() method that returns an instance of the DatabaseHelper you wanted to work with. Since you went ahead and created a public method to return yourself and instance of the Dao you also now have an easy way to get at a Dao for doing your data manipulation. Example class:<br />
<br />
<pre class="java" name="code">import java.sql.SQLException;
import java.util.List;
import com.j256.ormlite.android.apptools.OrmLiteBaseActivity;
import com.j256.ormlite.dao.Dao;
import android.os.Bundle;
import android.widget.TextView;
public class Main extends OrmLiteBaseActivity<databasehelper> {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
try {
Dao<data, long=""> dao = getHelper().getDataDao();
Data d = new Data(1, "Hello World");
dao.create(d);
} catch (SQLException e) {
e.printStackTrace();
}
try {
Dao<data, long=""> laterDao = getHelper().getDataDao();
List<data> result = laterDao.queryForMatching(new Data(1, "Hello World"));
TextView tv = new TextView(this);
tv.setText(result.get(0).getValue());
setContentView(tv);
} catch (SQLException e) {
e.printStackTrace();
}
}
}
</data></data,></data,></databasehelper></pre></li>
</ol></div>Corey Sunwoldhttp://www.blogger.com/profile/03034494611188304767noreply@blogger.com5tag:blogger.com,1999:blog-2061058624088955252.post-34639815677188551492011-02-05T15:29:00.000-08:002011-02-05T15:33:06.786-08:00'unicode' object has no attribute '_meta'It appears I have run across another annoying problem for which there is a lot of contradicting information. I'm working on a Django project and I ran into this error: 'unicode' object has no attribute '_meta'. What is really important is the context in which I received the error. There are a lot of different possible culprits and an even larger number of possible fixes.<br />
<div><br />
</div><div>The context within I was receiving this error was in a view function that was "supposed" to be returning a list of strings in json. If you have any experience with returning Django queryset results in json you probably immediately think of doing something like this:<br />
<br />
<pre class="python" name="code">#Not what you want!
from django.core import serializers
from django.http import HttpResponse
from myproject.myapp.models import MyModel
def get_my_strings(request):
some_models = MyModel.objects.filter(user=request.user)
my_strings = []
for s in my_strings:
my_strings.append(some_models.some_string)
#error will be thrown
my_strings = serializers.serialize('json', my_strings)
return HttpResponse(my_strings, mimetype='application/json')</pre></div><br />
<div>This is wrong.<br />
<br />
What you actually want is to use the simplejson.dumps function to serialize your data. Here is the correct form:<br />
<br />
<pre class="python" name="code">#Import simplejson instead
from django.utils import simplejson
from django.http import HttpResponse
from myproject.myapp.models import MyModel
def get_my_strings(request):
some_models = MyModel.objects.filter(user=request.user)
my_strings = []
for s in my_strings:
my_strings.append(some_models.some_string)
 #Corrected!
my_strings = simplejson.dumps(my_strings, indent=4)
return HttpResponse(my_strings, mimetype='application/json'
</pre></div>Corey Sunwoldhttp://www.blogger.com/profile/03034494611188304767noreply@blogger.com2tag:blogger.com,1999:blog-2061058624088955252.post-36312599060533113012010-12-14T20:39:00.000-08:002010-12-14T20:39:42.224-08:00Unable to build: Could not find dx.jar file<span class="Apple-style-span" style="font-family: inherit;">I got to update to the latest version of the ADT tonight when I hit the weirdest error out of the blue:</span><br />
<span class="Apple-style-span" style="font-family: inherit;"><br />
</span><br />
<span class="Apple-style-span" style="font-family: inherit;">Unable to build: the file dex.jar was not loaded from the SDK folder</span><br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br />
</span><br />
After way too long of Googling and not coming up with an answer I finally found it on some really obscure mailing list archive site.<br />
<br />
Solution:<br />
Look in the project with the error and delete the default.properties file. That is it. <br />
<br />
Just make sure you have the latest versions of Eclipse and ADT when you do it, and that should be it. Back to Android programming...<br />
<span class="Apple-style-span" style="font-family: Arial, Helvetica, sans-serif;"><br />
</span>Corey Sunwoldhttp://www.blogger.com/profile/03034494611188304767noreply@blogger.com9tag:blogger.com,1999:blog-2061058624088955252.post-22095962242740316362010-02-25T20:28:00.000-08:002010-03-13T20:13:38.980-08:00C# Equivalent to Java's "final"From <a href="http://stackoverflow.com/questions/2339074/c-can-parameters-be-constant">Stackoverflow:</a><br />
<blockquote><b>I'm looking for the C# equivalent of Java's <code>final</code>. Does it exist?</b><br />
Does C# have anything like the following:<br />
<pre class="prettyprint"><code><span class="kwd">public</span><span class="pln"> </span><span class="typ">Foo</span><span class="pun">(</span><span class="kwd">final</span><span class="pln"> </span><span class="kwd">int</span><span class="pln"> bar</span><span class="pun">);</span><span class="pln">
</span></code></pre>In the above example, <code>bar</code> is a read only variable and cannot be changed by <code>Foo()</code>. Is there any way to do this in C#?<br />
For instance, maybe I have a long method that will be working with <code>x</code>, <code>y</code>, and <code>z</code> coordinates of some object (ints). I want to be absolutely certain that the function doesn't alter these values in any way, thereby corrupting the data. Thus, I would like to declare them readonly.</blockquote><br />
To clarify the question a little bit, the poster is wondering whether a C# equivalent to final exists that allows you to prevent the changing of <b>parameter</b> values.<br />
<br />
The Java final keyword has a large number of uses, and C# uses several different keywords to account for several of those uses. For example, to prevent a class from being inherited by a child class, you can use the <a href="http://msdn.microsoft.com/en-us/library/88c54tsw%28VS.71%29.aspx">sealed</a> keyword in C# where you would use final in Java. Or if you had a class level variable, or field that you didn't want the value to change you could use the <a href="http://msdn.microsoft.com/en-us/library/e6w8fe1b%28VS.71%29.aspx">const</a> keyword and say "const int x;" where you would say "final int x" in Java. For a detailed explanation of all the many uses of the Java keyword final, check out this <a href="http://renaud.waldura.com/doc/java/final-keyword.shtml">link.</a><br />
<br />
There is than one use of the final keyword that C# does not have an equivalent for. When you pass a parameter to a method in Java, and you don't want that parameter's value to change <b>within</b> the scope of that method you can set it as final like this:<br />
<br />
<pre name="code" class="java">public Foo(final int bar) {
bar++; //Compiler error on this line
}
</pre><br />
Its important to note that its the value that will not change when you use the final keyword here. If we were to pass a reference to the object, we could call methods on that object that change the internal state of the object, but we couldn't set the reference to be a new object. Example:<br />
<br />
<pre name="code" class="java">public Foo(final MyClass o) {
o.ChangeState(); //Valid
o = new MyClass(); //Compiler error
}
</pre><br />
So where does that leave us in our C# code? Actually it turns out that there really is no strong need for an equivalent in C#. While it would certainly be nice to have the compiler check to make sure you aren't changing the parameter, in practice you really don't need it. If you have run across situations where you really did find a true need for such a feature please let me know.<br />
<br />
So if its not something you really need in C#, and Microsoft found reason to remove it, why has Sun/Oracle kept it in? Anonymous classes. In Java you can create an anonymous class in a method, and if a parameter is marked final that parameter becomes available to the anonymous class. While my Java experience is fairly limited, GUI programming is where I have seen the most examples of it. A good example would be adding an ActionListener to a JButton.<br />
<br />
<pre name="code" class="java">public JButton createButton(final MyClass o) {
JButton button = new JButton();
button.setAction(new ActionListener() {
public void actionPerformed(ActionEvent e) {
button.setText(o.toString());
}
});
}
</pre>In C#, we avoid the need for anonymous classes by using delegates as a reference to a method. That means we can do this:<br />
<br />
<pre name="code" class="csharp">class MyForm extends Form
{
MyClass o = new MyClass();
public void MyForm()
{
var button = createButton();
}
public Button createButton()
{
var button = new Button();
button.Click += button_Click;
}
public void button_Click(object sender, EventArgs e)
{
var button = (Button)sender;
button.Text = o.ToString();
}
}
</pre><br />
In conclusion, there is no equivalent to final parameters in C# but with the help of delegates we are able to avoid needing them where they are used most in Java.Corey Sunwoldhttp://www.blogger.com/profile/03034494611188304767noreply@blogger.com0tag:blogger.com,1999:blog-2061058624088955252.post-14692338613279164292010-02-11T20:49:00.000-08:002010-02-12T00:19:50.278-08:00Polymorphism and Complex ConditionalsI ran into a situation today on an old application I inherited where I thought I might be able to take advantage of some polymorphism to refactor some complex if/else structures. This lead me to the thought "what kind of performance impact would using polymorphism have compared to leaving this large if/else block?"<br />
<br />
After a quick google search I came across this:<br />
<br />
<a href="http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.90.8892&rep=rep1&type=pdf">http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.90.8892&rep=rep1&type=pdf</a><br />
<br />
It's a research paper written by Serge Demeyer at University of Antwerp, written in 2002 where looked into that very same question. I was honestly a little surprised by his results. <br />
<br />
To summarize the paper, he points out that over the years there has been great debate between programmers regarding the handling of conditional logic. On the one hand you have programmers wanting to leave the if/else structure because the time spent on refactoring would be too great and you would have a negative performance impact on the application. On the other hand you have programmers arguing that the code would be easier to read after refactoring, which would save a substantial amount of time on bug fixes and feature addition. While there is a substantial amount of evidence to show that the refactored versions of programs are substantially easier to maintain, there is no conclusive evidence as to whether the program is actually slower.<br />
<br />
For Serge's experiment, he uses a small c++ program against several different compilers. His results surprised me. For the majority of the compilers, the time to process was approximately the same when using polymorphism as switch statements. However, in all but one case the if/else structure was slower, and sometimes substantially slower. <br />
<br />
Serge concludes that with the advances in modern compiler theory, using virtual methods will not negatively impact performance.<br />
<br />
In the future I myself would like to look into this same situation using Java and C# to see what kind of difference refactoring conditionals into polymorphism will have on performance with languages that have just in time compilers and an intermediate language.<br />
<br />
<br />
<br />
tldr; <b>Polymorphism is faster and easier to maintain than conditionals.</b>Corey Sunwoldhttp://www.blogger.com/profile/03034494611188304767noreply@blogger.com4