I have a HTML list of about 500 items and a "filter" box above it. I started by using jQuery to filter the list when I typed a letter (timing code added later): $('#filter').keyup( function() { var jqStart = (new Date).getTime(); var search = $(this).val().toLowerCase(); var $list = $('ul.ablist > li'); $list.each( function() { if ( $(this).text().toLowerCase().indexOf(search) === -1 ) $(this).hide(); else $(this).show(); } ); console.log('Time: ' + ((new Date).getTime() - jqStart)); } ); However, there was a couple of seconds delay after typing each letter (particularly the first letter). So I thought it may be slightly quicker if I used plain Javascript (I read recently that jQuery's each function is particularly slow). Here's my JS equivalent: document.getElementById('filter').addEventListener( 'keyup', function () { var jsStart = (new Date).getTime()...
I suppose I might be being a bit picky here but it's important to note DI (Dependency Injection) is a programming pattern and is facilitated by (but does not require) an IoC (Inversion of Control) Framework. IoC Frameworks just make DI much easier, but it's not only DI that they do, they provide a host of other benefits over and above DI.
ReplyDeleteThat being said, I'm sure that's what you were asking: about IoC Frameworks: I used to use Spring.Net and CastleWindsor a lot, but the real pain in the beehiind was all that pesky XML config you had to write! They're pretty much all moving this way now, but I started using StructureMap for the last year or so, and since it has moved to a fluent config using strongly typed generics and a registry, my pain barrier in using IoC has dropped below zero! I get an absolute kick out of knowing now that my IoC config is checked at compile-time (for the most part) and I have had nothing but joy with StructureMap and its speed. I won't say that the others were slow (runtime), but they were more difficult for me to setup and frustration often won the day.
I believe they're all moving towards a more strongly typed config now - or at least providing the option, but some people love putting all the config in XML - personally I can't bare it, so I have stuck to StructureMap now.
I can't comment much on Ninject except that I listened to Nate on one of the Herding Code podcasts and he's one switched-on guy, and the screencasts I've watched have really tempted me to try it out - maybe on the next project - who knows.
Update: In a follow up to my comments here, I've been using Ninject (as promised) on my latest project and it has been an absolute pleasure to use. Words fail me a bit here, but (as we say in the UK) this framework is the Dogs'. I highly recommend it for any green fields projects where you want to be up and running quickly. I got all I needed from a fantastic set of Ninject screencasts by Justin Etheredge. I also can't see that retro-fitting Ninject into existing (above average) code being a problem at all - but then the same could be said of StructureMap in my experience. It'll be a tough choice going forward between those two, but I'd rather have competition than stagnation and there's a decent amount of healthy competition out there.
Other IoC screencasts can also be found here on Dimecasts.
Hope that helps,
Rob G