<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0"><channel><atom:link rel="hub" href="http://tumblr.superfeedr.com/" xmlns:atom="http://www.w3.org/2005/Atom"/><description></description><title>perseverance</title><generator>Tumblr (3.0; @harprits)</generator><link>http://harprits.tumblr.com/</link><item><title>Einstein vs Bohr</title><description>Einstein: God does not play dice&lt;br /&gt;&#13;
Bohr: Einstein, stop telling God what to do</description><link>http://harprits.tumblr.com/post/46757943088</link><guid>http://harprits.tumblr.com/post/46757943088</guid><pubDate>Sun, 31 Mar 2013 22:14:37 +0800</pubDate><category>quantum mechanics</category></item><item><title>"Ah! that feeling of reading first few lines of an old loved book again - it’s like first drops..."</title><description>“Ah! that feeling of reading first few lines of an old loved book again - it’s like first drops of monsoon rain after a long dry summer.”&lt;br/&gt;&lt;br/&gt; - &lt;em&gt;me :-)&lt;/em&gt;</description><link>http://harprits.tumblr.com/post/43151137966</link><guid>http://harprits.tumblr.com/post/43151137966</guid><pubDate>Fri, 15 Feb 2013 23:40:29 +0800</pubDate><category>books</category></item><item><title>Go Getable Code On Github in 7 Easy Steps</title><description>&lt;p&gt;This post is based on &lt;a href="http://code.google.com/p/go-wiki/wiki/GithubCodeLayout"&gt;Github Code Layout&lt;/a&gt; and &lt;a href="http://golang.org/doc/code.html"&gt;How to Write Go Code&lt;/a&gt;. But works from a slightly different angle. I&amp;#8217;ll list down steps to create a new go repo under &lt;strong&gt;your&lt;/strong&gt; own account at github. Also, helps illustrate the use of “go get” command and some concepts about structuring of go code.&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Let&amp;#8217;s start:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;1. Set GOPATH&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Set GOPATH to a directory of your choice that will act as workspace for your go project(s)&lt;br/&gt;&lt;br/&gt;example: &lt;em&gt;export GOPATH=/home/haps/langs/gomy/gows&lt;/em&gt;&lt;br/&gt;&lt;br/&gt;&lt;strong&gt;2. Create Base Path&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;In your GOPATH directory, create directory structure based on your github username as follows:&lt;br/&gt;&lt;br/&gt;cd $GOPATH&lt;br/&gt;mkdir -p src/github.com/&amp;lt;your github username here&amp;gt;&lt;br/&gt;&lt;br/&gt;example: &lt;em&gt;mkdir -p src/github.com/harprit&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;src&lt;/em&gt;&lt;span&gt; is the directory under GOPATH  that holds go code. Other two directories allowed under GOPATH are &lt;/span&gt;&lt;em&gt;bin&lt;/em&gt;&lt;span&gt; and &lt;/span&gt;&lt;em&gt;pkg&lt;/em&gt;&lt;span&gt;&lt;br/&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;github.com/&amp;lt;your github username&amp;gt; &lt;/em&gt;is your &lt;span&gt;“base path” that’ll serve as a unique identifier for your project(s)&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;3. Create Project&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Next under the base path, create the directory that will eventually hold the actual code for your project. I’ll use my new project’s name as gogithub which is same as my repo name on github.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;cd $GOPATH/src/github.com/&amp;lt;your github username here&amp;gt;&lt;br/&gt;mkdir &amp;lt;your project name here&amp;gt;&lt;br/&gt;&lt;br/&gt;example: &lt;br/&gt;&lt;em&gt;cd $GOPATH/src/github.com/harprit&lt;/em&gt;&lt;br/&gt;&lt;em&gt;mkdir gogithub&lt;/em&gt;&lt;br/&gt;&lt;br/&gt;&lt;strong&gt;4. Work on Project&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Next, move to your project directory and wget (or copy paste) uselessd.go from jmcvetta’s github repo. We are using this file as it&amp;#8217;s an example code that in turns depends on other repos like &amp;#8220;code.google.com/p/go.net/websocket&amp;#8221; and &lt;span class="Apple-tab-span"&gt; &lt;/span&gt;&amp;#8220;github.com/jmcvetta/useless&amp;#8221;. As we&amp;#8217;ll see, these dependencies will be automatically taken care of by “go get” command.&lt;br/&gt;&lt;br/&gt;cd &amp;lt;your project name here&amp;gt;&lt;br/&gt;wget &lt;a href="https://raw.github.com/jmcvetta/uselessd/master/uselessd.go"&gt;https://raw.github.com/jmcvetta/uselessd/master/uselessd.go&lt;/a&gt;&lt;br/&gt;&lt;br/&gt;example: &lt;br/&gt;&lt;em&gt;cd gogithub&lt;/em&gt;&lt;br/&gt;&lt;em&gt;wget &lt;a href="https://raw.github.com/jmcvetta/uselessd/master/uselessd.go"&gt;https://raw.github.com/jmcvetta/uselessd/master/uselessd.go&lt;/a&gt;&lt;/em&gt;&lt;br/&gt;&lt;br/&gt;&lt;strong&gt;5. Build and Install Project&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;uselessd.go  is a main file (uses main package) and can be considered a mini application in itself.  That’s it we are done, just need to install this app now.&lt;br/&gt;&lt;br/&gt;From your project folder (gogithub in my case), execute:&lt;br/&gt;&lt;em&gt;go get .&lt;/em&gt;&lt;br/&gt;&lt;br/&gt;Or, from any location, execute: &lt;/p&gt;
&lt;p&gt;&lt;span&gt;go get github.com/&amp;lt;your github username here&amp;gt;/&amp;lt;your project name&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;example: &lt;em&gt;go get github.com/harprit/gogithub&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;(you may use symbolic links to make this a bit convenient)&lt;br/&gt;&lt;br/&gt;This will download all repos used in main file and install the executable under your $GOPATH/bin folder. &lt;br/&gt;&lt;br/&gt;&lt;strong&gt;6.Verify Executable&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Executable can be verified as follows:&lt;br/&gt;&lt;br/&gt;&lt;em&gt;cd $GOPATH/bin&lt;/em&gt;&lt;br/&gt;&lt;em&gt;./gogithub&lt;/em&gt;&lt;br/&gt;&lt;br/&gt;This will start a web server using websockets.On hitting &lt;a href="http://localhost:3000/useless"&gt;http://localhost:3000/useless&lt;/a&gt;, you should get something like “not websocket protocol”.&lt;br/&gt;&lt;br/&gt;&lt;strong&gt;7. Upload Project to Github Repo&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;You can now upload your new go project to github. Please note that it’s your project that needs to be added to github not the entire workspace.&lt;/p&gt;
&lt;p&gt;go to $GOPATH/src/github.com/&amp;lt;your github username here&amp;gt;/&amp;lt;your project name here&amp;gt; and run the usual git commands.&lt;/p&gt;
&lt;p&gt;example: &lt;br/&gt;&lt;em&gt;cd /home/haps/langs/gomy/gows/src/github.com/harprit/gogithub&lt;/em&gt;&lt;br/&gt;&lt;em&gt;git init&lt;/em&gt;&lt;br/&gt;&lt;em&gt;git add uselessd.go&lt;/em&gt;&lt;br/&gt;&lt;em&gt;git commit -m &amp;#8220;first commit&amp;#8221;&lt;/em&gt;&lt;br/&gt;&lt;em&gt;git remote add origin &lt;a href="https://github.com/harprit/gogithub.git"&gt;https://github.com/harprit/gogithub.git&lt;/a&gt;&lt;/em&gt;&lt;br/&gt;&lt;em&gt;git push -u origin master&lt;/em&gt;&lt;br/&gt;&lt;br/&gt;This example code is at &lt;a href="https://github.com/harprit/gogithub"&gt;&lt;a href="https://github.com/harprit/gogithub"&gt;https://github.com/harprit/gogithub&lt;/a&gt;&lt;/a&gt; If you face any difficulty you may get, build and install this example code directly to your $GOPATH using the same go get command as follows:&lt;/p&gt;
&lt;p&gt;&lt;em&gt;go get github.com/harprit/gogithub&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;One last but very important thing&lt;/strong&gt; - when you add more go files in your project - always import paths relative to &lt;span&gt;$GOPATH/src i.e. import should include your base path.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;To understand this fully:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;go get github.com/harprit/gogreeter&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;(run $GOPATH/bin/gogreeter to verify installation)&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Check how the main.go file in this project imports internal greet package using:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;import &amp;#8221;github.com/harprit/gogreeter/greet&amp;#8221;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;and not just import &amp;#8220;greet&amp;#8221;&lt;/p&gt;
&lt;p&gt;This is important as it makes code aware of its repo host (base path) and is thus &amp;#8220;go getable&amp;#8221; i.e it builds, installs and runs seamlessly anywhere without any changes whatsoever.&lt;/p&gt;</description><link>http://harprits.tumblr.com/post/43010916097</link><guid>http://harprits.tumblr.com/post/43010916097</guid><pubDate>Thu, 14 Feb 2013 01:41:00 +0800</pubDate><category>golang</category><category>go</category><category>github</category></item><item><title>"The only article Lady Fortuna has no control over is your behavior. Good luck."</title><description>“The only article Lady Fortuna has no control over is your behavior. Good luck.”&lt;br/&gt;&lt;br/&gt; - &lt;em&gt;Last line in Fooled by Randomness by Nassim Taleb&lt;/em&gt;</description><link>http://harprits.tumblr.com/post/43150836259</link><guid>http://harprits.tumblr.com/post/43150836259</guid><pubDate>Tue, 15 Jan 2013 23:34:00 +0800</pubDate><category>randomness</category><category>Nassim Taleb</category></item><item><title>Square root by Newton’s method in Go</title><description>&lt;p&gt;Doing that famous first exercise from &lt;a href="http://en.wikipedia.org/wiki/Structure_and_Interpretation_of_Computer_Programs"&gt;SICP &lt;/a&gt;in Go:&lt;/p&gt;
&lt;script src="https://gist.github.com/4462542.js" type="text/javascript"&gt;&lt;/script&gt;</description><link>http://harprits.tumblr.com/post/39754124004</link><guid>http://harprits.tumblr.com/post/39754124004</guid><pubDate>Sun, 06 Jan 2013 01:05:00 +0800</pubDate><category>go</category><category>golang</category><category>Newton's Square Root Method</category></item><item><title>Square root by Newton's method in Scala</title><description>&lt;p&gt;&lt;span&gt;Doing that famous first exercise from &lt;/span&gt;&lt;a href="http://en.wikipedia.org/wiki/Structure_and_Interpretation_of_Computer_Programs"&gt;SICP &lt;/a&gt;&lt;span&gt;in Scala:&lt;/span&gt;&lt;/p&gt;
&lt;script src="https://gist.github.com/4462493.js" type="text/javascript"&gt;&lt;/script&gt;</description><link>http://harprits.tumblr.com/post/39751580294</link><guid>http://harprits.tumblr.com/post/39751580294</guid><pubDate>Sun, 06 Jan 2013 00:26:00 +0800</pubDate><category>scala</category><category>Newton's Square Root Method</category></item><item><title>Square root by Newton's method in Clojure</title><description>&lt;p&gt;Doing that famous first exercise from &lt;a href="http://en.wikipedia.org/wiki/Structure_and_Interpretation_of_Computer_Programs"&gt;SICP &lt;/a&gt;in Clojure:&lt;/p&gt;
&lt;script src="https://gist.github.com/4462525.js" type="text/javascript"&gt;&lt;/script&gt;</description><link>http://harprits.tumblr.com/post/39750795442</link><guid>http://harprits.tumblr.com/post/39750795442</guid><pubDate>Sun, 06 Jan 2013 00:14:00 +0800</pubDate><category>clojure</category><category>Newton's Square Root Method</category></item><item><title>Empty interfaces in Go</title><description>&lt;p&gt;Consider that you have to implement a collection in Go. A collection, by definition, must be able to hold any type. Something which Java Collections achieve using Generics (or the Object class before Generics). How do you define such as a generic type in Go? &lt;/p&gt;
&lt;p&gt;Check out the following struct definition of a list element in list.go implementation:&lt;/p&gt;
&lt;script src="https://gist.github.com/2330217.js" type="text/javascript"&gt;&lt;/script&gt;&lt;p&gt;It defines the Value as an empty interface{}. This is interesting - as an interface usually defines a set of methods. Any type that implements those method can be assigned to the interface type. But there&amp;#8217;s is no such restriction here at all - interface{} does not defines any methods for implementation.  This means that it simply can be satisfied by every Go type.&lt;/p&gt;
&lt;p&gt;The other side of coin is that you cannot call any method on such a type, since there is none defined. But this is fine as we are only concerned about collecting such types without worrying about there behavior. Crafty.&lt;/p&gt;</description><link>http://harprits.tumblr.com/post/20658689827</link><guid>http://harprits.tumblr.com/post/20658689827</guid><pubDate>Sun, 08 Apr 2012 01:08:00 +0800</pubDate><category>Go</category><category>golang</category></item><item><title>Java Library readResolve usage</title><description>&lt;p&gt;Haven&amp;#8217;t been using old-style static singletons much nowadays. But the Java Library always keep surprising you with things you may not have noticed before. Saw following small EmptyList implementation in Collections.java. The class makes use of readResolve() to dis-allow any other instance to sneak in after de-serialization.&lt;/p&gt;
&lt;script src="https://gist.github.com/2326276.js" type="text/javascript"&gt;&lt;/script&gt;</description><link>http://harprits.tumblr.com/post/18665008270</link><guid>http://harprits.tumblr.com/post/18665008270</guid><pubDate>Tue, 03 Apr 2012 22:49:00 +0800</pubDate><category>serialization</category><category>singleton</category><category>Java</category></item><item><title>Liskov Substitution Principle</title><description>&lt;p&gt;LSP is about well designed inheritance keeping both in mind: the domain understanding and the usage in code. When you substitute a subclass for it&amp;#8217;s base class its should be for flexibility, reuse etc. There shouldn&amp;#8217;t be any side effects / discrepancies / repercussions. If it doesn&amp;#8217;t feels right dump inheritance and use: Delegation / Aggregation / Composition.&lt;br/&gt;&lt;br/&gt;The good old Rectangle Square example (from &lt;a href="http://stackoverflow.com/questions/56860/what-is-the-liskov-substitution-principle"&gt;here&lt;/a&gt;):&lt;/p&gt;
&lt;div&gt;&lt;em&gt;In mathematics, a Square is a Rectangle. Indeed it is a specialization of a rectangle. The &amp;#8220;is a&amp;#8221; makes you want to model this with inheritance. However if in code you made Square derive from Rectangle, then a Square should be usable anywhere you expect a rectangle. This makes for some strange behavior.&lt;/em&gt;&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;p&gt;&lt;em&gt;Imagine you had SetWidth and SetHeight methods on your Rectangle base class; this seems perfectly logical. However if your Rectangle reference pointed to a Square, then SetWidth and SetHeight doesn&amp;#8217;t make sense because setting one would change the other to match it. In this case Square fails the Liskov Substitution Test with Rectangle and the abstraction of having Square inherit from Rectangle is a bad one.&lt;/em&gt;&lt;/p&gt;</description><link>http://harprits.tumblr.com/post/20651484372</link><guid>http://harprits.tumblr.com/post/20651484372</guid><pubDate>Thu, 29 Mar 2012 16:04:00 +0800</pubDate><category>Liskov Substitution Principle</category></item><item><title>Open Closed Principle</title><description>&lt;p&gt;Template, Strategy, Decorator are some patterns that facilitate OCP. Read &lt;a href="http://c2.com/cgi/wiki?OpenClosedPrinciple"&gt;this&lt;/a&gt; for discussion on the same and why it must not be taken to an extreme:&lt;/p&gt;
&lt;div&gt;&lt;em&gt;&lt;em&gt;This prevents you from introducing new bugs in existing code. If you never change it, you can&amp;#8217;t break it. It also prevents you from fixing existing bugs in existing code, if taken to the&lt;/em&gt;&lt;/em&gt;
&lt;div&gt;&lt;em&gt;&amp;#8230;&lt;/em&gt;&lt;/div&gt;
&lt;div&gt;&lt;em&gt;XP has shown us that there are many classes that can be altered frequently, at low expense, and to the benefit of the overall quality of the program. There is no need for these classes to follow the OCP, indeed adding otherwise unneeded code to do so is probably detrimental. However, those who have developed libraries, component based software, and software frameworks have shown that there is a tremendous value in having some classes that never change. These classes benefit greatly from the OCP.&lt;/em&gt;&lt;/div&gt;
&lt;/div&gt;</description><link>http://harprits.tumblr.com/post/20651483490</link><guid>http://harprits.tumblr.com/post/20651483490</guid><pubDate>Mon, 27 Feb 2012 03:27:00 +0800</pubDate><category>Open Closed Principle</category></item><item><title>Single Responsibility Principle</title><description>&lt;p&gt;&lt;em&gt;Single Responsibility = Single Reason For Change&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;For example, if for a change request we need to modify the class. Then in the next iteration, a change request of only a similar nature/type should demand a change in the class. Different types of change requests do not lead to changes in the same class.&lt;/p&gt;
&lt;p&gt;Type of change requests define SRP conformation/violation. Same class in one applications may be conforming to the SRP but may be violating it in another application. So, it depends on the changes.&lt;/p&gt;</description><link>http://harprits.tumblr.com/post/20651482587</link><guid>http://harprits.tumblr.com/post/20651482587</guid><pubDate>Sat, 21 Jan 2012 01:52:00 +0800</pubDate><category>Single Responsibility Principle</category></item><item><title>This One For ?:</title><description>&lt;p&gt;If else shorthand is one of the few things that makes Java code readable in that clutter of curly braces. Recently discovered there&amp;#8217;s a &lt;a href="http://en.wikipedia.org/wiki/%3F:"&gt;Wikipedia page&lt;/a&gt; for the usage of the same in different languages. Cool.&lt;/p&gt;
&lt;p&gt;Here&amp;#8217;s my go. Ever implemented a nullSafeEquals method in your utility code with a number of if else blocks (nested even) and still stay confused if you got it right or not. Observe the simplicity here:&lt;/p&gt;
&lt;script src="https://gist.github.com/2237404.js" type="text/javascript"&gt;&lt;/script&gt;</description><link>http://harprits.tumblr.com/post/20660109644</link><guid>http://harprits.tumblr.com/post/20660109644</guid><pubDate>Thu, 08 Dec 2011 02:33:00 +0800</pubDate><category>Java</category></item><item><title>Integration Tests</title><description>&lt;p&gt;&lt;ul&gt;&lt;li&gt;unlike unit tests, have more than one responsibility&lt;/li&gt;
&lt;li&gt;span over more than one component / architectural layer / classes&lt;/li&gt;
&lt;li&gt;may use some actual dependencies and may mock others - what exactly you want to test drives this&lt;/li&gt;
&lt;/ul&gt;&lt;/p&gt;</description><link>http://harprits.tumblr.com/post/20651480506</link><guid>http://harprits.tumblr.com/post/20651480506</guid><pubDate>Mon, 28 Nov 2011 19:03:00 +0800</pubDate><category>integration tests</category><category>testing</category></item><item><title>Unit Tests</title><description>&lt;p&gt;Any kind of dependency that is hard to understand / initialize / manipulate should be stubbed/mocked/whatevered using the appropriate techniques so you can focus on what the unit of code is doing, not what its dependencies do.&lt;/p&gt;
&lt;p&gt;Initially, unit tests are viewed as &amp;#8220;design documents&amp;#8221; for the code. But later (when related code is done), each unit test does serves to verify one unique thing about a piece of code.&lt;/p&gt;
&lt;p&gt;Usually, when an acceptance or integration test fails, related unit tests fail as well and are more helpful in pointing out the exact cause of the failure.&lt;/p&gt;</description><link>http://harprits.tumblr.com/post/20651478818</link><guid>http://harprits.tumblr.com/post/20651478818</guid><pubDate>Mon, 21 Nov 2011 17:54:00 +0800</pubDate><category>unit tests</category><category>testing</category></item></channel></rss>
