Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

comment on

( #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":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others exploiting the Monastery: (3)
    As of 2021-03-03 01:36 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      My favorite kind of desktop background is:











      Results (69 votes). Check out past polls.

      Notices?