Object oriented or structured - a comparison in Python. Also writing clean regular expressions
Archive - Originally posted on "The Horse's Mouth" - 2012-03-26 23:50:53 - Graham Ellis
Should I go "object oriented" with my code, or use functional coding? That's a big question, and the answer depends on the application you'll be writing, the language you'll be writing it in, the programmers concerned, the expected life cycle of the application, and whether you'll be able to reuse exising code or reuse your new code for other applications. Please discuss this with me during your course ;-)
At times, the two idioms turn out to be not quite as different as you may think - from last week's Python course, [here] is an example of a Python program that uses object (static) variables in structured programming way to save data between function calls, and [here] is an example - all be it much extended - that retains data within an object.
One of the complaints about regular expressions is that they're hard to read back later. And one of my complaints about many people who write regular expressions is that they make them hard to read back later.
In some languages, it's not natural to split regular expressions into readable, bite size sections - but it is in Python - there's an example [here] from last week's Python course.