begging for a hint in app design

B

Benny

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 :(

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 :eek:ther
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
 
S

Simon Strandgaard

Benny said:
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.
 
B

Benny

Simon said:
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
 
S

Simon Strandgaard

Benny said:
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 ?
 
B

Benny

Simon said:
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 :) but the details are a secret, sorry :)
perhaps sometimes it will be GPL, but first I want to make lots of webpages
within the framework.

benny
 
S

Simon Strandgaard

Benny said:
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 :) but the details are a secret, sorry :)
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
 
T

Thomas Fini Hansen

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_'. ;)
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top