tag:blogger.com,1999:blog-23881856886969249.post7392815998932865704..comments2024-01-12T16:27:17.222-06:00Comments on Josh (Formerly) In Antarctica: Units DSL in GroovyJosh Reedhttp://www.blogger.com/profile/02066492903706506905noreply@blogger.comBlogger6125tag:blogger.com,1999:blog-23881856886969249.post-92024979019766931782008-05-25T18:47:00.000-05:002008-05-25T18:47:00.000-05:00Not anymore. I arrived home in December.Not anymore. I arrived home in December.Josh Reedhttps://www.blogger.com/profile/02066492903706506905noreply@blogger.comtag:blogger.com,1999:blog-23881856886969249.post-78323598699871818682008-05-25T18:33:00.000-05:002008-05-25T18:33:00.000-05:00aare you in antartida?aare you in antartida?Marshttps://www.blogger.com/profile/15206685128956748158noreply@blogger.comtag:blogger.com,1999:blog-23881856886969249.post-28002990028244361602008-05-25T08:29:00.000-05:002008-05-25T08:29:00.000-05:00Your comment would be more useful had you used spa...Your comment would be more useful had you used spaces.<BR/><BR/>The code does not need to be thread safe. The enable() method can run multiple times without issue. Each time it simply overwrites the previous metaclass methods with the new version. The isEnabled flag just tries to save you useless cycles. But you are correct in your assessment that under some conditions the enable() method may run more than once. <BR/><BR/>If you're worried about it, check out the other two comments on the post for other options.Josh Reedhttps://www.blogger.com/profile/02066492903706506905noreply@blogger.comtag:blogger.com,1999:blog-23881856886969249.post-13868039578647531232008-05-25T03:29:00.000-05:002008-05-25T03:29:00.000-05:00Yourcodeisunfortunatelynotthread-safe.Betweentheif...Yourcodeisunfortunatelynotthread-safe.<BR/><BR/>Betweentheifstatementtochecktheenablementandthesettingofthevariableanotherthreadcouldrun...Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-23881856886969249.post-56402481920581956302008-05-23T15:11:00.000-05:002008-05-23T15:11:00.000-05:00Thanks for the comment. I think the enable() meth...Thanks for the comment. I think the enable() method is just a matter of taste. It actually modifies the metaclass on Number and Amount, which is 90% of the DSL. addUnitSupport() is the other 10% by adding support for assigning strings to Amount properties on a class. If you didn't do it until addUnitSupport() was called, then you wouldn't be able to do '3.m' anywhere until you had added unit support to a specific class. A static block would work as well if you knew you were always going to need the unit manipulation functionality. I just am hesitant about changing runtime behavior without some explicit invocation when I know I won't always need the extra functionality.Josh Reedhttps://www.blogger.com/profile/02066492903706506905noreply@blogger.comtag:blogger.com,1999:blog-23881856886969249.post-26047912815191030992008-05-23T14:55:00.000-05:002008-05-23T14:55:00.000-05:00Is a public enable() method really necessary? It ...Is a public enable() method really necessary? It seems like addUnitSupport() could take care of that for you (or possibly just enable as part of a static block in the UnitsDSL class).Anonymousnoreply@blogger.com