Friday, 4 January 2013

10 enemies of being a good programmer



FOI...

This article discusses the habits which would need to be avoided if a person wants to become a good programmer.

Introduction and background

The information technology is not a new term now. For a common person, this is the field which guarantees good money and life (in the context of INDIA). People working in this industry are looked up-to and generally considered intelligent than others. 
After working for quite some time in this industry, looks like the above points are coming very close to being a myth.

Definitely this industry has been life changer for many and also big employer, foreign currency grabber but by large it would be interesting to know what’s the reality at ground level.

Many would comment that the quote about intelligence is overrated and this is just another industry with revenues in dollars helping for mammoth turnovers.

The common minimum ingredient of this industry is a programmer (or a developer or coder) who is the one writing the programs which are supposed to make things happen. As in every field of life, there are good programmer and bad programmers. The other hot topic in this industry is whether this industry possesses chunk of good programmer or not. Many wouldn’t agree.

So, what makes a good programmer? This is debatable point and to make things simpler, let’s see this the other way round i.e. discuss the top 10 enemies which can prevent oneself from becoming a good programmer.

Objective

To know about the DONT's if anyone wants to become a good programmer.

Description
Programming world is a confusing world. There have been so many languages, technologies, platforms, infrastructures to choose from which doesn't make life of a programmer easy even though they are supposed to. In the scenario where business needs are outscoring the engineering practices, the programming has become a real complex thing increasingly challenged by time and budget. There has been lot of research into software metric to measure the performance and quality but it still not straightforward to categorize programmers and probably say who is good or bad. Following are list of points which if we can ensure while programming, would definitely result in better code quality, better planning and better professional life. These points are picked up from real incidences which always keep happening with considerable frequency and it is observed that such incidences leads to poor quality, performance and higher costs. These points are not just related to technical skill but rather the attitude, awareness, behavior.

1. Is it computer or my program: When something goes wrong there is a tendency to term that it must be something wrong with computers or something else other than me? It’s funny but it omnipresent statement one hears. Barring few cases, it’s always the program doing something wrong rather than computer. If we take environmental, infrastructural attributes into account while programming we won't end of saying this. This is the biggest enemy.

2. Its working on my PC: This is probably mostly used age old statement and many have encountered it umpteen times. It is hard to believe but it happens all the time that the programs work well on developer’s machine but fail after deployment... Do we program for our own pc or our programs are intended to run only on the developer’s machine? Surely not and this is caused by insufficient programming skills and not enough knowledge of working environments, necessary settings etc.

In most of such cases, mostly the programmer has forgotten to update the deployed environment with some settings/ configurations, some component missing etc. rather than anything else.

3. Finger pointing: I have just changed it but I didn’t cause this error, it must be somebody else who might have worked on the same stuff. This is a statement one would hear all the time and it’s generally the first reaction one would hear when asked about some error or fault. In reality, something is changed and the original functionality is also lost then these statements are made. This is quite intriguing that something is changed and before a change things were working and still the programmers say this. This depicts the lack of ownership as well as understanding and escapist attitude. Given the complexity and difficulty to find the facts, many are encourage saying this.

There is a small remedy to overcome this and which is the practice of performing unit testing and take my word, life would be easy.

4. Skipping the validation of user input: While programming for user interactive applications / programs, one tends to skip the validation of user inputs under the assumption that he has coded for it and it shall work. The minimum check which is like confirming the data entered in GUI doesn’t exceed the data type and lengths defined in the database. No wonder, many of the defects and also the program crashes arises out of lack of such validation.
It is better to always ensure that the data types and lengths on GUI matches with the ones defined in data source and also it handles the common pitfalls which can spell doom for hackers. 

5. Not estimating (or planning) the work or tasks: Most of the programmer (especially junior ones) has urged to jump into coding without estimating the work. Estimation is just not important from planning perspective but it gives an opportunity to revisit the scope as the estimates are bound to scope.

There might couple of tasks challenged by time and/or budget which can be performed well without estimates but not     all. Whatever may the work or tasks if it is estimated, then it ease out planning, controlling and monitoring and also         given an avenue for asking the help before it is too late?

6.   Swallowing the exceptions: Exception handling is still a mystery for many programmers and when he/ she don’t know how to handle the exception or there is lack of good exception handling mechanism, the exceptions are swallowed means not action is taken after the occurrence of such exceptions or errors.
     Today's programming languages offers far more sophisticated mechanism in the form of try-catch-finally. This           swallowing mostly results into application crashes putting programmers into awkward position.
7.   Blindly copying and pasting: In today’s internet era, everything is available on internet and code snippets are not exceptions to this. With super-efficient searches, it is possible to locate code snippet which can do one's job.  
   
Probably it can't be called wrong to copy such code snippets and use but unfortunately the usage is always coincided      by blindly copying or retrofitting which results into partial solutions not taking into account the existing scenario. Also      one has to remember that such code snippets needs more rigorous testing than your native code to make sure that it      is doing what is needed. Another example is copying from code samples or others code which generally skips the understanding curve resulting into inferior quality software and it is also difficult to change such program and   maintain too. So copying and pasting is unavoidable but it would be better to invest some time to understand what it is doing and what is expected to be done and perform this with sound judgment.
8. Not being latest: The technology paradigm is characterized by the continuous changes and improvements. While working hard and long, many programmers are not able to synch them up with such changes and improvements. This may result in inferior solutions or far more time investment than could be justified. Also there are many changes happening on software engineering front where new methodologies like Agile, XP are introduced which can address many pertinent challenges in development life cycle.

9.  Lack of Documentation/ comments/standardization: No denying the fact the programs are written to be executed by computers but they are also written which could be understood by others. Many programmers shy away from writing enough comments or documentation which can help others about why, how and when something is done. Essentially this makes other programmer not attempting to understand and write something which would add to confusion. There are many instances of coding horrors, coding mess, coding chaos which have one thing in common and i.e. lack of documentation and standardization. Essentially the programs shall be human readable.

10. Speed well than accuracy: This is a trap for even the proven programmers. Many programmers think that the programming is 100 ctr races and one has to be lightning fast to win this race and in the process the quality, accuracy is sacrificed. This catapults into more work (many would want this for continuity of their business) which is not good of one looks at cost and time. Accuracy could attain more priority and speed with accuracy could be the motto.  

Summary and Conclusion
This topic is exhaustive and complex to discussed and addressed on one write-up. Still these 10 point are put forth to touch base the perennial challenges in software industry. There may be more apt points and detailed discussions but hope that this write-up could help to bring some really interesting practices to the fore.

Source:http://www.dotnetfunda.com/articles/article2098-10-enemies-of-being-a-good-programmer.aspx

How technology powers supply chain





Supply chain is about managing a network of several interconnected businesses that are involved in the process of delivering the product to the end customer. Throughout this process, flow of information from one stage to another plays a crucial role as it ensures effective decision-making at the planning and execution stages.

When it comes to the flow of information, no other tool or resource can do it as quickly and accurately as technology. This is true when it comes to supply chain as well.

Today, technology in supply chain is much more than just computers. It includes varied aspects, right from factory automation, enhanced communication devices, data recognition equipments to other types of automated hardware and services.

Companies have also started using technologies like advanced versions of speech recognition, digital imaging , radio frequency identification (RFID), real-time location systems (RTLS), bar coding, GPScommunication , Enterprise Resource Planning (ERP), Electronic Data Interchange (EDI), etc to improve their processes.

These IT-enabled infrastructure capabilities not only help organisations achieve higher efficiency, but also reduce cycle time, ensure delivery of goods and services in timely manner and improve overall supply chain agility.

Use of technology in three arenas
Organisations use technology in three broad areas namely transaction processing, supply chain planning and collaboration, and order tracking and delivery coordination. In transaction processing, companies employ technology to increase efficiency of information exchanged regularly between various supply chain partners. Typically, in this area, technology enables easy order processing, sending dispatch advice, tracking delivery status , billing, generating order quotes, etc.

Technology also helps in supply chain planning and collaboration, thereby improving the overall effectiveness of the process. Here, technology is used to share planning-related information like customer feedback, demand forecasting, inventory level, production capacity and other data. This helps in managing waste and inconsistency arising out of unpredictable and logistically demanding markets. According to Mr Prashant Potnis, GM - IT and Systems at Spykar Lifestyle Pvt Ltd, "Statistical capabilities enabled by technology like importing historical sales data, creating statistical forecasts, importing customer forecasts, collaborating with customers, managing and building forecasts, etc. bring accuracy to a company's demand plans."

Lastly, technology is also useful for order tracking and delivery coordination, as it monitors and coordinates individual shipments, ensuring delivery of the product to the consumer without errors.

Employing technology at all these levels no doubt comes at a cost. However, apart from reducing physical work, technology improves the quality of information, expedites information transfer, and increases and smoothly manages the volume of transactions. Yogesh Shroff, Finance & Supply Chain Director at Nivea India Pvt Ltd, agrees. "A combination of process changes and use of advanced technology can help companies gain better returns on marketing and sales investments, reduce cost, strengthen relationships across the value chain and retain customers," he says.

While most companies have employed technology to manage their supply chain today, they have realised that conventional methods have to be pushed beyond their peripheries to sustain in highly competitive environments and fields. If applied correctly, technology holds the potential to turn supply chain into a major differentiating factor for any company.

Calling javascript function from CodeBehind with C#


Javascript works from the client side while server code requires server processing. 
It is not possible to direcly invoke a client event through a server event. However there exists a fairly simple methods to achieve this. I will explain one simple way to do it.

Injecting a javascript code into a label control

This is one of the simplest method to call a javascript function from code behind. You need to do the following:

1.     Create a new website project
2.     Add a label and button control on your Default.aspx page
3.     You body part of the markup should now look something like this: 

<body> 
    <form id="form1" runat="server"> 
    <div> 
        <asp:Label ID="lblJavaScript" runat="server" Text=""></asp:Label> 
        <asp:Button ID="btnShowDialogue" runat="server" Text="Show Dialogue" /> 
    </div> 
    </form> 
</body> 

4.     Add a javascript function to show a message box as shown below: 
<head runat="server"> 
    <title>Calling javascript function from code behind example</title> 
        <script type="text/javascript"> 
            function showDialogue() { 
                alert("this dialogue has been invoked through codebehind."); 
            } 
        </script> 
</head>
5.     Now double-click on the button and add the following code: 
lblJavaScript.Text = "<script type='text/javascript'>showDialogue();</script>";

6.     Run your project and click the Show Dialogue button

A message box will be displayed as shown below: 
screen shot of client side message box

3-Tier Architecture in ASP.NET with C# tutorial


   
In 3 tier programming architecture, the application development is broken into three main parts; these are: Presentation layer(PL), Business Acess Layer(BAL) and Data Access Layer(DAL). These separations ensure independent development of those layers such that a change in one does not affect the other layers. For instance a change in the logic of the DAL layer does not affect the the BAL nor the presentation layer. It also makes testing easier in that a whole layer can be replaced with a stub object.

 For example instead of testing the whole application with an actual connection to database, the DAL can be replaced with a stub DAL for testing purposes. The DAL deals with actual database operations. These operations are inserting, updating, deleting and viewing. The BAL deals with the business logic for a particular operation. The PL has the user controls for interacting with the application.

3-Tier programming architecture also enables re-use of code and provides a better way for multiple developers to work on the same project simultaneously.
  1. Start a new website project
  2. Design you page as shown below,
    3 tier form design
  3. Add sub-folders and class objects within the App_code folder as shown below,
    3 tier classes
  4. Code for the add button is shown below,
    protected void cmdAdd_Click(object sender, EventArgs e)
    {
        CustomerBAL cBal = new CustomerBAL();
        try
        {
            if (cBal.Insert(txtCustomerID.Text, txtFirstName.Text, txtLastName.Text) > 0)
            {
                lblMessageLine.Text = "Record inserted successfully.";
            }
            else
            {
                lblMessageLine.Text = "Record not inserted.";
            }
        }
        catch (Exception ex)
        {
            lblMessageLine.Text = ex.Message;
        }
        finally
        {
            cBal = null;
        }
  5. code for CustomerBAL.cs
    using System;
    using System.Collections.Generic;
    using System.Web;
    ///
    /// Summary description for CustomerBAL
    ///

    public class CustomerBAL
    {
        public CustomerBAL()
        {
            //
            // TODO: Add constructor logic here
            //
        }
        public int Insert(string CustomerID, string FirstName, string LastName)
        {
            CustomerDAL cDal=new CustomerDAL();
            try
            {
                return cDal.Insert(CustomerID, FirstName, LastName);
            }
            catch
            {
                throw;
            }
            finally
            {
                cDal = null;
            }
        }
  6. Code for CustomerDAL.cs
    using System;
    using System.Collections.Generic;
    using System.Web;
    using System.Data.SqlClient;
    using System.Data;

    ///
    /// Summary description for CustomerDAL
    ///

    public class CustomerDAL
    {
        public CustomerDAL()
        {
            //
            // TODO: Add constructor logic here
            //
        }
        public int Insert(string CustomerID, string FirstName, string LastName)    public int Insert(string CustomerID, string FirstName, string LastName)
        {
            //declare SqlConnection and initialize it to the settings in the section of the web.config
            SqlConnection Conn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["dbConnectionString"].ConnectionString);
            //===============================
            //prepare the sql string
            string strSql = "insert into t_Customers(CustomerID,FirstName,LastName) ";
            strSql = strSql + "values(@CustomerID,@FirstName,@LastName)";

            //declare sql command and initalize it
            SqlCommand Command = new SqlCommand(strSql, Conn);

            //set the command type
            Command.CommandType = CommandType.Text;

            try
            {
                //define the command parameters
                Command.Parameters.Add(new SqlParameter("@CustomerID", SqlDbType.VarChar));
                Command.Parameters["@CustomerID"].Direction = ParameterDirection.Input;
                Command.Parameters["@CustomerID"].Size = 20;
                Command.Parameters["@CustomerID"].Value = CustomerID;

                Command.Parameters.Add(new SqlParameter("@FirstName", SqlDbType.VarChar));
                Command.Parameters["@FirstName"].Direction = ParameterDirection.Input;
                Command.Parameters["@FirstName"].Size = 25;
                Command.Parameters["@FirstName"].Value = FirstName;

                Command.Parameters.Add(new SqlParameter("@LastName", SqlDbType.VarChar));
                Command.Parameters["@LastName"].Direction = ParameterDirection.Input;
                Command.Parameters["@LastName"].Size = 25;
                Command.Parameters["@LastName"].Value = LastName;

                //open the database connection
                Conn.Open();
                //execute the command
                return Command.ExecuteNonQuery();
            }
            catch
            {
                throw;
            }
            finally
            {
                Command.Dispose();
                Conn.Dispose();
            }
        }
    }
  7. Set the connection string on the web.config file
  8. Run the project

Sample Text

Sample text