Wednesday, August 14, 2013

Tips on Converting PHP to Perl-CGI

The story today is very similar to yesterday's. Last month I created a new butterfly identification page for my personal website, using PHP and SQLite. By choosing some colors and patterns, newbies (in the butterfly field) can identify any butterflies they may have seen in the field. The page worked well on my desktop but when I uploaded it to Tripod, I realized that they support only Perl and not PHP. So I decided to convert the PHP page to Perl, without having to recode it from scratch. I started by making a copy of the ".php" file and renaming it to ".cgi". Then I made the below changes to convert the PHP code to Perl. Hope these tips would be useful to someone who reads this post.

* Added the Perl shebang line at the top of the page
* Added the standard line to print the content type
* Enclosed all other HTML code within multi-line prints
* Replaced all instances of the PHP "echo" with the Perl "print"
* Replaced the database connection PHP code with the corresponding Perl code
* Replaced the database query PHP code with the corresponding Perl code
* Added a subroutine for getting the CGI parameters, something that PHP automatically did
* Replaced the PHP built-in hash "%POST" to the hash "%form" created by my subroutine
* Replaced the square brackets used for PHP hashes with the curly brackets used in Perl
* Removed the single or double quotes that were used to reference the hash values in PHP
* Replaced the not equal to operator "<>" of PHP with the Perl equivalent "ne"

P.S.: After all that hard work, I found that Tripod does not support the use of DBI.pm. So finally I had to replace the dynamic butterfly identification page with an XML-XSLT page where the readers have to look at a table giving colors and patterns to try and figure out which butterfly they had seen. Well, such is life!

Tuesday, August 13, 2013

Tips on Converting Python-CGI to Perl-CGI

Last month I created a new feedback page for my personal website, using Python. It worked well on my desktop but when I uploaded it to Tripod, I realized that they support only Perl and not Python. So I decided to convert the feedback page to Perl, without having to recode it from scratch. The groundwork for this took some time, as I had to install Active Perl and brush up my Perl knowledge by tweaking a few old Perl-CGI scripts. Today I created a copy of the CGI script and made the below changes to convert it from Python to Perl. Hope these tips would be useful to someone who reads this post.

* Converted the shebang line from #!/Python27/python to #!/Perl/bin/perl
* Added a semi-colon after every line of Python (now Perl) code
* Added a $ sign before every Python (now Perl) scalar variable
* Converted the multi-line prints from Python format (print """) to Perl format (print <<HTML)
* Removed the Python import line for "sys"
* Removed the Python import line for "time". Used Perl's localtime() function to get date and time
* Removed the Python import line for "cgi". Used a downloaded Perl code snippet to get the CGI parameters, choosing  one that takes care of both GET and POST parameters
* Converted the Python "if-elif-else" syntax to the equivalent Perl "if-elsif-else" syntax
* Converted the Python "try-except" code for opening a text file to the normal Perl file opening code, as Perl does not currently support "try-except"
* Converted the single-line file open and read code of Python to the equivalent Perl code
* Converted the Python syntax [filename.write("abc")] for writing to text file to the equivalent Perl syntax [print FILENAME "abc"]
* Replaced Python's text concatenation operator "+" with the equivalent Perl operator "."
* Removed Python's str() function, as Perl automatically takes care of converting variables based on the context
* Ensured use of "eq" operator instead of "==" operator in "if" conditions involving string variables

Tuesday, July 30, 2013

Introduction to SharePoint

A part of our Projects team has been spun off into a SharePoint team, which will adapt and implement a particular CRM template for Indian as well as overseas customers. Since our architect is also a part of this new team, he was able to provide some Web links to help me understand what SharePoint is all about

Microsoft SharePoint is a Web application platform. Simply put, it is a tool to store, to manage and to retrieve information. This information could be text or MS Office documents or other files, like videos. The main strength of SharePoint is that even non-technical users can use it as well as develop applications using it

Initially, SharePoint was used for content management and document management on Intranets but recent versions are much more powerful. You can use Sites to store and manage information, and share it on the Intranet or Internet. You can use Communities to collaborate with colleagues. You can use Content management, including integration with your existing Microsoft Office documents. Search allows you to retrieve information quickly and to find people within your organization. Insights allow you to effectively obtain information stored in a different repository, within a certain useful context. SharePoint enables no-code integration of data, documents and processes to create Composite applications

The most basic element in SharePoint is an Item (calendar entry, task, contact) or a Document (Word, Excel, PDF). Both Items and Documents can have metadata associated with them. They can be arranged using Folders

Items are stored in Lists while Documents are stored in Libraries. A List or Library uses Views to display information. VIews depend on context but the standard view is as rows and columns. Each row represents an Item or Document while its metadata is displayed in the columns. Metadata can be grouped into Content Types

Each List or Library is part of a Site, which is a container for data. Sites can be Team Sites, Project Sites or Internet Web Sites. They can be arranged in hierarchies and collected into Site Collections with a Root Site at the top and common site settings. Each Site has a default page (Homepage), along with various other Pages

Sites are viewed using a web browser. Hence there are Web Applications, which can contain several Sites or Site Collections and are hosted on Web Servers. Multiple SharePoint servers can be grouped into a Sharepoint Farm

In short, SharePoint provides a solution to all your information management needs with a secure and remote access. Andreas Glaser's website provides some good SharePoint tutorials that are very useful for beginners. Note that the content of this post has been adapted from his pages, and the SharePoint Wikipedia page

Friday, April 26, 2013

Introduction to SQLite

Our Product Development team has started the architecture and design process of an app for Android phones, which uses SQLite as a critical part of the app architecture. Since this was a new technology for both our architect and myself, I decided do some reading on the Web so that I could help him in the detailed architecture and design activities

Basically SQLite is an RDBMS that fits into a small file and exists as an integral part of a client application (unlike other RDMBS that exist as separate "database servers"). At the same time, it supports terabyte-sized databases and gigabyte-sized strings and blobs. The SQLite website calls it "a software library that implements a self-contained, serverless, zero-configuration, transactional SQL database engine". It also claims that SQLite transactions "are atomic, consistent, isolated, and durable (ACID) even after system crashes and power failures"

The website also claims that "SQLite is the most widely deployed SQL database engine in the world". The reason is not hard to see, as "SQLite is popular choice for the database engine in cellphones, PDAs, MP3 players, set-top boxes, and other electronic gadgets". Also, since "it requires no configuration and stores information in ordinary disk files, SQLite is a popular choice as the database to back small to medium-sized websites". SQLite is used by major corporations ranging from Adobe to Mozilla and Airbus to Toshiba

Wikipedia tells me that "D. Richard Hipp designed SQLite in the spring of 2000 while working for General Dynamics on contract with the United States Navy" and also that "SQLite implements most of the SQL-92 standard for SQL but it lacks some features. For example it has partial support for triggers, and it can't write to views". SQLite "is weakly typed in some of the same ways that Perl is: one can insert a string into an integer column (although SQLite will try to convert the string to an integer first, if the column's preferred type is integer)"

Writing PHP code for SQLite is simple, as PHP has the SQLite3 library pre-installed but it has to be enabled by uncommenting two lines in the PHP.ini file:
 extension=php_pdo_sqlite.dll
and
 extension=php_sqlite3.dll

Here are some simple lines of code for manipulating an SQLite database using PHP:
<html>
 <head>
  <title>PHP with SQLite</title>
 </head>
 <body>
  <h2>Testing PHP with SQLite</h2>
<?php
#Create or open SQLite database
$db = new SQLite3('mysqlitedb.db');

#Create table if it doesn't already exist
$db->exec('CREATE TABLE foo (bar STRING PRIMARY KEY)');

#Insert row in table or replace existing row
$db->exec("INSERT OR REPLACE INTO foo (bar) VALUES ('This is a test')");

#Read data from table and display it
$result = $db->query('SELECT bar FROM foo');
while ($row = $result->fetchArray()) {
print ("Value of <i>bar</i> in table <i>foo</i>: " . $row["bar"] . "<br>");
}
?>
  <br>
  <a href="index.php">Back</a>
 </body>
</html>

Wednesday, April 17, 2013

What is Software Architecture?

Today the architect in my team asked for my help in documenting the architecture of a new application. Since my experience of software architecture (or what I understood by that term) was so far restricted to participation in design discussions and creation of functional diagrams (System Overview) and technical diagrams (Database Design), I decided to understand what Software Architecture actually means. So I read some articles and blogs on the Web and noted down some of the interesting things they had to say (links embedded in this post, copyrights hereby acknowledged)

According to an article on MSDN, "Software application architecture is the process of defining a structured solution that meets all of the technical and operational requirements, while optimizing common quality attributes such as performance, security, and manageability. It involves a series of decisions based on a wide range of factors, and each of these decisions can have considerable impact on the quality, performance, maintainability, and overall success of the application."

In this definition of software architecture, Microsoft mentions both technical and operational requirements. But some authors, such as Patrick Kalkman in a Software Architecture Design article on CodeProject, aver that software architecture should focus on the non-functional requirements of the stakeholders, instead of being based on purely technical motives

An article on IBM developerWorks defines software architecture as per the IEEE Standard 1471-2000, the IEEE Recommended Practice for Architectural Description of Software-Intensive Systems, commonly  referred to as IEEE 1471. Thus "Architecture is the fundamental organization of a system embodied in its components, their relationships to each other, and to the environment, and the principles guiding its design and evolution." [IEEE 1471]

As per the IBM article, the standard also defines the following terms related to this definition:
  • A system is a collection of components organized to accomplish a specific function or set of functions. The term system encompasses individual applications, systems in the traditional sense, subsystems, systems of systems, product lines, product families, whole enterprises, and other aggregations of interest. A system exists to fulfill one or more missions in its environment. [IEEE 1471]
  • The environment, or context, determines the setting and circumstances of developmental, operational, political, and other influences upon that system. [IEEE 1471]
  • A mission is a use or operation for which a system is intended by one or more stakeholders to meet some set of objectives. [IEEE 1471]
  • A stakeholder is an individual, team, or organization (or classes thereof) with interests in, or concerns relative to, a system. [IEEE 1471]

The IBM article further lists the core characteristics of software architecture as follows:
  • An architecture defines structure
  • An architecture defines behavior
  • An architecture focuses on significant elements
  • An architecture balances stakeholder needs
  • An architecture embodies decisions based on rationale
  • An architecture may conform to an architectural style
  • An architecture is influenced by its environment
  • An architecture influences team structure
  • An architecture is present in every system
  • An architecture has a particular scope

Finally, going back to the first line of this post, you may want to ask if the "architect" in my team is really one, or just a senior software developer who is more involved than other team members in the design process. An article by Simon Brown offers the answer to this question.

Friday, March 15, 2013

5 Must-dos for Recovering Failed Projects - by Shoaib Ahmed

Can't resist re-posting this recent blog post from another Project Manager (with some edits by me), as it more or less reflects my own thoughts on the subject. I have given his name in the title and the link to the original blog post at the bottom of the page. I hope these would be enough by way of acknowledgement

How can one rescue a failed project? What are some of the things that need to happen before you can achieve any improvement?

Acknowledge the failings
When doctors treat patients with substance abuse, the first thing they try to instill in the patients is the acknowledgement that a problem exists. The environment around failed IT projects is exactly the same. It lurches from one problem to another while trying to apply band aids to keep things going. Until parties are willing to admit that problems exist, there is no hope for a resolution. If you keep doing the same things, there is no chance of the result being any different than what it is today. It is very likely that some within the project saw the train wreck coming and may even have voiced it. Seek those out to understand what went wrong.

Divorce emotional investments
One of the basic practices of IT is that software developers do not test their own code. It is not because they are not capable. In fact, they should be more capable than anyone else. However, as human beings we are predisposed to not finding holes in our creation. Same is true for the management of a project. The current status is a reflection of many decisions taken through the course of the project. Many in the management will feel the decisions were correct at the time with the information they had at hand. You need to remove the management decision makers from both the supplier and customer to ensure progress. Leaving them intact will risk required changes not happening

Aim for small wins
In a major failure it may sound counter intuitive to look for small wins, as the problem is a sizeable one. Most adults are reasonably sensible and not easily taken in by bulls**t. They are well aware that a major failure is not going to be resolved quickly. What you need to achieve at all costs is some confidence among your user base that improvements are underway and they can see a light at the end of the tunnel. Bigger your ambition is, more balls are in the air and higher is the chance of it all coming crashing down because of weak foundations. Identify how you are looking to improve, set target of small improvements and communicate honestly.

Throwing more resources is not always the answer
As Fred Brooks Jr has pointed out, the most reliable software is written by one or two man bands. The need for quicker output requires many more developers and as a result introduces complexities several fold. One of the major reasons projects fail is because communication is poor. Having large teams working on the recovery attempt is therefore more risky than the original project. It is a common tendency in projects to throw more resources at a problem. That is just about the worst things you can do in a failed project. With smaller wins, go for smaller teams.

Be prepared to abandon the project
For all the best will in the world, sometimes you will not be able to retrieve failed projects. Cost of retrieval may be higher than doing another project from scratch. It also may not give you the benefits you were after  because of the additional cost. You may find that there is more political will to spend in trying to fix something than re-doing it correctly or abandoning it. Be careful not to be seduced by that. A fully functional  replacement system that does 90% of the requirements may be better than an error prone system designed to deliver all of the requirements.

Link:

Thursday, March 7, 2013

RSS (not the saffron variety)

For much of this week, I've been helping one of my technical teams in publishing dynamic content using a secure RSS feed. So I thought this might be a good time to spread some gyaan (adapted from Web sources) about this technology that is tragically underutilized, at least in India. RSS stands for Rich Site Summary but is more popularly referred to as Really Simple Syndication. It is used to publish (suitable) Web data, along with metadata that describes the data, in a simple XML-based format. This data "feed" can be viewed by various programs including Web browsers and specialized RSS feed readers. Atom is an alternative to RSS for publishing Web feeds

RSS was designed to show selected data, such as news headlines, and provide links to more detailed data, such as news reports. But these links are not crucial if your data is limited and can be provided within the RSS feed itself, as was the case with my team

Every RSS feed contains a mandatory <channel> </channel> element, which encapsulates one or more <item> </item> elements. Each <item> element has three required child elements:
<title> - Defines the title of the item
<link> - Defines the hyperlink to the item
<description> - Describes the item
The description can be used to carry the actual data you want to publish. If your data contains special characters, including XML tags, you can enclose it within a <![CDATA[ ]]> element. Comments can be added using <!-- --> tags, similar to HTML

Your RSS feed file, which should ideally have a .xml extension, can be optionally validated for checking the syntax and then published to your web server. The feed can be updated either manually (by editing the file) or by using a Perl-CGI or PHP program to append new data to the file