ÓÑÇéÌáʾ£ºÈç¹û±¾ÍøÒ³´ò¿ªÌ«Âý»òÏÔʾ²»ÍêÕû£¬Çë³¢ÊÔÊó±êÓÒ¼ü¡°Ë¢Ð¡±±¾ÍøÒ³£¡
µÚÈýµç×ÓÊé ·µ»Ø±¾ÊéĿ¼ ¼ÓÈëÊéÇ© ÎÒµÄÊé¼Ü ÎÒµÄÊéÇ© TXTÈ«±¾ÏÂÔØ ¡ºÊղص½ÎÒµÄä¯ÀÀÆ÷¡»

VB2008´ÓÈëÃŵ½¾«Í¨(PDF¸ñʽӢÎÄ°æ)-µÚ19²¿·Ö

¿ì½Ý²Ù×÷: °´¼üÅÌÉÏ·½Ïò¼ü ¡û »ò ¡ú ¿É¿ìËÙÉÏÏ·­Ò³ °´¼üÅÌÉ쵀 Enter ¼ü¿É»Øµ½±¾ÊéĿ¼ҳ °´¼üÅÌÉÏ·½Ïò¼ü ¡ü ¿É»Øµ½±¾Ò³¶¥²¿! Èç¹û±¾ÊéûÓÐÔĶÁÍ꣬ÏëÏ´μÌÐø½Ó×ÅÔĶÁ£¬¿ÉʹÓÃÉÏ·½ "Êղص½ÎÒµÄä¯ÀÀÆ÷" ¹¦ÄÜ ºÍ "¼ÓÈëÊéÇ©" ¹¦ÄÜ£¡


develop¡¡code£»¡¡you¡¡have¡¡multiple¡¡possible¡¡ways¡¡to¡¡solve¡¡a¡¡problem¡£¡¡If¡¡you¡¡start¡¡messing¡¡around¡¡¡¡

with¡¡the¡¡original¡¡source¡¡code£»¡¡by¡¡the¡¡time¡¡you¡¡reach¡¡the¡¡third¡¡or¡¡fourth¡¡solution£»¡¡the¡¡code¡¡might¡¡¡¡

be¡¡a¡¡plete¡¡mess¡£¡¡Your¡¡fixes¡¡might¡¡make¡¡things¡¡worse£»¡¡and¡¡trying¡¡to¡¡backtrack¡¡in¡¡your¡¡source¡¡¡¡

code¡¡bees¡¡very¡¡difficult¡£¡¡¡¡



¡öNote¡¡¡¡To¡¡manage¡¡your¡¡source¡¡code£»¡¡you¡¡should¡¡use¡¡version¡¡control¡£¡¡However£»¡¡even¡¡with¡¡version¡¡control£»¡¡¡¡

when¡¡you¡¡delete¡¡past¡¡attempts£»¡¡ideas¡¡get¡¡lost¡£¡¡Thus£»¡¡while¡¡your¡¡source¡¡code¡¡will¡¡be¡¡clean£»¡¡you¡¡might¡¡forget¡¡¡¡

something¡¡you¡¡did¡¡three¡¡or¡¡four¡¡hours¡¡ago¡£¡¡Trust¡¡me£»¡¡this¡¡happens£»¡¡because¡¡developing¡¡source¡¡code¡¡is¡¡an¡¡¡¡

intensive¡¡thought¡¡process¡£¡¡



¡¡¡¡¡¡¡¡¡¡The¡¡solution¡¡is¡¡to¡¡create¡¡a¡¡shim¡¡that¡¡calls¡¡the¡¡TranslateHello£¨£©¡¡method¡£¡¡The¡¡shim¡¡is¡¡used¡¡¡¡

to¡¡fix¡¡the¡¡bug¡£¡¡The¡¡following¡¡shim¡¡code¡¡is¡¡a¡¡temporary¡¡solution£º¡¡



¡¡¡¡¡¡¡¡Public¡¡Function¡¡TrimmingWhitespace£¨ByVal¡¡buffer¡¡As¡¡String£©¡¡As¡¡String¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Return¡¡Translator¡£TranslateHello£¨buffer¡£Trim£¨£©£©¡¡

¡¡¡¡¡¡¡¡End¡¡Function¡¡



¡¡¡¡¡¡¡¡¡¡¡¡TrimmingWhitespace£¨£©¡¡is¡¡a¡¡method¡¡that¡¡trims¡¡whitespace¡¡from¡¡the¡¡string¡¡to¡¡be¡¡translated¡£¡¡¡¡

buffer¡£Trim¡¡is¡¡new¡¡functionality¡¡that¡¡preprocesses¡¡the¡¡buffer¡£¡¡Finally£»¡¡we¡¡call¡¡the¡¡original¡¡¡¡

method£»¡¡TranslateHello£¨£©£»¡¡to¡¡perform¡¡the¡¡translation¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡Of¡¡course£»¡¡we¡¡need¡¡to¡¡test¡¡the¡¡new¡¡method¡¡to¡¡see¡¡if¡¡it¡¡trims¡¡the¡¡string¡¡to¡¡be¡¡translated¡£¡¡The¡¡¡¡

following¡¡is¡¡the¡¡corresponding¡¡test¡¡code¡£¡¡



Dim¡¡verifyValue¡¡As¡¡String¡¡=¡¡TrimmingWhitespace£¨¡¨¡¡¡¡allo¡¨£©¡¡

If¡¡verifyValue¡£pareTo£¨¡¨hallo¡¨£©¡¡¡¡0¡¡Then¡¡

¡¡¡¡¡¡¡¡Console¡£WriteLine£¨¡¨Extra¡¡white¡¡spaces¡¡allo¡¡to¡¡hallo¡¡test¡¡failed¡¨£©¡¡

End¡¡If¡¡



¡¡¡¡¡¡¡¡¡¡The¡¡test¡¡calls¡¡the¡¡work¡­in¡­progress¡¡method£»¡¡TrimmingWhitespace£¨£©£»¡¡to¡¡see¡¡if¡¡everything¡¡¡¡

works¡£¡¡The¡¡verification¡¡code¡¡does¡¡not¡¡change¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡So¡¡that¡¡you¡¡get¡¡predictable¡¡results£»¡¡remember¡¡to¡¡call¡¡the¡¡shim¡¡and¡¡not¡¡the¡¡original¡¡method¡£¡¡¡¡

If¡¡you¡¡run¡¡the¡¡test¡¡code£»¡¡you¡¯ll¡¡see¡¡that¡¡the¡¡shim¡¡works£»¡¡and¡¡thus¡¡we¡¡have¡¡a¡¡solution¡£¡¡



Finding¡¡a¡¡Substring¡¡



Another¡¡solution¡¡to¡¡the¡¡whitespace¡¡problem¡¡is¡¡to¡¡find¡¡a¡¡specific¡¡substring¡¡in¡¡a¡¡buffer¡£¡¡Think¡¡of¡¡¡¡

it¡¡as¡¡a¡¡search¡¡solution£»¡¡where¡¡a¡¡method¡¡iterates¡¡over¡¡a¡¡string¡¡and¡¡attempts¡¡to¡¡match¡¡elements¡¡¡¡

of¡¡a¡¡buffer¡¡to¡¡some¡¡text¡¡that¡¡is¡¡being¡¡searched¡£¡¡The¡¡work¡­in¡­progress¡¡code¡¡is¡¡shown¡¡in¡¡Figure¡¡3¡­8¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡The¡¡test¡¡code¡¡is¡¡not¡¡shown¡¡here£»¡¡because¡¡it¡¡is¡¡similar¡¡to¡¡that¡¡for¡¡the¡¡previous¡¡solution£»¡¡with¡¡¡¡

the¡¡difference¡¡being¡¡the¡¡method¡¡being¡¡tested¡£¡¡¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡84¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

62¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡CH¡¡AP¡¡T¡¡E¡¡R¡¡¡¡¡¡3¡¡¡¡¡¡¡ö¡¡¡¡¡¡¡¡L¡¡E¡¡A¡¡R¡¡N¡¡IN¡¡G¡¡¡¡¡¡AB¡¡OU¡¡T¡¡¡¡¡¡ST¡¡R¡¡I¡¡N¡¡G¡¡¡¡¡¡M¡¡A¡¡N¡¡I¡¡P¡¡U¡¡L¡¡AT¡¡IO¡¡N¡¡S¡¡¡¡¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡IndexOf£¨£©¡¡attempts¡¡to¡¡match¡¡the¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡text¡¡¡°allo¡±¡¡in¡¡the¡¡variable¡¡buffer¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Work¡­in¡­progress¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡If¡¡the¡¡text¡¡is¡¡found£»¡¡an¡¡offset¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡method¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡that¡¡is¡¡not¡¡¡­1¡¡is¡¡returned¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡Function¡¡FindSubstring£¨ByVal¡¡buffer¡¡As¡¡String£©_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡As¡¡String¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡If¡¡buffer¡£IndexOf£¨¡¨allo¡¨£©¡¡¡¡¡­1¡¡Then¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Return¡¡Translator¡£TranslateHello£¨¡¨allo¡¨£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡If¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Return¡¡¡¨¡¨¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡Function¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡IndexOf£¨£©¡¡returns¡¡the¡¡index¡¡of¡¡the¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡first¡¡matched¡¡character£»¡¡which¡¡is¡¡2¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Visual¡¡Basic¡¡will¡¡always¡¡start¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡a¡¡¡¡¡¡¡¡l¡¡¡¡¡¡¡¡l¡¡¡¡¡¡¡¡o¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡counting¡¡with¡¡the¡¡value¡¡0¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Index¡¡0¡¡¡¡¡¡¡¡¡¡¡¡1¡¡¡¡¡¡2¡¡¡¡¡¡¡¡3¡¡¡¡¡¡¡¡4¡¡¡¡¡¡¡¡¡¡5¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Figure¡¡3¡­8¡£¡¡Finding¡¡a¡¡substring¡¡to¡¡solve¡¡the¡¡whitespace¡¡problem¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Which¡¡Is¡¡the¡¡Best¡¡Solution£¿¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Take¡¡a¡¡moment¡¡to¡¡think¡¡about¡¡which¡¡is¡¡the¡¡best¡¡solution£º¡¡trimming¡¡the¡¡whitespace¡¡or¡¡finding¡¡a¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡substring¡£¡¡The¡¡answer¡¡is¡¡neither¡¡is¡¡perfect£»¡¡each¡¡solution¡¡has¡¡its¡¡problems¡£¡¡This¡¡is¡¡a¡¡very¡¡mon¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡occurrence¡¡when¡¡you¡¡are¡¡developing¡¡software¡£¡¡You¡¡think¡¡you¡¡have¡¡all¡¡the¡¡corners¡¡covered£»¡¡and¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡then¡¡another¡¡scenario¡¡causes¡¡your¡¡software¡¡to¡¡fail¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Again£»¡¡I¡¡want¡¡to¡¡stress¡¡that¡¡you¡¡need¡¡to¡¡write¡¡more¡¡tests¡¡to¡¡figure¡¡out¡¡which¡¡scenarios¡¡might¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡cause¡¡your¡¡software¡¡to¡¡fail¡£¡¡For¡¡the¡¡solution¡¡of¡¡trimming¡¡whitespace£»¡¡writing¡¡another¡¡test¡¡causes¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡it¡¡to¡¡fail£»¡¡as¡¡shown¡¡in¡¡the¡¡following¡¡code¡£¡¡It¡¡cannot¡¡be¡¡tweaked¡¡to¡¡make¡¡the¡¡test¡¡succeed¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡verifyValue¡¡As¡¡String¡¡=¡¡TrimmingWhitespace£¨¡¨a¡¡¡¡allo¡¨£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡If¡¡verifyValue¡£pareTo£¨¡¨hallo¡¨£©¡¡¡¡0¡¡Then¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Console¡£WriteLine£¨¡¨Test¡¡failed£º¡¡cannot¡¡parse¡¡multiple¡¡words¡¨£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡If¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡In¡¡the¡¡test£»¡¡the¡¡leading¡¡¡°a¡±¡¡is¡¡considered¡¡the¡¡first¡¡character¡¡and¡¡is¡¡not¡¡trimmed¡£¡¡The¡¡verification¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡will¡¡fail¡¡because¡¡pareTo£¨£©¡¡cannot¡¡verify¡¡the¡¡misaligned¡¡buffer¡¡caused¡¡by¡¡the¡¡leading¡¡¡°a¡£¡±¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡If¡¡the¡¡new¡¡test¡¡were¡¡executed¡¡against¡¡the¡¡substring¡¡solution£»¡¡it¡¡would¡¡succeed¡¡and¡¡find¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡word¡¡¡°allo¡£¡±¡¡Because¡¡the¡¡new¡¡test¡¡caused¡¡the¡¡first¡¡solution¡¡to¡¡fail£»¡¡it¡¡would¡¡seem¡¡that¡¡solution¡¡is¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡a¡¡no¡­go¡£¡¡Our¡¡confidence¡¡has¡¡been¡¡increased¡¡in¡¡the¡¡second¡¡solution¡¡because¡¡the¡¡old¡¡test¡¡and¡¡the¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡new¡¡test¡¡did¡¡not¡¡fail¡£¡¡But¡¡don¡¯t¡¡be¡¡too¡¡hasty¡¡to¡¡consider¡¡that¡¡as¡¡the¡¡best¡¡path¡£¡¡The¡¡substring¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡solution¡¡fails¡¡with¡¡the¡¡following¡¡test¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡verifyValue¡¡As¡¡String¡¡=¡¡FindSubstring£¨¡¨allodium¡¨£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡If¡¡verifyValue¡£pareTo£¨¡¨hallo¡¨£©¡¡¡¡0¡¡Then¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Console¡£WriteLine£¨¡¨allodium¡¡to¡¡hallo¡¡test¡¡failed¡¨£©¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡If¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡85¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡CH¡¡AP¡¡T¡¡E¡¡R¡¡¡¡¡¡3¡¡¡¡¡¡¡ö¡¡¡¡¡¡¡¡L¡¡E¡¡AR¡¡N¡¡IN¡¡G¡¡¡¡¡¡AB¡¡O¡¡U¡¡T¡¡¡¡¡¡ST¡¡R¡¡I¡¡N¡¡G¡¡¡¡¡¡M¡¡A¡¡N¡¡I¡¡PU¡¡L¡¡A¡¡TI¡¡O¡¡N¡¡S¡¡¡¡63¡¡



¡¡¡¡¡¡¡¡¡¡¡¡The¡¡word¡¡tested£»¡¡¡°allodium£»¡±¡¡contains¡¡the¡¡characters¡¡allo¡£¡¡The¡¡verification¡¡will¡¡succeed£»¡¡¡¡

and¡¡this¡¡is¡¡an¡¡example¡¡of¡¡a¡¡false¡¡positive¡£¡¡



¡öNote¡¡¡¡It¡¡is¡¡important¡¡to¡¡have¡¡many¡¡tests¡¡that¡¡verify¡¡a¡¡multitude¡¡of¡¡different¡¡scenarios¡£¡¡You¡¡should¡¡have¡¡tests¡¡¡¡

that¡¡are¡¡supposed¡¡to¡¡succeed¡¡and¡¡those¡¡that¡¡are¡¡supposed¡¡to¡¡fail¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡The¡¡conclusion¡¡is¡¡that¡¡neither¡¡of¡¡the¡¡solutions¡¡works¡¡properly¡£¡¡With¡¡extended¡¡testing£»¡¡each¡¡¡¡

solution¡¡created¡¡new¡¡problems¡£¡¡We¡¡need¡¡to¡¡find¡¡another¡¡solution¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡DEVELOPMENT¡¡FRUSTRATIONS¡¡



¡¡¡¡¡¡It¡¡would¡¡seem¡¡that¡¡creating¡¡solutions¡¡and¡¡then¡¡creating¡¡tests¡¡that¡¡nullify¡¡the¡¡solution¡¡is¡¡a¡¡lesson¡¡in¡¡frustration¡£¡¡¡¡

¡¡¡¡¡¡You¡¡create¡¡code¡¡that¡¡does¡¡not¡¡solve¡¡the¡¡problems¡£¡¡What¡¡you¡¡must¡¡realize¡¡and¡¡take¡¡to¡¡heart¡¡is¡¡that¡¡this¡¡is¡¡part¡¡¡¡

¡¡¡¡¡¡of¡¡the¡¡software¡¡development¡¡process¡£¡¡Yes£»¡¡some¡¡people¡¡write¡¡code¡¡and¡¡don¡¯t¡¡worry¡¡about¡¡the¡¡tests£»¡¡but¡¡those¡¡¡¡

¡¡¡¡¡¡developers¡¡give¡¡software¡¡development¡¡a¡¡bad¡¡name¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡You¡¡want¡¡to¡¡be¡¡a¡¡trustworthy¡¡developer¡¡who¡¡tests¡¡your¡¡code¡£¡¡I¡¡have¡¡been£»¡¡and¡¡my¡¡wife¡¡is£»¡¡a¡¡software¡¡¡¡

¡¡¡¡¡¡development¡¡manager¡£¡¡In¡¡her¡¡words£»¡¡¡°I¡¡can¡¡deal¡¡with¡¡slow¡¡developers£»¡¡but¡¡I¡¡cannot¡¡deal¡¡with¡¡developers¡¡who¡¡¡¡

¡¡¡¡¡¡I¡¡cannot¡¡trust¡¡to¡¡write¡¡stable¡¡and¡¡robust¡¡code¡£¡¡The¡¡problem¡¡with¡¡untrustworthy¡¡developers¡¡is¡¡that¡¡I¡¡cannot¡¡let¡¡¡¡

¡¡¡¡¡¡them¡¡release¡¡code¡¡into¡¡production¡¡and¡¡always¡¡have¡¡to¡¡have¡¡somebody¡¡looking¡¡over¡¡their¡¡shoulders¡£¡±¡¡



Writing¡¡the¡¡Tests¡¡Before¡¡Writing¡¡the¡¡Code¡¡



The¡¡reason¡¡the¡¡previous¡¡solutions¡¡failed¡¡is¡¡because¡¡each¡¡solution¡¡was¡¡a¡¡knee¡­jerk¡¡reaction¡£¡¡¡¡

Knee¡­jerk¡¡reactions¡¡are¡¡those¡¡where¡¡when¡¡you¡¡encounter¡¡a¡¡bug£»¡¡you¡¡fix¡¡the¡¡bug¡ªno¡¡more¡¡and¡¡¡¡

no¡¡less¡£¡¡Instead£»¡¡you¡¡should¡¡figure¡¡out¡¡what¡¡the¡¡bug¡¡is¡¡trying¡¡to¡¡tell¡¡you¡£¡¡The¡¡original¡¡bug¡¡with¡¡¡¡

the¡¡leading¡¡whitespace¡¡was¡¡not¡¡a¡¡whitespace¡¡bug£»¡¡but¡¡a¡¡bug¡¡that¡¡was¡¡saying£»¡¡¡°Hey£»¡¡what¡¡if¡¡my¡¡¡¡

text¡¡is¡¡not¡¡aligned£»¡¡or¡¡part¡¡of¡¡a¡¡sentence£»¡¡and¡¡so¡¡on£¿¡±¡¡

¡¡¡¡¡¡¡¡¡¡¡¡To¡¡solve¡¡the¡¡bug£»¡¡you¡¡don¡¯t¡¡write¡¡code£»¡¡but¡¡you¡¡think¡¡of¡¡all¡¡of¡¡the¡¡tests¡¡that¡¡your¡¡code¡¡needs¡¡¡¡

to¡¡pass¡£¡¡You¡¡need¡¡to¡¡assign¡¡responsibility¡¡and¡¡define¡¡contexts¡¡that¡¡succeed¡¡and¡¡fail¡£¡¡In¡¡the¡¡¡¡

translation¡¡example£»¡¡the¡¡appropriate¡¡implementation¡¡approach¡¡would¡¡be¡¡to¡¡write¡¡the¡¡tests¡¡¡¡

before¡¡writing¡¡the¡¡code¡£¡¡Table¡¡3¡­1¡¡shows¡¡the¡¡contexts¡¡that¡¡fail¡¡and¡¡succeed¡£¡¡



Table¡¡3¡­1¡£¡¡Appropriate¡¡Tests¡¡for¡¡the¡¡Translation¡¡Program¡¡



Test¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Verification¡¡Result¡¡



allo¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Success¡¡



¡¨¡¡allo¡¡¡¨¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Success¡¡



word¡¡allo¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Fail£º¡¡you¡¡can¡¯t¡¡translate¡¡a¡¡single¡¡word¡¡without¡¡translating¡¡the¡¡other¡¡words¡¡



word¡¡allo¡¡word¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Fail£º¡¡same¡¡reason¡¡as¡¡with¡¡word¡¡allo¡¡



prefixallo¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Fail£º¡¡different¡¡word¡¡


¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­Page¡¡86¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­¡­

64¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡CH¡¡AP¡¡T¡¡E¡¡R¡¡¡¡¡¡3¡¡¡¡¡¡¡ö¡¡¡¡¡¡¡¡L¡¡E¡¡A¡¡R¡¡N¡¡IN¡¡G¡¡¡¡¡¡AB¡¡OU¡¡T¡¡¡¡¡¡ST¡¡R¡¡I¡¡N¡¡G¡¡¡¡¡¡M¡¡A¡¡N¡¡I¡¡P¡¡U¡¡L¡¡AT¡¡IO¡¡N¡¡S¡¡¡¡¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Table¡¡3¡­1¡£¡¡Appropriate¡¡Tests¡¡for¡¡the¡¡Translation¡¡Program¡¡£¨Continued£©¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Test¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Verification¡¡Result¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡alloappend¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Fail£º¡¡different¡¡word¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡prefixalloappend¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Fail£º¡¡different¡¡word¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡As¡¡you¡¡can¡¡see¡¡in¡¡the¡¡table£»¡¡most¡¡test¡¡cases¡¡are¡¡failures¡¡because¡¡the¡¡translation¡¡ponent¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡is¡¡meant¡¡to¡¡translate¡¡single¡¡words¡¡only¡£¡¡The¡¡test¡¡cases¡¡seem¡¡plete£»¡¡but¡¡in¡¡fact£»¡¡we¡¡are¡¡missing¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡one¡¡more¡¡set¡¡of¡¡cases£»¡¡which¡¡are¡¡outlined¡¡in¡¡Table¡¡3¡­2¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Table¡¡3¡­2¡£¡¡¡¡The¡¡Missing¡¡Test¡¡Cases¡¡for¡¡the¡¡Translation¡¡Program¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Test¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Verification¡¡Result¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Allo¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Success¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¨¡¡allO¡¡¡¨¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Success¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Text¡¡can¡¡contain¡¡mixed¡¡cases£»¡¡and¡¡from¡¡a¡¡human¡¡perspective£»¡¡mixed¡¡case¡¡is¡¡still¡¡the¡¡same¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡word¡£¡¡However£»¡¡the¡¡puter¡¡considers¡¡mixed¡¡case¡¡as¡¡a¡¡pletely¡¡different¡¡buffer£»¡¡and¡¡so¡¡we¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡must¡¡be¡¡able¡¡to¡¡cope¡¡with¡¡this¡¡situation¡£¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Figure¡¡3¡­9¡¡shows¡¡the¡¡working¡¡solution¡£¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Chaining¡¡ToLower£¨£©¡¡and¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Trim£¨£©¡¡together¡¡first¡¡obtains¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ToLower£¨£©¡¡returns¡¡a¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡the¡¡result¡¡of¡¡ToLower£¨£©¡¡and¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡lowercase¡¡copy¡¡of¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡then¡¡applies¡¡Trim£¨£©¡¡to¡¡it¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡the¡¡original¡¡string¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡Class¡¡Translator¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Public¡¡Shared¡¡Function¡¡TranslateHello£¨ByVal¡¡input¡¡_¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡As¡¡String£©¡¡As¡¡String¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡temp¡¡As¡¡String¡¡=¡¡input¡£ToLower£¨£©¡£Trim£¨£©¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡If¡¡temp¡£pareTo£¨¡¨hello¡¨£©¡¡=¡¡0¡¡Then¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Return¡¡¡¨hallo¡¨¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ElseIf¡¡temp¡£pareTo£¨¡¨allo¡¨£©¡¡=¡¡0¡¡Then¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Return¡¡¡¨hallo¡¨¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡If¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Trim£¨£©¡¡removes¡¡whitespace¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Return¡¡¡¨¡¨¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡Function¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡End¡¡Class¡¡



¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Figure¡¡3¡­9¡£¡¡¡¡The¡¡final¡¡trans
·µ»ØĿ¼ ÉÏÒ»Ò³ ÏÂÒ»Ò³ »Øµ½¶¥²¿ ÔÞ£¨0£© ²È£¨0£©
¿ì½Ý²Ù×÷: °´¼üÅÌÉÏ·½Ïò¼ü ¡û »ò ¡ú ¿É¿ìËÙÉÏÏ·­Ò³ °´¼üÅÌÉ쵀 Enter ¼ü¿É»Øµ½±¾ÊéĿ¼ҳ °´¼üÅÌÉÏ·½Ïò¼ü ¡ü ¿É»Øµ½±¾Ò³¶¥²¿!
ÎÂÜ°Ìáʾ£º ο´Ð¡ËµµÄͬʱ·¢±íÆÀÂÛ£¬Ëµ³ö×Ô¼ºµÄ¿´·¨ºÍÆäËüС»ï°éÃÇ·ÖÏíÒ²²»´íŶ£¡·¢±íÊéÆÀ»¹¿ÉÒÔ»ñµÃ»ý·ÖºÍ¾­Ñé½±Àø£¬ÈÏÕæдԭ´´ÊéÆÀ ±»²ÉÄÉΪ¾«ÆÀ¿ÉÒÔ»ñµÃ´óÁ¿½ð±Ò¡¢»ý·ÖºÍ¾­Ñé½±ÀøŶ£¡