[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Drawing the line between speed and simplicity/elegance
- From: Sean Conner <sean@...>
- Date: Thu, 7 May 2015 01:33:28 -0400
It was thus said that the Great Brigham Toskin once stated:
> I apologize if this is kinda long; I'll try to compress. First, my
> I've been working on a stack-based language, implemented in Lua. Being a
> C++ programmer, my first impulse was to wrap an array table with some ADT
> metamethods. After some futzing, my stack relatively fast, but fairly
> complicated for what it ultimately is—a LIFO.
As long as you can avoid nil, then table.insert() and table.remove()
implement a LIFO stack (since both default to the last position). That is:
push = table.insert
pop = table.remove
How much more compilicated is your ADT?
> The more general question: Where do we draw the line between writing simple
> code, and performance? Or phrased another way, how slow is too slow, for
> the sake of an elegant design? When I optimized the ADT code, it got uglier
> and more complex. When I optimized the coroutine prototype, it got simpler
> and more elegant.
If you can't get the answer/support the load with the current
implementation, then it's time to optimize, with one exception: when the
optimization doesn't change the code that much. For instance, lifting a
constant expression out of a loop (which Lua doesn't seem to do) as