|
|
-
When I was involved with the business fraternity during my college years, we used to hold car washes to raise the money necessary for our annual trips to leadership conferences. Everybody won: people got their vehicles washed at discounted prices, and our fraternity got the funds necessary to interact with some of the most influential people in the community at the state and national events.
Fast forward a few years, and JaxDUG, the developers group in Jacksonville, FL needs a certain amount of money to cover the facility and food expenses for an upcoming free day of learning for the community--the Jacksonville Code Camp. While the car wash idea is still an option, common sense tells me that a bunch of geeks are no match for bikini-clad college students in the car washing arena.
Instead of doing a car wash, I am throwing this idea out to companies interested in getting a good deal on their development dollars: for every $25 you donate to the CodeCamp, I will devote 1 hour of my time to your development or training engagement. I feel that I have a decent grasp on web layout and development (check out a couple of freelance projects I completed within the last couple of months here and here), knowledge of what it takes to get a successful project off the ground, including business analysis and project management (you learn best in the line of fire), as well as enough understanding of .Net 3.0/3.5 and Silverlight technologies to teach an introductory session or two.
For $25/hour, it's hard to find a better deal even in the remote parts of this world (and I will even check the spelling and grammar on everything, on the same day!). In addition to getting a solid ROI, you will also be a part of something great that benefits the community at large--after all, Code Camp is the biggest developer-centric event in the Northeast Florida. It's also free for anyone who attends.
Here's how to proceed if interested: e-mail me at echuvyrov at msn dot com, and we'll make this a win-win for everyone. You can also check out CodeCamp website to get an idea about the event, as well as sponsorship levels available.
Limit 10 hours per customer. Not valid with any other offer. Must present this blog entry at checkout. Valid thru August 10, 2008. LOL.
Of course, sponsor contributions without asking me to do anything are open with open arms as well. I am looking forward to hearing from you!
|
-
My presentation slides from yesterday's Silverlight presentation are attached to this post. Since this was a code walk-through session, I used the slides just to set the stage for key Silverlight concepts I was going to illustrate. Therefore, pardon the (short) length of the presentation.
I hope that those who attended felt that their time was well-spent and they have learnt a couple of things. Silverlight 2.0 Beta 1 is literally just 1 week old, so welcome to the bleeding edge of technology (LOL, attendees will know what I mean).
As was mentioned by the audience members, investing in learning WPF today is a good strategy to jump-start both Silverlight and future smart client software development efforts. Personally, I am excited about Silverlight, and, if there's desire, I'll do many more presentations about it, significantly improving on the test release of my demo app.
Thanks to everyone who attended--quite a few new faces, I am looking forward to seeing you in future meetings.
|
-
Type Inference != VB6 Variants
There seems to be a bit of confusion going on among people raised on Visual Basic 6 about one of the new features in .Net Framework 3.0--type inference. On several occasions, I have heard that type inference is basically the equivalent of an old feature of Visual Basic 6 where you could leave off the type declaration of a variable. It's important to realize that type inference is a different (and more programmer-friendly) animal altogether: with type inference, we have a stongly typed variable with compiler inferring the strong type of the variable at compile time. With Visual Basic 6, we had types of variants inferred at run-time, when an application was deployed, and it was the cause of many headaches and hours of technical support efforts. Let's take a look at a simple example to illustrate the key difference.
Suppose, we have the following VB6 code:
Dim strTest
strTest = "2a"
MsgBox (CInt(strTest) + 2)
This code will compile OK, but immediately after executing it, VB6 runtime will raise a "Type mismatch" error. Contrast this with the following
C# code:
var strTest = "2a";
System.Windows.Forms.MessageBox.Show((int)(strTest) + 2);
When you go to compile that code, you will get a compilation error stating that the C# compiler cannot convert type 'string' to 'int.' That's not your grandma's VB6 variant handling (although I do miss VB6 for many other reasons, since it was so fun to program in)!
Many people dismiss type inference as useless and potentially dangerous feature, but I believe it has a definite place in each .Net 3.0 programmer's toolbox. It may not be appropriate to use type inference for declaring variables of simple types (integer, string, etc.), but it's a real time-saver for more complex types, especially types derived from LINQ queries. Consider the following LINQ statement (borrowed from 101 LINQ samples):
var upperLowerWords =
from w in words
select new {Upper = w.ToUpper(), Lower = w.ToLower()};
Here, the type upperLowerWords is automatically inferred as a collection of objects, each object containing two properties: Upper and Lower. What would be the alternative to automatic type inference to arrive at the same result? Let's see, first we would have to declare the data class:
public class upperLowerWord
{
private string _Upper;
private string _Lower;
public string Upper
{
get { return _Upper;}
set { _Upper = value; }
}
public string Lower
{
get { return _Lower; }
set { _Lower = value; }
}
}
Second, we would have to declare a generic list of upperLowerWord classes and use LINQ query to retrieve the actual data:
IEnumerable<upperLowerWord> upperLowerWords = from w in words
select new upperLowerWord { Upper = w.ToUpper(), Lower = w.ToLower() };
I think it's clear that type inference (also referred to as "anonymous types" feature for the LINQ example above, since the new type is being created "on the fly") saves on manual typing. But even greater benefit of type inference, in my opinion, is that it allows you to concentrate on the logical flow of your application more so than on ensuring that all the types used are being correctly declared and no getter/setters are missed.
Windows Presentation Foundation Unleashed by Adam Nathan, et al.
The work load and a couple of fun side projects have finally caught up with me, and I did not get a chance to finish reading the "WPF Unleashed" book by Adam Nathan. But, I feel that I have read enough of it to state my opinion about the book.
The most important thing about “WPF Unleashed” is that it inspires. It inspires its readers to start developing application using the next generation of UI technologies--WPF. Full-color illustrations of what the future UIs will look like drive the point home. A detailed and in-depth breakdown of how to program these interfaces of the future only makes the book so much more valuable. The target audience is developers wishing to learn the intricacies of WPF programming, including constructing XAML and the C# code-behind involved. From the beginning, the author makes it clear that you may never have to write a single line of XAML by hand, since tools such as Microsoft Expression Blend could do that for you. But, his analogy of knowing HTML vs. coding in Dreamweaver or FrontPage is a valid one--sometimes there are and will be items not easily customizable via visual tools.
Allow me to briefly talk about book's contents. The first part of the book starts out with how we got to WPF: the history of graphical interfaces, intro to XAML, as well as some important new concepts in WPF, including the logical and visual trees, dependency properties, and routed events. The second part deals with building WPF applications: the overview of controls, sizing and positioning of the elements, as well as structuring and deploying an application. The third part talks about using Resources, Data Bindings, and themes. The fourth part is the coolest: 2D and 3D graphics, animations, as well as dealing with various types of media (music and video) are described, and Adam even briefly touches on speech recognition. The final part of the book deals with advanced subjects of creating user and custom controls, interoperability with legacy technologies (Win32 forms, ActiveX controls) and layout with custom panels.
One of the surprising things learned from the book was that new Vista features, including the Aero glass (transparent window border extended into the client area), are exposed via unmanaged APIs, so to consume these features in C# or VB.Net application (managed code), we must use the PInvoke method (that is, a DLLImport attribute).
For the final words: if you want to get inspired about WPF development, get this book, browse through it, and see what's possible in WPF. Then, keep it as a reference as you develop your applications. I am almost certain you will want your next project to be WPF-based after getting familiar with this work. 4 stars out of 4.
|
-
I promise not to write a novel this time around, just a brief post with links to information that I found valuable during this past week...
Larry O'Brien, whose 'Microsoft Watch' column in SD Times magazine I follow closely, points out the fallacy of several fundamental assumptions of software development--the assumptions that, to use his words, "were gospel" just a few years ago. The first victim is the superprogrammer productivity myth--you know, the one where a superprogrammer can code 20 times faster than a regular one. According to Larry, there really is no data (i.e., no scientific studies with a fixed control group) supporting this assertion. The superprogrammer axiom was popularized by Tom Demarco in his famous Peopleware book, and the chart below (respectfully borrowed from Larry's blog) laid the foundation for the belief that superprogrammers exist. While the chart itself does point out that productivity levels vary between different programmers, it's hardly enough on its own to generate a religious acceptance around the concept...

The second axiom revisited by Larry was the exponential increase of costs in software development over time, as shown in this graph (again, Larry's property):

William Taylor and Polly Labarre point out in "Mavericks at Work" that a true maverick would take a commonly accepted state of affairs, disagree with it, challenge it, and create something remarkable. Such was the case with Kent Beck, where he challenged the assumptions documented by the graph above with his Extreme Programming approach to software development. Now, we have something more closely resembling this:

Speaking of Agile Software Development, Steve McConnell is convinced that soon we will no longer refer to that approach as "Agile"--it will be simply referred to as Software Development. With South Florida's Architecture Group changing their name to "Agile," I have to concur.
|
-
If you missed my MVC presentation at January's Jax Architects meeting, let's just say that you missed more than a "Hello, World!" demo application and let the rumors do the rest. Suffice it to say that when I was at South Florida's Code Camp on February 2nd, Jeff Barnes was STILL talking about my demo project.
I hope this piques your interest and you come to the next Jax Architects meeting, scheduled for February 26th. Jeff Barnes is scheduled to talk about the features in Visual Studio Orcas that are specifically applicable to architects and, having seen a portion of his talk at South Florida's Code Camp, I can tell you that it's a very densely packed presentation. I only hope that Jeff has time to showcase his demos, particularly the ones pertaining to PLINQ and ADO Entity Framework.
Without further ado, let me re-iterate my general opinion about ASP.Net MVC framework expressed as the header to this blog entry: it's a big step towards the true separation of concerns (presentation from data) and enabling easier RESTful development, but, being in the preview stage (not even a beta yet!), ASP.Net MVC is a bit clunky in binding data to views, as well as suffers from a few bugs/problems that make it unsuitable for production initiatives today.
Let's start at why MVC is a big deal right now. When I first heard about MVC, I thought to myself "Haven't we already seen this on Patterns and Practices site? It's where people that are a hundred times smarter than I am implement so many design patterns that common folk like myself gets lost and starts thinking about 'olden days of Visual Basic 6 development." That thought turned out to be only partially correct, since this time around Microsoft is committed to bringing MVC framework into the mainstream development within Visual Studio Orcas. In essence, there will be two separate ways to build a web-based ASP.Net application in the near future: using the WebForms approach (the only way to build an ASP.Net web app today) and by following an MVC approach (once the production version is ready, that is).
When should you use MVC framework in place of WebForms? Based on my whopping experience with one (limited) application in MVC and hundreds of webforms built, I foresee myself using an MVC framework (when it's production-ready, of course) on:
1. Projects where the true separation of data from user interface is required (the large projects with thousands of items and multiple features pertaining to each item would generally fall into this category; there, we must have a place to centrally control the logic and all of the components).
2. Projects where "friendlier" or RESTful URLs are preferable for accessing products. For example, let's say we want to list the top 10 songs for year 2007. Using WebForms approach, our resultant URL may look something like
http://www.mytunes.com?year=2007&category=top10
If we were to use MVC framework, that same URL would look like
http://www.mytunes.com/2007/top10
MVC's URL is easier for customers to navigate to and remember, as well as friendlier for RESTful web services. If you are like me and have been living under the rock for the past couple of years, it turns out that there's more to web services development than the plumbing automatically put in for us by Visual Studio. Visual Studio.Net, beginning with version 1.0, built all of the web services infrastructure in accordance with the WS* set of standards and uses the SOAP model to achieve that. REST (which stands for REpresentational State Transfer) is an alternative way to build and expose web services. With REST, there are no web methods exposed by the web servers, there are just unique resources accessible on the web. All of RESTful operations represent some way of accessing and manipulating these resources. REST web services are much easier to setup (if you had to wire everything manually, that is) than comparable SOAP services, and many vendors (Amazon.com, for example) are developing both SOAP and RESTful web services on their platform. Note that the "friendlier" look of the URL is not a necessary requirement of REST; RESTful services can still be build with multiple '&' and '=' in the URL, but the 'friendlier' look is considered friendlier for REST (pun intended).
3. Projects where you simply want to feel like you've done it the 'Rails way' or the 'Jakarta Struts way.' Both Ruby-on-Rails and Jakarta Struts are correspondingly Ruby-based and Java-based implementations of MVC frameworks, albeit the Ruby developer at the Jax Architects meeting was somewhat skeptical whether the binding of models to views in ASP.Net MVC matches that same binding in Ruby. I think that the binding is not bad (once the bug not allowing me to bind fully from code-behind is fixed, that is) in a sense that we can pass .Net's custom types (dynamically defined from LINQ statements) into the .aspx page (the view) and bind properties of those types to UI controls. Because of the bugs, I gave this binding a "clunky" rating at the beginning of this entry.
Take a look at the presentation attached--I hope it provides an initial introduction to MVC framework and gives you an idea of how to start using it and where to turn for help.
|
-
Occasionally, I like to disturb the state of software engineering nirvana to force myself and those poor few who are listening to take a second look at the commonly accepted axiom or state of affairs. Today, I'd like to go out on a limb and suggest a multibillion dollar strategy shift for Microsoft, and I only want 0.1% of all the moneys saved as a result of adopting my strategic suggestion. So, here's my ambitious contribution to the world of software development this week:
Drop the VB.Net as a language and either build something that truly allows RAD of web and Windows-based apps, or put the savings into building a better Object-Relational Mapper, bringing functional languages to the masses, or donate them to a worthwhile cause. A worthwhile cause is, of course, in the eye of the beholder. Expanding Victoria's Secret fashion show is a very worthwhile cause, in my humble opinion.
There are three main reasons why I think that VB.Net should be going the way of the VHS tape: the language is too similar to C#, it is not even remotely "basic" anymore, and it has already served its purpose of giving VB6 developers perception that they weren't left behind during the migration to the .Net platform.
First, the abundant existence of web-based VB.Net to C# translators is a clear indication of extreme similarities between the languages. I've used those translators on multiple occasions, and I understand that they may not be perfect, but they are not bad. Because the languages have an almost identical set of features and are syntactically similar, I see no advantage in developing in one over the other. But I see a great pain and the expense of managing the two separate development environments, having all the samples written in both languages, etc.
Second, VB.Net did not do to web/smart client development landscape what Visual Basic 1.0 did to Windows development. If you had the painful pleasure of reading Charles Petzold's "Programming Windows, Fifth Edition" and if your mind works anything like mine, I bet on more than one occasion you thought "all these pages of C code just to display a window and process a few messages?" VB 1.0 abstracted much of the code needed for drawing windows and processing messages, and the market for business software exploded as a result. Unfortunately, VB.Net does not do the same for web development--you are still responsible for knowing quite a bit of (D)HTML, CSS syntax, and, of course SQL if you are working with the database.
Third, I believe that the reason VB.Net came into being was to offer what VB6 developers would have thought was a natural path towards building the next generation of applications. On the .Net platform, of course. With C# syntax being so Java-like, all the VB6 developers would have been hard-pressed to start using C# when you could potentially "write once, run everywhere." That reason for VB.Net existence is no longer valid--most developers have bitten the bullet and upgraded their applications by now (or in the process of doing so), and they have come to appreciate the power of the .Net framework itself with all the tools it provides rather than just the VB.Net language.
So, if in the near future you see Victoria's Secret fashion show tripling in size and all the models having the "Your Potential. Our Passion." tattooed on their back, please feel free to send me a "thank you" card. You will most likely find me in the islands, Lamborghini parked close by.
On the other hand, if you think that I have totally lost it after a recent head-bumping accident and I am totally missing the point with VB.Net, I welcome hate/constructive criticism mail as well. Direct it to "echuvyrov at msn dot com".
"Learning WCF" uses an unexciting approach to explain technology for technology sake
In an effort to stimulate discussion and perhaps occasionally give people a golden nugget of information at the user group meetings, we are continuing with the book reviews. This month I reviewed "Learning WCF" by Michele Bustamante. The motivation behind reading this book was to familiarize myself with the WCF technology and determine its applicability to the projects that I am working on currently and my future endeavors.
WCF is an amalgamation of previous technologies--ASMX, .Net Remoting, Enterprise Services--all encapsulated in a set of grandeur specifications with catchy names like "contracts, bindings, endpoints" that will certainly bring billions of dollars in consulting fees. Unfortunately, I was searching for ideas on how WCF can help me architect/develop distributed solutions that are better and more reliable than has been possible in the past. Sadly, Ms. Bustmante's book was not the place for answers to my questions.
Based on 6 reviews, Amazon.com had this book at a 5-star rating, which gave me a reasonable expectation that it must be a good place to start my WCF journey. My brain works best in a top-down decomposition manner, where I take the big picture, understand its place in the universe, and then break it down into smaller component parts. The author takes a different, more of a bottom-up, approach by throwing a lab at the reader, then explaining what happened during the lab and what technologies the reader has learned. I found this not to be very intuitive.
Main themes of the book are (please bear with me as I mainly recite the table of contents):
-Chapter 1: Definitions: Services, hosting, endpoints, bindings, metadata and behaviors -Chapter 2: Contracts: Service Contracts, Data Contracts, Message Contracts -Chapter 3: Bindings and types of bindings: BasicHttpBinding, WSHttpBinding, NetTcpBnging, etc. -Chapter 4: Hosting Services: type of hosting (self, IIS, and WAS) -Chapter 5: Instancing and Concurrency -Chapter 6: Reliability and message queueing -Chapter 7: Security -Chapter 8: Handling exceptions and faults
On the positive side, the coverage of various topics is pretty in depth. The author clearly has put in a considerable amount of time writing the material and code for the labs included. Unfortunately, it is not written in a very exciting manner--no jokes about Microsoft, and, the biggest disappointment of all (!), Victoria's Secret fashion show is not mentioned even in passing.
Generally, I felt that my time was not very well spent reading this material page-by-page. Perhaps a better approach would have been to treat this book as a reference manual, working through the labs to solidify individual concepts on as needed basis.
Bottom line: "Learning WCF" is not bad as a "how to" reference on WCF, but definitely not a good source on "why WCF, when WCF, and what is most appropriate WCF configuration for a given business scenario." This is "technology for technology sake" type of material, so if you don't like this approach, you are probably better off looking somewhere else. 2.5 stars out of 4.
Next month, I will briefly review "My Job Went to India: 52 ways to save your job" since outsourcing and relevance of software development in the future is something that's among my primary concerns. I am extremely interested in the opinions of the audience regarding the book and the offshore trends in general. I hope to see you there.
|
-
Hate him or love him, but Marc Andreessen, the founder of Netscape Communications, was named the blogger of year by the Inc. magazine. The Inc. magazine is geared towards both current and future entrepreneurs, so if you have a trace of an entrepreneurship in your blood, you will most likely find the information published by Marc very insightful, analytical, and to the point. Having spent some time reading Marc's musings, I was initially puzzled by his assertion that it's always important to be a small fish in a big pond. He urges everyone to "optimize at all times for being in the most dynamic and exciting pond you can find." After mulling this over for a short while, I finally shouted "Eureka," kicked the bathtub and signed up for the Jax Architects meeting. I was bound to be the small fish there, just sucking up all the knowledge coming my way. Big Kudos to Jeff Barnes of Microsoft for yesterday's very informative architects session; it gave me plenty of new directions to pursue to be better at architecting and managing the software systems. Major props to all attendees as well, the discussions are always interesting and offer fresh perspectives on the old issues. The arm wrestling match was an extra bonus (Ok, just kidding about that).
While I have designed, built, tested, held hand, kissed butt and generally gave my unconditional love to many software solutions throughout the years, every new application brings with it an opportunity to apply freshly gained knowledge. The most recent piece of research that I am looking forward to applying comes from IEEE 1471-2000, and it has to do with documenting software architectures. In the past, the documentation of my architectures consisted of multiple UML diagrams, user interface prototypes, Word documents and Excel spreadsheets documenting my schedule estimation efforts. I say "efforts," since software estimation is still an art that remains to be mastered by yours truly. Incidentally, I have yet to personally observe a detailed and accurate software estimating effort that does not involve reaching somewhere unknown (or unspeakable) and pulling out a random number of developer hours.
IEEE 1471 is the recommendation (not a mandate) on documenting software architectures. After the first glance at its recommendations, two thoughts crossed my mind:
1. I am already doing this today. 2. Why does it have to be so confusing--what the heck is the difference between a "view" and a "viewpoint?"
While I was already doing many things outlined in IEEE 1471, what I was lacking in my efforts was the completeness of architectural representation of the system. How did my Word documents relate to each other? What were the most important concerns of the system--security, reliability, accuracy, etc.--and how would anybody know that these concerns were the most important? At what point can you be certain that all of the concerns of the system and all of the potential stakeholders of the system are satisfied? The IEEE recommendation put those things in perspective for me.
Here are the main tenants of IEEE 1471 recommendations:
--The architecture of the system addresses all concerns of system's stakeholders. Concerns include security, accessbility, performance, functionality, etc. of the system. --A concern or a set of concerns can be addressed by one or more views of the system. A view is the representation of the whole system in the context of one or more concerns. --A viewpoint is the template from which we can develop individual views. Each viewpoint should have a name, describe what concerns it addresses and the stakeholders it is aimed at. Each viewpoint should also specify the modeling techniques, analytical tools, or language that will be used to construct the view.
The IEEE recommendation is clearly an evolutionary development of the Zachman framework that was developed in the 1980s. The Zachman framework, a de facto framework for documenting enterprise architectures according to Wikipedia, defines 6 perspectives (viewpoints) from which an enterprise can be viewed and offers 6 focus areas for each perspective. By filling in the resultant 6x6 matrix, an architect takes an additional step towards ensuring the completeness of the system's architectural description. Yesterday, Jeff Barnes briefly talked about Zachman framework at the Jax Architects meeting. In contrast to Zachman framework, IEEE 1471 does not dictate any preset viewpoints of the system; it simply recommends documenting the architecture in the form of viewpoints and views.
So, for my next project, the very first thing I will do is fire up a word processor, write down a comprehensive set of concerns of all stakeholders of the system. I will then create empty viewpoint templates addressing those concerns. From these viewpoints, I will develop the views. After that, I will systematically drilldown to the lowest level of detail in each view, eventually even getting to you, the stick-man with the giant bubble.
Here's to all the big fishes already following the IEEE 1471 guidelines--Cheers and have a great weekend! Hoping to see many of you at our next "geek outing" in December--we will meet somewhere informally (probably Dave and Buster's so I can kick Bayer's butt in basketball) to drink beer and (possibly) talk about software architectures. Bayer White will post the information on JaxDug's website regarding the location and time of this meeting.
|
-
Quick: if a square object inherits a rectangle object, what OO principle does this violate?
If your answer is Liskov Subsitution Principle (or Design by Contract principle), you can probably stop reading this now, since there is little new information for you below. If, however, you are having trouble thinking about OO principles beyond encapsulation, inheritance, and polymorphism (which, arguably, can be classified as both features and concepts of object orientation) and would like to learn a bit more, read on.
To paraphraze Dr. Dobb's Architecture Portal, "poor architectural design is everywhere; the brilliant designs are very rare." Obviously, lack of sufficient understanding of business processes is one major cause of poor systems design; but the other major cause is the lack of knowledge of OO principles. I am guilty of producing a few designs that I would rather not take a second look at, but there's hope for me yet, as I try to be a bit better each time I do it. Without further ado, let's get back to the square inhereting from rectangle.
For the mathematically inclined (or those who need a sleep aid), here's the formal definition of Liskov Substitution Principle (LSP for short):
What is wanted here is something like the following substitution property: If for each object o1 of type S there is an object o2 of type T such that for all programs P defined in terms of T, the behavior of P is unchanged when o1 is substituted for o2 then S is a subtype of T.
In simpler terms, this means that it should be possible to use any subclass in place of its parent class. To observe the violation of this principle when using a square class that inherits from a rectangle, think about a method testing the calculation of the area of rectangle. Let's say it's defined like this:
public int testCalculateArea(Rectangle r) { r.Width = 10; r.Height = 20; return r.Width * r.Height; }
If an object passed in to testCalculateArea() method is a rectangle (not a square), the result of the execution of the method above is clearcut: 200. However, if the object passed in to that method is a square, the result is not so obvious--should it be 100, 400, or 200? There's a violation of LSP here, and the real answer is that the square object cannot be polymorphic with the rectangle object without violating LSP.
Open Closed Principle Let's say we modify the testCalculateArea() method above like this:
public int testCalculateArea(Rectangle r) { if r.isSquare() { return r.Width * r.Width; }
else { r.Width = 10; r.Height = 20; return r.Width * r.Height; } }
Before the code could run, we would have to modify the original Rectangle class to include the method called isSquare(). Doing so would violate the Open Closed Principle (OPC), part of which states that classes should be sealed to avoid cascading changes to the existing clients of the code. Another part of the OPC states that classes should still be open for extension and adaptation. The easiest way to think about OPC is that public interfaces of the base classes should not be altered; but via sub-classing, addition of private fields/methods, and applying the Inversion of Control principle (discussed below), the classes can be extended.
Inversion of Control Principle Also known as the "Hollywood Principle," the premise of the Inversion of Control (IoC) technique is simple: "Don't call us, we will call you." The IoC is a well-established technique: think about the callback functions that you may have registered with the remote, long-running web service to update the GUI upon the return of the data. This change of control flow, where the web service calls into the GUI (like Hollywood calling me) instead of the standard GUI calling into web service and waiting for data (me calling
Hollywood for years and still not being able to convince them of my unrivaled artistic ability) pretty much sums up the IoC principle. This tried-and-true OO principle could enhance user experiences with an application, reduce the load on the servers, and it is used extensively in various frameworks.
Dependency Inversion Principle Dependency Inversion Principle is really a fancy name for the simple statement borrowed from the GoF's "Design Patterns": Program to the interfaces, not the implementations. A more formal definition (borrowed from DDJ) could go something like this:
-Higher level modules should not depend on lower level modules. Both should depend on abstractions (interfaces or abstract classes). -Abstractions should not depend on implementations.
There is really not much else to say about the Dependency Inversion, it's a simple, yet fundamental principle of OO design.
Single Responsibility Principle Another one of the fundamental principles, Single Responsibility Principle (SRP) is best summarized by Martin Fowler who said that "there should not be more than one reason for a class to change," or the class should have a single responsibility. If a class has more than one responsibility, it becomes more difficult to understand and reuse, because the responsibilities get coupled. And just as described in Steve McConnell's Code Complete, this cohesion (AKA single responsibility) principle should apply at the method level as well.
According to DDJ, the challenge with SRP is getting the granularity of responsibility right. For instance, should a business entity class persist itself into the database? There are several opinions and patterns on that, including Martin Fowler's "ActiveRecord" patter where each business class wraps a database row. But, there are several other authoritative statements that talk about separating the two concerns (business logic and persistence to the database).
The challenge with adhering to good OO principles is that the payback is not immediately apparent. There's a certain element of faith that requires a bit of extra diligence on the part of designer/architect for a promise of easier maitenance, better reuse and better stability of the system. But just like an artist trying to better him or herself with each stroke of the brush, applying these principles will, in time, give us the opportunity to paint a masterpiece that, in Geekland, will rival Dali's "The Persistence of Memory."
|
-
Why Software Sucks
We are experimenting with a couple of new ideas for the JaxDUG meetings (for example, Jonathan's Code Katas session is planned for December), so we started incorporating a 5-10 minute book review each month. Depending on users' interest, we will continue or drop it in the future. As I warned Jonathan though, people will be stuck with my eccentric literature choices unless someone else volunteers for these brief presentations (e-mail me or post the comments to this blog entry if interested). For my next review, I'll take on something more .Net software engineer-friendly, namely, the "Learning WCF: A Hands-on Guide" by Michelle Bustamante.
For the first book review this past Wednesday, I emphasized that the free books we get at Microsoft sessions could actually be quite interesting. A good example of this is 'Why Software Sucks' by David Platt. Since it was one of the last freebies to go at the Jax Architects meeting, I expected that book to become best buddies with "Developing ActiveX controls with Visual Basic 6.0" inside my spacious closet. But, surprisingly, I found it insightful and entertaining.
To briefly recap my presentation:
The main point of the book, which is written by a software engineer for non-technical folk by the way, is: "Know your user, for she is not you." Throughout the chapters, the author drives the point home that we, the geeks, build software for the geeks and not for the real users. The poor paper clip of Office 97 gets a heavy pounding as the biggest waste of programming time ever in Chapter 1, which deals with user interface design and usability testing. Starbucks and UPS get lambasted in Chapter 2 for their user-unfriendly web sites. Chapters 3 and 4 talk about security and the annoying "You must register for this web site" requirements of the millions of web sites these days, the requirements that actually make the universe less secure, according to the author. Dave Platt also touches on the psychology of the geeks, and postulates (yes, I am a proud geek for using that word!) that software would have been much more user-friendly if we had more women entering the field. Obviously, one man's opinion that I tend to agree with, but that has triggered some discussion during the meeting (a very, very good thing!).
Whether you agree or disagree with the points raised by Dave Platt, I still believe that you will find his style of writing entertaining and full of golden nuggets of information (the origin of the word "debugging," for instance). It is also full of Microsoft jokes, and I give Microsoft major props for giving away the book in which the company is made fun of (in a harmless kind of the way, of course). I'd give this book a 4-out-of-4 stars, but it's probably because my view of the software world perfectly matches Dave Platt's perspective.
Gartner on 14 Delivery Models Transforming IT
Yet another "Run for Cover if you are a software geek!" article from the consulting powerhouse that brought us the big three letters transforming the industry (S, O, and A, voted as the most confusing acronym of the year, BTW). The way I interpreted all 14 points was that techology, both hardware and software, is going to be increasingly outsourced due to IT services becoming a simple commodity, similar to electricity and water. Basically, the "IT Doesn't Matter" by Nicholas G. Carr deja vu. The original piece by Mr. Carr sent the technology community through the roof (just google or "live search" the "IT Doesn't Matter"), with rebuttals that we, the geeks, matter a lot to the enterprise.
Verbatim, this is what Mr. Margevicius said:
"[There are] parallels between these future simplifications of IT with the evolution of other important infrastructure services once maintained by businesses at large.
For example, there was a time businesses used to concern themselves with generating their own electricity or providing their own telecommunications service. In each case, as new methods of delivery emerged, they were able to take advantage of the service without maintaining the requisite infrastructure."
My personal opinion (and hey, that's what this blog is for, right--to express my personal opinions) is that a well-nurtured, talented internal IT force will always be a major asset to the company. Just as the owner (or part-owner) of the local restaurant is much more likely to provide you with the great customer service than one of the temporary employees, the internal IT staff with the strategic role in the enterprise is much more likely to implement the technological solutions that will drive business growth and/or reduce costs. It could be as simple as identifying areas within technology that need improvement (and those are omnipresent), and as complex as building the next generation of business analysis tools for the enterprise. That human element of IT, the fact that we are not just a group of cyborgs with a 3-line instruction set "Veni. Vidi. Codi." (sorry, Apple) is what I believe does make the IT strategic. The ability to nurture that talent, play on everyone's strengths, is what can deliver that strategic advantage to businesses.
Of course, now if only all of the managers thought the same way...
Whether you think I am right on or full of ya-know-what, I'd love to hear from you, so let me have it...
|
-
In my first ever blog post, I want to go ahead and get the mandatory milestone of any introductory programming course out of the way. So, here it goes:
Hello, Blog World!
With that monumental accomplishment out of the way, I can focus on the subject of my recent mini-presentation to the Jax Architects users group, namely DLINQ and its potential impact on .Net application architectures. The basic idea of my presentation, perhaps a bit stretched, was that with DLINQ and anonymous types in C# 3.5 it is easier and more appropriate to work with denormalized database tables in scenarios where high performance and availability are of topmost priority. But let's start at the beginning and see how we can arrive at this conclusion...
LINQ (Language INtegrated Query) is the newest feature of .Net 3.5 Framework. .Net Framework 3.5 is available as a separate download or as a part of Visual Studio 2008 (in Beta 2 as of this writing). Without rehashing Microsoft's documentation, LINQ simplifies working with data, making querying and filtering lists of data a snap. LINQ to SQL (also known as DLINQ) is a subset of LINQ and it allows easy access and manipulation of data inside SQL Server databases (only SQL Server databases, however, as of VS 2008 Beta 2). Although many people refer to DLINQ as an implementation of Object-Relational Mapping (ORM) for .Net, I would say that a true Object-Relational Mapping mplementation would make the software developer completely oblivious to the existence of the database. A true ORM allows a developer to create and use objects in code that automatically end up in the database without extra effort or knowledge of the database layer. Since DLINQ does not do that (rather, it creates attribute-based mappings of SQL Server tables to objects in the special 'DataContext' conduit class), I would refer to DLINQ as the 'enabler of strongly-typed access to database data'.
To take full advantage of LINQ (and DLINQ), some prerequisite knowledge of new features in .Net 3.5 is required. Those features are (see the attached presentation for my attempt to graphically explain them):
1. Anonymous Types 2. Object/Collection Initializers 3. Extension Methods 4. Query Syntax 5. Lambda Expressions
Let's take a look at each one of these features in some detail.
1. Anonymous types, in my opinion, is the most radical, powerful, and unusual feature in .Net 3.5. In essence, an anonymous type allows us to define/shape strongly typed objects "on the fly." For example, given the following declaration
var strIAmAString = "I really am a string"
the variable strIAmAString becomes of type string, with all of the string methods invokable on this variable and available in VS 2008 via IntelliSense after its declaration. 'Anonymous Types' is Microsoft's reference to what has been known for a while as "duck typing" in other languages, such as Ruby. Duck typing is best explained by paraphrazing the old saying, "if it looks like a string, acts like a string, then it must be the string." The 'var' declaration above indicates that the type of the variable that follows will be derived based on its initialization, which must be present during the declaration of that variable. Anonymous types cannot be used as method parameters, however, since the compiler needs to know the types of method parameters during the compilation time.
The real power of anonymous types lies in the fact that we can declare custom objects "as needed," use them and throw them away. This feature comes particularly handy when coupled with strongly-typed access to database (DLINQ), where, at any moment during the program flow, we can go directly to the data tables and construct custom objects containing the necessary data. The example below creates a new set of objects, AmericanAuthors, each containg properties for the first and last name:
var AmericanAuthors = from a in dt.Authors where a.CountryOfBirth == "USA" select new { AuthorFirstName = a.FirstName, AuthorLastName = a.LastName }
2. Object/Collection Initializers is a fancy name for the short way to set values on an object. For example, both of the code segments below initialize an Author object:
C# 3.0: Author author = new Author { LastName = “Chuvyrov”, FirstName = “Eugene” }
C# prior to 3.0: Author author = new Author(); author.LastName = "Chuvyrov"; author.FirstName = "Eugene";
Nothing earth-shaking for sure, but a handy feature nevertheless.
3. Extension methods is the reference to the ability to add new methods to existing CLR types in .Net 3.5. In the example below, the new method IsValidEmailAddress is added to the string type (borrowed from Scott Guthrie's blog, where you could also find more details about the extension methods). Note the usage of keyword 'this' in the parameter declaration, which glues everything together:
public static bool IsValidEmailAddress(this string s) { Regex regex = new Regex(@"^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$"); return regex.IsMatch(s); }
After this declaration (and making sure that the method is in the namespace accessible to our program), we could use (with IntelliSense support even!) the new method in the following manner:
string emailAddress = "bill@microsoft.com" if (emailAddress.isValidEmailAddress()) …
4. Query Syntax is a reference to a more readable way to query data inside .Net 3.5. In other words, it's a feature that enables writing LINQ queryies without requiring a PhD in Computer Science. You don't have to use query syntax when writing LINQ queries, but stick with Lambda expressions and Extension Methods (described below). Consider the following two examples, which produce equivalent results:
Without Query Syntax: IEnumerable<AuthorArticles> results = dt.AuthorArticles.Where(aa=>aa.LastName.StartsWith(“Chuvyrov”))
With Query Syntax: IEnumerable<AuthorArticles> results = from aa in dt.AuthorArticles where aa.LastName.StartsWith(“Chuvyrov”) select aa;
Query syntax makes querying for data a lot more SQL-like and a somewhat more readable. Without Query Syntax, an understanding of Lambda expressions is a must, and I will briefly cover Lambda expressions in the section below.
A few more words on the structure of Query Syntax: every query expression begins with a "from" clause and ends with either a "select" or "group" clause. The "from" clause indicates what data you want to query. The "select" clause indicates what data we want returned, and what shape it should be in.
5. The easiest way to conceptualize Lambda expressions is to think of them as ways to write concise inline methods. Or, you can think of them as shorthand for anonymous methods introduced in C# 2.0, but I prefer "inline methods" myself. The attached presentation contains an example of writing out Lambda expressions as anonymous methods. Here, I would only like to emphasize that Lambda expressions would always have three parts:
-the left part indicating the object accepted as parameter (note that this could be derived, or "guessed", by Visual Studio 2008, so you don't have to supply the type of this object) -the '=>' separator just to confuse us normal folk; its sole purpose in life is to separate the left part from the right part of the Lambda expression -the right part that actually evaluates some programmer-defined expression and returns a value
If you need step-by-step instructions on modeling databases using LINQ to SQL, please refer to Part 1 of Scott Gu's blog:
For the fear of this first blog post running way too lengthy (too late, I realize!), let me get to the point already:
With the availability of anonymous types and other tools in C# 3.5, should database always matter to .Net Developers? Should developers always blindly follow Codd's normalization principles ("The key, the only key, and nothing but the key, so help us Codd")? Should architecture of any data-dependent processes always have a separate "database design" phase?
Let's say we have a standard e-commerce application, where customers shop for different kinds of products. We may store different types of products in different tables in relational DBMS, and each product may have specific shipping instructions, customization properties, etc. Imagine all of this data being stored in relational database while thousands of customers are hitting our application. Wouldn't it make a lot of sense not to have to perform a dozen joins simply to get to the data for a single customer? And while we are at it, wouldn't it be cool not to ask five different programmers to go to their cubes and build a zillion stored procedures gathering all these data pieces while you sit and think about the best possible abstraction layer for all of the SQL code they will write?
What I am getting at is that, perhaps, in certain situations where performance is paramount and the number of joins required by the RDBMS is excessive, the use of relational database may no longer be appropriate. The DLINQ technology could become the enabler of the easy querying of in-memory persistent objects, or some sort of denormalized database structures. Some authors on the Internet already argue that RDBMS is dead, or at least dying. For example, Todd Hoff of http://highscalability.com/ states:
“The problem is joins are relatively slow, especially over very large data sets, and if they are slow your website is slow. It takes a long time to get all those separate bits of information off disk and put them all together again. Flickr decided to denormalize because it took 13 Selects to each Insert, Delete or Update. “
There are several ways we could about denormalizing the data storage: some advocate putting all of the data into a single BLOB field in the database, and have separate database columns for fields that are searchable. Others (like myself) think that a more appropriate solution would be a single database table resembling a giant spreadsheet with customer names, product names, etc. duplicated many times over.
Of course, there's an issue of maintaing consistency of denormalized data, which may seem as somewhat unchartered and perhaps dangerous waters at the moment. Fear not, however, since the giants came before you, as evident by eBay following the BASE (Basically Available, Scalable/Soft state & Eventually Consistent) approach to data storage. Still, for small shops with more limited resources and expertise, performance vs. consistency is an important architectural decision that DLINQ perhaps just made it a bit simpler.
Do you denormalize data in .Net applications on a regular basis? Do you think DLINQ will make the dealing with denormalized data easier, more abstract? Will DLINQ be a factor when considering the potential denormalization of the database?
Let me know at echuvyrov at msn dot com.
Resources:
ScottGu’s Blog: LINQ to SQL, 9-part series http://weblogs.asp.net/scottgu/archive/2007/09/07/linq-to-sql-part-9-using-a-custom-linq-expression-with-the-lt-asp-linqdatasource-gt-control.aspx
Bill Wagner’s Blog on LINQ: http://srtsolutions.com/blogs/billwagner/archive/tags/LINQ/default.aspx
|
|
|