Ask a Question related to Ruby, Design and Development.
-
Philip Mak #1
Should "new" methods do anything?
A programming style question:
Should "new" methods actually do anything, or should they only perform
initialization?
For example, let's say I have a class called "Httpd" which runs an
HTTP server. Should its interface be like this:
server = Httpd.new(:listen_port => 80) # Initialize the server
server.run # Run it
Or like this?
Httpd.new(:listen_port => 80) # Initialize and run the server
The latter way is more streamlined, but feels bad for some reason that
I can't quite put into words right now.
Philip Mak Guest
-
Proj cannot run on LCDS 2.6 ES due to "Unable to resolveresource bundle "datamanagement" for locale "en_US"
hi, all, We have developped an application on Flex Build 3 (run successfully), but failed when we try to deploy it on Tomcat with LCDS 2.5 ES... -
Using Acrodat SDK methods with VB ("PDEText ")
Has anyone used "PDEText PDETextCreate" methods in VB. If so, do you have an example and the modules for a VB.NET app? I've done C, but a long-long... -
Log::Dispatch - How to "die" a script after all other methods are called???
I want to use Log::Dispatch to log activity using a number of methods (screen, files, e-mail, etc). If I encounter a certain error threashold... -
CFINPUT type="radio" w/ "value" requires "label"
On a Flash form, when you specify type='radio' and value='whatever', the value of the 'value' attribute will be displayed as a label if no 'label'... -
"Start" "Program" "Menu" list is empty
For what ever reason my list of installed programs in my "Start" "Programs" menu is empty. Anyone know how to restore the list. Thanks for your... -
Aredridel #2
Re: Should "new" methods do anything?
--=-xt6+981JgEI+5w0faYqy
Content-Type: text/plain
Content-Transfer-Encoding: quoted-printable
On Fri, 2003-09-12 at 14:03, Philip Mak wrote:Let it return self.> A programming style question:
>=20
> Should "new" methods actually do anything, or should they only perform
> initialization?
>=20
> For example, let's say I have a class called "Httpd" which runs an
> HTTP server. Should its interface be like this:
>=20
> server =3D Httpd.new(:listen_port =3D> 80) # Initialize the server
> server.run # Run it
>=20
> Or like this?
>=20
> Httpd.new(:listen_port =3D> 80) # Initialize and run the server
Then:
Httpd.new(:listen_port =3D> 80).run
Well, perhaps you want to wait to run until you've checked some>=20
> The latter way is more streamlined, but feels bad for some reason that
> I can't quite put into words right now.
things...
--=-xt6+981JgEI+5w0faYqy
Content-Type: application/pgp-signature; name=signature.asc
Content-Description: This is a digitally signed message part
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)
iD8DBQA/YicstP09exA3hooRAmRhAKDKuJR5RYYlaw0M1+MNcRestyuLSw CgoNzX
VsuKjF25CVlcnH0zm4ll288=
=Ie5W
-----END PGP SIGNATURE-----
--=-xt6+981JgEI+5w0faYqy--
Aredridel Guest
-
Weirich, James #3
Re: Should "new" methods do anything?
From: Philip Mak [mailto:pmak@aaanime.net]
I prefer the initialize only approach. If you tried to subclass Httpd, then> Should "new" methods actually do anything, or should they only perform
> initialization?
running from initialize might start the server before the subclass has
completed initialization.
And if you want streamlined, Aredridel suggested chaining run.
--
-- Jim Weirich / Compuware
-- FWP Capture Services
-- Phone: 859-386-8855
Weirich, James Guest
-
Sean O'Dell #4
Re: Should "new" methods do anything?
Philip Mak wrote:
I don't think it will cause any harm to your program, but to me it's> A programming style question:
>
> Should "new" methods actually do anything, or should they only perform
> initialization?
>
> For example, let's say I have a class called "Httpd" which runs an
> HTTP server. Should its interface be like this:
>
> server = Httpd.new(:listen_port => 80) # Initialize the server
> server.run # Run it
>
> Or like this?
>
> Httpd.new(:listen_port => 80) # Initialize and run the server
>
> The latter way is more streamlined, but feels bad for some reason that
> I can't quite put into words right now.
non-intuitive as to what "new" does. I don't think many people would
expect that simply creating the server also launches it.
In those cases, I usually make a class method to combine the
functionality, i.e.:
server = Httpd::launch_server(:listen_port => 80)
.... and keep the class like this:
class Httpd
def initialize(listen_port)
# init only
end
def run
# launch the server
end
Httpd::launch_server(listen_port)
server = Https.new(:listen_port = listen_port)
server.run
return server
end
end
Sean O'Dell
Sean O'Dell Guest
-
Simon Strandgaard #5
Re: Should "new" methods do anything?
On Fri, 12 Sep 2003 21:21:01 +0000, Sean O'Dell wrote:
[snip]> Philip Mak wrote:>> A programming style question:
>>
>> Should "new" methods actually do anything, or should they only perform
>> initialization?[snip]>
> server = Httpd::launch_server(:listen_port => 80)>
> Httpd::launch_server(listen_port)
> server = Https.new(:listen_port = listen_port)
> server.run
> return server
> end
Yes, Factory methods is nice.. it can also look like this :-)
Httpd.launch(options=nil)
Https.new(options).run
end
--
Simon Strandgaard
Simon Strandgaard Guest
-
Austin Ziegler #6
Re: Should "new" methods do anything?
On Sat, 13 Sep 2003 05:03:51 +0900, Philip Mak wrote:
I would say:> For example, let's say I have a class called "Httpd" which runs an HTTP
> server. Should its interface be like this:
> server = Httpd.new(:listen_port => 80) # Initialize the server
> server.run # Run it
> Or like this?
> Httpd.new(:listen_port => 80) # Initialize and run the server
> The latter way is more streamlined, but feels bad for some reason that I
> can't quite put into words right now.
server = Httpd.new(:listen_port => 80)
server.run
or
Httpd.new(:listen_port => 80) do |server|
...
end
If there's a block given, then both run it and stop it when the block
completes.
-austin
--
austin ziegler * [email]austin@halostatue.ca[/email] * Toronto, ON, Canada
software designer * pragmatic programmer * 2003.09.12
* 18.25.22
Austin Ziegler Guest
-
Gavin Sinclair #7
Re: Should "new" methods do anything?
On Saturday, September 13, 2003, 6:03:51 AM, Philip wrote:
> A programming style question:> Should "new" methods actually do anything, or should they only perform
> initialization?> For example, let's say I have a class called "Httpd" which runs an
> HTTP server. Should its interface be like this:> server = Httpd.new(:listen_port => 80) # Initialize the server
> server.run # Run it> Or like this?> Httpd.new(:listen_port => 80) # Initialize and run the serverThe method is "doing too much", a common problem. You may want to> The latter way is more streamlined, but feels bad for some reason that
> I can't quite put into words right now.
pass the server to another method which runs it, or not, based on some
other things.
Gavin
Gavin Sinclair Guest



Reply With Quote

