http://www.perlmonks.org?node_id=249301

artist has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks,
I like to generate the efficient code from the truth table and would like to know if we have any tools available.

For example, sulfericacid like to design a system to add/remove email addresses via CGI form based upon if users have provided proper fields and email address exists or not in the database. While talking in CB, I created the truth table.

name email add emailexist step:					
T    T     T   T	  warn 1. email exists in database
T    T	   T   F	  action 1: add email in database
T    T	   F   T	  action 2: remove email from database
T    T	   F   F	  warn 2. email doesn't exist in database
T    F	   -   -	  warn 3. email empty
F    T	   -   -	  warn 4. name empty
F    F	   -   -	  warn 5. name and email empty
Notes:
Name: 'T' If user has provided name
Email: 'T' If user has provided email
Add: 'T' if radio button for 'add' is checked. (other option is to remove
Emailexist: 'T' if email exists in the database
- : It's not relavent.
Sample code
if(form){ if(name){ if(email){ if(option=add){ if(stored){ warn1:email exists } else{ action:add email } } else(option=remove){ if(stored){ action:remove email } else{ warn2: email doesn't exist } } } else{ warn3: email empty } }else{ if(email){ warn4: name empty } else{ warn5: name and email empty } } }

According to me, the truth table provides the business logic. While programming we convert the business logic in the code. If we can represent the business logic in truth table and have the code-generator, it would be very helpful. With few fields, it could be common sense, with more fields it is usually a long mental/paper exercise to come up with good code. Our focus will be rightly shifted towards truth table generation in these type of case.

artist