• RSS
  • Print this article!
  • Digg
  • del.icio.us
  • DZone
  • Facebook
  • Mixx
  • Google Bookmarks
  • Design Float
  • Reddit
  • StumbleUpon
  • Technorati
  • Live
  • TwitThis
Home > Development Best Practices > Making Development Easy

Making Development Easy

May 10th, 2009

When it comes to development often times the hardest part of the process is knowing where to start. Starting in the wrong direction can ultimately change how your project will end up. Hopefully this article will open your eyes to an effective way to developing and make your life that much easier.

Bottom Up Development

Often times developers starting out dive right in and get right into the details. Working from the bottom up … hence the catchy name. The problem with this is the developer often gets caught up in the details and loses vision of the over picture.

So if a developer needs to create a function that steps through an array and adds up the sum of the numbers they might do something like:

1
2
3
4
5
6
$array = array('1','5','15','23');
    $sum = 0;
    for ($i = 0; i < count($array); i++){
        $sum += array[$i];
    }
    echo $sum;

Although this is a really simple example it already illustrates a problem in the code. Say there was an array that had a letter in it then this code could break. Granted these changes aren’t difficult to fix at this point, but if there was a far more complex example then it can become a real pain in the tush. Code like this works but the developer lost sight of the architecture of the code. So what’s the solution ????

Top Down Development

Planning the structure first solves a lot of problems.

Using top down development you might start like this:

1
2
3
Initialize values
    add up values
    display sum

Layout everything in plain English so you can wrap your head around it.

After that you fill in the code. The beautiful thing is you can comment your initial list and you will have fully documented code.

1
2
3
4
5
6
7
8
9
//Initialize values
    $array = array('1','5','15','23');
    $sum = 0;

    //add Up Values
    $sum = addUpValues($array);

    //display sum
    display($sum);

You’ll notice that this time around functions were used to simplify the process. This encapsulates code into easy to use packages. Inside the addUpValues function you would have the loop adding up the values, and inside the display function you would have the echo statement.

1
2
3
4
5
6
7
8
9
10
11
function addUpValues($array){
        $sum = 0;
        for ($i = 0; i < count($array); i++){
            $sum += array[$i];
        }
        return $sum;
    }

    function display($sum){
        echo $sum;
    }

So now if you wanted to do checking for letters in the array it’s all within one function and you don’t have to worry that it’s going to affect any other code. As for the display function, I know it seems a bit of an overkill to make a function for an echo statement. If you think about it, you can do far more advanced things then just echoing a statement and you still wouldn’t have to change the original code. So working your way from the top down you make life a lot easier for making changes in the future, and that’s the name of the game.  In all these examples PHP is used but this can be applied to any development language.
Here is an example using HTML:

1
2
3
Menu
Body
Footer
1
2
3
4
5
6
7
8
9
10
11
12
<!-- Menu -->
<ul>
    <li>Home</li>
    <li>About</li>
    <li>Contact</li>
</ul>

<!-- Body -->
<div>This is the Body</div>

<!-- Footer-->
<div id="footer">This is a footer</div>

They say it usually takes about 100 hours for a developer to naturally fall into this form of development. Hopefully this will help you to start a little earlier and save you some time in the process.   More PS3 time….SWEET.

  • RSS
  • Print this article!
  • Digg
  • del.icio.us
  • DZone
  • Facebook
  • Mixx
  • Google Bookmarks
  • Design Float
  • Reddit
  • StumbleUpon
  • Technorati
  • Live
  • TwitThis
Comments are closed.