Community Coding Contest 2010 - Looking for Input and Prizes

4. January 2010

Now that it's 2010, and over a year since the first Community Coding Contest came to an end, I'm thinking about running the contest again in 2010.

Last time it ran for 3 months and we had 6 really great entries. This time around I'm thinking that it may be better to accept entries for 6 months, and have the voting run for a full month. This will give much more time for entries to be submitted, and for people to work on their entries before submitting and/or voting begins.

These are just some initial thoughts, and I'm going to need input on everything from YOU (the community) before I can make a final decision as to when and how to run the contest again. I'd really appreciate if you could fill out the following survey and tell us what you think.

Community Coding Contest 2010 Pre-Contest Survey

Also, we will need some prizes donated before the contest will be able to go on. If you or your company are interested in donating prizes or monetary support (web hosting fees, mailing expenses, etc.) for the contest, please contact the contest directly here: http://communitycodingcontest.org/contact.aspx

You can view the official contest website here: http://communitycodingcontest.org

Thanks, and I look forward to hearing more about what everyone thinks!

asp.net, ASP.NET MVC, Bing Maps, C#, Silverlight, vb.net , , , ,

Simple Port Scanner Written in VB.NET 2003/2008

20. January 2009

I was looking over some of the old prototypes I've written in the past, and I can across a Simple Port Scanner that I originally wrote in VB.NET 2003. I originally wrote this back in 2004 (I think), and even posted a compiled version on my website that I have since removed/deleted. So, since it's just sitting on my hard drive collecting virtual dust, I thought I'd post it here in case anyone else can find it usefull.

This Port Scanner implements Multi-Threading via the ThreadPool class in the .NET Framework, so at the very least it can be used as an example of how to use the ThreadPool class to queue up "work units" to be executed asynchronously.

Also, as you see in the screenshot below, there is a "Service" column shown in the Grid. This column tells you what Protocol/Service is normally run on that specific port. It doesn't check for that Protocol/Service on that port, but it helps as a quick reference as to what Protocol/Service may be running there. It's nice sometimes to not be required to memorize all the possible Protocols/Services that run on some of the most common ports used. This list of Port Numbers and Services is stored in th eApp.Config file.

Here's a couple download links for the source code in VB.NET 2003 and VB.NET 2008 Solution/Project files:

VB.NET 2003 - Simple Port Scanner Source Code (15kb)

VB.NET 2008 - Simple Port Scanner Source Code (16kb)

General, vb.net , ,

Develop Software for the Microsoft Windows Platform for FREE

11. December 2008

I've been lucky enough to get 2 free MSDN subscriptions over the last few years, so I've never needed to purchase Visual Studio, Office or SQL Server. The first MSDN subscription I won in a blogging contest back in 2006, and the second I got when I won the Microsoft MVP award earlier this year (2008). Before you start to think that I'm braging; just let me point out that I am very greatful for this. Below is a list/guide that I would follow if I wasn't so fortunate, and I'm not talking about softare piracy (that really is stealing!).

Now the point of this post... What if I didn't win these MSDN Subscriptions? Then, how exactly would I obtain the software necessary to do my job?

No the answer isn't to borrow CD/DVD's from work or a buddy. And, No it's not to fire up Bit Torrent. The software I mention below (all of it) are all freely available to anyone.

Free Tools for Developers

There a quire a few tools out there of various types. Below, I'll focus on the ways you can obtain, for FREE, software that you may otherwise have to pay for. Also, there are so many tools of various kinds, so I'll just be focusing on the main ones that you should be aware of.

Integrated Developement Environment (IDE)

  • MS Visual Studio Express Editions - These are FREE editions of the full Visual Studio product. There is no restriction to selling the software you build using these tools, and they contain all the features necessary for you to build your software. These include Visual Basic Express, Visual C# Express, Visual C++ Express and Visual Web Developer Express.
  • SharpDevelop - This is a FREE, Open Source IDE for developing .NET applications. It's been around since before Microsoft released the Visual Studio Express editions.
  • MS Silverlight Tools for Visual Studio 2008 SP1 - This is a FREE add-on to Visual Studio (both Full Editions and Free Express editions) that enables you to build Silverlight 2 applications. You can find more info on this here.

Database

  • MS SQL Server Express Edition - This is a FREE edition of SQL Server. There are some scalability requirements with it, but it's still perfect for development purposes.

Other Tools

  • .NET Reflector - This allows you to easily view, navigate and searh through the class hierarchies of any .NET assembly; even if you don't have the source code. This tool is invaluable, since it can decompile .NET assemblies and show you the VB.NET, C# or IL code.
  • Internet Explorer Developer Toolbar - This is an add-on to IE7 that adds a much improved (and needed) set of client-side/javascript debugging tools.

There are plenty of tools you can use to develop software for the Microsoft/Windows platform that are completely FREE. All you need is a copy of Windows to begin with, and that comes with any PC you buy.

How to obtain paid tools at No Co$t

Since you can't exactly go to Microsoft.com and download the Full/Paid versions of their software for Free; there are time when they give it away. You just need to look out for those nice opportunities and take advantage of them.

Here's a couple examples in the past that I took advantage of, if I remeber them correctly:

  • Once upon a time there were some online screencasts for VB.NET from Microsoft. If you viewed a certain number of them within a certain time period, then you could enter your mailing address and Microsoft would send you a copy of Visual Basic .NET 2003 for FREE.
  • Back in 2005, Microsoft had this "Ready to Launch" tour that was put on by the MSDN Events people (it was a free conference). If you attended you got a CD/DVD pack that included the Full, RTM versions of Visual Studio 2005 Standard Edition and SQL Server 2005 Standard Edition for FREE.
  • In Dec. 2006, Microsoft gave a bunch of copies of Visual Studio 2008 Professional edition to the Wisconsin .NET Users Group to give away at a special Launch/Holiday meeting that month.
  • In early 2008, Microsoft put on the {Heroes Happen Here} events across the country, again they were free copies of Windows Vista Ultimate w/ Service Pack 1, Visual Studio 2008 Standard, SQL Server 2008 CTP, and Windows Server 2008 1 year trial.

As you can see, I've been able to take advantage of a few FREE opportunities to obtain the tools I need to do my job. I really encourage you to take advantage of these if you can.

 

Happy coding, now go get your Free Tools. And, remember, Do Not Pirate Steal Software; would you want someone to steal the software you write, the same software you're trying to make money on?

 

asp.net, C#, database, Silverlight, vb.net , , ,

A Couple VB.NET Language Tips for C# Developers

31. October 2008

Originally, I started out as a Visual Basic developer, and have since moved mostly to C#. However, when doing consulting work, I do need to cross back and forth quite often. Here are a couple VB.NET tips that you probably aren't aware of if you're mostly a C# developer. Some VB.NET developers may not even know about then either.

Null Coalesce

Null Coalescing is really simple in C#:

// If "someValue" is Null then set "i" to 0 (zero)
// otherwise set it to the value of "someValue"
int? i = someValue ?? 0;

But what about VB.NET?

<code:VB>

Dim i = If(someValue, 0)

</code>

Granted the VB.NET Null Coalesce is a method call, but at least there's still an equivalent available in the language. Also, I believe this is something that was introduced in VB.NET 9.0.

Ternary Conditional Operator

This is the ability have a complete If..Else..Then statement on a single line and have it return a value. This is really simple in C#:

// This performs the same logical operation as the Null Coalesce example above
int? i = (someValue == null ? 0 : someValue);

How about in VB.NET?

<code:VB>

Dim i = If(someValue = Nothing, 0, someValue)

'' The above can be simplified, since if the first parameter is equal to "Nothing"
'' then the "true" (second) parameter is return, otherwise the
'' "false" (third) parameter is returned.
Dim i = If(someValue, 0, someValue)

'' Also to further simplify, you can just pass in the "false" (second) parameter
'' and if its equal to "Nothing" then the "false" (second) parameter is returns,
'' otherwise the value itself is returned.
Dim i = If(someValue, 0) 

</code>

Lock Statement

You may be familiar with the lock statement in C#, especially if you're used to worrying about concurrency.

lock (expression)
{

    ...Some Code...

}

At first it appears to not exist in VB.NET, but they just named it SyncLock instead:

<code:VB>

SyncLock (expression)

    ...Some Code...

End SyncLock

</code>

 

Please, excuse the bad syntax highlighting for the VB.NET code, it seems that my instance of BlogEngine.NET doesn't like to highlight too many blocks of code within the same post.

C#, vb.net , ,

.NET: Why aren't Private Abstract methods allowed?

26. February 2008

Sometimes when creating base objects you want to create methods that are overridable by object that inherit the base object, but keep the methods from being public. However, the compiler throws an exceptions when you try to define a method as "Private Abstract".

Why doesn't the compiler like "Private Abstract" methods?

The reason for this is Private methods can not be overriden. So, essentially the Abstract is useless if the method is Private.

How can I create a "Private" method that's able to be overriden?

Simple, you just declare the method as "Protected Abstract". Protected defines that the method is only accessible from within the class that declared it, and from within any derived class.

C#, SoftwareBasics, vb.net ,

Introduction to LINQ

24. January 2008

What is LINQ?

LINQ (Language INtegrated Query) is more than just a new method of embedding SQL queries within code. It allows to to perform Strongly Typed queries on any kind of data, just as long as the collection of data implements the IEnumerable interface.

The most important part is "Language Integrated". This allows you to more easily write queries in C# 3.0 and VB 9.0 such as:

IEnumerable<Person> filterExample1 = from Person in people
                                                               
where Person.FirstName.ToUpperInvariant().StartsWith("J")
                                                                select Person;

 

Instead of:

IEnumerable<Person> filterExample2 = people
                                                            .Where(p => p.FirstName.ToUpperInvariant().StartsWith(
"J"))
                                                            .Select(p => p);

As you can see the second option takes a little longer to write and isn't quite as easy to read as the first option or a standard SQL query. It essentially allows us to query our data in a SQL-like fashion that we're already familiar with.

The second important part of LINQ (and probably just as important) is since all you query code is written in .NET, you get the benefit of things being Strongly Types, and the compiler type checking the code at compile time. You'll no longer get strange type exceptions at run-time with LINQ that you would traditionally get if you used SQL string within your code.

There's more than one type of LINQ?

Yes, but don't get scared away just yet. The different types of LINQ are for querying different types of data. The differnet types of LINQ are as follows:

  • LINQ to Objects - This type is geared towards working with collections of Objects, hence the name.
  • LINQ to SQL - This type is geared towards working with data from a database.
  • LINQ to XML - This type is geared toward working with data in XML documents.

In the rest of this article we'll be using LINQ to Objects.

Basic Query Syntax

First lets look at the following example; which filters out all the Person objects with a FirstName that starts with the letter "J":

IEnumerable<Person> filterExample1 = from Person in people
                                                                   
where Person.FirstName.ToUpperInvariant().StartsWith("J")
                                                                    select Person;

 

First we declare the collection of data we're going to query from using the "from" operator, "from Person in people". "people" is our collection that inherits from IEnumerable<T> and "Person" is type of object that collection contains.

Second we define any query criteria using the "where" operator. You can define as many where clauses as necessary.

And lastly, we declare the data we're going to select using the "select" operator.

One thing to note when using LINQ: you must define the data to select Last, as compared to First with the SQL language.

Other Simple LINQ Examples

"orderby" Operator: The "orderby" operator allows you to sort your query results.

IEnumerable<Person> orderByAge = from Person in people
                                                                    orderby Person.Age
                                                                    select Person;

 

"let" Operator: The "let" operator allows you to declare a new variable within the scope of the query. This new variable can only be used by query clauses that are declared after the use of the "let" operator.

IEnumerable<Person> letExample1 = from Person in people
                                                               
let firstname = Person.FirstName.ToUpperInvariant()
                                                                where firstname.StartsWith("J")
                                                                select Person;

 

Select Distinct Items: You can use the Distinct() method to grab just the distinct items in the collection.

IEnumerable<String> distinctExample2 = (from Person in people
                                                                      
select Person.FirstName).Distinct();

 

Conclusion

As you can see, LINQ is rather simple to use the basics of. However, it is rather involved and will definately take some time to master.

For further reading:

C#, SoftwareBasics, vb.net ,

2008 Microsoft Launch Event and Free Software

21. January 2008

On February 27th in Los Angeles, CA, Microsoft is kicking off a series of "HEROES happen {here}" launch events nationwide. These are the official launch events for Windows Server 2008, Visual Studio 2008, and SQL Server 2008. And, one of the best parts is everyone that takes part in one of the events will be taking home a promotional kit with versions of all three products.

Since the Milwaukee event isn't until May 8th, I've registered for the Chicago event on March 11th. I don't want to wait that long!

For More Information

C#, vb.net

.NET: How to Alias Namespaces and Data Types

26. November 2007

One of the little known features of .NET is that you can give complete namespaces and data types alias's that you can reference them with in code.

Aliasing Data Types

For this example we'll give a different name to the integer data type:

In VB.NET:

Imports MyInteger = System.Int32;

In C#:

using MyInteger = System.Int32;

Now to use the alias in code:

In VB.NET:

Public myVariable As MyInteger = 4;

In C#:

MyInteger myVariable = 4;

Aliasing Namespaces

For this example, lets assume we want to use an alias to rename the System namespace to Sys to its easier to type.

In VB.NET:

Imports Sys = System;

In C#

using Sys = System;

With the above alias in place, you can change this:

System.Int32 myInt = 4;

Into this:

Sys.Int32 myInt = 4;

Usage Tips

Usage #1: A good use of aliasing would be when you are working on a large project and you are dependant on another developer to finish their class or namespace before you can comlete a piece of your code. You can create "dummy" or stub objects and namespaces of your own and them give them an alias that is what the actual name will be when the other developer is finished. Then when they're finished, you can just take out your alias's and include their namespaces and everything will work fine. This trick allows you to still keep coding and successfully compiling without exceptions caused by the namespaces or objects not existing.

Usage #2: Another good use of aliasing would be if you are using Int32 in your code now, but you want to make it easier to switch to Double or Int64. Using aliasing allows you to change one line of code to change the data type that is being used.

Usage #3: The last usage tip and probably the best one, is to use aliasing to eliminate the confusion of Ambiguous data types when using multiple namespaces each having objects with the same name. This way you wont have to type out the entire namespace when using the ambiguous objects.

kick it on DotNetKicks.com

C#, General, SoftwareBasics, vb.net

Microsoft to release .NET Framework 3.5 as Shared Source!

3. October 2007

Scott Guthrie announced on his blog today, that Microsoft will be releasing the source code for .NET 3.5 as shared source under the Microsoft Reference License (MS-RL). You will also be able to enable debugging support within Visual Studio 2008 for the .NET Framework.

This is really cool. I have always used .NET Reflector to peek into the source of the framework, but now I'll actually be able to look at the code itself.

More Info:
Releasing the Source Code for the .NET Framework Libraries - Scott Guthrie

.NET Framework 3.5 Is Shared Source - DotNetKicks.com

asp.net, C#, vb.net , ,

Parallel FX Library: Optimize your code for Multi-Core machines

12. September 2007

I was reading the October 2007 edition of MSDN Magazine and came across an article titled "Parallel Performance: Optimize Managed Code For Multi-Core Machines." At first I thought that this was just another article explaining how to use the ThreadPool in .NET to improve the performance of you app, but they are actually talking about the new Parallel FX Library that is about to reach its first CTP.

What is this Parallel FX Library?

Simple... It's a .NET library that is designed to make is much easier to optimize .NET applications to utilize multiple processor cores automatically if they are available. If you run on a single core system, it'll just run on one core. But, if you run on an 8 core system, it'll utilize all 8 cores to get things done.

How does it work?

There are a few different things explained in the article that you can do, but the one that sticks out the most too me is Parallel.For. The reason I find it so interesting is because of its simplicity to use.

Take a normal For loop in C#:

for (int i = 0; i < 100; i++) {
   a[i] = a[i] * a[i];
}

Now the optimized version using Parallel FX:

Parallel.For(0, 100, delagate(int i) {
   a[i] = a[i] * a[i];
});

Now isn't that simple to do? The Parallel.For does all the optimizations for you to spawn off multiple threads (one per cpu core) to do parallelize the work and get it done as fast as possible. Remember, when running on a single core system, the Parallel.For wont give you any performance boost, but when you run on a 2 or more core system the benefit just scales with the number of cores.

Could I inadvertently decrease performance?

Yes, you must keep in mind what tasks can be run in parallel or you could render some of your optimizations meaningless.

Look at the following nested Parallel.For:

Parallel.For(0, 100, deleagate(int a) {
   Parallel.For(0, 100, delegate(int b) {
      result[a, b] = 0;
      for (int c = 0; c < 100; c++) {
         result[a,b] += a1[a,c] * a2[b,c];
      }
   });
});

Even though the above code will still run, you are making the nested Parallel.For meaningless since it cannot be correctly multi-threaded since the machine probably doesn't have enough cores to run every iteration of this matrix in parallel. Another reason that the nested iterations wont multi-thread properly is because they are very dependant on the outer Parallel.For to run. There is also the hit on memory (however very small) that you incur by uing Delegates

What are the requirements?

It requires the .NET Framework 3.5 or higher. I don't know when it's to be released, the first CTP isn't even yet available. The article did state that it's expected in Fall '07.

How do I find out more?

Well, you can read the article in the October 2007 edition of MSDN Magazine (I would have posted a link to it here, but I could find the link since it's not October yet.) Otherwise, good luck searching for information. The reason I decided to post about it is actually because I tried searching on google and the only information I could find was the hard copy of MSDN Magazine sitting in front of me.

I really encourage anyone interested in reading more about the Parallel FX Library to go read the MSDN article, since I've only summarized a small part of it (it's actually 7 pages long.)

Updated 9/17/2007 - The article has since becom available online, so I've put the link within the article where appropriate. http://msdn.microsoft.com/msdnmag/issues/07/10/Futures/default.aspx

C#, vb.net