One of the most frequent comments in The Scripting Games this year was along the lines of, "you should have submitted this as a function, not a script." Of course, the second-most frequent comment was something like, "you shouldn't have submitted this as a function."
Let's be clear: if an assignment explicitly asks for a function, you should write one. What we're debating are the pros and cons of aÂ single tool being written one way or another. Read that again:Â a single tool.Â If you're writing a library of tools, it's obvious that writing them as functions for inclusion in a single file (like a script module) is beneficial.
Some argue that any tool is potentially going to be included in a function... so why not write it that way to begin with? Others argue that functions are a smidge harder to test, so why not just write a script?
This is a debate I don't personally have a strong stake in. I mean, we're literally talking about aÂ single keyword.Â TakeÂ any script, add theÂ function keyword, a function name, and a couple of curly brackets, and you've got a function. This really shouldn't be a criteria when you're looking at a contest entry... or even when you're looking at something a colleague offered to you.
Or should it?