From: Andreas Schwarz Date: 2004-08-23T23:40:43+09:00 Subject: [typo] Re: How to check syntax Andreas Schwarz wrote: > Graham Nicholls wrote: > >> Andreas Schwarz wrote: >> >> >>> Graham Nicholls wrote: >>> >>> >>>> OK, so its not a syntax error. Pedants :-) There ought to be a >>>> utility to >>>> look for variable references, etc. >>> >>> >>> This is almost impossible in dynamic languages like ruby. Variables can >>> be defined everywhere, in eval(), conditional code, etc. You don't find >>> out until you execute it. >> >> >> I had a feeling that this was the case. >> >>> > Now, I realize that this may be hard as >>> >>>> its presumably akin to part of writing a compile. What I'd like to >>>> know, >>>> then is how to avoid the above - its a real nuisance in "scripting >>>> languages" (Oh and if you don't like that term, get over it - you know >>>> what I mean, python, perl(ugh!) Ruby & the like) >>> >>> >>> Use unit tests. >> >> >> Could you elucidate. Typically this is pretty small stuff - my larger >> projects tend to be coded in C, although unit testing can presumably be >> applied there. >> >> Heres a slice of code: >> >> ,----[ /home/graham/src/hsb/add_logo ] >> | #!/usr/bin/env ruby >> | # >> | =begin >> | Parse an input file (which is intended to be an Informix -produced text >> | file containing PCL escape sequences) for a pattern which will >> introduce a >> | logo. The pattern looks like this: > > [...] > >> As you can see, theres not much to it - an hours work or so - I'd >> rather not >> have to spend much time writing testing - ISTM its easier to fix a bug >> when >> it rears than spend ages trying to eliminate all possible bugs > > > Your example seems to be very easy to test; feed it a few different > files and compare the output to the expected result. This is especially > helpful to make sure that you DON'T > break anything when you change the code.