Chapter 26. Project Complete

You’ve done it! You’ve completed the Library Project and met with acclaim from users and fellow programmers alike. And you’ve also accomplished something that few thought was possible: you slogged through all 26 chapters of this book. You’re probably anxious to get on with your life as a highly paid software consultant, working just six months per year as the programmer who other programmers call when systems fail. Well, I won’t keep you too long. But there are a few more issues to discuss concerning the Library Project and programming in general.

The Library Project

The Library Project is filled with features that target small library-style organizations. But it may not meet everyone’s needs. And that’s OK. The users know your address and phone number; you’ll hear from them. When they call, you can tell them that the software wasn’t designed for everyone; no software can be. All software, even general-purpose applications such as Visual Studio, can never meet the needs of every person or organization. What is important is that the features included in the project meet the needs of the intended audience. That audience may be the card-catalog-using public, or it may just be a small library with one part-time staff member.

Still, there is always room for improvement. Because the Library Project’s real target audience was you—the student of Visual Basic and .NET—it did not have all the features that most libraries would require. Looking quickly back through the source code, I came up with at least the following changes that could be made to the project to bring a lot more value to library administrators and users:

Error logging

The application includes rudimentary error detection and handling features, but they could definitely be improved. The logging feature used in the application’s GeneralError method (which includes a call to My.Application.Log.WriteException) sends the written content to any registered log listener. We just used the default listeners, but we could have added listeners to centrally collect error reports and details in a database or file for later analysis.

Error handling

When an error does occur, most of the Library code simply reports the error and moves on. Some methods ignore errors completely. In general, the code could do a better job of processing error results. Some errors are more fatal than others, and specific errors should include additional options that the user can access to better recover from the fault.

Multithreading

We did not discuss or take advantage of any of the threading features included in the .NET Framework. Processor-intensive activities tend to kill the responsiveness of the user interface, but there are ways to mitigate the impact. In the Library Project, two specific areas would benefit from the use of background worker threads, either using the features of the System.Threading namespace directly, or by using the BackgroundWorker control: (1) searching for library items through the ItemLookup form; and (2) processing overdue and fine data for a single day at all locations through the MainForm.ActDoProcess_Click event handler.

User interface and presentation

Although I included some cute graphics on the main Library Project form and the Splash form, I didn’t do much beyond that. Mostly it was an issue of time and effort, but I also have very little talent for the graphic arts. The program could use an update in its general look and presentation. And with the new graphics features available through the Windows Presentation Foundation (WPF), you could enable some really amazing effects with little programming effort.

User interface consistency

Although I tried to be careful, there are probably labels, controls, and error messages that use two different names for the same thing. Perhaps I used the word book or DVD when I should have used the more general term item. Although tracking down such inconsistencies is a lot of work, it increases the level of professionalism in your application. It also makes the task of foreign-language translation easier when localizing the program.

Testing new databases

The LocateDatabase.vb form builds a connection string from the fields supplied by the user, but it does not test the connection to see whether it works. Providing an option to test the entered values could reduce long-term errors. An even better option would be to let the user search for the database, similar to the way that SQL Server itself sniffs out and presents located servers and databases.

Numeric title searches

The checkout and check-in features let you locate an item either by name or by bar code. If you enter a number, the program assumes that you have entered a bar code and retrieves the matching item. But some book titles are numeric. For instance, David McCullough’s book 1776 would cause the program some difficulty if each copy did not include its own bar code. An enhancement to the program would provide the user additional disambiguation options when a numeric entry matched both a bar code and a title.

Enhanced item searches

Although I have much reason to be impressed by my item lookup code, the program could do so much more. When you use the card catalog systems at larger libraries, the lookup features include “proximity searches” that return results that are alphabetically close to the search terms provided by the user. SQL Server also has a “full text search” option that could be used to broaden the item lookups.

Reserves and holds

I started to add a “reserves” feature to the Library Project so that patrons could add their names to a waiting list for checked-out library items, and have those items placed aside by the library staff when they were returned by the previous patron. Although this would be a cool and useful feature for a library, it didn’t add any pedagogic value to the book, so I left it out. But I still hear the software sniffling and crying once in a while when it thinks of the feature that might have been. This would be a great enhancement for “version 2.”

Incomplete item history

On the PatronRecord.vb form, the Fines list shows a patron’s previously checked-out library items only if those items had once been overdue and had incurred fines. Items that were returned on time cannot be displayed in the list using the current form logic. A satisfying change would add a “Show all returned items” checkbox that would include these checked-in items. This would allow a librarian to charge for things such as damage on items that were otherwise free of fines.

Return of missing items

If an item is marked as missing, the library staff may charge the patron for the loss of the book. If the patron later returns that item, the librarian can process a reimbursement to the patron. But the program could make this task easier by automatically marking the item as eligible for such a refund. This would require a new status field on the PatronCopy database table to track this status.

Bar code design interaction

The BarcodeLabel.vb form is, I think, pretty amazing with its graphics preview of the bar code. But the preview is unidirectional only; the user is not able to select a display element by clicking on that element in the preview. Instead, it is necessary to click on the related item in the DisplayItems list. Enhancing the program to detect clicks on the preview and to translate those clicks into item selections would make the program much more like other applications that support basic drawing features.

Database setup features

Although we built the setup program for the main Library application, we skimped on the server side, only providing the database creation scripts as text files on the installation media. A more professional system would provide a separate installation program that could build and configure a new database from an existing SQL Server installation.

Support for library standards

Just as the software development world has standard formats and protocols such as XML, library systems also share common standards. Two accepted standards are MARC (Machine-Readable Cataloging, a standard card catalog data format) and the Z39.50 interface (a communications protocol used for inter-computer searches and data retrieval). Incorporating these standards into a small library system may be overkill, but they would bring a much higher level of automation and convenience to the library staff.

Bug fixes

I probably left a few bugs in the application. No, wait. I think I put them in there on purpose to test you, to see whether you were learning and growing in your programming skills. Did you find them?

These are just some of the improvements that I thought of off the top of my head. If I had gone all the way down to my shoulders, I could have come up with even more. If your software will target the general population of users, you will probably release updates on a regular schedule, such as annually, and charge appropriately for the improved features. If you wrote the application for one specific customer, the updates may be more frequent, even weekly or daily in some cases. Whatever the audience size, your opportunities to improve and enhance the software will be regular and ongoing.

Visual Basic Flexibility

I started using Visual Basic back when version 2.0 of the product was still in vogue. As a result, I picked up some pre-.NET coding habits that have been hard to break, even with my full-time focus on .NET code. I’ve reached a level of comfort in my Visual Basic coding, and that comfort shows in my .NET programming style.

As I mentioned in earlier chapters, many of the features that previously existed in Visual Basic before .NET were moved out of the language and into Framework classes. The most noticeable of these were the mathematics features now found in the System.Math class. But there were other non-math Visual Basic language keywords that also became class methods. Many of these appear in the Microsoft.VisualBasic namespace, including methods such as Left, Trim, and MsgBox.

When I wrote the Library Project code, I freely used some features found in the Microsoft.VisualBasic namespace. Although I don’t have a problem with this practice, you may encounter other Visual Basic developers who don’t agree with how I’ve written the code. They point out that most, and possibly all, of the features in Microsoft.VisualBasic have Framework Class Library (FCL) equivalents, and these should be used for reasons of compatibility with other .NET languages and systems.

A key example is the MsgBox function. I’ve used it throughout the Library source code. The keyword MsgBox has always been a part of the Visual Basic language, but beyond its continued existence in Microsoft.VisualBasic, it is not a part of the Framework classes. Instead of MsgBox, other programmers (including C# programmers) use the System.Windows.Forms.MessageBox.Show method. It does offer more options than MsgBox, and it displays a message box that is every bit as beautiful as the Visual Basic version. But for me, my fingers have gotten used to typing the short six-character MsgBox keyword. (MessageBox.Show has 15 characters!) Also, the arguments passed to MessageBox.Show are slightly rearranged from those used in MsgBox. Using both of them in a single program could result in some confusion.

Supporters of MessageBox.Show emphasize that if you ever needed to convert Visual Basic code to C#, the presence of MsgBox would slow down the conversion. Although I understand this and other concerns, I have not yet been fully convinced that there is any problem using MsgBox. Any conversion tool that existed to change Visual Basic code into C# would certainly know how to handle MsgBox.

Tip

Beginning with the 2008 edition, Visual Basic includes something called “runtime agility.” This is a fancy marketing way of saying that you can now compile and deploy Visual Basic applications without the need for the Microsoft.VisualBasic namespace and related assembly. Although this isn’t a big deal for most desktop or ASP.NET applications, the ability to compile a Visual Basic program with fewer dependencies, and hence a smaller “footprint,” does have implications for the quick download of custom logic over the Web through Microsoft’s Silverlight product. If you will target this platform, it will be a good idea to omit all references to features found in Microsoft.VisualBasic.

As another example, consider the older Exit Sub statement. It still exists in Visual Basic for .NET, but the new Return keyword performs the same job of immediately exiting from the current method. (Return had a different meaning in Visual Basic before .NET, but now it only exits methods.) You can use either Exit Sub or Return in your code; they are identical in functionality. There are programmers who consider the older Exit Sub statement to be—well—older. But unlike my reticence to leave my favored MsgBox method, I have wholeheartedly embraced the new Return statement. If it were just an issue of Exit Sub versus Return, I might not have made the switch. But there is the related issue of Exit Function versus Return. I was never happy with the way that pre-.NET Visual Basic functions obtained their return values through an assignment statement to the name of the function. I was ready to make the switch to the newer Return statement. I did so for clarity; keeping the return value as close as possible to the statement that triggers the return to the calling code is a good thing. Before .NET, you might assign the return value, and then not leave the function for dozens of lines. Combining the assignment and the return in a single statement makes sense to me. From there, it was a short trip to replacing Exit Sub with Return. You will not find (I hope) a single Exit Sub statement in the Library Project. My transformation in this area is complete.

Why do I bring all this up? I do it to encourage you to make flexibility your friend when it comes to the different coding variations that exist in Visual Basic. If two different ways of developing a block of code seem to be morally equivalent and you can make the logic clear no matter which method you pick, choose and enjoy the coding style that you are most comfortable with. Some programmers may tell you to do it one way or another, and that’s OK. (If you are part of a development team, the entire team should agree on a common style.) Remember that Visual Basic is a “general-purpose” programming language, and it has a certain amount of flexibility built into the language and related features. Experiment with the variations, and find patterns that you enjoy and that increase your effectiveness as a developer.

The Programming Mindset

As you enter deeper into the world of software development, you will quickly discover that the application-building process is about much more than syntax, statements, and logic. It is also about who you are as a programmer. The way that you think about software, and the care with which you approach the task of programming, have a direct impact on the quality of the code you write. This is certainly true in other areas of life. If you are a portrait painter, but you don’t take your strokes seriously, or if you are sloppy in your use of paints and brushes, it will show in the low quality of your work.

In one of my previous books, The Visual Basic .NET Style Guide (Prentice Hall), I wrote about three traits that provide a strong basis for the programming life:

Discipline

The act of self-training with a goal of increasing order, focus, and quality in your projects and work ethic

Planning

The careful analysis and implementation of procedures and standards that scream out for quality

Ethics

The inner character drive that shows itself through public and private honesty in attitudes and actions

If you are deficient in any of these three areas of your programming life, your applications and code will also be deficient by a similar factor. I have tried to sprinkle some humor and fun throughout the pages of this book. But on this point, I make no jokes. You need these three elements in your work life.

If you are serious about a career in software development, take the time to ask yourself questions that focus on these three aspects. Do I employ regular discipline on the way that I craft my software? Do I create reasonable and reliable plans, and then stick to them during a project? Do I exhibit ethical standards in the way I communicate with my customers, my employer, my coworkers, and even myself? If you are not able to answer these questions to your satisfaction, find resources that can help you overcome the lapses. It will make your programming work so much easier, and it will positively impact the other areas of your life as well.

Summary

Now you’ve really reached the end of the book. You can read through the appendixes and the index if you’re still hungry for more. But a better solution would be to find out if I’ve come out with the next edition of the book and buy it. Ha!

I thank you for taking the time to read through Programming Visual Basic 2008. I wrote it so that you might expand your understanding and expertise of a very practical and enjoyable subject: Visual Basic. And enjoyable is the key word. Nobody has to be a computer programmer, no matter what historians say. You should take on the role of a Visual Basic developer only if you truly take pleasure in helping other people become more productive through specialized or general software. If, even after reading this book, you find coding to be a bore and sheer drudgery, I recommend the food services industry as an alternative.

For those of you still excited about Visual Basic programming, have as much fun with it as possible. Microsoft is constantly updating the language and its Visual Studio shell so that you can really enjoy yourself as you program. Why do you think Microsoft put in all of those animation features? Take time to go beyond the mundane in your code and in your user interfaces. Challenge yourself by trying out new features within the language and in the framework. And above all, smile each time you successfully complete a project. Your author, and your users, will thank you.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.119.166.75