Sunday, November 9, 2008

Presentation Tips

I know there are umpteen number of tips out there about how to give presentations, how to prepare for preparations etc. I don't intend to repeat the same stuff here. Instead there is 1 point that is very important, at least in my point of view, and which I haven't seen in any of these lists.

According to me, one should always try to give the presentation from his/her own laptop/desktop. This case comes into the picture when you have a long presentation which will be taken by multiple speakers in parts. The reason giving presentations on another machine can be problematic is that you don't know the locations of most files and folders, how some things work/don't work on that machine, quirks thrown up by that machine on certain user actions etc. It wouldn't be a good experience to look flummoxed in front of your audiences when you can't find a particular window or folder :-)

So, in my opinion, using your own machine is one more stepping stone towards having a successful, smooth presentation

Tuesday, October 28, 2008

Importance of sending Status Reports

In this post I would like to highlight the importance of having a habit of sending regular status reports to your manager and also, if need be, to your immediate team.

I generally send out the report on Friday evenings so that the manager has an idea of what happened during the week, before that week ends. One can also send the report on Monday mornings but then, that would, theoretically at least, mean you are communicating to your manager a tad late. Status reports that I send out contain 3 main sections :
  1. Activities completed this week : What were the things you worked on and managed to complete this week (do not include items that you are still working on and haven't completed, those will go into the next section)
  2. Actions items for next week : What things are you planning to work on and/or complete in the following week
  3. Blocking issues : This is the most important section that you should send out to your manager. Communicate clearly issues that restrict your progress and follow up on them to get them sorted out asap

Given these sections, one can either send out a simple list of activities for each section or have multiple columns under the first 2 sections to be more elaborate. The columns that I include under the first 2 sections are :

  1. Activity : The activity that you completed/are going to complete in the following week
  2. Effort : An indication of the effort needed for completing an activity (if that activity falls under the first section) or an estimate of the effort that will be required(for activities that are part of the second section)
  3. Main challenges/points : Highlight the main technical issues that had to be /will need to be addressed/solved to complete the stated activity

The big question in your mind would be, why should I waste somewhere around half an hour every week in sending this to my manager, who might not even give it anything more than a cursory glance. Well, here are some of the reasons why that half an hour will be a time well invested :

  1. When you sit to jot down the activities, it helps you to get an idea of how much work has been done and allows you to get an understanding of how efficient you are being at what you are doing. You will be able to catch early signs when there is a need for you to pull up your socks and work harder.
  2. Jotting down the action items for the coming week streamlines your work and thinking
  3. Highlighting the blocking items gives you a better chance of getting it resolved sooner so that you can get back on track with your work
  4. If you organise your status reports in a separate folder (like I do using Outlook rules), you can just take a look at the status reports to get an idea of what all work you did during any given time period. This will prove priceless when you sit down at the year end to fill up your performance review.
  5. Finally, and probably most importantly, it's your chance to show off your efficiency and abilities to your manager. Thanks to this post for highlighting this point

I agree that some of these advantages are already inherent in software development methodologies like Scrum, but there are plenty of other reasons, as can be seen from the list above, for you to use regular status reports. Feel free to add more advantages or some of the best practices you follow when it comes to status reports. Also, share your views if and why you think that sending status reports is a waste of time.

Sunday, October 5, 2008

Dataset v/s DataReader

In this post, I will be discussing the behavioral characteristics and the performance differences of the DataSet and the DataReader as well as indicate the suitability of use of these objects in various scenarios.

The Dataset is a "disconnected" data store. What this means is that the DataSet object need not maintain a connection with the database at all times, a connection is needed only at the time of fetching data and updating it. The DataSet can be populated with data using something like this ,

SqlConnection conn=new SqlConnection();
conn.ConnectionString="Data Source=.;Database=TempDB;Integrated Security=true;";
SqlDataAdapter da=new SqlDataAdapter("select * from Temp",conn);
DataSet ds=new DataSet();
da.Fill(ds);
conn.Close();
//Process data in the DataSet ds

As can be seen from the above snippet, once the data has been read into the DataSet, the connection can be closed immediately. The data can still be accessed from within the DataSet.

DataReader, on the other hand, is a "connected" data store which means that there needs to be a connection maintained to the database in order to be able to access the values in the DataReader. The DataReader can be populated with data using something like this ,


SqlConnection conn = new SqlConnection();
conn.ConnectionString = "Data Source=.;Database=TempDB;Integrated Security=true;";
conn.Open();
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = "select * from Temp";
cmd.CommandType = CommandType.Text;
SqlDataReader rdr = cmd.ExecuteReader();
while (rdr.Read())
{
//Process the data read from the DB
}
conn.Close();

Notice here that the connection is closed only after iterating through the entire record set returned by the query.

As can be seen from above, a DataSet, although providing a lot of flexibility in terms of usage scenarios, is memory intensive. Since it is a disconnected data store, it stores all the data read from the database in memory. As can be inferred, this can really slow down the application if the DataSet is populated with millions of rows of data. On the other hand, the DataSet provides "random" access : any record stored in it can be directly accessed and records can be accessed in any order desired. One can also go back and forth through the DataSet records. Another important flexibility with DataSets is that data within it can be modified and the updates will be percolated to the database automatically. Thus, a DataSet is suitable for scenarios in which data update is needed or where random access is needed but should be used cautiously when huge data is being fetched from the database.

As for the DataReader, it is almost an opposite of the DataSet. Since it maintains an open connection to the database at all times, it needn't store data in local memory. Instead records are read in chunks on a need basis. Thus, it proves to be pretty efficient in terms of memory usage. However, this efficiency comes at a cost : records within a DataReader can be traversed only forward and that too, only once. If a record needs to be read a second time, the query needs to be executed again as there is no provision to move backwards through the DataReader. Also the data read through the DataReader is read only. Thus, a DataReader lends itself to scenarios where huge amounts of data are being read without having the need to update them or have random access over that data.

Accessing return value of SPs

When working with databases, it is recommended that all the database queries should be moved to Stored Procedures (hereafter referred to as SP). This makes perfect sense because having all the queries in one place makes it easy to debug in case the database integration is not working as well as makes it less cumbersome to make changes (since it is known where those changes need to be made and the changes need not be duplicated in multiple code files). Given this best practice, it is often a requirement to capture the return value of the SP in order to determine whether the SP execution succeeded or failed.

ADO.NET has the SqlCommand and SqlConnection objects to allow the user to invoke the SP and have access to the results returned by the SP. Specifically, there are 3 methods that can be used to execute a query or an SP on the database :
  1. SqlCommand.ExecuteNonQuery() : Used for queries which don't return any value, i.e. insert, update and delete queries
  2. SqlCommand.ExecuteScalar() : Used for queries which are guaranteed to return a single value
  3. SqlCommand.ExecuteReader() : Used for queries that return multi column and/or multi row result sets

There is 1 important difference in the use of these 3 methods when it comes to accessing return values. It turns out that when using ExecuteScalar() and ExecuteNonQuery(), we can access the return value immediately following this method call whereas, for the ExecuteReader() method this is not the case. If we try to access the value of the parameter object created for the return value, it will have a null value. The return value is set only after we iterate through the entire result set returned by the reader object. The reasoning behind this behaviour can be as follows. If the result set was returned successfully, it means the SP succeeded so there's no point of checking the return value. It only makes sense to check the return value in case there was no result returned. The return value will then enable us to determine whether there was actually no data in the database for the given query or there is a bug which caused incorrect results to be returned.

Do keep this slight variation in the behaviour of the ExecuteReader() the next time you use it.

Sunday, September 21, 2008

Javascript : Creating Textbox watermarks

One of the common requirements when working with web page forms is to have some default text show within a text box and make it disappear when the user enters something in the text box, in other words, create a text box watermark.

Now if you are working with ASP.NET then an easy way to do this is to use the AJAX Control Toolkit's 'TextboxWatermark' control and just link the AJAX control to the text box in which we want the watermark to appear. The AJAX control provides a number of options to control the watermark. However, if you are working with pure HTML pages then, you are stuck with Javascript and need to figure out a way to control the watermarking. I recently wrote some code to do the same and would like to share it in this post.

Assuming you have a html page added to your project, the following steps would enable the watermarking of the text box :

  1. The first step obviously is to define the basic HTML tag which will add a normal text box to your page. Here's a sample code for this :

    <input id="txtUsername" name="txtUsername">

  2. The next step is to define a variable which will store the string that will act as the watermark (Thanks Pratik for sharing this best practice with me). The advantage of creating a variable is that it makes it easy to perform comparisons (which will be mentioned in a later step) and also requires you to change the watermark text in only one place.

    var gcUsernameTbDefaultText='Please enter a username';

  3. The trick to have the watermark appear and disappear is to capture the 'onblur' and 'onfocus' events and manipulate the contents of the text box. The following code snippet shows functions being called for these 2 events.

    <input type="text" id="txtUsername" name="txtUsername" onfocus="clearTextbox('txtUsername',gcUsernameTbDefaultText);" onblur="showDefaultText('txtUsername',gcUsernameTbDefaultText);" />

    As you can see, the functions called when the events occur are passed the id of the text box on which the watermark is needed and also the watermark text, making these functions generic and usable with any text box.

  4. The last and final step is to implement the 2 functions that do the actual manipulation. So here they are :

    • function clearTextbox(objId,text)
      {
      try
      {
      var obj = document.getElementById(objId);
      //Clear the textbox only if the textbox contains the original default value
      if (obj != null && obj.value.toString().toLowerCase() == text.toLowerCase())
      {
      obj.value = "";
      }
      }
      catch (e)
      {
      alert(e.message);
      }
      }

    • function showDefaultText(objId,text)
      {
      try
      {
      var obj = document.getElementById(objId);
      if (obj != null && obj.value == "")
      {
      obj.value = text;
      }
      }
      catch (e)
      {
      alert(e.message);
      }
      }

So there you have it, simple text box watermarking. There are 2 improvements one can do on this implementation :

  1. Dynamically apply styles in order to show the watermark text in gray, with some sort of transparency and have the normal text with normal appearance
  2. This approach won't work with 'password' text boxes since even the watermark will appear as asterisks. This post talks about implementing watermarks for password text boxes

Review : Dropbox

I recently came across a new file sharing service called Dropbox. The service is currently in beta and comes with an optional client side software which makes working with the service really simple.

The service comes with a 2GB space limit for free usage, with plans for providing more storage at different pricing options. The site is really easy to use and pretty fast (they have made good use of AJAX to make as few page refreshes as possible). The single, most prominent, differentiating factor between dropbox and the other tons of file sharing services out there is the desktop app that comes with the service. A folder is created as part of the local file system and works just like any other local folder : you can seamlessly drag and drop files and folders into the dropbox folder and the changes will be synced to their servers and eventually to other users connected to the shared folders. If you have the system tray icon running, you will also get notifications anytime your dropbox folder contents are changed by other users.

This desktop app makes it really easy to work with the service and cuts down on the learning curve. This folder contains 2 sub folders by default : Public and Photos. The public folder is supposed to contain the files and folders that you want anyone to be able to access. For each file in this folder, dropbox generates a link which can be sent out to anyone (Even non-dropbox users) and they would be able to access the files. The Photos folder represents a photo gallery. Each sub folder in here will become an album on the web interface and you can drop any photos within these folders. The service has been built on top of the incredibly useful Amazon's Simple Storage Service (S3).

Here are the pros and cons of the service in my view :

Pros :
  1. The web interface is really fast and easy to use, complimented nicely by the desktop app, making the service extremely user friendly
  2. The site uses SSL for transferring any content over the Internet, making the process safe and secure
  3. Dropbox supports all 3 major OSes : Windows, Mac and Linux
  4. It uses the "Delta sync" technique to sync the files and folders. What this means is that the entire file isn't uploaded every time it has been changed. Only the parts that have been changed are uploaded thereby saving precious bandwidth and reducing syncing times

Cons :

  1. The storage limit of 2GB is pretty limiting, specially if you are planning to store images and audio/video content
  2. It doesn't handle conflicting changes really well currently, taking only the first change and requiring users to manually resolve conflicts

Overall, I found the service really useful and simple to use. Instead of trying to implement too many features, the dropbox team has given importance to simplicity and they have come up with a service which does minimal things, but does them really well. I would definitely recommend people to at least give it a try, at least I am going to keep it installed and will use it whenever I need to share stuff with my friends. It is much easier than going to a website and uploading files from there and sending the resultant links through email.

Let me know your experience with the service and what you liked/disliked about it

Saturday, August 30, 2008

Review : Viewzi

In today's day and age, search is becoming more and more critical to Internet users. As the amount of data on the Internet is growing exponentially, it's becoming very difficult to find exactly what you need since there are so many variations of everything on the net. Add to this the potential revenue to be earned via ads and you have one very lucrative field (Online ad revenues are estimated to be around $80 billion by 2010).

The success of Google and the above mentioned factors have all led to a proliferation of search engines : each one promoting itself as the next potential Google killer. However, it is not very easy to create a scalable search engine which is also good at returning relevant results. One needs a very good indexing algorithm, just having enough infrastructure is not enough. I have seen and tried a number of search engines including (and the now infamous) Cuil which went down on the very first day even after generating a lot of hype before its launch. Another one, which is pretty useful but whose usefulness is currently just limited to Wikipedia, is the semantic search engine Powerset. Semantic means that the search engine is able to "understand" the contents of the web pages and hence, allows users to query in natural language rather than the user having to frame his query in a way that the search engine can understand. Powerset has shown potential and Microsoft's acquisition of the company is a testament to this.

However, the one search engine I've liked the most (amongst the latest ones of course :) ) is Viewzi. It has an extremely appealing visual interface which certainly impressed me the first time I tried it. Instead of the normal hyperlink (famously called the "ten blue link") design, it has a number of different "views" (actually it has the "ten blue link" design as one of the views, for the traditional people I suppose). Each of the views has a number of sources, for example, for the "Simple text view" the sources used are Yahoo and Google. The site has about 15 different views (talk about spoiling the customer for choice). Some of my favourite views are :
  1. Video view : Sources are youtube (has to be), blinkx and veoh. The results appear as 3 horizontal bars across the page and are very intuitive to use
  2. MP3 view : This view uses seeqpod and mp3 realm as its sources. The best thing about this view is that you can play songs directly from the search page. Here is an example search for Shaan
  3. Timeline view : This is a very informative and at the same time attractive way of looking at results. The results are laid out from left to right along a timeline and scrolling at the ends will move the timeline accordingly. One can also look at a glimpse of the article by clicking on one of the results. Just check out this view for Sachin Tendulkar, its amazing

Here are the pros and cons of this tool, in my opinion :

Pros :

  1. The visual attractiveness has to be the USP for this site. I have not seen any other search engine come anywhere close to its ease of use and interactiveness
  2. The results are fairly good for common queries
  3. There are no ads (at least not yet)

Cons :

  1. To be a real threat to Google and be a major contender in the search engine industry, the site needs to add more sources for getting better results
  2. One major limitation of the service currently (and something which they will hopefully fix soon) is an absence of a toolbar. all the other major search engines have one, even new ones like Scour. Toolbars make it really easy for the user to perform searches without disrupting his current page. I think it would be even more useful for viewzi given its multiple views options.

I think that there has to be something disruptive like viewzi or the vertical search engines which can break the near monopoly of Google in the search business and make search a level playing field again. The only concern for me is that Google can just as easily buy such engines for a huge amount and increase its monopoly. Let's hope Microsoft or Yahoo gets to viewzi first and maybe that will narrow the gap in the search market share.