susanBuck / e15-spring22

0 stars 0 forks source link

Contemplating the Best Way to Process the Form for Project 1 #13

Closed patrickgarsow-harvard closed 2 years ago

patrickgarsow-harvard commented 2 years ago

I wanted to have a discussion with the class about how best to process the form for Project 1. The instructor has provided many different options and as far as I can understand from the Project 1 guidelines we are not required to use any specific method.

Option 1: Just use a view and a controller.

We can use the index.php and index-view.php method. The one issue discussed in the lecture videos is that refreshing the form causes a resubmission.

Option 2: Use a view and a controller with a limiting passthrough of a processor

So the second option I see is that we can use a processor to pass the form data through so we prevent dataflow in reverse. For the Project 1 example this would be to use a $_SESSION[] to store the on form field and then passing that session data to the controller to have the logic applied.

Option 3: Use something that looks similar to a MVC (Model View Controller)

This solution would be passing the form data from the view to a model that collects the data and applies organization and structure then pass the data to a controller which completes the business logic that then hands back to a view to display the results.

I feel like this is the most valuable solution in a project that is much more complex with many more form entries but I am not sure if it is worth the time. I also was not a fan of collecting the data in the processor in an array and then passing it to a controller, storing the data in local variables. I think The better solution would be to use the multidimensional array created with the session to use in the functions that complete the tasks required of the project. I see both risk and reward but feel in this instance reward would be outweighed. This of course is only the case if you think this option is the best solution.

What does everyone else think?

Interested to know other thoughts about this.

susanBuck commented 2 years ago

I'll reserve comment since this seems more directed at classmates. Just wanted to note I saw this post and am not ignoring it. : ) I can chime in later after other students have the opportunity to reply.

pllealfunes commented 2 years ago

I am personally going with Design C. I like that I can see results on the same page and I only have to deal with 3 files unlike Design B. Also, like you said resubmission isn't great when it comes to Design A. Good luck!

dauger27 commented 2 years ago

I've gone forward with Design 2. A basic PHP script that uses the $_SESSION functionality and jumps back to the main controller. It avoids the pitfalls of Design 1 without introducing the complexity of Design 3.

YvaGithub commented 2 years ago

Although I am still struggling to get my code to work again after I merge it to the "form" page. I am going with method # 2 since it seems to be simple and will fulfill the criteria of the assignment. Especially, it will prevent the form from being resubmitted anytime we submit it.

gkorodi commented 2 years ago

I guess I ended up with #3 as well. For me it is just easier to use a model class. Easier to unit test and simple to call from the bare-bones controller.

Great points throughout. Thank you for bringing it up.

archerdave commented 2 years ago

Absolutely, go for the organized code. There are a number of reasons.

Regarding storing data in local variables vs working straight with the global $_SESSION, it takes some work for the computer to determine the return value of something. If it's a function, it needs to go through all the steps of the function. If it's an equation, it needs to evaluate the equation, etc. If it's the value of a variable, it only needs to use the variable to reference the value. If you need to access that value more than once, it is cheaper to run the evaluation and store it in a variable. In an array, there would need to be two lookups. One to find the array, and then a second one to find the value stored in that specific spot in the array. Now, in the case of using something like

echo $_SESSION['answer'];

vs

$answer = $_SESSION['answer'];
echo $answer;

you aren't really saving a lot either way. But in a larger program, or with a more involved function than an array lookup, you could be looking at significant cost savings in terms of computing power and application response speed.

And finally, the time to build these habits this is now, while we are practicing and learning.

susanBuck commented 2 years ago

All great input from the replies above 👍

Personally, I think "form design C" is the best match for this project. Like @pllealfunes noted, I think it makes sense in this context to see the results and also see the form to continue to interact with the application.

But "form design B" is also totally fine, and as @dauger27 and @YvaGithub noted, it's slightly more straightforward.

(I think I noted in lecture that design B or C would fit the bill for this project, so I stick by that here. : )

As to the finer points of extracting values into variables vs. working with it directly from the session array - here I would defer to what makes the most sense from a code clarity/organization standpoint. From a performance perspective, it's splitting hairs and you won't notice an appreciable difference between the two.

+1 to @archerdave's note about building good habits from the get-go!

patrickgarsow-harvard commented 2 years ago
  • Bug are harder to track down and squash in un-organized code.

@archerdave I think everything comes back to the organization of code that an MVC solution offers. That was really my considerations for the method I chose. Not that I condone going ahead but where I feel that MVC goes a little too far is on easier/simpler projects like P1. If you just look at the base implementation of something like Laravel you see that the complexity that a base MVC can create might not be the right choice if an easier solution is available. If I had to read and reference the entire Oxford dictionary to write a Tweet that might be a little overkill right?

patrickgarsow-harvard commented 2 years ago

Awesome discussion everyone, thanks for all of the feedback! This helped me understand the scenario more and allowed me to make my decision.