Beyond Web Logs

Discuss technology, web development, networks and more ...

Recent posts

Tags

First time here? At BeyondWebLogs we discuss technology, web development, personal development, networks and more. You can subscribe to the RSS feed so that you keep up to date with the latest content. Now, on with the regular content...

Simple Open Source Logging Framework for .Net

There is a new simplified open source logging framework in the block for .Net developers. Here is the link for your review:

Live Labs Logging 

Do let me know if its of any help!

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Categories: Better Coding
Posted by Waqas on Thursday, May 29, 2008 12:07 PM
Permalink | Comments (0) | Post RSSRSS comment feed

Free tool to analyze your C# code to produce elegant, consistent code - Microsoft Source Analysis

Here is a new tool from Microsoft called "Source Analysis" that perfoms its analysis on source code directly, unlike FxCop which only works on binaries.

The ultimate goal of Source Analysis is to allow you to produce elegant, consistent code that your team members and others who view your code will find highly readable. In order to accomplish this, Source Analysis does not allow its rules to be very configurable. Source Analysis takes a one-size-fits-all approach to code style, layout, and readability rules. It is highly likely that you will not agree with all of the rules and may even find some of the rules annoying at first - However, the majority of teams using this tool within Microsoft have found that after a short adjustment period, they came to appreciate the rules enforced by Source Analysis, and even began to find it difficult to read code not written in this style. 

Source Analysis comes with a set of default rules analyzers covering approximately 200 best practice rules. These rules are full compatible with the default layout settings in Visual Studio 2005 and Visual Studio 2008.

Specifically, these rules cover the following, in no particular order:

  • Layout of elements, statements, expressions, and query clauses
  • Placement of curly brackets, parenthesis, square brackets, etc
  • Spacing around keywords and operator symbols
  • Line spacing
  • Placement of method parameters within method declarations or method calls
  • Standard ordering of elements within a class
  • Formatting of documentation within element headers and file headers
  • Naming of elements, fields and variables
  • Use of the built-in types
  • Use of access modifiers
  • Allowed contents of files
  • Debugging text

After installation, Source Analysis can be run from within the Visual Studio IDE, and can also be integrated into MSBuild-based command line builds.

Source Analysis for C# can be downloaded Here.

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Categories: Better Coding
Posted by Waqas on Monday, May 26, 2008 7:57 PM
Permalink | Comments (0) | Post RSSRSS comment feed

Difference between "?" and "??" operators in C#

Conventional Code:

   string f(string inputString)
    {
        if (inputString != null)
            return inputString;
        else
            return "";
    }

Better code with operator ?

    string f(string inputString)
    {
        return (inputString != null) ? inputString : "";
    }

Much better code with operator ??

    string f(string inputString)
    {
        return (inputString) ?? "";
    }

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Categories: Better Coding
Posted by Waqas on Sunday, May 11, 2008 2:09 PM
Permalink | Comments (0) | Post RSSRSS comment feed

Design Patterns Book - Gang of Four - 23 Design Patterns

Here is the book that can be used as a reference library of the recognized 23 design patterns as well as some principles of object-oriented programming.

 

Download (Right Click and Save) 

 

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Categories: Better Coding
Posted by Waqas on Tuesday, February 12, 2008 11:29 PM
Permalink | Comments (0) | Post RSSRSS comment feed

Regular expressions - A Simple Tutorial

Regular expressions are a very powerful tool to validate, and find/replace, substrings inside text. They enable you to define very complex patterns, and their processing can be much faster than working with the String class's Replace, Substring, IndexOf, and the other basic methods.
The following tables summarize the most frequently used syntax constructs for the regular expressions. In the first table, you can see how to express the characters that we want to match.

Character escapes

Description

 

 

Ordinary characters

Characters other than .$^{[(|)*+?\ match themselves

\b

Matches a backspace

\t

Matches a tab

\r

Matches a carriage return

\v

Matches a vertical tab

\f

Matches a form feed

\n

Matches a newline

\

If followed by a nonordinary character (one of those listed in the first row), matches that character — for example, \+ matches a + character

In addition to single characters, you can specify a class or a range of characters that can be matched in the expression. That is, you could allow any digit or any vowel in a position, and exclude all the other characters. The character classes in the following table enable you to do this.

Character class

Description

.

Matches any character except \n

[aeiou]

Matches any single character specified in the set

[^aeiou]

Matches any character not specified in the set

[3–7a–dA–D]

Matches any character specified in the specified ranges (in the example, the ranges are 3–7, a–d, A–D)

\w

Matches any word character — that is, any alphanumeric character or the underscore (_)

\W

Matches any nonword character

\s

Matches any whitespace character (space, tab, form-feed, new line, carriage return, or vertical feed)

\S

Matches any nonwhitespace character

\d

Matches any decimal character

\D

Matches any nondecimal character

You can also specify that a certain character or class of characters must be present at least once, or between two and six times, and so on. The quantifiers are put just after a character or a class of characters and enable you to specify how many times the preceding character/class must be matched, as the following table shows.

Quantifier

Description

*

Zero or more matches

+

One or more matches

?

Zero or one matches

{N}

N matches

{N,}

N or more matches

{N,M}

Between N and M matches

As an example, suppose that you have the expression [aeiou]{2,4}\+[1–5]*: This means that a string to correctly match this expression must start with two to four vowels, have a + sign, and terminate with zero or more digits between 1 and 5.

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by Waqas on Tuesday, February 12, 2008 11:11 PM
Permalink | Comments (0) | Post RSSRSS comment feed

Avoid using DataBinder.Eval for better performance

The DataBinder.Eval method uses reflection to evaluate the arguments that are passed in and to return the results. Consider to limit the use of DataBinder.Eval during data binding operations to improve ASP.NET page performance.

Consider the following ItemTemplate element DataBinder.Eval.

<ItemTemplate>

 <tr>

  <td><%# DataBinder.Eval(Continer.DataItem, "fieldname1") %></td>

  <td><%# DataBinder.Eval(Continer.DataItem, "fieldname2") %></td>

 </tr>

</ItemTemplate>

Using explicit casting offers better performance by avoiding the cost of reflection. Cast the Container.DataItem as a DataRowView.

<ItemTemplate>

 <tr>

  <td><%# ((DataRowView)Continer.DataItem)["fieldname1"] %></td>

  <td><%# ((DataRowView)Continer.DataItem)["fieldname2"] %></td>

 </tr>

</ItemTemplate>

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by Waqas on Tuesday, February 12, 2008 6:43 PM
Permalink | Comments (0) | Post RSSRSS comment feed

Difference between UriBuilder.ToString and UriBuilder.Uri.ToString

UriBuilder.ToString - The resulting string always contains port, even if it is the default port. For example - http://localhost:80/wiktips

UriBuilder.Uri.ToString - The resulting string only contains the port if it is not the default port for the scheme. For example - http://localhost/wiktips

Therefore, in most of the cases UriBuilder.Uri.ToString should be used to omit redundant port specification.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by Waqas on Tuesday, January 01, 2008 9:40 AM
Permalink | Comments (0) | Post RSSRSS comment feed