2 ms·
It appears you are doing this because you are never really sure what sort of data is being sent to your application. I would dump this sort of idea in favor of
by johnnymonster 13y ago
It appears you are doing this because you are never really sure what sort of data is being sent to your application. I would dump this sort of idea in favor of schema validation. if you are going to get data from a client application where the client developer can screw up the data, why not just validate the data as a whole before accepting it then you know your structure.
I really just can't stand all the type checking all over the place, it makes the code feel like all your reading is type checking and not the real logic of what is going on in this function.
Additionally, returning an empty string when i mess up a data structure is horrible for debugging. I would have to actually go into the code now to figure out why an empty string came back instead of processing as I thought it should.
if your really worried about exposing errors to the end user. wrap that whole thing up in a try catch block instead, log an error and don't display anything to the end user.
- macspoofing 13y ago>It appears you are doing this because you are never really sure what sort of data is being sent to your application. He's doing this because he wants type safety in his functions. If you have that, you eliminate one source of bugs. >I really just can't stand all the type checking all over the place, it makes the code feel like all your reading is type checking and not the real logic of what is going on in this function. That's a big problem with his approach. It's not scalable, and you can't rely on it (inevitably, developers will take shortcuts and you're going to have a hodgepodge of type checks littering your code). He might as well use TypeScript or Dart or Google Closure Compiler. >I would have to actually go into the code now to figure out why an empty string came back instead of processing as I thought it should. Problem number two with his approach. He doesn't actually have compile-time checks which is where you want your type-checks to be. Instead it's all run-time (and he ignores the errors), which raises the question, what the heck is he actually gaining from all this? Again, he should just use TypeScript or Dart or Google Closure Compiler.