Jump to content

function or no function?


phpeeved

Recommended Posts

Hey guys, currently working on a project for school where we are building a small web application, very basic stuff... Login page, different accounts, some uploading and really just trying to keep things dynamic while utilizing a flat file database...

 

I have a question with regards to the login page. I always hear more experienced developers telling me to keep things modular. I am trying to have my logic and data seperated, and I will be building a lot of functions for this site.

 

However, the functions are for things that I will be calling I'm various areas of the page. The login though, is just a single instance on the first page the users come to.

 

In your guys experience, would you create a login function? Or just code it right at the top of the login page?

 

Any input you guys have would be greatly valued.

 

Thanks for your time,

 

J

Link to comment
Share on other sites

 


In your guys experience, would you create a login function? Or just code it right at the top of the login page?

 

If you put everything else in functions then why make a n exception for the login? And are you sure that the login code will only ever be used on the login page?

 

But think about testing also; you cannot easily automatically test PHP code that is embedded in a piece of HTML, while it's very easy to execute a function and see if it returns true or false.

Link to comment
Share on other sites

If you put everything else in functions then why make a n exception for the login? And are you sure that the login code will only ever be used on the login page?

 

But think about testing also; you cannot easily automatically test PHP code that is embedded in a piece of HTML, while it's very easy to execute a function and see if it returns true or false.

 

I cant think of any other instances where I will have to use the log in code again, so I was just wondering if that what the basis on knowing whether or not you should make a function for it. Thanks for your guys response, I will turn my login code into a function now.

Link to comment
Share on other sites

 


I cant think of any other instances where I will have to use the log in code again, so I was just wondering if that what the basis on knowing whether or not you should make a function for it.

 

Functions enable code re-use, so in the most strict sense that is the criterium; no re-use: no function. But in modern programming you always have at least two uses: once in your application and once in your unittests.

Logging-in of course ican be re-used all over the place; on the main login form, but also in login popups that appear when you visit a bookmarked page inside the restricted area, in datafeeds, basically in every situation where you ned to access restricted data while you're not logged in.

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.