Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which should one code first, functionality or validity checks?

When coding up, say, a registration form from scratch, does it make sense to get it functioning with the expected inputs first, and then go back and catch/handle the unexpected inputs and deal with errors?

The alternative would be to process the input, checking any constraints and insuring that they are handled properly, and then dealing with getting the typical use case functioning correctly.

Is one way preferable to the other, and if so why? Also, is there an alternate way to go about this sort of 2-part task?

To clarify, by validity, I mean more than just data validation, including business rules, such as "No more than X people can register for this event"

like image 612
cdeszaq Avatar asked Nov 29 '22 20:11

cdeszaq


2 Answers

The best thing to do, in my opinion, is to get a decent first version working which may not deal with all of the unexpected cases completely, but is made thoughtfully and modularly. You can then go back and perfect the logic so that your tests pass.

In the real world, this method pays off because you're more likely to be productive and interested when there's something working with a few kinks, rather than just being stuck trying to figure out all the edge cases in your head and deal with them at the start.

like image 127
mandaleeka Avatar answered Feb 19 '23 20:02

mandaleeka


One way would be to take a TDD approach (assuming you write unit tests). Start off by writing your unit tests, then work on getting those unit tests to pass.

In my opinion UI work should be done last since you probably have plenty to do on the back-end functionality.

like image 29
Miyagi Coder Avatar answered Feb 19 '23 18:02

Miyagi Coder