Re: Constructing sequences

new topic     » goto parent     » topic index » view thread      » older message » newer message

On Tue, 28 Jun 2005 20:05:31 +0400, Igor Kachan <kinz at peterlink.ru>
wrote:

Please don't do this:
F=machine_func(22, name) -- dir
       ...
	if machine_func(19,{fn,-1}) then end if   --seek
	   F=repeat(0, machine_func(20,fn))       --where
	if machine_func(19,{fn,0}) then end if    --seek

It costs absolutely nothing to define
constant M_SEEK  = 19,
	 M_WHERE = 20,
	 M_DIR   = 22,

And hence (at the very least) code:
F=machine_func(M_DIR, name)
	...
	if machine_func(M_SEEK,{fn,-1}) then end if
	   F=repeat(0, machine_func(M_WHERE,fn))
	if machine_func(M_SEEK,{fn,0}) then end if

If you can show a (run-time) difference, I'll eat my hat, and even the
saving of a routine call is highly questionable, as of course it goes
without saying that
F=dir(name)
	...
	void = seek(fn,-1)
	F=repeat(0,where(fn))
	void = seek(fn,0)

is far, far, far more readable (given that I have only copied relevant
lines so the above does not entirely cohere), and, again, in a
practical real-world example if you can show any measurable gain,
I guess I'll eat my other hat.

>But dir() is not that bad too, I think.
>Adds just a small fraction of one millisecond
>to the process, but gives very clear code.
I wholeheartedly agree. Your example does show an overhead of calling
dir() 5000 times, but very few real-world programs will do that.

Use code which is readable, even when you need it to be fast.

Regards,
Pete

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu