Stack Overflow profile for Roopesh Shenoy

Being A Better Programmer

One thing that has really helped me in my career as a programmer is continuous training. But it’s also incredibly hard to get out of the pressures of daily work, allocate a block out of personal  time to keep up with latest trends and work on my personal development plan as well as executing on it.

Based on this experience, I am designing a personalized training course/planner which will help you make the best out of your personal-development time.

  • I will help you assess your current software-development skills
  • Will provide specific, personalized recommendations and help you create goals with specific timelines; breaking large six-month goals into smaller, 15-day to 30-day goals
  • Will work with you to help you achieve these goals
  • Repeat

30 days will cost you a nominal price $10 (Rs. 500 if you are in India). Of course, with money-back guarantee!

If you know someone else who might be interested, please help spread the word!

Git-Svn–Working With Multiple But Selected SVN Branches

(Starting from a trunk-only checkout)

Who doesn’t like Git? And who doesn’t have to work with SVN?!

It’s a fairly common practice in a project that I’m working on, for several developers to use git-svn to avoid having to deal with Subversion pain; rest of the team is not ready to move on from SVN, so this is the next best thing we, git-lovers, can do.

Since our work is limited to a particular directory in SVN and there are lots of other things in that same SVN Repo, plus we have a branch per release policy, my repo had only the trunk checked out (+ one of the old release branches). The .git/config file looked something like this –

    repositoryformatversion = 0
    filemode = false
    bare = false
    logallrefupdates = true
    symlinks = false
    ignorecase = true
    hideDotFiles = dotGitOnly
[svn-remote "svn"]
    url = https://<svnurl>/<ourSpecificDirectory>/trunk
    fetch = :refs/remotes/git-svn
[svn-remote "rb-1013"]
    url = https://<svnurl>/<ourSpecificDirectory>/branches/RB-10.13
    fetch = :refs/remotes/rb-1013

The two remotes, actually work like two separate remotes. The “rb-1013” would download all the data from SVN all over again, without worrying about what “git-svn” already had.

Now I had to checkout another branch – and doing it this way would take hours just to download all the data again. I could use the “-r” flag and start from a specific revision, but that too will still download all the artifacts at least – and I just din’t have so much time. It also din’t make sense to me that we need to download all those revisions when the trunk already has the same revisions as the branch uptil the point of branch creation. So, after quite some research, this is what I did.

  • Backed up my git repo (:D)
  • Removed all the rb related references from .git/config (the section for rb-1013 above – just to clean up, din’t really need that branch any more).
  • Changed the git-svn reference in config file from – >

[svn-remote "svn"]
                url = https://<svnurl>/<ourSpecificDirectory>/trunk
                fetch = :refs/remotes/git-svn


[svn-remote "svn"]
        url = https://<svnurl>/<ourSpecificDirectory>
        fetch = trunk:refs/remotes/git-svn
        branches = branches/{RB-10.26}:refs/remotes/branches/*

Basically this is to ensure that the branches are related to the trunk, so same commits are not downloaded again. The refs/remotes/branches/* is a wildcard that creates remotes for each branch that is present. And the high-lighted portion is a comma-separated filter will restrict the branches we download.

Note that since the overall trunk path is still same, it din’t break the existing revisions in master (which pointed to git-svn).

  • git svn fetch

That took a long while with no response – after some more research, I found the .git/svn/metadata file – opening this showed that the file was indeed getting updated, something called branches-maxRev was getting updated – it started searching from revision 0 to see where the branches were created which are not yet fetched locally.

Note that it was *not* downloading all the revisions, it was just searching svn to see when it created the branch (because we don’t have that info locally).

Not fast-enough though – CTRL-C!!

  • Found the second reference below – basically suggesting if we know the revision on which the SVN branch was created, we can speed up the process. No problem right? Well, went to https://<svnbaseurl>/viewvc and used the browser client to see that the RB-10.26 branch was created on revision 29313
  • Re-run the above command but with this revision

    git svn fetch –r 29313:HEAD

    Ok, some things start downloading! I can see RB-10.26 in the refs path in git-svn logs.

  • After everything downloads, verify using “git branch –r”
  • BOOM!

And it works. Took a few minutes to download the diff revs, but now I have a new remote: /branches/RB-10.26. Now I create a new branch in git to point to this reference

  • git checkout –b production26 remotes/branches/RB-10.26
  • and verify

git svn info

Shows the branch instead of trunk – switching to master shows trunk.

The actual git-svn download took few minutes – I’ve never been able to download an SVN branch *ever* so fast, especially when using SVN, so this is a big win for Git, even when working with SVN!



3 Laws For Software Developers

I now propose these three laws for any useful Software Developer –

  1. A Developer may not, through action or inaction, let the user do more work than necessary
  2. The developer may not, let the computer do more work than necessary, as long as it does not conflict with the First Law
  3. A developer may not do more work than necessary, as long as such it does not conflict with the First and the Second Laws.

Note: 2nd and 3rd Laws might interchange in priority depending on scale.

Bonus Law: You will make the world a better place. Break all 3 laws if you have to.

Inspired from Asimov’s 3 laws of robotics.

Religious Practices For Programmers

I was asked recently to come up with a checklist for developers to improve code quality. There are definitely a lot of things on the internet for this, but what the hell, here’s my $0.02 worth.

Apart from years of penance and discipline, here’s a few things that should definitely help. This is written targeting C# developers but a large part of it should apply to all developers.

Key things to keep doing daily –

  • Refactor – the first version of code that “works”, will more or less suck – it will be un-optimized, violate DRY principle, might have unnecessary code, won’t have enough tests, etc. It’s only refactoring that improves things. So consciously keep enough time to refactor the code once it is in working state. This is the single most important thing that people forget to do – it’s crazy even. With this one single rule, your code will improve several folds in terms of quality.
  • Remember that code needs to be read and maintained long after it is written – write code that people will find a delight to read or modify. Try to follow simple things such as –
    • Separation of concerns
    • Automated testing
    • Leveraging type system wherever possible for compile-time guarantees
    • Use better language constructs to keep code as concise as possible. A line of code that doesn’t exist is a line of code that can’t have a bug!
    • Higher and higher levels of abstractions
  • Keep on the lookout for repetitive code, or work that you are doing that did not make you think – for e.g. if you are just copy pasting from another place in the application, it means that there is a strong opportunity to refactor, such that you *don’t need* to copy paste (for e.g. a single method call, maybe with optional parameters for conditional handling).
  • Spend more time on thinking than typing – you are a developer not a typist
  • Have good typing speed though – you want whatever you think of to come on to the screen without breaking your thought process
  • Keep on the lookout for tools that will make life simpler. Resharper for instance, helps you with a lot of silly mistakes.
  • Don’t use the tools as a crutch though. For e.g. you should be able to make out good code from bad just by looking at it.
  • There will be occasional instances where you need to put in a hack – always keep this as the very very last option. And add enough comments to warn others that this is not a pattern to be followed
  • Do not sacrifice long-term maintainability for short-term gains – even if the business asks for it. Simplify things if possible – but don’t compromise quality. (for e.g. we might not make the feature extremely configurable, but still it can follow good coding practices such that it can be added later easily if needed).

Use better languages – F#, Haskell, OCaml, etc. I know you probably want me to tell you how to write better code with C#, but there is a ceiling we *will* hit with certain tools. If you use a kitchen knife to do a surgery, there is only so much you can improve via practices and skill. Just imagine how difficult it would be to do things in C++ and have same kind of quality that we have now with C# code (considering additional overhead in terms of memory management, for e.g.), spending the same effort. Some common C/C++ code bugs (such as memory leaks) just aren’t valid C# code in a lot of cases. There is a similar boost you get with F# and Haskell (where a lot of common bugs in C#, such as run-time null-reference exceptions, are just not valid code in F#/Haskell). That, along with tremendous conciseness, will make code quality better, even for the same developer.

F# Revisited

Sometime last year, I wrote an article demonstrating BDD with C# and F#. The accompanying source codes were hosted on github.

Now I’ve been doing some more functional programming recently and took an opportunity to revisit the F# code I had written then. As it turns out, I had written the first version in Object oriented style in F#. Switching to functional style has made it even more elegant and concise. The difference – 55 lines of code, versus 120 earlier (versus some 200 odd lines of code in C# for the same functionality).

Some of the differences –

  • Using Records instead of Types to encapsulate data (e.g Date)
  • Using base types directly wherever it makes sense (for e.g. int for Year instead of a separate Year type)
  • Using independent functions rather than enclosing them within types

These three go together – functions as first-class citizens means that we no longer need to define types just to house them.

  • Using simpler syntax – for instance, avoiding unnecessary braces
  • Using more powerful language features – using type inference, pattern-matching, higher-order functions a lot more aggressively
  • Some cheating Smile – smaller variable names, fitting more on one line (both, only where it doesn’t affect readability).

I find the new version a lot simpler to understand, with very little distractions such as instantiating objects or trying to access their properties.

The Power Of Functional Languages

I’ve been always intrigued by functional languages, learning bits and pieces of it whenever I got time, but recently I started skilling up on Haskell for building the backend systems for Makkajai.

This example below just emphasizes the power of functional programming vs imperating programming. This is an example from Learn You a Haskell for Greater Good.

“which right triangle that has integers for all sides and all sides equal to or smaller than 10 has a perimeter of 24?”

The solution to finding the answer programmatically in Haskell –

let rightTriangles' = [ (a,b,c) | c <- [1..10], b <- [1..c], a <- [1..b], a^2 + b^2 == c^2, a+b+c == 24]

If you observe carefully, the expression just resembles the problem statement, mathematically defined. There is no logic that needs to be written, no dirty for loops that iterate and check whether the conditions are met or not – and yet haskell is able to produce a result, which in this case is [(6,8,10)].

This is the power of functional programming – most of your code starts resembling your problem statement rather than the logic to arrive at the answer. Not only is it easier to write this code, it is also easier to read and maintain compared to anything you might write in C# or Java (go ahead, try it!).

The only mainstream language that is just as powerful is SQL – which is declarative again instead of imperative. Imagine if you had to describe to the database how to fetch the data, rather than just describe the constraints and let the database do it’s job? It’s surprising that SQL is almost universally accepted but similar concept in application programming has not yet become mainstream.

Kashmir–Heaven On Earth

Got badly sun-burnt, lost my sun-glasses, lost a water bottle, nearly got lost myself a couple of times – and yet this turned out to be my best vacation ever!

I went for a trek recently, visiting the great lakes of Kashmir. 21 trekkers, 5 guides, a team of helpers, tents, sleeping bags and mules to carry them – more than 80 kms in 7 days – all in all a trek to remember! There were at least 3 SLR cameras with semi-professionals operating them, so I did not bother clicking a single photograph. Luckily, others did.

The amazing Vishnusar lake – the water was icy cold and only 3 out of 21 ventured in for a swim; though no one lasted for more than a few minutes.


(courtesy: Varuna Raina)

The pretty Krishnasar lake had a bit less water this time around – the land mass I’m standing on down there is usually submerged. All the good though, cause it made for a good amount of reflection!


(courtesy: Anand Rathi)


Vishnusar again – though now in early morning mist

Vishnusar (anurag)

(courtesy: Anurag Srivatsava)


The magnificient Gadsar lake –

Gadsar (anurag)

(courtesy: Anurag Srivatsava)



(courtesy: Khurram Haque)


Although the photos look great, nothing can describe the actual moments spent in the mountains – cold breeze kissing one’s face, sunlight dancing around the snow and water causing beautiful effects, valleys filled with colourful flowers, sheep and horses grazing lazily on the green grass – these just have to be felt. I can go on and on – a hot cup of tea or a warm camp fire in cold evenings, a refreshing swim in a cold lake after a tiring trek, the step that you cautiously take on a fast-disappearing trail, which if you miss, could be your last – all these just make you live in the moment and forget about past and future just the same.


PS: For a day-by-day account of the entire trek, head-over to Varuna’s travel logs.

Transactional DDL In PostgreSQL

Recently I came across a comparison of Transactional DDL support in various databases, on the postgresql wiki.

For me  this has been an eye-opener – having started my career with Oracle databases, I was brought up thinking that ddl statements are always outside transactions, without questioning why it must be so.

PostgreSQL not only supports transactional DDL, it does so in the most intuitive way – you just wrap these statements in a transaction block and everything can be rolled back if necessary. No auto-commits (like Oracle/MySQL does), no need for specific Isolation levels (like SQL Server) – works quite robustly without any problems.

Just one more reason for me to pick Postgres as the database of choice for my upcoming projects. Then of course, there is that thing about Postgres actually being the most advanced database and open source at the same time.

Learning Kannada–Week 1

Now that I am learning Kannada from scratch, I started searching for effective ways of doing so – here are some of the things I have found useful so far.

Kannada Baruthe – Useful starter website – collection of daily usage words and phrases, along with audio – great for beginners. The content is broken into several categories such as Starters, Greetings, Enquiry, Directions, Relationships, Numbers and more, so that it is easy to learn and get used to the context.

A couple of useful Mobile apps – these are great because you can use them when travelling, when you are generally doing nothing else.

Kannada Kali – A basic app, decent enough to get you started with some basic conversations. There is a cool feature to practice writing basic alphabets, although it would have been nice if they had given the english phonetics of the alphabets in the same place – that’s in a different category altogether (so you’re expected to know the alphabet when you actually practice writing them)

Learn Kannada – this one’s good because it allows you to search through it’s content so it’s easy to find something – extremely handy, especially for quick reference. However it does crash a lot, I think my poor Samsung Galaxy pop can’t handle this search all that well

Of course, nothing beats google translate when it comes to ad-hoc translations on either sides.

An Audacious Project – Languages of India

It is a known fact (at least to my friends and family!) that I am a keen enthusiast of Technology in Learning and also pursuing a venture in the same. Today I also embark upon a new personal project that has the potential to change me as a person – the project is

Learn all 22 Official languages of India (aside from English)

“Wait, What?” you say. “That’s preposterous! You live in Karnataka and can’t even speak Kannada properly yet!”.

Thank you for pointing that out. I am not proud of that fact. But I intend to change it. Starting now, I am going to dedicate a good amount of time to learning basic Kannada vocabulary, and at least pick up some Kannada literature to read. But I don’t want to stop there. I want to try and learn at least the 22 languages, maybe even learn some of the other popular local languages and dialects.

Well enough for me means being able to strike a conversation with the locals, being able to read basic words (at least sign posts but would be nice to be able to read a book), watch local cinema/TV shows without needing a translator/sub-titles and so on.

I already know 3 Indian languages pretty well – Konkani (my mother tongue), Hindi and Marathi (courtesy of my upbringing in Mumbai). I can speak broken Kannada and understand quite a bit of it but can’t read or write it yet. I think that’s half-way into the 4th language.. so 18.5 more to go!

Why do I want to do this? I think it’s a pity I know English really well and can also speak few words of French/Japanese but can’t really say a single word in Tamil, Telugu or Urdu. I would really like to be able to speak to locals in their own languages whenever I visit different places in the country. I also think it’s important for my education related work; localization of education does seem to be a huge untapped opportunity but more so because it’s just so much easier to talk to people and understand their problems once the language barrier is crossed. And a problem-solver I am!

I know this is a life-long project, but I’m going to try and go as fast as I can. At the same time, I think the journey is more important than the destination and hope to learn more than just the languages themselves – local culture, cuisines, traditions, history, etc. I will keep this blog updated about my progress. Wish me luck!! And I will take any help/advice you have to spare, I will definitely need it!