RE: pass by reference
- Posted by bensler at mail.com Feb 20, 2002
- 470 views
I think you misunderstood, The question was not "Why would I want to use typechecking", but "why would I want to use typechecking to make my program crash" Typechecking would make more sense if we could modify the variable in question. Alot of the times, you would be able to change the variable being typechecked to a default value. This would save your program from crashing. As a customer who purchases software, I would be appalled to run a program that I paid money for, to have it crash with some error message that doesn't help me at all. Reminds me of Microsoft :P It makes alot more sense to at least ATTEMPT to rectify the problem before resorting to the BLACK screen of death. Let's face it. EVEN IF you write a program that is 100% error free, it's usually the user who is the cause of the error. And if I'm distributing a program, I want to be sure that I can minimize any program/user errors. There are lots of other uses for typechecks that can mutate it's variable. For example: In exoticaX, I have incorperated the ability to pass either a RGB sequence, OR a color value (atom) to the routines. The routines, in turn, have to determine if it's RGB or a Color value, and convert it if nessecary. There are about 50 or more routines in exotica which take a color parameter. That's about 50 lines or more of mundane code to type and make typing mistakes in. If I could mutate the variable from a type check, all I would need is a type defined like this: type color(object c) if sequence(c) then c = make_rgb(c) end if return 1 end type and then in my routines, all I need is this: procedure some_routine(color c) end procedure I should say, that my suggestion is to have pass by reference ONLY for type checking, not general routines. Like goto, pass by reference, CAN be a good thing, but on the whole, I think it's more detrimental than helpful. Makes for lots of oversights, having to check if a routine is going to modify the variable you pass it or not. Pass by reference isn't nessecary for routines, as you can just use a function. It's alot safer and easier to understand/read. Chris tone.skoda at siol.net wrote: > > ----- Original Message ----- > From: <bensler at mail.com> > > > Why on EARTH do I want to type check my variables only to make my > > program crash 'elegantly', albeit better than the current alternative(no > > type checks). > > With type checking your code fails sooner (when it would fail any way > only > at some other place) and you are closer to the source > of your problem. You find out what's wrong in less time. Faster > debugging. > Same with assert in C. > >