Archive for April, 2009

Presentation Material on Design Patterns for INETA Live

I’d like to thank INETA for hosting the event and everybody who attended to it. As promised, here’s a link where you can download the material (slides and samples). See you next time!  🙂

Leave a comment

Virtual BBM April 23 2009: follow-up

We’ve had our second Virtual Brown Bag Meeting today. At some point, there were 15 attendees; I noticed some were at the first meeting, and some were new to it. Hopefully we’ll see this number increasing in the future.

Here are the things we’ve covered this week (I’m sorry, but I just don’t have time to put more details here. Check out the link to the recording at the bottom of this post to watch the meeting):

  • Entity Framework with POCO
  • VS tip
    • How to set keyboard shortcuts to increase/decrease the editor’s font site (look for the IncreaseTextEditorFontSize and DecreaseTextEditorFontSize macros).
  • May/June 2009 CODE Magazine (the “open source” issue): good articles on Windsor Castle, NHibernate, Mocks and Stubs…
  • Karl’s Seguin free book on “Foundations of Programming”
  • Uncle Bob’s blog post: Code Inevitable? Rumblings from ACCU
  • WPF: Dependency Properties, Attached Properties, Attached Behaviors, Model-View-ViewModel and DataTemplates
  • Refactoring code to use a fluent interface
  • Alternative to dynamic instantiation (DynamicMethod versus Activator.CreateInstance)

Here’s a link to the recording, in case you’ve missed it or want to go back and revisit some of the points.

Next week I will be out to a client and won’t be able to attend to the meeting. We’ll find somebody to start off the meeting and promote others to presenter as the meeting goes on.

Leave a comment

Material from Presentation at the Lubbock .NET User Group

I’m back from my quick trip to Lubbock, TX. I did a presentation on OOP over there. We’ve covered the core concepts, as well as the S, O, and I parts of SOLID. We’ve also squeezed some explanation on delegates, events, Action and Predicate, some brief functional programming with C#. Not bad, I don’t think. 🙂

The material from the presentation can be downloaded here.

Leave a comment

Virtual BBM April 16 2009: follow-up

Last week we’ve had our very first Virtual Brown Bag Meeting (click here to learn more). About 14 people showed up, which was beyond my expectations, since it was just the first meeting, and I had only announced it in a few places (my own blog, Twitter, and VAN’s Google Group). I’ve heard some great feedback about it, so we’ll keep this going.

Things We’ve Covered

Here are a few things we’ve covered in the first meeting:

Things I’ve Adopted or Will be Adopting Soon

I’ve been using SlickRun for several years now. It’s the very first tool I install right after installing the O.S. And I use it a LOT! I’ve always heard of people using both SlickRun and Launchy, since they complement each other. When I saw Executor at this 1st Virtual BBM, I just knew I had to take a serious look into it. Executor is much like a mix of SlickRun+Launchy; it has pretty much the best of both, and more. I’ve adopted it as my main launcher tool, and I’ll probably have a separate post just about it. I’m still going to keep SlickRun around because I use it’s Jot feature quite often.

Another thing I’ve had at the back of my mind for quite some time now is AutoHotKey. After seeing a little demo of it at this last BBM, I’m convinced I also have to take a serious look into this tool, too. My immediate use is going to be for creating BDD-style test names, but I can see how I’m going to be using it for many other things. However, I’ll need to spend some time learning its scripting language.

Things We’ve Learned in General About How to Handle the Meeting

We’ve recorded the session, but I’ve made the mistake to not record it to the LiveMeeting servers, so I only have it on my computer. I’ve uploaded it so you can download it here, though.

One thing we’ve established at the meeting was that whoever has anything to share must change the “Feedback” flag on LiveMeeting to “yellow”:

Feedback

That helps the facilitator (that is, whoever’s helping the group stay on track as the main presenter) to promote the person to a presenter. Once you’ve been promoted to a presenter, go to the LiveMeeting toolbar at the top of your screen, click Content, Share, and then either pick Share a Program or Share Your Desktop, depending on what it is exactly that you want to share:

Share

Also, we’re using LiveMeeting’s voice-over-IP features for the audio part, so make sure you have a microphone and speakers plugged in (for better quality, trying using a headset).

What’s Next?

That’s it for now. Do not forget our next Virtual BBM is tomorrow (Thursday), at 12pm Central Time. Bring in your tips and let’s share!

If you have any suggestions or comments, please don’t hesitate in letting me know, so we can improve the experience for everybody.

Leave a comment

Learn and Share at the Virtual Brown Bag Meetings

When I do my presentation on “productivity”, one of the things that I always mention is “brown bag meetings”. The concept has been introduced to me by good buddy Lynn Evans, and we’ve been doing it at the company (less often than I’d like) for some time now. I’ve also got some of our clients into doing it, and they always give me feedback saying they’re glad I got them into it, and they’ve been holding weekly meetings every since.

The idea is simple: once a week, people bring their “brown bag lunch” to the conference room, and we share tips and tricks. Unfortunately, there are developers who are either:

  • The only developer in the company, or
  • Working for a company that wouldn’t support such effort, or
  • Working as an independent developer

So who’d they have “brown bag meetings” with?

In order to cater for that, we’re starting a “virtual” brown bag meeting. The meetings are going to be hosted by the Virtual ALT.NET website through LiveMeeting (one of the most important aspects of ALT.NET is “continuous improvement”, and that’s what the brown bag meeting is all about!).

We’ll start doing it every Thursday, from noon to 1pm (Central Time). Depending on how things go, maybe different groups can held the meeting at different times so to account for different time zones.

In order for this to work, it’s vital that more than one person bring something to share. Of course, if we end up having a large number of people, it may not be possible for everybody to share, but we’ll figure something out if that turns out to be the case.

So all you have to do is to log on to the meeting by clicking here, and then watch people giving tips away while you eat your lunch, and between one bite or another, you contribute with some tip yourself! 🙂

Here are some ideas of things you can bring in as something to share with others:

  • A shortcut in Visual Studio, Windows, whatever, that you’ve learned or have been using for a while;
  • A tool (free or commercial) that you can’t live without it;
  • A tool that you may have run across, find it to be interesting, but are not sure about it yet. Maybe somebody else already uses the tool and can jump in;
  • An article, book, or blog posts you’ve read and want to talk about. It may be something you’ve read and couldn’t quite understand; maybe somebody else can shed a light on it for you;
  • Some command, language feature, workaround, design pattern, etc., anything you’ve learned or run across and could share with the others;
  • Something that you’ve found a way to implement but still think that there’s got to be a better way to do it; maybe somebody else can tell you what the other way is;

So that should allow us to get started. Join us, share, learn, get to know other people. It’s a win-win, isn’t it?  🙂

When: every Thursday, from noon to 1pm (Central Time)
Where: that’d be wherever you are. Just connect to http://snipr.com/virtualaltnet

See you online!

Leave a comment

Material from my presentation at the Bartlesville .NET UG yesterday

I’ve posted the material here. Thanks everybody who showed up! (quick post… got busy here).  🙂

Leave a comment

Follow up to my “Intro to LINQ” session at the MS TechDays

As promised during my session, I’m going to be addressing every unanswered question from my session in this post (we just didn’t have much time to take many questions…). So here we go!

“…don’t forget to mention how to update/delete/add to the database using LINQ”

Those operations are taken care of by the “DataContext” object. That object keeps track of changes made to the result set you get back from the query. So you make changes to the objects, and whenever you’re done, make a call to SubmitChanges() on the datacontext object.

“Is type inference related somehow to dynamic language features, javascript, and stuff?” and “isn’t c# losing its strongly typed features with LINQ?”

Nope, not at all. Dynamic language features aren’t checked during compiled time. The type inference feature in C# does check typing information during compile time. When we use type inference we must assign a value to the variable in the line where we declare it, because that’s the only way the compiler is able to infer the type based on the value being assigned to the variable. Also, an anonymous type is a strongly typed object, even though we don’t define those classes ourselves; the compiler will generate IL code for those types based on how we’ve initialized the type (what property names and type of values we’ve assigned to them).

“Can you have a return result (vs. void) in the foreach delegate/lambda?”

Not in the ForEach method, no. That method takes in an Action<T> delegate, which returns void. That method is specifically designed to go through every item in the list and perform some sort of action using the item. There are methods that take either a Function or Predicate delegate, which do have a return type. If you look up those delegates you’ll find examples of using it.

“Can the .dbml file be used to build up the class of the underlying schema; or is there a better approach; or is it off base to want to know some much about the actual underlying database structure (break separation of concerns). What should one do to get a deep sense of the database schema?”

I’m not entirely sure I understand the questions, but let me try to clarify that: the dbml file is a file containing classes that model the underlying database. For example, for a given “Northwind” database, you’ll have a “NorthwindDataContext” class, which in turn will have Customers and Products properties. Those properties are a kind of collection of Customer and Product types, which are classes that model those tables in the database, and therefore, have properties that map to columns in those tables.

You should probably do some research on Object-Relational Mappers (ORM), and things like NHibernate, in order to get a good understanding of separation of concerns regarding the impedance mismatch between objects and databases.

“Why is “foreach” always underlined in blue when you type it?

I’m guessing you’re asking the about the connector lines between the braces. That’s a CodeRush feature.

“Is LINQ working with WMI queries?”

I haven’t messed with that myself, but I’ve found this for you: LINQ to WMI. I hope this helps. 

“You mentioned about the same performance using LINQ vs. traditional foreach. Are there circumstances where performance does become an issue?” and a related question “is that right that you said there is virtually no performance difference between using LINQ, and doing it manually with for loops?”

Correct. LINQ ultimately performs a foreach, so whether you do the foreach yourself, or let LINQ do it, performance is about the same. However, check the answer to the next question. There’s the Hooked on LINQ website.

“Is there a performance gain in using LINQ"?”

Not currently. However, there will be when the next version of Visual Studio comes out. We’ll get what’s called “parallel extensions”. With that will be able to just add a call to .AsParallel() to our query expression, which will cause the query to have items processed in parallel in multi-core machines (which is the case of pretty much every new computer).

“Do you have any good reference for more LINQ?”

I like the chapters in this book covering LINQ, because it explains things under the hood: C# in Depth. I’ve heard great comments about LINQ in Action, but haven’t had a chance to check it out myself.

There’s the Hooked on LINQ website, and also a few blog posts of mine here, here, here, and here.

“If the query is only invoked when it is referenced first time, only every time it is reference; hence is it important to cache it if it is to be referenced multiple times?

When the query expression is defined, and query does not get executed. Every time there’s a foreach against the query expression, it does get executed. If you need to run multiple foreach’s on the query, but don’t want the query to be executed every time, just call .ToList() on the query expression, which is going to execute the query once, put its results into a List object, and then you can iterate through that list as many times as needed.

“Can LINQ query a database other than SQL Server?”

LINQ to SQL is specific to SQL Server. LINQ to Entities, on the other hand, uses the Entity Framework, which can be targeted to databases other than SQL Server.

“Why is LINQ written in reverse order?”

I assume you’re referring to the fact that in traditional SQL (such as T-SQL), “select” comes before “from”, whereas in LINQ, “from” comes first, and “select” comes last. That’s also something that bothered me on the beginning: I had been working with T-SQL and the built-in SQL that Visual FoxPro had had for so many years, and then I was faced with this weird thing that had a “select” coming at the end. Once I saw the reasoning behind that decision, I started seeing old SQL as the “reversed” one.  🙂

I’ll explain. First, think of Intellisense support. We type “select “, and then what? How would any tool know what list of columns to display so I could pick from it? The list could show all tables with their related columns, but what if we are also going to have JOINs in that query? Until we’ve actually provided the FROM and the JOIN parts of our query, it’s impossible for Intellisense to know what list to show for the “SELECT” part.

Second, coming to think about it, SELECT coming first doesn’t even make sense for somebody reading the code. If we think about what we want the results of our query to look like, the following thought seems to make sense: “first I need to know from which main source I’ll be retrieving the data, then I need to know whether I need to join that source with others, then I need to know how I want that data filtered, then I need to know how I need the data grouped and/or ordered. And finally, out of all of that, I need to finally decide the shape of the results, such as which columns I want, or even whether the product of my query is going to be a more complex, hierarchical object”.

In order words, the “select” can only be satisfied at the end of the expression, once all the other things have been established.

I have an example from the real world that always comes to my mind when I think about the whole “from/select” in LINQ. In Brazil, the address format looks like this:

Rua Marcos Moura, 243
Some City, State – 12345

Notice that the first thing we see is the name of the street, or avenue, or whatever, and only after that we get to see the number. I think that makes a lot more sense than the address format in the U.S. Why? Let’s say somebody is about to die, and she asks you to deliver a very important message to somebody. She tells you the message, and then starts saying the address: “they live at 987…”, and then bang! she dies. Now what the heck do you do with just that number? We can knock at the door of every place whose number is 987.

On the other hand, if the person said “They live at Whatever Av…”, and then dies, at least you could narrow the number of doors you’d have to knock at in order to deliver the message.  🙂

“superb, superb – bravo – sat through 2 hours of a talk this past weekend on the same concepts. Claudio’s explanation is far superior”

That’s flattering. Thank you. It’s always great to know I’ve been able to clarify something to somebody.  🙂

Leave a comment

Material from last night’s presentation at the Ozark DNUG

I’ve just uploaded the material (slide decks and source code). It can be downloaded here.

I think the presentations went pretty well, and got some great feedback from it. It was great seeing some old buddies there, and meeting new ones.

One interesting thing: when I first read Robert C. Martin’s book, “Agile Principle, Patterns, and Practices in C#”, I thought of creating some sort of book club, having developers study and discuss each chapter of the book. Due to my lack of time, I never executed the plan. Talking with Zack last night, he mentioned he started doing that as a virtual club on LiveMeeting. I definitely want to see whether I can join them.

Also, we’ve discussed the idea of having “brown bag lunches” over LiveMeeting. I’m seriously interested in getting involved on that one.

3 Comments

Follow up to my “Composite Apps – Prism” presentation at the MS TechDays

Here’s a few questions I got from my session on the “Composite Application Guidance for WPF and Silverlight” (aka. Prism) for the MS TechDays, along with my thoughts on it:

What issues have you run into resistance-wise with people moving from WinForms to WPF, and then taking the leap to a composite UI framework such as Prism? I’m seeing pushback due to training, retooling, and general "fear of the unknown."

Going from WinForms to WPF isn’t easy. Sometimes it seems like going from DOS to Windows. In a way, it may be easier for a developer to go from WebForms to WPF, since XAML looks kind of similar to HTML, or since web developers are used to laying out controls using HTML tables (whereas in WPF one can use “grids” as layout controls).

There are lots of things to learn in WPF, including XAML, dependency properties, attached properties, data binding, styles, templates, animation, visual and logical trees, etc. The current tools (Visual Studio 2008 and Expression Blend 2) aren’t solid yet; fortunately, both Expression Blend 3 and Visual Studio 2010 look promising, coming up with fixes and new features that address many of the current pain points.

With that said, WinForms isn’t going anywhere. The .NET Framework didn’t add anything new to it after version 2.0. All the big improvements regarding framework and tooling are aimed at WPF. Anybody in need of creating Windows applications today should probably consider WPF. Learning WPF has the extra advantage of reusing good part of that knowledge and skill when creating Silverlight applications, which is likely to be a big thing in the years to come.

In regards to taking the leap to a composite UI framework such as Prism, I don’t think it matters whether the developer is working with WinForms or WPF: either way there’s a learning curve there, given the fact that most developers aren’t used to creating composite applications. Most developers are used to creating forms that show all of its elements when open in the Visual Studio IDE. When building a composite application, the developer won’t really see what it looks like until the application is run. So that’s a first hurdle: getting used to the fact that during design time we only get to see the individual pieces (usually “user controls”) of a jigsaw puzzle (the actual application).

Another aspect that comes into play is that composite applications should really be built with separated presentation patterns in mind (Model-View-Presenter, Model-View-Controller, Model-View-ViewModel, etc.). The reason for that is to keep a clear separation between the UI and the other parts of the application. This is another thing that most developers aren’t used to; they’re used to open up a form in the IDE, drop a button onto the form, double-click the button so to add an event handler, and stuff a bunch of code in that event handler (retrieve data, update other UI controls, validate data, etc.). Driving a developer away from that way of building applications doesn’t happen overnight.

I haven’t really used the previous efforts coming from Microsoft regarding the creation of composite application (such as the “Composite Application Block”), but what I’ve heard from other developers who have is that they were really hard to understand, and were way too coupled to the other application blocks (data, configuration, dependency injection, etc.). Fortunately, Microsoft understood that feedback and addressed those issues with Prism, whose Composite Application Library can be considered very small (just a few core pieces to learn) and very loosely coupled (one can use whichever frameworks they want for UI controls, data access, dependency injection, etc.).

So, going back to your list of pushbacks:

  • Training: yes, WPF is a new thing, and therefore developers have some learning to do.
  • Retooling: the main tool for developers in WPF is still Visual Studio, so there isn’t much difference there, other than learning things that are specific to WPF (such as how to hook  up data binding, and things like that). However, in order to create visual appealing applications, the developer should also learn how to use Expression Blend, unless the company has professional designers working on the project who are doing all the visuals of the application.
  • “Fear of the unknown”: WPF can’t really be considered an unknown at this point anymore; it’s been released about 2 and a half years ago, and it is definitely where Microsoft is going with UI development. Regarding the architecture and practices followed by Prism (composite application, separated presentation patterns, loosely coupled modules, etc.), those aren’t unknown because they’re new (they’ve been around for a long time now); they’re unknown because both companies and developers, unfortunately, choose the quick-and-dirty-big-pile-of-spaghetti-code route when writing applications.

Where have you seen Prism (or WPF) hinder overall application performance or introduce sluggishness? Because of dependency properties and an event manager, there’s quite a bit running "behind the scenes." Have you identified anything specific?

I haven’t really noticed anything there. Prism does add some overhead, since it needs a couple extra objects to be able to do the UI composition; however, that doesn’t seem to be noticeable. WPF itself should perform better than WinForms in some cases because it offloads UI rendering to the graphics card (provided a good card is available), freeing the CPU to do more important stuff (such as running business logic).

I was concerned at first that you picked the stock trader app to demo, as that can be a bit overwhelming to someone new to Prism (but nowhere near as overwhelming as the SCSF reference apps!). I really like how you toned it down though, and focused on some very targeted and isolated areas of code, without trying to explain how the entire app comes together.

That’s great feedback. Thank you. I was worried that maybe I should have showed more code, but for the time I had available for the session, it seemed better to me to concentrate on the core concepts of Prism, show a little bit of what the code looks like around those concepts, and what kind of thing can be found in the reference implementation. Hopefully that gave people enough information to go ahead and inspect the reference application on their own now.

How did you do the polls? Was that part of LiveMeeting? I’ve gotta figure that out and try it in an upcoming webcast!

Yup, that’s a feature of LiveMeeting, extremely simple to setup: in “contents”, you just pick “add poll” (or something like that). Then you add your question, the available options, and you’re all set.  🙂

I hope I’ve been able to clarify some of those points. Please let me know of your own experiences using Prism.

3 Comments