|
Posted by Phlip on 09/17/05 15:22
www.douglassdavis.com wrote:
> PHP
Is it too late to switch to Ruby?
That's not a joke; it's an excellent language that will lead to very elegant
solutions here.
> My delima is this... let's say you wanted to do something like this in
> a class, and you needed all 3 of these vars to be defined.
>
> class MyClass4
> {
> var $one = array(1,2);
> var $two = array(3,4);
> var $three= array($one, $two); // a two dimensional array.
> // ... more code below
> }
>
> But you knew that these would always remain the same, and there was no
> need for putting them in every class. Meaning, if they are not static,
> it's just a waste of space.
Premature optimization is the root of all evil. In this case, if you need an
object, even as a compilable comment, create an object.
Put another way, it's easier to make clean code fast than make fast code
clean. Clean code is easy to read and understand. Create an object that
duplicates its instances of these heavy members. Then get your program to
work, and then think about _explicitely_ replacing the heavy members with
references to shared single instances of their data.
> Also, there are no static initializer blocks like java.
Write them yourself. In Ruby, they would be...
@@one ||= [1,2]
one is a class variable, and if it's not assigned yet then create an array
and plug it in.
--
Phlip
http://www.greencheese.org/ZeekLand <-- NOT a blog!!!
[Back to original message]
|