You are viewing a plain text version of this content. The canonical link for it is here.
Posted to rivet-dev@tcl.apache.org by Tom Brown <tb...@michiana.org> on 2004/05/18 19:24:03 UTC

Code example in documentation

Free Geek Michiana has a very small development team. We are learning 
Rivet/TCL. Soon (I hope) we will be generating enough code to offer 
examples for documentation.

I implemented the example of an HTML form and the corresponding Rivet 
action file <vars.rvt> at http://tcl.apache.org/rivet/html/examples.en.html.

I was confused about the purpose of the example code. <vars.rvt> seems to 
be a cross between testing the form and the developer (do the variables 
exist?) and testing the contents of the variables and the user (do the 
variables contain data?). Both types of test are valid.

The following code, a variation on <vars.rvt>, just tests the data.

Tom

<!-- vars.rvt -->
<!--
   Assumes variables exist and tests for data content.
   Prompts user to enter missing content.
-->
<?
set errlist {}
set title [var get title]
set salary [var get salary]
set boss [var get boss]
set skills [var get skills]

if { [string length $title] == 0} {
   lappend errlist "<b>Please enter a title</b><br />"
}

if { [string length $salary] == 0} {
   lappend errlist "<b>Please enter a salary</b><br />"
} else {
   if { ! [string is digit $salary] } {
     lappend errlist "<b>Salary must be a number</b>"
   }
}

if { [string length $boss] == 0} {
   lappend errlist "<b>Please enter a boss</b><br />"
}

if { [string length $skills] == 0} {
   lappend errlist "<b>Please enter skills</b><br />"
}

if { [llength $errlist] != 0 } {
   foreach err $errlist {
   puts "<p><b> $err </b></p>"
   }
} else {
   puts "Thanks for the information!"
   ?>
   <table>
   <tbody>
   <tr>
   <td><b>Title:</b></td>
   <td><? puts $title ?></td>
   </tr>
   <tr>
   <td><b>Boss:</b></td>
   <td><? puts $boss ?></td>
   </tr>
   <tr>
   <td><b>Salary:</b></td>
   <td><? puts $salary ?></td>
   </tr>
   <tr>
   <td><b>Skills:</b></td>
   <td><? puts $skills ?></td>
   </tr>
   </tbody>
   </table>
   <?
}
?>



---------------------------------------------------------------------
To unsubscribe, e-mail: rivet-dev-unsubscribe@tcl.apache.org
For additional commands, e-mail: rivet-dev-help@tcl.apache.org


Re: Code example in documentation

Posted by Tom Brown <tb...@michiana.org>.
> > I was confused about the purpose of the example code. <vars.rvt>
> > seems to be a cross between testing the form and the developer (do
> > the variables exist?) and testing the contents of the variables and
> > the user (do the variables contain data?). Both types of test are
> > valid.
>
>Well, good code takes all possibilities into account.
>
>Keep in mind that someone could always just create a URL 'by hand' to
>see what happens if 1) they omit variables 2) add extra variables 3)
>submit 'odd' values for variables, and so forth...  So it's up to you
>to program defensively.
>
>An idea for the future might be to create some library code that does
>this for you...  Something like this:
>
>CheckVar varname tclvar type
>
>It assigns the variable if everything is ok, or performs some action
>if not?  Just thinking out loud...
>
>In any case, does that make sense?


Makes sense. Linux Journal had an informative article recently about 
writing PHP code that validates input and stops malicious url hacks, among 
other security considerations. Portions of the article will be generalizable.

http://www.linuxjournal.com/article.php?sid=7237

>Thanks for looking over the examples - more would definitely help, and
>I certainly don't consider the existing ones to be perfect.  Writing
>docs for something you know intimately is tough, at times.

LTSP just published a Free Geek Michiana howto re converting IBM NetVista 
token ring thin clients into LTSP Ethernet thin clients. I wrote and 
formatted the doc, and the two team members who hacked the NetVista edited. 
Writing useful howtos is indeed difficult and time consuming.

http://www.ltsp.org/contrib/index.php

Tom



---------------------------------------------------------------------
To unsubscribe, e-mail: rivet-dev-unsubscribe@tcl.apache.org
For additional commands, e-mail: rivet-dev-help@tcl.apache.org


Re: Code example in documentation

Posted by "David N. Welton" <da...@dedasys.com>.
Tom Brown <tb...@michiana.org> writes:

> Free Geek Michiana has a very small development team. We are
> learning Rivet/TCL. Soon (I hope) we will be generating enough code
> to offer examples for documentation.

Great!  I'm glad to see that:-)

> I implemented the example of an HTML form and the corresponding
> Rivet action file <vars.rvt> at
> http://tcl.apache.org/rivet/html/examples.en.html.

> I was confused about the purpose of the example code. <vars.rvt>
> seems to be a cross between testing the form and the developer (do
> the variables exist?) and testing the contents of the variables and
> the user (do the variables contain data?). Both types of test are
> valid.

Well, good code takes all possibilities into account.

Keep in mind that someone could always just create a URL 'by hand' to
see what happens if 1) they omit variables 2) add extra variables 3)
submit 'odd' values for variables, and so forth...  So it's up to you
to program defensively.

An idea for the future might be to create some library code that does
this for you...  Something like this:

CheckVar varname tclvar type

It assigns the variable if everything is ok, or performs some action
if not?  Just thinking out loud...

In any case, does that make sense?

Thanks for looking over the examples - more would definitely help, and
I certainly don't consider the existing ones to be perfect.  Writing
docs for something you know intimately is tough, at times.

-- 
David N. Welton
   Consulting: http://www.dedasys.com/
     Personal: http://www.dedasys.com/davidw/
Free Software: http://www.dedasys.com/freesoftware/
   Apache Tcl: http://tcl.apache.org/

---------------------------------------------------------------------
To unsubscribe, e-mail: rivet-dev-unsubscribe@tcl.apache.org
For additional commands, e-mail: rivet-dev-help@tcl.apache.org