Jonathan S. Shapiro wrote:
> As I sent earlier from my cell, I'm not convinced about keyword
> arguments on procedures, but here is something mildly relevant:
>
Hi,
Keyword arguments is a very important feature, especially when dealing
with low-level code as well as in game-code. The reason is that one
tends to make functions that take many parameters, and it is a royal
pain in the butt to manage all of the parameters. Here's an example from
our Goal language:
(with-cnt-vif-block (dma-buf :vif1 (new static vif-tag :cmd
(vif-tag-type flusha)))
(dma-buffer-add-uint64 dma-buf
(new static gif-tag64 :eop 0 :nloop 1 :nreg 2 :flg
(gif-flag reg-list))
(gs-reg-list prim rgbaq)
(new static gs-prim :prim (gs-prim-type sprite) :abe 1 :tme 1)
clr
(new static gif-tag64 :eop 1 :nloop num-strips :nreg 4 :flg
(gif-flag reg-list))
(gs-reg-list st xyz2 st xyz2)
)
The interesting to notice here, is that with keyword arguments (here
only for the constructor form (new static ...)) the code gets much more
readable.
The equivalent C/C++ code for (new static gif-tag64 :eop 1 :nloop
num-strips :nreg 4 :flg (gif-flag reg-list)) would be something like:
pDmaBuffer->Append(MakeGifTag64(numStrips, 1, 0, 0, 0, kGifRegList, 4));
Which is quite frankly quite unreadable, or alternatively using a union
(probably most readable in C):
GifTag64 gifTag64;
gifTag64.nLoop = numStrips;
gifTag64.eop = 1;
gifTag64.id = 0;
gifTag64.pre = 0;
gifTag64.prim = 0;
gifTag64.flg = kGifRegList;
gifTag64.nreg = 4;
*pDmaBuffer = gifTag64.value;
pDmaBuffer++;
As you can see, having keyword arguments (with default arguments) helps
tremendously in these cases.
Thanks,
PKE.
--
Pål-Kristian Engstad ([email protected]),
Lead Graphics & Engine Programmer,
Naughty Dog, Inc., 1601 Cloverfield Blvd, 6000 North,
Santa Monica, CA 90404, USA. Ph.: (310) 633-9112.
"Emacs would be a far better OS if it was shipped with
a halfway-decent text editor." -- Slashdot, Dec 13. 2005.
_______________________________________________
bitc-dev mailing list
[email protected]
http://www.coyotos.org/mailman/listinfo/bitc-dev