Thursday, January 23, 2014

Aspect Oriented Programming: Separate your logging code from the functionality code and other cool stuff!

A good logging framework is critical for even the most simple of software. You could be writing your code in Java or C++ or Rails and using either a custom home built logger or a standard logging framework like log4j, but you have to be logging.

And if you have been logging, you know how ugly and cumbersome it makes your code look. It would be nice to somehow separate the logging code from the functionality code.

Aspect Oriented Programming

Preface
A concern is anything which impacts the code of a program. Separation of concerns simply means that each piece of code addresses a single concern. This leads to modular programming which is easier to code and more importantly leads to less bugs and the code is easier to change.

When a single piece of code addresses multiple concerns, we call that cross cutting concerns. The best example of a cross cutting concern is logging. The log statements are usually present throughout the code. A change in the logger code can impact any other functionality.

The problem of cross cutting concerns is addressed at various levels by
  • Object Oriented Programming
  • Functional Programming
  • Aspect Oriented Programming
However, Object oriented programming (code is classified into objects) or Functional programming (dividing the code into simple functions) cannot really solve the problem described above (separating the logger code).

Monday, July 9, 2012

Accessing your heroku account from multiple clients

C:\Users\ABC>git clone git@heroku.com:mn.git -o heroku
Cloning into 'mn'...
The authenticity of host 'heroku.com (50.19.85.132)' can't be established.
RSA key fingerprint is 8b:48:5e:67:0e:c9:16:47:32:f2:87:0c:1f:c8:60:ad.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'heroku.com,50.19.85.132' (RSA) to the list of known
hosts.
Permission denied (publickey).
fatal: The remote end hung up unexpectedly

The above error can come when you are doing an operation in your Heroku account from a different machine (other than the one you had used to log-in for the first time). The Heroku log-in generates a public key on the very first log-in attempt. Now, each client that needs to log-in to Heroku, must generate a public key. Since it does not happen automatically on subsequent log-ins, it needs to be done manually for each machine that you intend to use to operate your Heroku account from.

This is how you can generate a public key and add it to your Heroku account
$ ssh-keygen -t rsa 
$ heroku keys:add

The first command would  generate a public key. And, the second one would add it to your account. You can see all the keys added to your Heroku account by:
$ heroku keys
 
More information on the above topic can be found on:
https://devcenter.heroku.com/articles/keys

Hope it helps! :)