From: Martin Man Date: 2002-02-16T20:51:17+09:00 Subject: Arguments' positions ambiguity (Was: Keyword arguments) --ibTvN161/egqYuK8 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sat, Feb 16, 2002 at 12:33:23AM +0900, Paul Brannan wrote: > On Fri, Feb 15, 2002 at 08:09:15AM +0900, Martin Man wrote: > > IMHO (after having worked with Objective-C in the past) the above=20 > > problem with > > File.open et al, can not be solved by using keyword arguments as propos= ed > > above. >=20 > I'm not sure I follow your logic. It sounds like you are advocating > keyword arguments, but then you say that they don't solve the problem? > Why, then, would I want to use keyword arguments? well, what I wanted to say was that simply implementing keyword arguments= =20 "the Ruby Way" does not resolve the ambiguity with arguments' positions smalltalk --------- in smalltalk you have the fixed position of arguments and their fixed names and you are forced (in positive way) to call methods (or send messages to objects) that way, see the example from avi@beta4.com (Avi Bryant) avi> I am a huge fan of Smalltalk's keyword syntax - it allows a method to avi> have lots of meaningfully named minute variations (my favorite example avi> is the trio of Dictionary methods at:, at:ifAbsent:, and avi> at:ifAbsentPut: - try finding this last method in any other language) avi> and has a nicely self-documenting rhythm. so I'll add example from pseudo ruby - objective-c dict =3D [Dictionary new] =20 print [dict at: 1], [dict at: 2 ifAbsent: "number two is missing"],=20 [dict at: 4 ifAbsentPut: "four"] =20 this would produce something like this (without colons, etc.) nil, number two is missing, four ruby ---- ruby already has ability to name arguments and exchange them, e.g. File.open (name =3D "xxx", mode =3D "yyy"),=20 =2E..., implementation enabling keyword arguments will add another wonderfull possibilites to generate funtion argument names dynamicaly, because they'll just be symbols, e.g. sym =3D :mode File.open (name =3D "xxx", sym =3D 0777) =2E., BUT, that does not resolve in any way the original problem with swapp= ed arguments of function (File.open (name, flags, mode) instead of File.open (name, mode, flags), or the other way around :-)) unless you force the developer to explicitely name each and every argument passed to the functio= n. take for example this snipet extracted from somewhere around testgtk.rb main_vbox =3D Gtk::VBox.new frame_horz =3D Gtk::Frame.new("Horizontal Button Boxes") self.border_width =3D 10 self.add(main_vbox) main_vbox.pack_start(frame_horz, true, true, 10) being fun of gtk, but lacking gtk documentation ATM, I can somehow deduce what's going to happen till I reach the call to main_vbox.pack_start, do te= ll me what do you imagine this method is trying to acheive without looking to = the docu. and now see how probably would the same code look in obj-c main_vbox =3D [VBox new] frame_horz =3D [[Frame new] setTitle: "Horiz ...."] [[self setBorderWidth: 10] add: main_vbox] [main_vbox packWidget: frame_horz expand: true fill: true padding: 10] doesn't that read much better ?? (or at least a bit better :-)) and the ruby way with symbols main_vbox.pack_start (:child =3D> frame_horz,=20 :expand =3D> true, :fill =3D> true, :padding =3D> 10) also not bad, but I'm starting to smell some line-noise there :-) >=20 > Paul >=20 rgds, martin --=20 1024D/6E060223 2CC0 4AF6 92DA 5CBF 5F09 7BCB 6202 7024 6E06 0223 http://mman.dyndns.org/mman.gpg --ibTvN161/egqYuK8 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 iD8DBQE8bkb1YgJwJG4GAiMRAounAJ9RCLaETsGTmMRMuHkuBYxCrlxYKACgoh9U 9Uqz90nk+B34Dw9D9zQxcJw= =Fu85 -----END PGP SIGNATURE----- --ibTvN161/egqYuK8--