Share
Preview
Minimize your development time and make it easier to meet your deadlines.
 ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌
ALEX WEB DEVELOP

Alex
Code faster with the "Top-Bottom" technique
by Alex
Top-Bottom


Hey,
Alex here.

Building a web application takes time.
But sometimes it can take too much time, because of the way we code.

Fortunately, there are some techniques that you can use to minimize the development time, and to make it easier to meet your deadlines.

Today we'll look at the top-bottom technique - a very simple yet effective strategy to avoid getting lost in your code.

Let's see how it works.



The "gas law" problem.
Physics tells us that a gas expands to fill its entire container.
The larger the container, the more the gas expands.

The same happens with coding, too.
The more "room" you give to your application, the more stuff you can code into it.
This is why it often seems like you always need to add more and more classes, functions, and features. And with that, the development time keeps increasing.

To prevent a gas from expanding too much, you need to put it into a closed container.
You can apply the same strategy to coding: to prevent your code from growing forever, you need to set some limits to your apps.

This is what the "Top-Bottom" technique is about.


The Top-Bottom technique.
When you code, you usually start from the most basic blocks.
Basic functions, variables, and so on. This is the standard bottom-top approach.

For example, let's say that you are writing an authentication class.
With the standard bottom-top approach, you start by writing the Session variables, the SQL queries, the validation functions.
And in the end, you put it all together to get the class working.

The problem with this approach is that you know where you start... but you don't know where you will get to!

You can get lost in your code, never really getting any closer to the end.
And you can keep adding more and more features, because you don't have a clear "finish line" in mind.
Just like a gas, your code keeps expanding.


The top-bottom technique solves this problem.
Instead of coding the basic functionalities first, with the top-bottom approach you start by writing the top-level functions of your app.

Let's go back to your authentication class.
Instead of beginning from the basic properties, start by defining the top-level functions, such as:
  • adding a new user
  • editing an existing user
  • logging in/out

And so on.
Of course, at this point you can just write the function definitions, like this:

public function addUser(string $user, string $passwd)
{
   //...
}


And here is the thing: once you have written the main top-level functions, you have defined the class limits.

From there, you can only go backwards to implement all the functions and the required bottom-level code.

And here is where the "magic" happens.

As you go backwards, you have a clear and limited path to follow. You cannot keep coding indefinitely.
It's much easier now to have a clear view of your app, and to avoid getting lost in the process.

Writing the top-level functions first is like building the "container" first, so that your code cannot expand indefinitely like a gas.



That's all for today.
Now send me a reply with your questions and let me know what you think.

Until next time,
Alex



Share the knowledge

Did you like this email? Share it with your friends!
Click here to share it



Premium products to improve your skills

PHP courses

PHP Security Mastery
It would be great to stop worrying about web attacks, right? You know, to be confident that your code is always as secure as it should be.
So, how do you make your PHP code always secure?
You can do that by using the defense techniques that I teach you in this course (with real code examples).

Click here and see for yourself.


Resources

Alex Web Develop - My tutorials.
Alex PHP café
- My Facebook group where to talk with me and other developers.

Background vector created by brgfx - www.freepik.com




You are receiving this newsletter because you subscribed to Alex Web Develop.

If you unsubscribe, you will not get any more emails from me.

Alessandro Castellano, P.IVA (VAT ID): 07012140484, via Luigi Morandi 32, 50141 Firenze FI, Italy

Email Marketing by ActiveCampaign