This is Scott McFarlane's Typepad Profile.
Join Typepad and start following Scott McFarlane's activity
Join Now!
Already a member? Sign In
Scott McFarlane
Charlotte, NC
Recent Activity
Hi Tony, You are correct. I guess I had it in my mind that Dispose would not get called in the event of an Excecption being thrown. But as you point out, uderstanding the internals of LINQ as well as the compiler magic that comes with using yield really helps get your head around the whole thing. Thanks!
1 reply
I have encountered issues when using yield inside a transaction in this way. It works great if everything goes well, but have you tried to see what happens if an exception is thrown in the calling code? Generally when you need this kind of pattern (getting all the objects of a particular type) you are ultimately going to *do something* with those objects. So I would recommend passing a delegate into these functions, such as Action<Line> (and the function itself would return void.) This still gives you the performance advantage of only iterating through the objects once, but it also gives you much more control over the behavior when exceptions occur. Bruno, download the code from my AU2012 class CP2657. It's full of examples of this!
1 reply
Just so you know, I still want your job.
Toggle Commented Aug 17, 2012 on A slice of Raspberry Pi at Through the Interface
1 reply
That is awesome! Way to go Jim!
1 reply
Hi Kean, Your classes look very interesting. I hope our schedules don't conflict so I can attend them. The two classes I will be teaching, which your readers may be interested in are: CP2654 - Automated Testing with the AutoCAD .NET API CP2657 - Programming AutoCAD with C#: Best Practices Good luck in the football tournament, and have a great (well deserved) vacation. I look forward to seeing you in Vegas! - Scott
1 reply
Hi Kean, Thanks for posting this, although I apologize for causing you to take this detour. The moral of this story is that these days our programs (including those written for AutoCAD) are never self-contained or self-reliant. We reach out beyond our boundaries into the file system, external databases, web services, and even other COTS applications. Sometimes AutoCAD is the center of that universe, acting as a consumer of data and/or functionality provided by other systems, and sometimes it simply acts as a provider of data and/or functionality to another system. The role that AutoCAD plays is entirely dependent on the nature of the application, although at times this role may not be obvious at first. In the case of this exercise, AutoCAD’s role is to gather a few input parameters and then act as a display canvas for 2D and 3D geometry – something AutoCAD is great at, but certainly not the only option. (Incidentally, this is basically the same role that AutoCAD played in your “Kinect” series, right?) Anyway, my point isn’t to paint an overly simplistic view of AutoCAD, but as AutoCAD programmers, I think we need to really take a step back and think in more abstract terms about the true role AutoCAD plays in our applications. I have found that by doing this, the separation of concerns becomes crystal clear. I look forward to your next post… :)
Toggle Commented Apr 10, 2012 on Architecting for the Cloud at Through the Interface
1 reply
I think an important but perhaps less obvious lesson here isn’t so much that you can consume a web service from an AutoCAD program, but how you can separate the concerns of your application into those that are dependent on the AutoCAD API, and those that are not. And whether you actually use a remote web service or not, just shifting your thought process into a “service-oriented” mode will usually result in a better design, with more loosely coupled, reusable components. When I really pay attention to it, I’m always surprised at how little of the code in my AutoCAD programs is actually dependent on the AutoCAD API. Even more separation can be achieved through simple abstractions (like your Circle and Sphere classes). Having most of your program logic in non-AutoCAD-dependent components has significant advantages. Those components are more reusable (say, by a program that is like AutoCAD but not – if such a thing exists), they are easier to maintain (they don’t need to be changed or recompiled for new AutoCAD releases), and they can be unit tested inside of Visual Studio. Oh, and of course, they can more easily be migrated into web services later.
1 reply
Works like a charm for me. That was really the only change to your code that I made, but I'll email you my code just in case.
1 reply
Hi Kean, Since your CheckPaletteSetState command method is defined inside the PaletteSet2 class, you’re allowed to access non-static events on any PaletteSet2 instance within the scope of that method. Just make your event non-static, and then change the code that fires the event to: if (ps.PaletteSetClosed != null) ps.PaletteSetClosed(ps, new EventArgs()); Merry Christmas! - Scott
1 reply
Congratulations, Kean... I almost missed your note at the end. As soon as I started reading, my thoughts went straight to that moment during your AU class and I was tempted to scroll down and paste my resume into the "comments" section. Oh well...
Toggle Commented Dec 16, 2011 on Moving on (and yet not) at Through the Interface
1 reply
>> he has an energy level that I could probably only achieve by setting myself on fire. Amen to that.
Toggle Commented Nov 30, 2011 on A quick AUpdate at Through the Interface
1 reply
It is indeed astonishing how few code changes were necessary to make this work. As we wait for .NET 5, I have found Parallel LINQ (PLINQ) quite useful for tasks like this. I'm too lazy to learn F# at this point.
1 reply
I also like ReSharper (http://www.jetbrains.com/resharper). I know it's not free, but it pays for itself every day I use it.
1 reply
Scott McFarlane added a favorite at Through the Interface
Jan 19, 2011
Scott McFarlane is now following Kean Walmsley
Jan 19, 2011
I wonder if instead you could "squirt" a lisp expression to the command line. Would that make it culture-independent? string cmd = String.Format( CultureInfo.InvariantCulture, "(list {0} {1} {2}) ", pts.Average(a => a.X), pts.Average(a => a.Y), pts.Average(a => a.Z) );
1 reply
Scott McFarlane is now following The Typepad Team
Jan 18, 2011