Rob Kraft's Software Development Blog

Software Development Insights

Archive for December, 2011

Resolving missing System.Windows.Forms.DataVisualization in nant build

Posted by robkraft on December 11, 2011

We added some new features in our code this week that required System.Windows.Forms.DataVisualization. No problem until we ran the nant build and it failed with:

The type or namespace name 'DataVisualization' does not exist in the namespace 'System.Windows.Forms' (are you missing an assembly reference?)

We tried copying the DLL several places, even though we later discovered this was unnecessary. The DLL exists in the GAC and we only need to add the reference to the DLL in the nant .build file.

It turns out that the problem exists in the nant.exe.config file we use. This file notoriously has several errors and needs to be updated. I found a copy of nant.exe.config that we need at http://pastebin.com/YxxaKADS. I simply copied the 2 lines at 121 and 122 and pasted them into our nant.exe.config build file and the problem was solved.

121. <include name="System.Windows.Forms.DataVisualization.Design.dll" / >
122. <include name="System.Windows.Forms.DataVisualization.dll" / >

Advertisements

Posted in Coding, Dev Environment | Leave a Comment »

Find Stored Procedures that are not using all the Parameters Passed into them. SQL Server.

Posted by robkraft on December 10, 2011

This last week we discovered a bug in a stored procedure. We were passing a parameter into a stored procedure used to do an insert, but the value was not used in the actual insert statement, and thus the value was not stored in the database table. The problem was easy to fix, but as with all bugs, I ask if there is a way we can prevent the bug from recurring. We came up with an SQL statement that we can run to identify all the stored procedures that have unused parameters into them. We then set up a unit test to run every night to let us know if any of our stored procedures have this flaw. Here is the stored procedure that should work on any version of SQL Server from 2005 on up.

SELECT ROUTINE_NAME, P.PARAMETER_NAME
FROM INFORMATION_SCHEMA.ROUTINES R
INNER JOIN
INFORMATION_SCHEMA.PARAMETERS P
ON P.SPECIFIC_NAME = R.ROUTINE_NAME
WHERE ( (LEN(OBJECT_DEFINITION(OBJECT_ID(R.ROUTINE_NAME)) ) - LEN(REPLACE(OBJECT_DEFINITION(OBJECT_ID(R.ROUTINE_NAME)) , P.PARAMETER_NAME, ''))) - LEN(P.PARAMETER_NAME) = 0)
ORDER BY 1,2

The clever piece of this query is that we use the Information_Schema.Parameters to get a list of all the parameters in each stored procedure, and then we replace all occurrences of the parameter name in the stored procedure with an empty length string. If the length of the stored procedure prior to our substitution and subtracting the length of the parameter name just once is equal to zero, then we know the parameter only occurs once, in the input, and that it is not used within the body of the stored procedure.

Note, you may want to include an additional clause in the where clause if you want to exclude some of the system stored procedures.

Posted in SQL Server | Leave a Comment »

Binary Serialization Notes in .Net 4.0

Posted by robkraft on December 5, 2011

I ran into a problem using binary serialization recently.  Some of the objects that I was serializing were really large.  By really large I mean that they were 2,000,000 bytes long instead of the expected 2,000 bytes long.  I could not find a good source of information about binary serialization other than this fine article:  http://www.diranieh.com/NETSerialization/BinarySerialization.htm
But even that article left we with questions.  I ended up writing tests to find my answers.  Here are my notes:

  • In Binary Serialization, fields are serialized (in XML serialization they are not).
  • Properties are serialized in both Binary and XML.
  • In Binary Serialization, if you add a property for the field, the field and property are not both serialized (at least for simple properties).
  • Static fields and properties are not serialized.
  • Private fields ARE serialized in Binary Serialization.
  • Properties without setters (ReadOnly properties) are not serialized.
  • Make sure that you do not serialize events.  That is what caused my objects to grow 1,000 times larger.

Make sure to apply this attribute to any events you define:
[field: NonSerialized]
public new event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;

We also wrote unit tests to make sure our objects did not experience unintended excessive growth in the future:

   1:  [Test]
   2:  public void TheSizeOfOneModuleShouldNotExceed25000bytes()
   3:  {
   4:  var module = ModuleList.GetByModuleID(3);
   5:  long lBuffer = 0;
   6:  using (MemoryStream buffer = new MemoryStream())
   7:  {
   8:   BinaryFormatter formatter = new BinaryFormatter();
   9:   formatter.Serialize(buffer, module);
  10:   lBuffer += buffer.Length;
  11:  }
  12:  Assert.That(lBuffer, Is.LessThan(25000));
  13:  }

				

Posted in Coding, Visual Studio 2010 | Leave a Comment »

Encapsulating code in business objects almost always means better code

Posted by robkraft on December 3, 2011

Good examples of better coding are not always easy to find, but here is one.  A good coding principal is to encapsulate business logic in business objects instead of including business logic in the user interface.  This is the foundation of coding using object oriented principles.  One specific example is to compare these two ways to write the same code:

 1: buttonDelete_click()
 2: {
 3:     If myObject.HasChildren then
 4:         ShowMessage("You can't delete an object with children.")
 5:     End if
 6: }
 7:  
 8: buttonDelete_click()
 9: {
 10:     If myObject.AllowDelete = False then
 11:         ShowMessage(myObject.ReasonDeleteNotAllowedMessage)
 12:     End if
 13: }

The first code sample may be the first to come to mind, but the first solution that comes to mind is often not the best.  The second code sample is superior because it places the logic for AllowDelete inside the business object, and thus it makes that logic re-usable in other places.  Perhaps you have an import utility that could use the same logic, or perhaps you want to write unit tests.  In the second example, you can write unit tests to make sure that the AllowDelete property is being set correctly; but the first example would require UI testing to confirm this.

In my example, the code inside of the .AllowDelete property probably looks like this:

 1: Public bool AllowDelete()
 2: {
 3:     If (this.HasChildren == true)
 4:         Return false;
 5:     End if
 6: }

By placing this logic in the business object, it would be easy to expand it later and the additional logic would apply to all user interface and batch processing code that uses it.

Any time you can encapsulate some logic within an object, it is probably worth the smalladditional amount of time to do so.

Posted in Code Design, CodeProject, Coding | 1 Comment »

The Next Generation of User Group Meetings

Posted by robkraft on December 2, 2011

In the Kansas City metro I’ve noticed an increase in the number of computer user groups forming to meet and discuss and learn about software technologies.  Some of these groups have exploded on the scene with an average attendance of more than 30 people per meeting, which outdoes groups that have been existing more than a decade with less than 10 people per meeting.

But I think it is time to try to do more.  I think we can do a better job.  I think the goal is to increase the knowledge of technologists about all the things they are interested in; and I’ve noticed that some of the most popular meeting topics are about “other things”.  For example, training on Ruby at the .Net meeting produces a large crowd; and training on IIS at the Java meeting produces a large crowd.  Why is that?  I believe it is because most developers recognize the need to have at least some knowledge of the tools they don’t regularly use.  By raising our own awareness of other tools and techniques, we are open to more possible ways to solve problems.  More importantly, after we have learned the basics and some pros and cons of a new tool or language, we are less intimidated by that tool or language and more open to consider using it in future projects.

What does this all mean for user groups?  I believe that we should continue to have the “Special Interest Groups” to focus on the arcane and specific features of the group’s named technology.  But I believe we need a general interest group that presents tools and technologies at a high-level (introductory level) that can be marketed to the entire community of developers in the metro.

How do we go about this?

  1. We need to find a venue to host these meetings.  My hope is that we can draw 50 to 200 people at each meeting.  Therefore, we would want a venue that can accommodate such a crowd.
  2. We need to identify topics of presentations that can be presented as introductory material to this large audience.
  3. We need to find good presenters that are enthusiastic about presenting and answering questions on these topics.  In addition, the      presents will probably, but not necessarily, need to create the presentation.
  4.  We need to get the word out to all IT people in the KC Metro about the event.  And I want to jump on my soap box here and say that the goal is not to get as many bodies as possible at the event; the goal is to make everyone in the KC Metro that might be interested in this topic aware of the opportunity to learn.
  5. We need coordinators to bring all these elements together at the same place and time.
  6. Optionally, we could obtain sponsors to help pay venue costs if any, and to provide food, drinks and prizes; but I don’t believe that food, drinks, or prizes are necessary to draw the crowd.
  1. Now I am not sure what venues can hold this many people.  I believe that JCCC could do it, and probably would be open to it; but their business needs usually come first.  Red Nova Labs and VML both seem to have large venues, but I don’t know if they are large enough.  Can you suggest other venues?
  2. The list of potential topics is long.  I will start a list with these items: TDD, Agile, Kanban, Starting in Ruby, Perl, JavaScript, Jquery, HTML5, CSS3, SQL, Unit tests, Inversion of Control, Asp.Net, MVC, MVVM, SQL Injection and XSS, Starting in .Net, Starting in Java.
  3. The list of good presenters is also long.  In fact, the current local user groups, those that I collectively refer to as Special Interest      Groups, could serve as the training grounds for finding presenters.  If you know someone that gave a great presentation at a local user group, then recommend that person and their presentation for the new general interest group.  Also we need to hear from presenters      about topics they would like to present.
  4. We already know several ways to get the word out.  www.KansasCityUsergroups.com, and www.kcitp.com and linkedIn.  We would, of course, set up a simple web site with info about the upcoming event.  We could contact all the local groups and have them announce the meeting.  We might also spread the word by creating a meetup for the event.  We could start a twitter hash tag as well.
  5. We need people to do these things.  I believe that if we can get 5 to 10 people behind this to do the work, it will be enough to make it happen and those 5 to 10 won’t get burned out.  Personally, I would like to be one of the marketers to spread the message about the upcoming meetings, and I hope Mike Gelphman would work with me.  I would leave it to others to find the venue, topic, and presenter.
  6. If a vendor reads this blog and wants to step forward, then please do so.  Of if you want to contact potential sponsors, please do so.  They are certainly welcome, especially if we incur venue costs that the sponsor will pay for.  But this is primarily about increasing the skill levels of our technologies and those making technology decisions, not about selling products.

The OWASP group has a pretty good speaker agreement that I believe we could copy for this group as well.  Perhaps a similar agreement from venue host and sponsor would be helpful. https://www.owasp.org/index.php/Speaker_Agreement

Who wants to see this happen?  Who wants to be a driver to make this happen?  Let’s make the software developers in the Kansas City metro the best in the world!

Posted in CodeProject, Coding, Project Management, Resources and Tools | Leave a Comment »