From: Martin Man Date: 2002-02-15T08:09:15+09:00 Subject: Keyword arguments (Was: File.open weirdness) --3V7upXqbjpZ4EhLz Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Feb 15, 2002 at 04:59:23AM +0900, Craig Files wrote: > "David Alan Black" wrote: > >=20 > > Put the permissions after the mode :-) > >=20 > Thanks, this is contrary to the information in the "Programming Ruby" > book, where the example for File.new shows the permissions before the > mode. >=20 hi all, sorry to bother you once again with keyword arguments, but previous example with File.open clearly shows the need for change. I've searched the archves and checked TODO in ruby's cvs repository and found two syntax proposals. func(:arg1 =3D xx, :arg2 =3D yy) func(arg1: xx, arg2: yy) I like the second one more because it's less verbose, but IMHO (after having worked with Objective-C in the past) the above problem w= ith File.open et al, can not be solved by using keyword arguments as proposed above. Assuming the arguments of a function must be named,=20 e.g. the symbol for respective argument of a function must always be present File.open (name: "xxx", mode: 0yyy) and the old-C-style syntax=20 File.open ("xxx", 0yyy) is forbidden (just hypothesis), we surely gain a lot, cause these stupid and time-consuming mistakes like the one above can't happen anymore, because we force the developer to name the arguments, but at the same time we make a develper completely confused because he/she still must remember what the ar= gs for a function are (because they still can be swapped), e.g. File.open (mode: 0yyy, name: "xxx") And now see the beauty of smalltalk's position-fixed-named-arguments syntax (something that even lisp doesn't have) [File open: "xxx" withMode: 0yyy] The general syntax here (that you all obviously know :-))) is [receiver message: arg1 withArg: arg2 anotherArg: arg3 andYetAnother: arg4] to compare, in ruby we have receier.message (arg1, withArg: arg2, andYetAnother: arg4, anotherArg: arg3) another hypothetical example with GUI MessageBox.question ("Quit ?", windowTitle: "Are you sure...?") compared to [MessageBox question: "Are you sure...?" windowTitle: "Quit ?"] =2E..what do you think guys about all that stuff, looking forward to hear s= ome objections... :) thanx for reading so far, and thanx for cool programming language :-) martin --=20 1024D/6E060223 2CC0 4AF6 92DA 5CBF 5F09 7BCB 6202 7024 6E06 0223 http://mman.dyndns.org/mman.gpg --3V7upXqbjpZ4EhLz Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.6 (GNU/Linux) Comment: For info see http://www.gnupg.org iD8DBQE8bEMTYgJwJG4GAiMRAlw6AJ0WuhxOQok9iW+muvn5b/dTtrZ2eACgmK4P fGcN5WQ8iMmRiwnt4xwmFLs= =Iwyc -----END PGP SIGNATURE----- --3V7upXqbjpZ4EhLz--