[Ilugc] [TIP] perl tutorial II (conditionals and looping)

  • From: suraj@xxxxxxxxxxxxx (Suraj Kumar)
  • Date: Sun, 4 Dec 2011 07:50:05 +0530

On Sun, Dec 4, 2011 at 6:48 AM, Girish Venkatachalam <
girishvenkatachalam at gmail.com> wrote:

Most of perl's conditionals are written using the regex construct:


That is not true. Like all conditionals, it depends on the program's
context... and program's context is entirely dependent on the programmer.

Good programmers don't use regexes for everything (especially "most
conditionals") because it makes it
   1. difficult for other programmers to sit through and figure out what
the regex is trying to do
   2. difficult to be precise, there could be many possible matches
   3. impossible to separate implementation logic from business logic
   4. (CPU-wise) expensive to do something that could have been better
designed with alternate, non-english based approaches

Regexes make for some shabby, unmaintainable code. Use regexes only when
absolutely necessary. For most machine-machine communication, there are
well defined data interchange formats than human language that needs "regex
parsing" (data interchange/serialization formats such as YAML, JSON, XML,
etc.,). For most human-machine communication, there are MVCs (like perl
Catalyst) that let you separate business logic from the data representation
and user interaction. You can still use regexes, but such frameworks
minimize your urge (as perl "scripters") to use regexes and other bad
practices.

More than raw language skills, good practices make good programmers.

Cheers,

  -Suraj

-- 
Career Gear - Industry Driven Talent Factory
http://careergear.in/

Other related posts: