tag:blogger.com,1999:blog-15136575.post6197774277172832150..comments2023-10-17T12:00:16.772+01:00Comments on Code rant: Adventures in Repetitive CodeMike Hadlowhttp://www.blogger.com/profile/16441901713967254504noreply@blogger.comBlogger10125tag:blogger.com,1999:blog-15136575.post-33825902607941040122010-09-14T10:56:54.746+01:002010-09-14T10:56:54.746+01:00Hi Chris,
Agreed, but this is a little utility to...Hi Chris,<br /><br />Agreed, but this is a little utility to insert static data. I didn't think it waranted fully encapsulating NH.<br /><br />Hi Steve,<br /><br />That's very nice. Higher-order functions really do lead to some nice refactorings. It's a shame you can't put extension methods on methods:<br /><br />MyMethod.MyExtensionMethod();<br /><br />Would be really cool. This works though:<br /><br />((Action)MyMethod).MyExtensionMethod();<br /><br />but it's ugly :(Mike Hadlowhttps://www.blogger.com/profile/16441901713967254504noreply@blogger.comtag:blogger.com,1999:blog-15136575.post-47789869568205667572010-09-13T19:45:21.468+01:002010-09-13T19:45:21.468+01:00I wrote something similar a while back:
http://ste...I wrote something similar a while back:<br />http://stevesmithblog.com/blog/eliminate-repetition-with-action-lt-t-gt/<br /><br />I like the in-lining of the action, though. Very nice.Steve Smithhttp://SteveSmithBlog.com/noreply@blogger.comtag:blogger.com,1999:blog-15136575.post-24030200728834056722010-09-11T11:09:36.277+01:002010-09-11T11:09:36.277+01:00@fschwiet @Mike - I think we are all right! But M...@fschwiet @Mike - I think we are all right! But Mike is obviously the most right. At the end of the day it's all about what works for your project and the people/plans you have.<br /><br />Like Mike's version, I feel we now have closure...Ben Taylorhttp://bentaylor.org/noreply@blogger.comtag:blogger.com,1999:blog-15136575.post-69076628663272965282010-09-11T04:53:14.378+01:002010-09-11T04:53:14.378+01:00"the happy place for any developer is when he..."the happy place for any developer is when he's the dumbest guy in the room."<br /><br />Aint that the truth?!<br /><br />I don't think passing ISession around all over the place is good. Seems like a leak in abstractions to me. I think what you're looking for is the Unit of Work pattern.<br /><br />I know that ISession is basically that. But hard-coupling to NH smells bad to me. :)Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-15136575.post-75871754011745471012010-09-10T23:20:48.093+01:002010-09-10T23:20:48.093+01:00Ben,
Maybe it's not a very good example. I gu...Ben,<br /><br />Maybe it's not a very good example. I guess the point I wanted to make was that you should try to remove 'boiler plate' code whenever possible. Look at what is different in otherwise similar blocks and boil it down to that. It's kinda accidental that the ids in this case are incremental, maybe I should have made them 4, 7, 11 and 243 instead :)<br /><br />I feel your pain, the happy place for any developer is when he's the dumbest guy in the room. Working in any team where you are encouraged to dumb down your code so that other people can understand it can be really fustrating.Mike Hadlowhttps://www.blogger.com/profile/16441901713967254504noreply@blogger.comtag:blogger.com,1999:blog-15136575.post-7558475816614869982010-09-10T17:43:29.584+01:002010-09-10T17:43:29.584+01:00If someone doesn't get lambda expressions, the...If someone doesn't get lambda expressions, they're likely the type that abuses extension methods if they use them at all. I think the inline lambda is pretty clean, it isolates the function to where its used.<br /><br />If this is something thats going to be reused broadly, then I think I'd prefer the insert roles class as opposed to an extension method, as then I have options to replace the dependency when testing.<br /><br />Its really just preferences though, any of them are reasonable.fschwietnoreply@blogger.comtag:blogger.com,1999:blog-15136575.post-54666998634242007982010-09-10T15:51:34.721+01:002010-09-10T15:51:34.721+01:00Yes, they certainly exist. IME there is no proble...Yes, they certainly exist. IME there is no problem when someone (e.g. you or me) is around to help them get them up to speed. However, I have seen problems on larger (50+), co-located projects where skill levels are, er, varied.<br /><br />Don't get me wrong. I have a rep on my current project for my (over)love of lambda :) Personally, I think everyone should know and love Action & Func. I am using them in place of strategy classes etc a lot these days.<br /><br />The example here just looks a bit awkward to me. I think it's the need to duplicate the Action call and manually increment the IDs. That still looks like duplication to me. The extension method looks DRY-er regardless of reuse requirements.Ben Taylorhttp://bentaylor.org/noreply@blogger.comtag:blogger.com,1999:blog-15136575.post-48230037377193804192010-09-10T15:16:43.607+01:002010-09-10T15:16:43.607+01:00Hi Ben,
Yes, if reuse is the aim then the inline ...Hi Ben,<br /><br />Yes, if reuse is the aim then the inline closure is not the way to go.<br /><br />As for these Action/Func fearful devs, do they actually exist? I've worked with people who hadn't seen/used lambdas before, but they got up to speed pretty fast.Mike Hadlowhttps://www.blogger.com/profile/16441901713967254504noreply@blogger.comtag:blogger.com,1999:blog-15136575.post-59546372276445211732010-09-10T14:19:22.001+01:002010-09-10T14:19:22.001+01:00Obviously, the extension method InsertNamedRoles s...Obviously, the extension method InsertNamedRoles should be called SaveNamedRoles.Ben Taylorhttp://bentaylor.org/noreply@blogger.comtag:blogger.com,1999:blog-15136575.post-46172330229723489912010-09-10T14:16:25.448+01:002010-09-10T14:16:25.448+01:00While I'm a big fan of Action and Func code, a...While I'm a big fan of Action and Func code, an extension might be nicer. It would remove the need to specify the ID and could be easily reused in other tests (as well as being understood by Action/Func fearful devs).<br /><br />Something like below (typed in the comment, may not compile :)...<br /><br /><br />static void InsertRoles(ISession session)<br />{<br /> session.SaveNamedRoles("Administrator", "Order Processor", "Customer", "Guest");<br />}<br /><br />public static class TestSessionExtensions<br />{<br /> public static void InsertNamedRoles(this Isession session, params string[] roles)<br /> {<br /> //TODO loop roles and save each (just increment id)<br /> }<br />}Ben Taylorhttp://bentaylor.org/noreply@blogger.com