Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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


In reply to Code generation from truth table. by artist

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (4)
As of 2024-03-28 17:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found