|
... easy answer: use type="any" Why? because CF is a dynamically typed language, and it seems from your description that you've got an argument where dynamic typing comes into play. So using "any" would be correct. If you believed that there was only the possibility that a date could be passed into this function during normal application flow and typed the argument type="date", CF would throw a runtime error if somehow the thing being passed into the function wasn't a date. On the other hand, if you typed the argument "string" or "any", but still expected it to be a date that was passed in, CF would again throw a runtime error if somehow the thing being passed into the function wasn't a date, but this time it would be on your DateFormat() function. In a general sense, either ColdFusion throws a runtime error or it throws a runtime error. So in what way does strong typing the argument help you in this particular situation? It doesn't. In the end, strong typing your arguments only seems to be useful in CF if you want to force CF to throw an error before the function is run in an exceptional situation. Maybe you wouldn't want a function to complete only half it's job - it would leave your app in an unstable state. So better to throw the error beforehand than in the middle somewhere. Otherwise, in situations where you've got dynamic typing in play, I would use type="any" and deal with normal application flow within the function. I know we use variable names like "myDate", but we need to remember that in many cases, that variable is dynamically typed, so it's actually representing something like "myDateOrStringOrEmptyString" Strongly typed arguments aren't as useful or helpful as they might seem in a dynamically typed language that is compiled at runtime and doesn't support null. Phillip Senn wrote:
|
- [CFCDev] Re: MachII Plugin... Greg Brown
- Re: [CFCDev] Re: MachII Plugin... Matt Williams
- Re: [CFCDev] Re: MachII Plugin... Peter J. Farrell
- Re: [CFCDev] Re: MachII Plugin... Peter J. Farrell
- Re: [CFCDev] Re: MachII Plugin... Greg Brown
- Re: [CFCDev] Re: MachII Plugin... Peter J. Farrell
- Re: [CFCDev] Re: MachII Plugin... Greg Brown
- Re: [CFCDev] Re: MachII Plugin... Matt Woodward
- Re: [CFCDev] Re: MachII Plugin... Greg Brown
- Re: [CFCDev] Easy question Charlie Griefer
- Re: [CFCDev] Easy question Nando
- RE: [CFCDev] Easy question Phillip Senn

