From: "christoforever@..." Date: 2008-10-10T23:17:39+09:00 Subject: Re: Thread: super should be first line or last line? On Oct 10, 9:43 am, Stefan Lang wrote: > 2008/10/10 christofore...@gmail.com : > > > While playing around with ruby threads I noticed that if you dont call > > super when subclassing a thread you will get an initialization error. > > So ok we throw a super in the initialize method and that clears things > > up. Unfortunately if you put super as the first line in the initialize > > method the rest of the initialize will not execute but the block which > > is part of the initial thread creation gets initialized. However if > > you put super as the last statement in the initialize method, the > > whole initialize gets executed and then the block from the thread > > creation gets executed. Does anyone else find this a bit funny? And > > what is a good practice when subclassing thread... to put super first > > or last statement in the initialize method? and is there any benefit > > for either? > > Sorry, I haven't a direct answer. Do you have a good reason to > subclass Thread? There's probably a better way to achieve what > you want without subclassing. > > Stefan I've simply worked around the problem. I wanted the subclassed thread simply to hold much more personal info( if you will ) related to that particular's threads behavior/action with in the environment its running. There are many of threads going at any one time, and the info within each one is both different and needed for each. By putting super at the bottom of the initialize method i've solved the problem I just thought it was a bit funny that if I put super at the top the block associated with the creation of the thread gets called first and then the rest of the initialize method runs. I guess I've just been treated so kindly with java threads that doing things a bit differently ( in terms of threads) through me for a loop. However I still believe this is a bad design decision on behalf of thread creation with ruby. Seemingly no matter what the initialize method (imho) should be executed first ..... though as im writing this Im now thinking there is reason to have both. I suppose there could be reasons to have the block called first and then initialize the thread just as well as there are reasons to have the thread be initialized first and then call the corresponding block. Anyone have any opinions on the subject?