Placeholders are visual aids, with a wide variety of implementations. As it's more of a concept than an actual official feature, you don't really need to know about placeholders in order to be in web development. But boy, do they help. In every aspect of the job.
Implementing placeholders in the back-end
Sometimes the project gets too big. You lose track of all the little things you have to do in order for it to work. So, in order not to end up being bogged down by minutia, especially if the piece of code you're planning to write is really long, you'll need to step back and look at the big picture.Big picture moment, yo. |
Let's say, for example, you are writing a login procedure. You have the front-end, which is essentially a login text field, a password text field, and a submit button. Your work at the back-end is pending - you of course need to check for an existing login/password match, and then if there's a match, you need to check the user's access rights. Superadmins have access to everything and have no expiration date. Admins have access to certain areas outside of normal access and have no expiration date. Normal users have access only to a limited set of features and have an expiration date - if that expiration date has arrived, they are not automatically logged out.
Sound like a lot? Hell no, it's a pittance! I've deliberately scaled this down for ease of explanation.
Now, how should we approach this? Just wade in and start coding? Dear me, no. You'd be making things hell of a lot easier on yourself if you divided and conquered. I'm not even talking about Object-oriented Programming here. Just use comments judiciously to provide placeholders for each segment, like so.
//BEGIN get login variables
//---
//END get login variables
//BEGIN check existing login/password
//---
//END check existing login/password
//BEGIN check user type
//BEGIN superadmin
//---(display superadmin links)
//END superadmin
//BEGIN admin
//BEGIN check access rights
//---(display links according to access rights)
//END check access rights
//END admin
//BEGIN user
//BEGIN check expiration
//---(log user out if account expired)
//END check expiration
//END user
//END check user type
//BEGIN display normal user links
//---
//END display normal user links
//---
//END get login variables
//BEGIN check existing login/password
//---
//END check existing login/password
//BEGIN check user type
//BEGIN superadmin
//---(display superadmin links)
//END superadmin
//BEGIN admin
//BEGIN check access rights
//---(display links according to access rights)
//END check access rights
//END admin
//BEGIN user
//BEGIN check expiration
//---(log user out if account expired)
//END check expiration
//END user
//END check user type
//BEGIN display normal user links
//---
//END display normal user links
So, where it says //---, you just substitute that with whatever code you need to write.
This will add a whole lot more lines to your code, but you'll be able to leave anytime, return and see what you've missed out! Also, segmenting it this way allows you to divide your procedural code into logical blocks.
No, this is not some super-genius hack for enterprise level programming. In fact, if you were a super-genius, you probably would have enough intellectual capacity and brainpower to not bother at all. For the rest of us mere mortals, this is a nice lifehack.
No comments:
Post a Comment