Jump to content

Good practice?


DiscoBiscuit

Recommended Posts

Hi,

I have a User class which has lots of small methods to validate a users details, such as check_username_length, check_passwords_match etc.  Is it better to call each of the methods separately or to just combine them into one large method and call that instead?

 

Secondly, I recently read a tutorial which suggested using heredoc syntax to add the entire contents of the page to a single variable and then echoing this at the end of the code, is this really a good idea, or would it be better to simply use lots of include files?

 

I realise it may just be up to personal preference, but I'm interested in other people's opinions.

Thanks.

Link to comment
Share on other sites

Hi,

 

I would usually do both. Have the smaller methods such as usr_check() that actually do the tasks and the a lager method such as usr_create() which uses the smaller methods to complete the whole task.

 

That way your script can create a user in this example but should you need to create another script that needs to check a user you don't need to rewrite the usr_check() code.

 

Plus if you ever wanted to create users in a different way you can always copy the usr_create() rename the function and make the changes. The core of the code would more than likely be the same and therefore would still be able to function using the smaller methods.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.