[TFUI] User Input Validation

Phlip <phlipcpp-/[email protected]>
Newsgroups gmane.comp.programming.test-first-user-interfaces
Message-ID <[email protected]>
Imagine if you operate a walled city, and you order
the best elite troops to guard the walls, scout for
approaching enemies, and make a note of each character
entering the city gates. But you dismiss the
constables and investigators who rooted out crime and
corruption on the city streets and inside your palace.
You would not remain in charge for very long.

If your program intercepts any and all bad user input
at the GUI Layer, your sense of security may be false.
All code layers must be able to reject such data, at
the cheapest moment to detect the problem. Then, an
accurate report of the problem must transmit back to
the user; literally translated into their language.

Learn exception handling for your language, and make
certain you understand its pitfalls.

User input may cause any layer to throw an exception.
The exception must cause any intervening layers to
roll their state back to before the input happened.
Keep a single handler in your message pump procedure
itself to catch, log, localize, and present the bad
news. The /Exceptional C++/ books by Herb Sutter cover
these topics in great detail, with scenarios that
should also be studied in other languages.

A Layer is two generalized Façades, one for each other
Layer nearest it. By "Façade Pattern”, we mean the
published modules - the ones other layers call -
expects inputs might be invalid, and has simple
mechanisms to deflect them. Deeper modules inside a
Layer can assume data is safer. 

Prefer preventing the input itself to going thru all
that work and risk - early detection could be the
simplest thing. But sometimes only internal modules
can efficiently detect errors, and they invert this
guideline.

Suppose your user provides a file name. You check the
file’s size, as a spot-check that the file name is
useful, then pass it to the Logic Layer. But this
opens the file and discovers it’s locked. That layer
must propagate this exact, detailed error condition
back to the GUI Layer. The GUI Layer itself should not
check for file locks, because negative results are
useless. 

Another task or process could lock the file during the
split second before our Logic Layer actually tries to
open the file.

So, by this analysis, the GUI Layer should not even
bother to spot-check the file’s size. That would
duplicate the error recovery mechanism. Even simpler,
maybe the GUI Layer itself could open the file, pass a
handle into the Logic Layer, then close the file. But
something must still check each file read and write
worked, so our analysis has moved the error recovery
mechanism back to the Logic Layer!

Test error recovery using the "Crash Test Dummy”
pattern from Test-Driven Development. Test Fixtures
for the GUI Layer simulate a "Mock User” with fat
fingers.


=====
Phlip
  http://industrialxp.org/community/bin/view/Main/TestFirstUserInterfaces


	
		
__________________________________
Do you Yahoo!?
Yahoo! Movies - Buy advance tickets for 'Shrek 2'
http://movies.yahoo.com/showtimes/movie?mid=1808405861 


To unsubscribe, email:
TestFirstUserInterfaces-unsubscribe-hHKSG33TihhbjbujkaE4pw@public.gmane.org
 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
     http://groups.yahoo.com/group/TestFirstUserInterfaces/

<*> To unsubscribe from this group, send an email to:
     TestFirstUserInterfaces-unsubscribe-hHKSG33TihhbjbujkaE4pw@public.gmane.org

<*> Your use of Yahoo! Groups is subject to:
     http://docs.yahoo.com/info/terms/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.