From: Ara.T.Howard@... Date: 2004-10-05T01:05:05+09:00 Subject: Re: Too Many Ways? On Mon, 4 Oct 2004, David A. Black wrote: > I have to admit (and my lack of C++, Java, etc. is probably showing through > here -- i.e., I'm perfectly willing to believe there's something fundamental > I'm just missing), I have never understood the idea of differentiating > methods by number of arguments. To me it's sort of like differentiating > them based on what letters the argument names begin with. What if two > slightly different forms of the method both, by chance, took three > arguments? Would one add a dummy argument? no - because you would also have a different signature (else the methods wouldn't be 'slightly different' (probably) : // // move from src to preallocated dest - leaving src untouched // int move (const char * const src, const char * dest); // // move from src to dest - creating dest and freeing src // int move (char * src, char * dest); the idea is this - the compiler can tell you two things about your methods at compile time : the types of the arguments and the number of them. it can use this infomation to generate a case statement for you - eg it can know which one to call freeing you from writing code like case argv.size when 2 arg0, arg1 = argv case arg0 when String ... end when 3 ... ... end you get the picture. i think it's more of an artifact of "this is everything the compiler can possible know and we make this functionality availible for you since it's there anyhow" rather than "we've implemented this handy feature through blood sweat and tears". add to this the fact that variadic functions are quite painful to write in a platform neutral way in c or c--. > The whole thing has always seemed to me like a gimmick/workaround for > languages with design problems. i think it's more the compiler than the language itself. bascially the only other way to do it would be so say - i'll just pass you everyting on the stack and you can do what you want with it (variadic functions). the problem there is that, due to lack of rtti, you cannot also know the types of you arguments (witness format strings in printf) and so you must completely disgard type safety and simply blind cast all args to their types. this will core dump, of course, if done incorrectly. i'm not saying it can't be done in a compiled lang. (take ocaml for example - which boxes vars similarly to ruby) - just that the problem is, to a large degree, stemming from the compiler design and not the lang design itself. for example, a compiler could box all vars and make this info availible to the runtime - in fact, i think there is a 'typeof' macro (or maybe this is the compile time one - if forget) for gnu c-- that does tell you runtime type. (if this were about ruby i'd look it up and paste some example code but i care so little about knowing any more c-- i couldn't even be bothered). > (Again, all based on gut reaction and probably not enough education....) i really don't think you want to get 'educated' on this topic. ;-) kind regards. -a -- =============================================================================== | EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov | PHONE :: 303.497.6469 | A flower falls, even though we love it; | and a weed grows, even though we do not love it. | --Dogen ===============================================================================