|
Type checking ... I'm with Hal on this one. See his newsletters on the
issue at halhelms.com if you haven't already. If you're going to do type checking in a situation where you don't have absolute control over the type, then you need a mechanism to deal with situations where the type might be incorrect - probably an error handling routine at the point where you call the method (the one with an argument that is strongly typed). Now, if it's possible that the type could be incorrect in normal application flow, then error handling is most likely the wrong approach. Error handling should be reserved for exceptional situations. Then you need some sort of filtering code deciding "well, if it's numeric, then call the method that requires a numeric argument. If it's not, then do something else." If you open up your argument to "any", then you can do that checking within the method. Which might make more sense. Why delegate part of a method's or an object's responsibility to another bit of code when probably the method should be able to deal with the matter itself? I think sometimes we assume that typing an argument is the same as checking that an argument meets our criteria. It isn't. Typing an argument throws a runtime error in ColdFusion. It's for exceptional situations. Again, if what you are trying to achieve is to check an argument to see if it matches your criteria, you probably should use IsNumeric() either before you call the method or after so you have a mechanism to deal with it. I say "probably" because i think that using error handling for normal application flow is probably bad practice. Now, in the case you use IsNumeric() for instance before you call the method to handle normal application flow, what good is it to type the method as a numeric? And if you use type="any" and check the argument to see if it's numeric after it's passed in, well, you're not typing the argument as numeric. (So what good is it?!) In my opinion, if a strongly typed method "blows up" during development, it's probably not an exceptional case that should trigger an error, like your database server dying or CF heading into a reboot. And ... even if it is an exceptional case, either the error is going to say "such and such argument is not of the correct type" or it going to say "arguments.suchAndSuch is not numeric" when your query is expecting a numeric argument. So all that said, what good is typing in ColdFusion? Since it's compiled at runtime, if something goes wrong, either you get a runtime error if it's strongly typed or you get a runtime error if it isn't ... Unless you use code like IsNumeric() to establish application flow for unusual but anticipated cases, and then typing isn't really needed, or can't be used. Now i'm not saying that strongly typing an argument is never useful. But i do feel that it's usefulness in CF is much more rare than in a strongly typed, pre-compiled language like Java where your code won't compile if you've made a mistake and tried to pass a variable typed as a string into an argument that accepts only numerics. But you can't do that in ColdFusion, because a) you can't strongly type a variable and b) it's compiled at runtime. Aaron Roberson wrote: It seems that every time I create a cfc with arguments other than |
- [CFCDev] Need Help with Arguments in CFCs Aaron Roberson
- Re: [CFCDev] Need Help with Arguments in CFCs Nando
- RE: [CFCDev] Need Help with Arguments in CFCs Jason Daiger
- RE: [CFCDev] Need Help with Arguments in CFC... Peter Bell
- Re: [CFCDev] Need Help with Arguments in CFC... Nando
- Re: [CFCDev] Need Help with Arguments in... Aaron Roberson
- RE: [CFCDev] Need Help with Arguments in... Jason Daiger
- RE: [CFCDev] Need Help with Arguments in CFCs Nolan Erck
- Re: [CFCDev] Need Help with Arguments in CFCs Aaron Roberson
- RE: [CFCDev] Need Help with Arguments in CFC... Peter Bell
- Re: [CFCDev] Need Help with Arguments in... Aaron Roberson
- RE: [CFCDev] Need Help with Arguments in CFCs Kadrioski, Darin

