Begging for a hint in app design

dear list,

with ruby you can quickly progress and suddenly I’m despaired, because I
know I have to make decisions, but I don’t know which ones :frowning:

I tried to break down the problem to its core

so the following is pseudo code. its roughly the way my application
currently works:

···

##########
#the content of the main file of the app
##########
module MyComponents
class Components # what is common to all subclasses
def initialize(args, other)
@args = args
@other = other
# do something
end
def concat()
return @args.to_s + @other.to_s
end
end
end

class MainClass
attr_reader :other
def initialize(file, compname, args, other)
@file = file
@compname = compname
@args = args
@other = other
# do something
end

    def ini_component()
            require(@file)
            puts eval("#{@comp_name.capitalize}.new(@args, @other)")
            # do something
    end

end

this is in a loop: many the instances of MainClass are build with

different parameters
test = MainClass.new(‘testcomp.rb’, ‘mycomp’, 'hi ', ‘peter’)
test.ini_component

end of loop

#here comes an example file (testcomp.rb) with a component class in it

module MyComponents
# there are pleny others of them, each class has its own rules
# but once the behaviour is defined it wont change
# (only “args” and “other” will change)
class Mycomp < Components
def initialize(args, other, specials = nil)
@specials = specials if specials
super(args, other)
# do something depending on “args” and "other"
return self.concat
end
end
end

so far from being elegant, this code kind of works.

  • I have plenty of MainClass instances and plenty of instances of subclasses
    of Components (though Im not sure, maybe a singleton is sufficient, since
    it does always the same (args and others are changing)) and the number of
    subclasses of Components will be growing as I intend to add the subclasses
    every now and then in new files, thats why I choose a module (don’t want
    them to conflict with other classes flying around)
  • all components are only invoked by MainClass.

my problem is: I dont want to pass “args” and “other” everytime a Components
subclass is initialized (since its already in the MainClass) and I guess it
is expensive. the components subclasses are only used within the context of
MainClass. I want the app to be as fast as possible: what is the best
design therefor (thinking of mixture, modules, inheritence etc)?

thank you,

benny

my problem is: I dont want to pass “args” and “other” everytime a Components
subclass is initialized (since its already in the MainClass) and I guess it
is expensive. the components subclasses are only used within the context of
MainClass. I want the app to be as fast as possible: what is the best
design therefor (thinking of mixture, modules, inheritence etc)?

    def ini_component()
            require(@file)
            puts eval("#{@comp_name.capitalize}.new(@args, @other)")
                                                      ^^^^^^^^^^^^^
                                                      ^^^^^^^^^^^^^

I would probably pass ‘self’ to the instance.
Then a few cycles later, the instance can fetch the necessary data
from the owner.

···

Benny linux@marcrenearns.de wrote:

            # do something
    end


Simon Strandgaard

Simon Strandgaard wrote:

I would probably pass ‘self’ to the instance.
Then a few cycles later, the instance can fetch the necessary data
from the owner.
damned me. you’re right. sometimes I’m simply blind, thanx anyway

Benny wrote:

Simon Strandgaard wrote:

I would probably pass ‘self’ to the instance.
Then a few cycles later, the instance can fetch the necessary data
from the owner.
damned me. you’re right. sometimes I’m simply blind, thanx anyway

Its always ok to ask… I am for that matter normally blind to see my own
problems myself (thats why Im addicted to rubytalk).

It looks like you are preparing something with a lot of subsystems.
I am curious to what you are preparing ?

···


Simon Strandgaard

Simon Strandgaard wrote:

Benny wrote:

Simon Strandgaard wrote:

I would probably pass ‘self’ to the instance.
Then a few cycles later, the instance can fetch the necessary data
from the owner.
damned me. you’re right. sometimes I’m simply blind, thanx anyway

Its always ok to ask… I am for that matter normally blind to see my own
problems myself (thats why Im addicted to rubytalk).

It looks like you are preparing something with a lot of subsystems.
I am curious to what you are preparing ?

a webframework based on FCGI and YAML
YAML templates are parsed to HTML with Javascript and stuff from a database
mixed in.

it works :slight_smile: but the details are a secret, sorry :slight_smile:
perhaps sometimes it will be GPL, but first I want to make lots of webpages
within the framework.

benny

Simon Strandgaard wrote:
[snip]

It looks like you are preparing something with a lot of subsystems.
I am curious to what you are preparing ?

a webframework based on FCGI and YAML
YAML templates are parsed to HTML with Javascript and stuff from a database
mixed in.

it works :slight_smile: but the details are a secret, sorry :slight_smile:
perhaps sometimes it will be GPL, but first I want to make lots of webpages
within the framework.

Watch out not inventing something useless. I went to a presentation of
David’s ruby-on-rails project, it seems to be The_Right_Way to build
huge web sites. Its always a good idea to see how other has solved
a paticular problem, before trying to solve it yourself.

The presentation got recorded and resulted in a 160 mbytes video.
The second hour is truely amazing… however the first hour is
just buisness talk. He talks american and pronounce the words ok,
I had no problems with understanding. I recommend you to see it.
http://www.loudthinking.com/arc/000232.html

···

Benny linux@marcrenearns.de wrote:


Simon Strandgaard

Watch out not inventing something useless. I went to a presentation of
David’s ruby-on-rails project, it seems to be The_Right_Way to build
huge web sites.

I was there too, and while I wont quite go for ‘The_Right_Way’, I’ll
agree to ‘A_Very_Very_Good_Way’. :wink:

The presentation got recorded and resulted in a 160 mbytes video.
The second hour is truely amazing… however the first hour is
just buisness talk.

I’ll agree, second part is where he really put his code where his
mouth is. Though, the first hour did give a bit of interesting
background.

···

On Sat, May 22, 2004 at 03:57:47PM +0900, Simon Strandgaard wrote:


Thomas
beast@system-tnt.dk