Archive for August, 2007
In this third and final article we will finish up our comparision of the System.String Class to the string functions in the Microsoft.VisualBasic Namespace. If you would like to read the previous articles, read Part I here and Part II here.
Split and Join
These handy string functions move a delimited string to an array or vice versa. Both the System.String and Microsoft.VisualBasic Namespace have these functions available. Is there any reason to prefer one method to the other?
In performance testing, the VB functions lag behind. They’re 40-50% slower than the System.String functions. It looks like this is primarily due to them doing costly object conversions rather than using only straight string values. When we look at the available overloads the System.String functions have the VB version beat there as well with the ability to exclude blank entries and to use an array of delimiters.
When it comes to these functions, System.String is clearly a better choice for your development needs outside of importing legacy code. Even then, there is a significant performance improvement to be found by switching to the new .NET method.
Len
Len, another classic BASIC function, returns the length of a string. System.String has the Length property that provides the same information. Is one better than the other?
Performance-wise, these two functions show little difference over 1000’s of iterations. There doesn’t appear to be any reason to prefer one over the other in this case plus there is no functional difference. I’m kind of partial to using the property value rather than the VB function since it encourages thinking of .NET strings as objects. However, at the core, it’s really only a personal preference thing.
Replace
Replace does what it says, it replaces one character, or group of characters, in a string with a replacement string. How do our two namespaces match up with this function?
The performance test showed that the System.String function was about 7-12% faster than the VB function. If you’re doing a replace over many iterations, this means that there is some performance value to using the .NET String function.
When we look at overloads, the Microsoft.VisualBasic Replace has optional parameters for the start, count, and compare method that the System.String version doesn’t have. If your replacement logic needs these additional parameters, then it’s probably worthwhile to consider using this version of the function.
All in all, which one to use in this case depends on your needs. If you need speed, System.String is the ticket. If you need flexibility, Microsoft.VisualBasic provides it.
Space and StrDup
Space is another venerable BASIC function that’s used to generate a blank, space-filled, string. You may also remember its cousin, String$, that filled in any character in the same manner. This function isn’t in .NET, of course, since it would conflict with the String class. Instead, it has been replaced with the StrDup function. The equivalent System.String function to these two methods is using the New method to generate the string, like so:
Dim HundredSpaces As String = New String(" "c, 100)
Where the first parameter is the character value to use (note the c suffix on the string to define it as character value, not string) and the second is the length. Note that unlike the Space function, you can specify any single character or an array of character values.
Now, let’s see which one performs the best. The performance of both methods is virtually identical. No performance penalty is incurred by using the Microsoft.VisualBasic functions. In fact, in some testing, StrDup outperformed New String and Space by about 10% while in other tests they were dead even. Perhaps the StrDup function is implemented differently.
When we look at the overall functionality there are some factors that lean toward using StrDup. It accepts both Char and String values, thus reducing the need for conversion and/or clumsy array syntax. It will do object conversion internally, if you’re running without Option Strict on (not recommended). Plus, its performance is good. Of course, it is a rather obscure replacement function so you may find that sticking with .NET String functions is better than having to explain what it does each time.
That’s all for this series of articles comparing System.String to Microsoft.VisualBasic string functions. Please let me know what you think by leaving me a comment.
Share This Article:
These icons link to social bookmarking sites where readers can share and discover new web pages.
August 15th, 2007
In my previous article, How To Make Debugging .NET Windows Services Easier, I mentioned using a console or WinForms app to scaffold a Windows Service app for debugging and initial development. Unfortunately, there is a little ‘gotcha’ that needs to be addressed if you decide to do this.
When you’re ready to convert, you’ll want to set the startup object of your Windows Service to the name of your class that contains the service code, including the standard service Protected Overrides OnStart, OnStop, etc., and remove any test forms or Sub Main code from your project. What you will see in the My Project Application tab after doing this is that the old startup objects will remain on the list while your desired class isn’t on the list as shown here:

So, what can you do to correct this problem?
To handle this, you’ll need to edit a hidden generated Designer file because when you switch project types, certain code is not automatically generated. To get to the hidden file, bring up the Solution Explorer window and click on the ‘Show All Files’ button. It’s at the top and is the button circled in red below:
Next, you’ll want to expand the your service’s module to reveal the Designer module, as circled in blue above. Open this file and add the following code to it:
' The main entry point for the process
<MTAThread()> _
<System.Diagnostics.DebuggerNonUserCode()> _
Shared Sub Main()
Dim ServicesToRun() As System.ServiceProcess.ServiceBase
' More than one NT Service may run within the same process. To add
' another service to this process, change the following line to
' create a second service object. For example,
'
' ServicesToRun = New System.ServiceProcess.ServiceBase () {New Service1, New MySecondUserService}
'
ServicesToRun = New System.ServiceProcess.ServiceBase() {New MyService}
System.ServiceProcess.ServiceBase.Run(ServicesToRun)
End Sub
Of course, you would replace ‘MyService’ with the name of your service class. Now, when you go back to the My Project Application tab and click on the StartUp Object drop down you’ll see your service class on the list. Select it and you’ll be ready to compile your application as a Windows Service.
Please let me know if this article was helpful to you or if you have any other questions about this or other Windows Service issues by leaving me a comment.
Share This Article:
These icons link to social bookmarking sites where readers can share and discover new web pages.
August 14th, 2007
In this continuation of my series comparing the .NET String class to the string functions Microsoft.VisualBasic we will take a look at some additional functions and correct an oversight from the first article in this series.
String.TrimEnd and String.TrimStart
In my previous discussion, I had said that the String Class didn’t have an RTrim and LTrim type function. I was wrong. I had overlooked these two functions. These two functions provide the same functionality plus having the overload for a character array of values to trim. Given my other observations from my previous article, I’ll now have to say there is little reason to use LTrim or RTrim except backward compatibility.
Asc and Chr
These two functions have been a mainstay of BASIC development for several decades. Asc returns the character code for a string value while Chr does the opposite, returning a string for the specified character code. There are also the ‘W’ versions of these functions that do the same for Unicode characters sets. But, what does the String class offer in this area? As far as I can tell, it doesn’t offer a direct replacement, at least not an obvious one (if you know of one, please leave me a comment and let me know too).
Instr and InStrRev
Instr is another longstanding BASIC function while InStrRev is new, having been introduced in VB6. They both return the position of the first occurrence of one string within another string, although going from different directions. What is the System.String equivalent to these functions and how does it compare?
System.String uses the IndexOf and LastIndexOf functions to do the same thing. In addition to these functions, you also have the IndexOfAny function that gives you even more options. The primary difference between the two functions is that, as expected, the System.String function return value is zero based while the Microsoft.VisualBasic functions are one based.
What does the performance look like? In my testing I found the performance of these functions to be almost identical. In long running test loops one version of the function would be better while in another run the other would do better.
So, which should you use? I think that in the long run a VB.NET programmer will be better off to use the System.String functions since using a zero base consistently will prevent nasty one-off bugs from entering code. However, it is OK to keep old reliable Instr around for legacy code since it doesn’t seem to incur any performance penalty.
Format Functions
Format is another function that has been around for ages in BASIC. In VB6 Microsoft added some new formatting functions for currency, dates, and numbers. System.String has its own Format function. So, which is better?
In this case, System.String has the Microsoft.VisualBasic namespace soundly beaten. Its function routines are more powerful, thanks to overloads that allow you more formatting flexibility. Plus, it is about 20-30% faster since it avoids costly type conversions. Thus, my recommendation would be to always use the System.String Format function. Given the conversion performance hit, you may even want to change your legacy code if you can.
That’s all for this installment. There are some other functions I’ll be looking at in a third and final part coming up later this week. As always, if you spot anything inaccurate or if you have questions, please feel free to leave me a comment. Your participation is appreciated.
Share This Article:
These icons link to social bookmarking sites where readers can share and discover new web pages.
August 13th, 2007
Tiger Teams often refers to a team of specialists who penetrate security systems on their side in order to test them. It also is used to refer to an ad-hoc team pulled together to solve a particular crisis or thorny problem, such as the team NASA flight director Gene Kranz put together to deal with the Apollo 13 explosion. In this article, we’ll examine how you can put together a problem solving team within your organization.
Why ‘Tiger Team’?
Many IT organizations have support group within their development section. However, most have unappealing names like “Internal Support” or “Operations and Processes Support Group” or some other decidedly unexciting name. By giving this kind of work a dull name, particularly one with support in the title, it generates the perception that the work is dull and perhaps even dead end. Using an exciting name for the work spices up the assignment and sells it better within and outside the organization by adding prestige, importance, and maybe just a little mystique to the assignment. You don’t have to call it tiger but at least use something that builds excitement and doesn’t drain it away.
What Does A Tiger Team Do?
The job of this team is to take care of short term, high priority, projects and problems that always seem to come up. For example, while you’re working on a new release, a critical security flaw shows up in the previous release. Rather than going into a panic and pulling people off the new work in a disorganized fashion, the tiger team goes into action and fixes the problem. Another example would be if the accounting department needed a quick set of reports for investors, the team could put them together quickly. The idea is for this team to provide a quick solutions to unexpected scenarios.
Another use for this kind of team is to provide support to an existing project team. An example of this would be if the project team needs to have additions and changes made to the source control system ASAP. The tigers could step in and take care of it without taking the full team off course. They could also do things like bringing new programmers up to speed and other such things that would take primary project programmers off their assignments.
In general, the assignments should not be any longer than 1 to 2 weeks (preferably even shorter), not involve more than 1 or 2 people, and should be very limited in scope.
Who Should Be On A Tiger Team?
Many organizations have downtime for members between projects. These people are ideal for tiger team assignments. If you don’t have a lot of downtime in your group, pick one person as the tiger on each development team along with one alternate. This allows team leads and managers to factor this into schedules and lets the person with this assignment know that they may have to switch gears from time to time.
Another key factor is to rotate this assignment throughout a development team and base assignments to it on personal work preferences. Bear in mind that some programmers thrive on this kind of work while others dislike it. Some programmers welcome a change of pace from a current project while others find it an annoying distraction. Take this into account. While everyone should take a turn at it, know your team’s preference and juggle your scheduling of this assignment accordingly, perhaps giving those who enjoy it more of these assignments than those who don’t.
If done wrong, assignment to such a team can be seen as punishment and thus become undesirable and unappreciated work. For example, keeping people assigned to doing this kind of work long term without assigning them to a full sized project generally isn’t a good idea. Many programmers will find this demotivating. However, when done right, it can be a positive recognition of a team member’s contributions to the organization and provide critical cross-training within your group. Make sure that you provide as much genuine praise for those who do this kind of work as you do to those working on full sized projects.
Your Thoughts
Have you tried tiger teams or other similar groups within your organization? What was the result? Do you have any other observations about the article or ad-hoc teams? Please leave a comment and let me know.
Share This Article:
These icons link to social bookmarking sites where readers can share and discover new web pages.
August 12th, 2007
This is the last article in my series on applying United States Marine Corps leadership traits and principles to software development team leadership. In this article, we’ll look at some of the principles of leadership where the traits are put into practice.
Here are the other parts of this series:
Know Your Team and Look Out For Them
As team lead, you need to know what the strengths and weaknesses of each team member are. For example, if one person is strong on writing backends and another is strong on UI, assign them to tasks that play to their strengths. If you need to cross-train members, put a strong member with a weaker member. The better you know your team, the more effective they will be. Likewise, if you don’t know or ignore team members capabilities and preferences, you will soon run into difficulty. Use your judgement to make the right choices for you, your team, and your organization.
Also, watch out for your team’s welfare. If a project sponsor insists on your team developing a 12 month project in 6 months, have the moral courage to stand up to them. Don’t just roll over and let your team suffer under an unrealistic schedule.
Keep Your Team Informed
In the Marines and Navy, scuttlebutt was originally the term for a cask of water. Of course, as men drew water they talked and thus the term came to mean exchanging rumors and gossip. The ‘water cooler’ rumor mill is strong in some organizations. As a team lead, it is your job to make sure that you keep your team well informed about your organization and that they aren’t depending on rumors. Playing “I’ve got a secret” with your team is a sure way to damage morale. Have the integrity and dependability to keep your team correctly informed.
Certainly, there will be times you have confidential information. In those cases, show your loyalty to your organization by keeping it secret. However, you should also look out for your team in this case, particularly if the news is bad.
Set Goals You Can Reach
How many team leads have gotten into trouble by agreeing to schedules that they couldn’t keep? A lot, I would wager. It is your job to only accept work that your team can accomplish within the time frame given. Read up on project estimation and negotiation tactics to help protect your team from futile death marches. Your team may be good but don’t ask the impossible from them. Likewise, giving little make-work assignments one after another to a team of crack developers will frustrate them. Set the right goals for your team.
Make Sound and Timely Decisions
Knowledge and judgement are needed to make a sound decision while initiative is needed to make it a timely one. If you’ve made a bad choice, have the courage to change it before more damage is done. While you should avoid changing your mind frequently, sticking with a failing plan or development tool decision will only bring more trouble upon you and your team. Part of making good decisions is knowing when to make a change and when to stick with it despite the odds.
Know Your Job
Honestly, if you don’t know programming well you really don’t need to have a team lead job. This should go without saying but many organizations promote faces and personality over technical skills. As a technical team lead or IT manager it is your job to stay informed on the latest trends. You don’t want to be the kind of manager who says something like, “Oh, Ajax, I clean my kitchen with that” or “Orcas? Yeah, I saw one of those at Sea World.” Instead, you want to be in the know on all the latest trends.
If you don’t know, then have the courage to admit it. Don’t try to fake it in a ‘pointy haired boss’ fashion. Instead, learn from your team when you can. This not only improves your knowledge but improves the morale of the team too.
Teamwork
Encouraging teamwork seems like a no-brainer, doesn’t it? However, I’ve seen a number of teams fail because of interpersonal problems, cliquish behaviors, backstabbing, work hogging or avoidance and other such problems. Make sure that the people on your team are getting along. If they aren’t, find ways to help them deal with each other and, as a last resort, find a way to restructure your team. Ignoring these kinds of personal problems will only make things worse for your team. If you find one member is hogging all the work or avoiding taking on work, make an effort to better distribute the work. Whatever you do, don’t entertain gossip about a team member from another team member. This is a major morale killer.
Also, try to schedule social time together for the team. This might be as simple as lunch or drinks after work as a team once a week or so or something more elaborate on a less frequent basis. Be careful not to exclude some team members from these activities and try your best to schedule them in such a way that everyone can attend easily. While people may not show it, being ‘disinvited’ from such gatherings can be quite a morale killer.
OK, that’s all for this article and the series. Let me know if you liked it or have questions by leaving me a comment.
Share This Article:
These icons link to social bookmarking sites where readers can share and discover new web pages.
August 11th, 2007
Next Posts
Previous Posts