Wednesday, August 26, 2009

Maxing HTML and PHP code

Note: This article was written in 2008, when I was working in small firm. Publishing it again here for newbies.
After working for about one year in website development industry of Pakistan I’ve realized a very serious issue. This may be happening in other countries as well, as I haven’t had worked with international organization, especially professionals.

The problem is maxing presentational logic with business logic. In simple words I would say maxing HTML with server scripting language like php, asp, coldfusion etc.
Here I would appreciate Microsoft professionals who have done tremendous job by developing Asp.net language. The way they have separated asp.net and html code from C# and VB.NET code is fabulous. However I would like to mention that in the beginning-in early versions of ASP.NET-the problem was there. However with the passage of time and introducing newer and more mature versions like ASP.NET 2.0 they have addressed lots of issues.
Before going into the details of problem mentioned above I would also like to comment about some companies who are providing open source solutions for languages like PHP etc. The contribution made by oscommerce (having the above drawback), zencart(I haven’t studied but heard that it is a bit mature shopping cart solution than oscommerce) and joomla(very nice and more mature content management system) to php cannot be ignored.
The most important contribution is made by those who have developed frameworks(MVC’s) like Zend, Symfony, cakePhp, mojave(lacking documentation and community support) etc. One cannot imagine how worthy and brilliant job they have done and how easier they have made work for lazy professionals like me.

Two months back I was introduced to mojavi by our company senior web developer. In the first few days I was exhausted and bored. However after developing a simple login application in mojavi I found it quite helpful. But things didn’t move forward coz of lacking documentation and community support.

I stopped working in mojavi but the virus of working in frameworks sneak in my heart and I started googling different frameworks.

Next few days I studied cakePhp, symfony and then zend, red their documentation, browse their community support sites and forums and also red articles about their differences.

Finally and luckily I selected Zend framework-This was because of small configuration overhead of zend framework than other frameworks.

After working in zend MVC I realized how easier it is to make a web application and how easy it is to extend and maintain existing one.

Now let me discuss the real problem which has made me sick since last few days.

After joining new organization 6 days back I was assigned a project for modification. The project was constructed in oscommerce. Boss was expecting that I would finish some small modification in few hours but I trapped in the middle and was unable to browser where modification needs to be made.

When boss arrived and asked me about the modification I was having no idea what to say and I felt a bit shy at that time. After telling him that I haven’t completed the modification he was a bit shocked and worried because he might be thinking that I was not a right person for the post I had been hired. He took me to his office and asked me about projects I had previously worked on. After showing him my projects he got satisfied but still I could see uncertainty in his eyes.

Why all this happened and why I trapped in the middle will I think clear the problem I have mentioned in the beginning..

As I have already mentioned that project was constructed in oscommerce so those how know or have worked in oscommerce will better understand the way oscommerce has been developed. Although they have separated php code form html up to some extent, however it is not as mature as joomla content management system or model view controller frameworks.

Well, oscommerce was not a big obstacle. The more irritating thing was the way previous programmer had implemented and constructed the pages. After working in office for about 10 hours I managed to complete some modifications but not entire.

When I came home, installed oscommerce and started doing the same modifications it took me minutes to complete them.

So I took some deep breathes and started thinking about whom to be blamed. But after thinking for about two hours I realized that no one could be blamed because client needs their projects soon, so developers only think about the construction not about what will happen in future if he himself or someone else try to extend or modify the project.

Lot of website have been made in similar scenarios and situations.

So as a professional one needs to be very careful while modifying the project.

Although professional developed application based on the client recommendations however I think we professional should think seriously about the future extensions and maintenance and try to make application both client and professional friendly.

Tuesday, August 18, 2009

Installing Ruby on rails in four easy steps

Ruby on rail is used for web application development.
Ruby is object oriented language.
Rail is framework that uses Ruby language to develop robust and scalable web application.
Ruby on rail installation is simple, newbie however find it a bit tricky first.
Here in this article I am going to tell you how can Ruby on rails be installed in windows XP.

1. Download latest version of Ruby from http://rubyforge.org/projects/rubyinstaller/
2. after the installation double click the exe file. this will start setup wizard which will guide you to the end.
3. once Ruby is installed next step is to set path
=>start => control panel => system =>advance => environment versiables
click path and press edit.
add
;C:\Ruby\bin


at the end of the path, I assumed that you have installed Ruby in drive c.
press oK.
4. now in command prompt

write

gem update --system


when the process completed, write

gem install rails


you have done. now its time to create your first project

in command prompt, write
rails firstproject


Once the projec is create, in command prompt, write

cd firstproject
ruby script/server


now browse

http://localhost:3000/

you will see ruby on rails welcome page.

Public transport some facts

Public transport (also public transportation or public transit or mass transit) comprises passenger transportation service which is used by public [1].
An important role played by public transport in the society is to enable all the member of the society to travel, not only those having driving license and have access to their own automobiles.
Public transport like all other services and facilities in the third word countries is a real dilemma. Elite, which mostly uses their own private automobiles and vehicles, like all other public institutions, organization and facilities, rarely consider improvement in these services. As they never ever use it, so why care about it?
The fact however is, if government gave proper resources and made some improvements, public transit can play a very vital role in generating fair amount of revenue.
Traffic jam which is a real problem in the big cities can be decreased be providing well-designed transport system which is considered more dense then private transport.
I have been using public transport in my beloved country for the last two year, and can say that it has made me mentally sick.
People behave like animals. I am not blaming them for behaving like this, as they are put like animals in buses. They don’t care walking on your feet and pushing with their hands.
Young people specially students stand near entrance, making it hard for the people to get in and out.
Situation become even more deteriorating when a person with his bag selling books, handkerchiefs, toffees, and homeopathic medicines arrived in crowd and start speech explaining benefits of the product he owns.
Beggars also contribute to the noisy environment, trying hard to collect money for no work.

Tuesday, August 11, 2009

Dojo: Creating image using dojo script

Dojo provides numerous functionality like:
1.Easy and smooth creation of different widget such as dojo grid, forms, datapicker, calendar etc.
2.Prolific method of interacting with html elements.
3.Achievement of ajax functionality with far more less code.
In this article I am going to discuss how to create an image element using dojo script and attach that image to certain html element.
In order to achieve functionality on loading the page, you will need to use dojo.addOnLoad() method. This takes the following form.
<script>
dojo.addOnLoad(function(){
alert(‘called on load of page’);
});
</script>


Now in the next few lines we are going to put the actual functionality.
<script>
dojo.addOnLoad(function(){
dojo.extend(dojo.NodeList, {
addImage: function() {

return this;
}
});
});
</script>

The most important things here are extending dojo.NodeList and then adding addImage function that initially has nothing, but we are going to add real functionality to it later on. This addImage method will contain the functionality for creating an image.
The question here however is, why we extend NodeList.
Well this is pretty simple. If you want to achieve functionality like;
dojo.query(‘input[id=name]’).addImage().removeClass(‘complusory_image’);
you will need to extend you method from NodeList. Doing so will enable you to access entire NodeList method in the way above.

Don’t worry about dojo.query() method, I will explain it shortly for you.
Now lets put the real script for creating img tag in our addImage method.
var img = dojo.doc.createElement('img');
dojo.attr(img, {
src: "path/to/imges/img.png",
alt: "This is my simple image",
style: {cursor: "pointer"}
});

In the first line we have created img tag. In the second line we have attached different attributes to the img. You can define as many valid attributes associated with img tag as you wish.

The code in the addImage function looks, however, a bit different. See the following code.
<script>
dojo.addOnLoad(function(){
dojo.extend(NodeList, {
addImage: function(args){
this.forEach(function(n){
var img = dojo.doc.createElement('img');
dojo.attr(img, {
src: "path/to/imges/img.png",
alt: "This is my simple image",
style: {cursor: "pointer"}
});
dojo.place(img, n, "after");
});
return this;
}
});
});
</script>

The function for addImage contain args as parameter. This means that the image tag created can be attached to as many html elements as you like. In the forEach loop we create image tag and attach at to the arguments passed to it.
Now in the dojo.addOnLoad function, at the end, write the following script.
dojo.query(‘input[id=name]’).addImage();

The above script states that attach an image to input tag having id equals to name.
It you want to attach element to all input tags on your page, write
dojo.query(‘input’).addImage(); 

The final script on my page look like this.
<script>
dojo.addOnLoad(function(){
dojo.extend(NodeList, {
addImage: function(args){
this.forEach(function(n){
var img = dojo.doc.createElement('img');
dojo.attr(img, {
src: "path/to/imges/img.png",
alt: "This is my simple image",
style: {cursor: "pointer"}
});
dojo.place(img, n, "after");
});
return this;
}
});
dojo.query("input[id=name]").addImage();
});
</script>