Tuesday, January 5, 2016

Pitfalls of Object Oriented Programming

As I try to understand Javascript as a language one of the things which I need to unlearn is Object Oriented Programming. With Ecmascript 6 and tools like TypeScript from Microsoft, so far I have managed to write a lot of object oriented programs in Javascript which essentially is a functional language. 
So first thing which I need to do is unlearn OOPS. Here are a few pitfalls of OOPS : 

1) A Class is a collection of Data and Methods which operate on this data. As a programmer trying to learn OOPS this was very unintuitive, but once you start practicing OOPS, it becomes the obvious choice and all the apprehensions like why exactly should I keep my data definitions and  Functions together goes away. Going back to my learning days, I once again find it unintuitive. 

2) The way a function behaves in a class can be totally dependent on the state of the object which can be hidden from the consumer of the class. e.g. I can easily write a class which like 
public class Calci{
    private var toggle = false;
    public int Add(a,b){
        toggle = ! toggle;
        if(toggle) return a + b;
        return a - b;
    }
}
The behavior of method Add totally depends on a the state of the Calci object which is hidden from the consumer. So understanding what a method does in object oriented program can be tricky sometimes. Although this is an advantage when compared to Procedural language where the behavior of the function can be dictated by a global variable which is declared somewhere in a different file. But then I have visibility in the scope and if I try it hard I can figure it out. 

3) No Class Hierarchy is correct : No matter how much thought one gives into create a right class hierarchy. One does end up in a situation where the hierarchy is not correct. This is one of the major reasons for refactoring the code while developing projects. As the code size grows it becomes rather difficult to refactor as the change impacts all the ecosystem. 

4) You get a lot of rings and bells attached with any class which you choose to reuse. e.g. If I derive from a Car class I get the method Drive for free even though I may not want to drive an auto-drive car. 

As one learns javascript one should ensure that we don't fall back on the knowledge we acquired while learning OOPS and try to apply them in this new paradigm. Next up is to figure out what kind of inheritance is possible in javascript, how we can use it, and how it differs from classical inheritance of OOPS.

Wednesday, May 13, 2015

Why Database is not suitable for a Queue

There are many applications which use database as a queue in order to orchestrate a long running business process. While it is enticing and easy to do so here are a few reasons about why the developer should avoid doing it...

1) Work distribution : As the number of messages flowing through the system increases the work distribution has to be managed by using locks or by using a Z axis scaling i.e. partition the message table and let different processes handle it. It becomes difficult to manage the failure cases e.g. if the process responsible to manage a particular partition goes down how do I bring up another process to pick up that partition. This is a problem which can be easily solved by event driven queues with horizontal scaling. 
2) Database loads : As the messages passing through the system increase the load on the database starts increasing. This means that the database needs a scaling which is much more costly then scaling a queue bases solution. 
3) Deleting and archiving the queue related tables is expensive as they are indexed. 
4) Database has to be polled to see the pending work items while an event driven queue can simply call the worker process when a new message pops into the queue. 

So while it may be enticing and easy to use database to orchestrate queue related workflows one should refrain from taking this technical debt as it would be really hard to pay it back in the future...

Abhishek

Tuesday, November 19, 2013

My struggles with a Mac

For the first time in my life I am away from a PC. I recently got a Mac and I have my struggles going on now... To begin with there were a few usability issues like the trackpad tap not working as a click which were simple preferences tweak. Then came the big one 
1) The Eclipse installation on Mac was not picking the proxy from the Safari settings so I had to set them myself. That can be done by downloading the Pac file from the automatic configuration script URL and then setting the right proxy in the Eclipse Network Connection Preferences section.
2) My Lync for Mac is not working for some reason. This still needs to be figured out. I will update this section once I am able to sort that out. 
3) There is no Propose New Time functionality in the Outlook Calendar. (Sad :()
4) The Outlook Calendar in Mac shows 1 hour slot as big as 2 hours in my Outlook Calendar in Windows which I am used to. This can be changed by going to Organize Menu and playing with the Scale. 

There will be more and I will keep updating this blog post for the small tweaks :). 

nJoi!!!
Abhishek

Wednesday, September 25, 2013

Server Side Image Generation from SVG

With SVG gaining so much traction lately many people are using that as a de-facto rendering technology in HTML world. This allows you to create awesome graphs and charts to visualize data using libraries like d3. 

There's one little problem which keeps you awake though and that is the fact that sometimes there are requirements to send the same graphics in and email as a image or a pdf and that becomes impossible because of the fact that there are no headless webkits available on the server side to do the rendering and convert them to image. Faced with this problem I explored a few options. The path I chose is 

1) Use EnvJS as a server side DOM.
2) Using EnvJS create a Batik SVGDOM everytime you encounter a SVG Element. 
3) Use Rhino to host EnvJS (the server is a java server)
4) Use Batik to convert the Batik SVGDOM into an image.


And it works just fine.. 

Happy Coding!!

Abhishek

Thursday, September 13, 2012

ACS With Windows Azure Webrole

I always wanted to make the ACS work in an Azure webrole. Somehow I was not able to put a sample together.

Seems like someone else has done it for us Smile. Check http://social.technet.microsoft.com/wiki/contents/articles/2590.aspx for step by step guide on how would you deploy azure ACS authenticated webrole on Azure.

~Abhishek

Friday, August 24, 2012

Performance Counters in Windows Azure Web Role

I tried adding some performance counters for Windows Azure Web Role in the OnStart method of the WebRole and interestingly it was not getting enabled. The code just executed fine with no results present in the “WADPerformanceCountersTable”.

There are a few things which need to be done correctly to ensure that this works

1) The WebRole code should be running in the elevated context. In order to make sure this happens you should add a tag in ServiceDefinition.csdef file under the WebRole which is trying to add the counter. See screenshot below

image

2) If you are trying to update an existing deployment the new performance counters may not be picked up. To ensure that they are delete the existing deployment and create a new one. It seems that that the performance counters are picked up based on an xml file under the “wad-control-container” blob. This xml file is made for each deployment and for some reason it was not getting updated for my case.

Hope this helps…

¬Abhishek

Tuesday, August 14, 2012

Block Blob Vs. Page Blob

Windows Azure storage services provide ability to store large binary files using Blob storage. So if I have a large binary file which I want to store on Azure I can use the Blob Storage.

But now comes a tricky part. There are 2 types of blob storage available on Azure viz. you can store a large file as a Block Blob or a Page Blob.

The scenarios in which to use Page Vs. Block Blob according to MSDN documentation here is that Block Blobs are to manage the upload of large files in parallel while Page Blobs are good for Random read and write operations on a Blob. This one went right over my head.

What if I have a conflicting scenario e.g. I have a huge VHD file which I want to be uploaded in parallel and once uploaded do random read and write on it as needed. So I am not really sure which one should I use in such a case. I guess I would go for the Page Blob because upload is a one time operation for VHD file and after that my hypervisor will keep modifying the file for the life of the file. So it is more important that the random read and write operations are faster then the upload speed.

The technical difference can be summarized in the below table

Factor

Block Blob

Page Blob

Max Size 200 GB 1 TB
Chunk Size Each Block can be 4 MB Each Page can be 512 Bytes
Write Operation Multiple blocks can be modified and then a Commit Operation commits the modifications in a single go The write operations happens in place and the commit is done then and there rather then waiting for a separate.

So all in all.

Parallel upload == Block Blob

Random Read Write == Page Blob

Hope this helps

¬Abhishek