Method Arguments In Ruby(skorks.com)
skorks.com
Method Arguments In Ruby
http://www.skorks.com/2009/08/method-arguments-in-ruby/
4 comments
I wonder why such a simple topic is in the top ten of HN? Is that stuff not more or less obvious? I mean for people working with Ruby?
I have been finding more and more that things which are obvious to some are not necessarily obvious to others. Not everyone is a guru in every skill and everyone has to start as a newbie with all new skill you learn.
What about for people who are not working with Ruby but are curious about how it compares? How about those who have just started working with Ruby and are just learning? Think back to the first time you started reading about Ruby, was all the info you ever wanted freely available and clearly laid out? I am betting no.
This is why these days whenever I learn anything new (or think of something I know really well), as soon as i get it straight in my own head I go and write it up. It helps me clarify it even further for myself plus, since the information is out there it may end up helping others who are learning about the same topics.
Anyway, that's how I feel.
What about for people who are not working with Ruby but are curious about how it compares? How about those who have just started working with Ruby and are just learning? Think back to the first time you started reading about Ruby, was all the info you ever wanted freely available and clearly laid out? I am betting no.
This is why these days whenever I learn anything new (or think of something I know really well), as soon as i get it straight in my own head I go and write it up. It helps me clarify it even further for myself plus, since the information is out there it may end up helping others who are learning about the same topics.
Anyway, that's how I feel.
Perl6 has a very rich set in its spec: http://perlcabal.org/syn/S06.html#Parameters_and_arguments
There are a few Perl5 ports of which MooseX::Method::Signatures is probably the best implementation: http://search.cpan.org/dist/MooseX-Method-Signatures/lib/Moo...
There are a few Perl5 ports of which MooseX::Method::Signatures is probably the best implementation: http://search.cpan.org/dist/MooseX-Method-Signatures/lib/Moo...
Java has the same types of method arguments.
C# (.NET 3.5) misses one type of method argument: the default parameter (it will be shipped with .NET 4.0). I have to admit, it happened only once that I missed default parameters in C#. however, there's a workaround to solve this problem: http://msdn.microsoft.com/en-us/library/aa287762(VS.71).aspx
C# (.NET 3.5) misses one type of method argument: the default parameter (it will be shipped with .NET 4.0). I have to admit, it happened only once that I missed default parameters in C#. however, there's a workaround to solve this problem: http://msdn.microsoft.com/en-us/library/aa287762(VS.71).aspx
> it happened only once that I missed default parameters in C#
I actually missed it lots of times. You can work around it by overloading the method, but that's boilerplate for a simple concept.
I also miss named arguments (in both Ruby and C#). When reading the code, when a method has more arguments than one I often forget what the arguments are or their positioning, and it is a lot more readable to specify the arguments by their names ...
I actually missed it lots of times. You can work around it by overloading the method, but that's boilerplate for a simple concept.
I also miss named arguments (in both Ruby and C#). When reading the code, when a method has more arguments than one I often forget what the arguments are or their positioning, and it is a lot more readable to specify the arguments by their names ...
lockfile( path = '/var/run/script', timeout = 60,
Ruby doesn't support that. It only has syntactic sugar for the case in which the argument of the method is a hash, but then the method definition becomes less clear.I totally agree with you! the code is definitely more readable. I think the object initalizer (e.g. var o = new MyObject(){ID=123};) was a step in the direction of named parameters.
however, it looks like named parameters will be shipped with .NET 4.0: http://geekswithblogs.net/michelotti/archive/2009/01/22/c-4....
however, it looks like named parameters will be shipped with .NET 4.0: http://geekswithblogs.net/michelotti/archive/2009/01/22/c-4....
It would be good to say what version of Ruby this is about.
I'm guessing it's 1.8.7, but 1.9, the current version of Ruby (though likely not the most used) offers additional (and in some cases, different) ways to manage arguments.
I'm guessing it's 1.8.7, but 1.9, the current version of Ruby (though likely not the most used) offers additional (and in some cases, different) ways to manage arguments.