proglog

cat /sundar/thoughts | grep -i programming > proglog

Reference Types in Java

Java supports four types of references(Strong, Soft, Weak and Phanthom). We have these reference types to control the memory allocation and de-allocation from our programs. Having only strong references and let the GC manage memory may be simple, but we wont have any control.

  • Strong references:
    Strong references are normal references to the objects which we use every day in our java programs. Objects with strong references are eligible for garbage collection only when we de-reference the objects. This is one of the potential candidate for memory leaks.
1
2
  this.myObject = new MyObject();  // Strong reference creation. 

  • Soft reference
    Garbage collector will collect the soft reference objects only when it needs to (e.g. when its reaching memory limit). All soft references will be reclaimed before an OutofMemory exception is thrown. Soft references are mainly used for caching purpose, say you want to cache large image files.
1
2
  this.softref = new java.lang.ref.SoftReference(obj);

Soft references are relatively stronger than weak reference (another type!). I would call it as lazy reference i.e. We ask GC to delay the garbage collection till the end or necessary.

  • Weak reference
    Weak references are references to the objects which are not gaurenteed to exist when we try to access the object. Garbage collector (GC) will eagerly kill the weakly referenced objects.

    Weak references are Garbage collected even though the memory is abundant. References are cleared before finalizer runs. this.weakref = new java.lang.ref.WeakReference(obj);

  • Phanthom reference
    Phantom reference points to an object which is already dead. This is the least strong referenes of all. Only use of Phanthom reference is to cleanup after finalisation but before reclaiming the memory.

  • If an object cannot be reached by any of the above four reference types then its eligible for garbage collection.

  • References:
    Understanding weak reference
    Why do we need weak reference
    Phanthon refernce

Uses of Git

GIT is a distributed version control created by Linus Torvalds in 2005. After linux it is one of the most influential program written by Linus and it changed the way people think about version control systems. Eventhough originally intended to be used as a source code management system, now git has widespread use other than managing the source code. Git when used with other tools solves various problems and can be used for the following purpose,

  • Database
    Git can be used as a database for your application. If you need a distributed database with versioning then git is a good choice. There are many database implementations built on top of git. Distributed peer to peer database systems are good for occasionally connected clients.
    prophet
    gimd

  • Dropbox clone
    Git can be used as a automated file syncing service. There are few dropbox clones built on top of git already.
    Dropbox clone
    sparkleshare
    dvcs autosync

  • Wiki
    Github and Bitbucket provide a wiki backed by git. Collaboration tools such as wikis can be run by using git.
    git-wiki
    ikiwiki - Perl suggested in the HN comment
    gitit suggested in the HN comment

  • Bug tracking
    Distributed bug tracking is possible with tools such as Ditz and git.
    ditz

  • Simple version control
    Git repositories are very easy to setup (Just use the command “git init” to create a repo), so it can be used as a private version control without any server. It can be used to version control your documents. You can version any folder you want, i use git to manage multiple versions of my documents. We can move around the repo just by moving the folder to some other location.

    It can be used to store org-mode TODO files, notes in a git repository and synchronize between machines (laptop, desktop etc).

    Another use of versioning the /etc folder suggested in reddit

  • Deployment
    Git can be used for deploying your application. A good example is Heroku in which each application is a git repository and you deploy the application just by pushing your changes. In the past ftp was used in similar cases For e.g deploying to a webhosting server.

    You can setup git for deployment in your own webserver as well.
    Using git for deployment

    Another use case is to use git for delivering updates to desktop applications. For e.g. If we have a python based desktop application, we can have each installation as a clone of the central repository and user has to just pull the repository (This can be provided as a menu item as well).

  • Backup tool
    Git can be used as a backup tool. If git is used with a central server we can be assured to restore the data to any past version and there is no single point of failure.

    Common problem with off-site backup is that people do not test their backup. I have seen cases where people did backups and while restoring they discovered that they could not restore their backup!

    Git does not help solve all the backup problems, but it has good use as a backup tool.
    bup suggested in the HN comment
    git as backup tool 1
    git as backup tool 2

  • Websites and Blogs
    We can run static sites, blog with git and static site generators such as jekyll or octopress. It is a hackers way to run a blog.
    Blogging like a hacker
    Octopress - github
    Octopress - Heroku

  • Other uses
    Gittorrent: A a peer to peer protocol for synchronizing git repositories.

Conclusion: Given the variety of ways in which git can be used, I think git is for everyone and not just for developers. It is worth its learning curve. As there are many excellent git hosting services, you can store all your data in the cloud and move to another service if you dont’t like them. There is no problem of vendor lockin. Happy gitting!


Hacker news discussion: http://news.ycombinator.com/item?id=3571040

Hello 2012!!

Its a new home for my blog! For sometime i was thinking about moving to a git-backed blog, and also thinking of implementing my own appengine application with git as backend. I discovered jekyll in Alvaro Videla’s blog. I experimented with Jekyll and liked it.

I have decided to migrate to jekyll for the following reasons:

  • Simplicity of jekyll
  • I own all my blog data! I can move freely to my own server.
  • Use git to keep all programming projects and thoughts organized
  • I love distributed version control :)

Looking back in 2011 i had lot of crushes - Haskell, Scala, Node, jquery mobile, git, python. Out of all i learnt git and python properly. Others i experimented a lot and it was great to learn about bleeding things.

Here we go to future and these are the next steps:

Organizing life in a text:

In 2012 I will be organizing my life in a plain text (Tag line would be “Year of plain text”). I have already taken baby steps for the following.

  • Use git and plain text for blogging. - This blog!
  • Use Emacs org mode for TODO’s and tracking habits. - Private git repository in [bitbucket] (http://bitbucket.org)
  • Keep learning and toys organized in one place. - [Whoopee](https://github.com/devsundar/whoopee)

Personal projects in 2012:

  • Photoman: Automate photo management. Photos are part of life and it captures the moment. Keeping it organized and sharing (getting shared photos) is a pain and many photos get missed. To solve this problem I already have a toy [photoman](https://github.com/devsundar/whoopee/tree/master/toys/photomanager). I will be developing a script which i can rely for all my photmanagement.
  • Brahma: Automating system installation and configuration [Brahma](https://github.com/devsundar/brahma) - Never again i have to spend hours/days to install and configure my desktop.
  • iweb: Customize the web dashboard (https://github.com/devsundar/iweb). I don’t like iGoogle and Netvibes. I wanted a programmer dashboard which i can customize to my tastes, so I am writing my own.
  • dolphin: Python based project which automates communication, tasks. Goal is to have a smart and simple to use system. This is a private project.

Tools to master in 2012:

  • Scala, Haskell, C++, Python
  • HTML5, Javascript, django, jquery
  • git, emacs, Archlinux

My old blog is in the location (devsundar) [http://blog.devsundar.com] and data will be migrated to this blog in the coming weeks.