Jump to content

2 function or 1?


Recommended Posts

Suppose you have 2 types of users for your app, business and regulars, and these, fill in a different type of registration form, with different fields each. The question is, do you write one function for the registration, for both type of users, or 2 functions, each called depending on the user type. From your experience what you would do. I think of writing one, but complexity worries me.

Link to post
Share on other sites

depends on the registration requirements of each, but probably better to write two. as you are already anticipating, the cyclomatic complexity could get troublesome if their differences are significant enough. Perhaps there are some reusable elements you could share between the two of them (like validation or something like that) but even from a testing standpoint, the simpler the function, typically the better.

Link to post
Share on other sites

Will your users know if they are regular or business users before they fill the form in? What if they fill in a business form and then find out they should have filled in the regular form (or the other way round)? To make it easier for your users - and for you - why not have just one form. Some fields will always have to be filled in (name, email etc) and some will be optional and these can all be on the same form. One of the things I have learned since taking up programming and web design is that the best way of starting a project is to get a pen and paper and write down EXACTLY what it is you want to achieve and then the steps you can take to reach it. So the first question you should ask (based on your post) if... why do I need two different forms? If you have no good answer than stick to one.

Link to post
Share on other sites

I would say it depends on the size of, and amount of commonality between, the two datasets. If you have two registration forms, each containing dummy values in hidden fields for the data not applicable to each registration, although it may be a little less efficient in terms of data storage, you should end up with just one relatively simple (if big) function that handles both registration types. If you want to post an overview of the datasets involved, I'll try to offer a more definative opinion.

Link to post
Share on other sites

The differences between the two forms are not big.In the business form, the user just fills also the type of business(carshop, hairdresser...etc). Of course all the other fields are common-name, username, password...etc.I think is is better to have one registration form and 1 function to handle it. An when the user who is going to register is a business I will just use javascript to reveal(the otherwise hidden) the corresponding fields. That is the plan I have come.

Edited by jimfog
Link to post
Share on other sites

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.   Paste as plain text instead

  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.

Loading...
×
×
  • Create New...