XP is just a number | |
PerlMonks |
C# reinvents @_by stefp (Vicar) |
on Sep 19, 2001 at 03:43 UTC ( [id://113241]=perlmeditation: print w/replies, xml ) | Need Help?? |
It is no better to be the man of one language than to be the man of one book. So I am studying C# and find it quite to my taste. No small feat after too much Perl programming:
C feels too low level. C++ is too complicated. Java is just bondage. The problem with a new language is: one wants his favorite idioms to translate readily. So what about @_ in C#? I love @_ (and I hate it, but I know how to use a hash ref if I want to have some equivalent of named parameters). The idea is that the caller passes as many parameters as it wants. The caller gets them in @_ and figures out what to do with them. You knew that. :) So I was curious to see how this idiom of using an implicit array translates in C#. the params keyword indicates that an unknown nunber of parameters can be used for the calling of the function foo and that they will be available in the callee in the vals array. In C you would have to use va_start(),va_arg(), va_end(). Neither Java, nor C++ have foreach keyword, so they must use an explicit iterator object. I am too lazy to write the equivalent Java code. Too ugly. you may want to read A comparative overview of C#. -- stefp A unix fan that likes a MS product. Everything happens!!
Back to
Meditations
|
|