CodeBetter.Com
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @CodeBetter

Raymond Lewallen

Professional Learner

June 2005 - Posts

  • Information on RAID configurations

    RAID stands for Redundant Array of Inexpensive Disks.  RAID levels that exists are levels 0 – 7, but the most popular are 0,1,3 and 5.  I will give a brief overview of those levels below.

    RAID provides you with redundancy and fault tolerance of your data, in most configurations.  This allows for high availability of your data even when a hard drive completely fails.

    Always have hotspares configured.  A hotspare is a disk that is configured to take the place of a failed disk.  When a disk failure in the RAID occurs, the hotspare will add itself to the array to take the place of the failed disk.  The RAID will then begin to rebuild itself, at the same time still providing you access to your data, naturally with a performance hit until the RAID has completed rebuilding itself.

    Use hardware RAID whenever possible.  This means using a controller, just like a SCSI controller, to configure and host the RAID.

    • Higher performance because the hardware handles the array.
    • You can boot from a RAID.  In order to house your operating system on a RAID 1, you must use hardware RAID controllers.
    • Greater features and flexibility.
    • You can move the controller and hard disks to a different machine and your RAID is still intact.

    Avoid software RAID configurations if possilbe.

    • You take a major performance hit.
    • You cannot boot to a software RAID because the operating system must be running in order to access the RAID.
    • You cannot configure hotspares in a software RAID.
    • You cannot move the RAID to a different machine.  Only the operating system that configured the RAID has the information required to access and configure the array.
    • If your OS crashes, so does your RAID.  All gone, bye bye data.

    RAID 0

    • No redundancy in this configuration, but allows for the best performance because of it.  Fastest write performance of any RAID configuration.
    • At least 2 hard disks are required, usually of the same size and speed.
    • Size is equal to the smallest hard drive in the RAID * the number of drives.

    RAID 1

    • Also referred to as “mirroring”.  Redundancy is is acheived by writing identical data to both drives.  If one drive fails, the other drives has all your data.
    • Requires 2 and only 2 hard disks.
    • The size of the array is the size of the smallest drive in the array.
    • Commonly used for operating systems.

    RAID 3

    • In an R3 configuration, data gets striped across multiple disks at the byte level.  A single disk is used to store parity information and the failure of any one disk, including the parity disk, will not cause failure of the array.  The major bottleneck in this solution is the single parity disk, which much be accessed every time information is written to the array.
    • Requires at least 3 hard disks.  2 for storing data and 1 parity drive.
    • Size of the array is equal to the size of the smallest drive * (total number of drives – 1)
    • RAID 4 – Same as RAID 3, but the data is stiped in block and not bytes.  This improves the performance of reading data.

    RAID 5

    • This is the most popular RAID configuration for storing data, such as your database files.  Unlike RAID 3, parity information is striped across all disks in the array, just like the rest of the data.  This gives R5 a performance increase over R3 when writing data.  Like RAID 4, it uses block level striping for improved read performance.  Fault tolerance is maintained by making sure that the parity information for any particular block of data is not written on the same drive that contains the actual data.
    • Perfect for storing of data where the majorty of access to the RAID will be read access, especially when configured with smaller stripe sizes.
    • Requires at least 3 hard disks.
    • Size of the array is equal to the size of the smallest drive * (total number of drives – 1)
    • RAID 6 – same as RAID 5, but parity information is written twice.  The difference in R5 and R6 is improved fault tolerance, but with a performance hit.
  • A new blogging community and a new feed to add to my rss aggregator.

    Looks like its time to add a new group feed to my aggregatorDevAuthority.Com, a Dave Balzer site, is taking some of the DNJ bloggers who are fed up with the ongoing issues DNJ has been having for awhile now.  He apparently has an open invite for people to come over there and blog.  So some of the people you used to receive in your DNJ feed will no doubt start coming up in the DevAuthority feed instead.

    DevAuthority is a great name for a website, and will be a successful place with good bloggers, no doubt.  So if you are looking for a place to blog, the original suggestions have always been DNJ or geekswithblogs.com.  I think now my suggestion would be to contact Dave at DevAuthority and get setup there.  It looks like its going to be a great site.

  • A look into the a workday of an XP developer

    A day in the life of an XP developer is pretty easy to understand.  There isn’t much involved.  Because developers are relieved from making any business decisions, this saves time.  Because a customer is readily available to ask questions when they arise, this saves time.  Because you have unit tests in place to test code when writing and refactoring, this saves time.  In XP, developers only work 8 hours a day, so the more time spent writing code, naturally, is time best spent by you and money best spent by the customer.

    The day of a developer starts with coffee, Pepsi or Mountain Dew.  But seriously, the day of a developer begins with the other developers in a quick stand up meeting.  This meeting is meant to be quick and to discuss what you did yesterday and what you are going to do today.  This keeps everybody in the loop.

    After the meeting, developers pair up.  Somedays you might be the driver and writing code, other days you might be the navigator keeping everything in check.  In the meeting you’ve already discussed the goals for the day.  Now its time to git er done!

    Because developer tasks are small, the next part of the day may or may not repeat itself, depending on the number of tasks you wish to accomplish this day.

    Start writing your unit tests.  Make sure your tests fail.  Now write your code.  Only write enough code to make the test pass.  Once the test passes, now refactor the code.  Keep refactoring and removing lines of code until any single line removed from that point on will make the test fail.  This is part of simple design.

    Now, assuming you have completed the task during the same day you started it, integrate it into the project source control.  Now everybody else has access to it: the latest version of the code.

    If you have more tasks you can complete in the same day, start it.  Maybe pair up with someone different this time.  Begin the cycle of test-code-refactor-integrate again.  If it gets to the end of the day, which is 8 working hours, and you have not completed a particular task, throw it away.  Don’t check it in, don’t integrate it.  Since your tasks are small and simple, you can start again on it in the morning.  The time you’ve spent working on it so far is time well spent.  You’ll come back tomorrow with good ideas and a better idea of the task and what is needed to accomplish the task.  If you keep working, you’ll start to get tired, frustrated and produce bad code.  Just throw it away and take away what you’ve learned from it.

    Go home, spend some time with your family.  Play a game on the computer, watch a movie, play your guitar, read to your kids or do whatever it is you do to relax.

  • Welcome Jeffrey Palermo to CodeBetter!

    A big fat warm welcome to Jeffrey Palermo, the newest (and a great, I might add) addition to the CodeBetter team!  I've been a long time reader of Jeffrey's, and am looking forward to the intelligence, ideas and overall conversations he'll bring to the already awesome team of CodeBetter!

    So welcome to CodeBetter, Jeffrey!  We're very glad to have you!

  • Create a web service directly from Sql Server 2005 using an HTTP Endpoint

    What is an HTTP Endpoint in Sql Server?  Well, it is a way to create a usable interface using HTTP or TCP for SOAP, T-Sql, Service Brokering and a few other things.  I’m just going to tell you, quick and simple, about creating a web service to return data, although you can return scalar values, messages and errors too.  The results returned are serialized into Xml.  If you have Windows 2003, you don’t have to have IIS installed.  Sql server will use the http.sys module in the Win2K3 kernel.

    So lets look at creating a usable web service from within Sql Server.  Lets start with creating a stored procedure.

    Create stored procedure to return list of employeesuse adventureworks
    go

    create procedure dbo.GetEmployees
    As
    select e.employeeid, e.title, c.FirstName + ‘ ‘ + c.Lastname As Fullname from HumanResources.employee e
    inner join person.contact c
    on e.contactid = c.contactid
    go

    Now, lets create our sql server web service, known as an HTTP ENDPOINT.

    The Sql 2005 code to create the HTTP ENDPOINTuse adventureworks
    go

    CREATE ENDPOINT GetEmployees
        STATE = STARTED
    AS HTTP
    (
        PATH = '/Employee',
        AUTHENTICATION = (INTEGRATED),
        PORTS = (CLEAR),
        SITE = 'localhost'
    )
    FOR SOAP
    (
        WEBMETHOD 'EmployeeList'
            (NAME='AdventureWorks.dbo.GetEmployees'),
        BATCHES = DISABLED,
        WSDL = DEFAULT,
        DATABASE = 'AdventureWorks',
        NAMESPACE = 'http://AdventureWorks/Employee'
    )
    go

    There we go.  We now have a web service!  You access and use this endpoint the same way you would any other web service.  You can create multiple WEBMETHODs in a single endpoint, just seperate them with commas in the FOR SOAP statement.

    Here are the values you can use for the “STATE” argument:

    • STARTED—listening and responding
    • DISABLED—neither listening nor responding
    • STOPPED—listening, but returns errors to client requests

    Here are the “AS HTTP” arguments you can use:

    • Path –  The virtual URL path on the server where the Web service will reside
    • Authentication 
      • INTEGRATED – most secure. It will try to use Kerberos-based authentication if possible (otherwise, NTLM).
      • DIGEST is not as secure as INTEGRATED. You should use it only if INTEGRATED authentication is not possible.
      • BASIC authentication is the least secure. You should use it only if you can't implement either INTEGRATED or DIGEST authentication methods. BASIC requires SSL as the Port value.
    • Ports –  CLEAR (HTTP - port 80 by default) SSL (HTTPS - port 443 by default)
    • Site –  The name of the server on which the Web service is running

    So, now lets put our endpoint to work.  First, create a new windows application project, and add a web reference to it.  When you browse for the web service, it won’t be discovered automatically.  You have to type in the url and click “go”.  The url in this case is http://localhost/Employee?wsdl.  You’ll see the EmployeeList method come up in the list, just like using any other web service.  Go ahead and add the service and rename it to whatever.  I called mine “adventureWorksService”.

    Now we just add code like using any other webservice.  I’ve added a button to click to populate the listbox on my form.  So here it is:

    A VB.net form that loads the results of the stored procedure into a list box.

    Public Class Form1

     

        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

            ' Create a new instance of the web service

            Dim employeesProxy As adventureWorksService.GetEmployees = New adventureWorksService.GetEmployees

     

            ' You have to pass in credentials to authenticate yourself to use the service.  We are just going to use

            '   the same credentials we have logged into our computer as.

            employeesProxy.Credentials = System.Net.CredentialCache.DefaultCredentials

     

            ' The result of a SELECT statement via an endpoint can be converted to a DataSet

            Dim ds As System.Data.DataSet = DirectCast(employeesProxy.EmployeeList, DataSet)

     

            ListBox1.DataSource = ds.Tables(0)

            ListBox1.DisplayMember = "FullName"

            ListBox1.ValueMember = "EmployeeId"

     

        End Sub

    End Class

    I am having problems with my Adobe Photoshop, so I don’t have any screenshots to show you.  You’ll just have to trust me.

    Here are the other return values from the endpoint:

    • Select statement – Convert to DataSet
    • Select statement FOR XML – Convert to XmlElement
    • Error or Message – WSDL SqlMessage
    • Output parameter – WSDL SqlParameter
    • Row count – WSDL SqlRowCount
    • RETURN statement – Convert to Int32

    Tada!  There you go!  A web service straight from Sql Server!

  • System.NullReferenceException - Object reference not set to an instance of an object. 3 common causes in VB.Net.

    Every once in awhile, you come across this exception: System.NullReferenceException – “Object reference not set to an instance of an object.”  You see people asking about this everywhere; about why are they getting this error.  Below are a few common causes for this.


    Note, regardless of the scenario, the cause is always the same in .Net: You are trying to use a reference variable who's value is Nothing/null.  When the value is Nothing/null for the reference variable, that means it is not actually holding a reference to an instance of any object that exists on the heap.  You either never assigned something to the variable, never created an instance of the value assigned to the variable, or you set the variable equal to Nothing/null manually, or you called a function that set the variable to Nothing/null for you.

    1. In VB.Net, you are trying to access a string that has not been initialized.  In C#, this isn’t possible.  You can’t even compile code like the following in C#

    C# won't compile this

                            private void TestString()

                            {

                                        string a;

                                        if (a.Length == 0)

                                        {

                                                    Console.WriteLine("Yes");

                                        }

                            }

    However, in VB.Net, you can compile the equivalent, and that lead right down a road to the mentioned exception.

    VB will compile, but throw a runtime exception.

        Private Sub TestString()

            Dim a As String

            If a.Length = 0 Then

                Console.Write("Yes")

            End If

        End Sub 

    Remember, a string is a reference type (a character array) that has to have a value.  You don’t have to use the “new” keyword, but by default the value is Nothing/null.  You would have to at least initialize to a = String.Empty, or to some other actual value, before it will compile in C#, or run without exception in VB.Net

    To fix this above problem in VB.Net, set [a = “something”] before you attempt to do anything with it.

    2. You never created a new instance of an object.  Again, this is code that C# will not compile, but VB.Net will, and throw a runtime error.  Same as a string, any reference type must be initialized.  Strings and some other CTS types have a misconception of being value types, like Integers, and they are not.

    C# will not compile.

                            private void TestObject()

                            {

                                        ArrayList b;

                                        b.Add("Hello");

                            }

    Here is the VB equivalent, that will compile, but throw the mentioned exception.

    VB will compile but throw an exception.

        Private Sub TestObject()

            Dim b As ArrayList

            b.Add("Hello")

        End Sub

    To fix the problem, you need to say [Dim b As New ArrayList] in the above code.

    3.  You created the object, but killed it too soon.  Here is a simple example of that.

    Don't kill objects too soon.

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

            TestObject()

            ShowCount()

        End Sub

     

        Dim b As New ArrayList

     

        Private Sub TestObject()

            b.Add("Hello")

            b = Nothing

        End Sub

     

        Private Sub ShowCount()

            Console.Write(b.Count.ToString())

        End Sub

    A more complex example would be that you disposed of a class that maybe you use to access the database.  This killed the connection and command objects.  But then, somewhere else, you tried to call a method of that class that used those objects that no longer exists.  Again, same exception gets thrown, but coming from withing the instantiated class itself.

    c = a.GetOrders() will throw an exception.

    Public Class Class2

     

        Dim a As New MyDataAccessObjects.Customers

        Public Sub New()

            LoadData()

            LoadMoreData()

        End Sub

     

        Private Sub LoadData()

            Dim b As New Collection

            Try

                b = a.GetCustomers()

            Finally

                a.Dispose()

            End Try

        End Sub

     

        Private Sub LoadMoreData()

            Dim c As New Collection

            Try

                c = a.GetOrders()

            Finally

                a.Dispose()

            End Try

        End Sub

     

    End Class 

    The GetOrders function inside of Customers requires an instance of a connection, but you disposed of the required objects required to access the database back up in LoadData() when you called a.Dispose().  Be careful when you clean up your instances, that you are not using them again somewhere.  This is most common in classes where you are using class-wide instantiated objects.  If you create and drop your objects within each method, this isn’t going to be a problem, and you are actually following a better guideline by creating at the last necessary moment, and destroying at the first possible moment, not to mention avoiding possible exceptions like InvalidReferenceException.

  • Changes and enhancements to full text indexing in Sql Server 2005

    Sql Server 2005 brings some good enhancements to full-text searching capabilities.  But why would you want to use full-text searches?  Well, it is not always the case where people are given a drop down box of choices to choose from when wanting to perform a search.  Certainly, that scenario is beneficial and efficient, as we are guaranteed to be able to make the most out of our indexing and data structuring techniques when we know the exact data that we are going to be querying.  What is even better is that more times than not, that drop down list is populated from an indexed field in the database somewhere.

    What matters is when you are allowing people to enter in their own criteria for returning results, like a free text box.  In this scenario, most people use a LIKE clause, and that works very well.  However, the LIKE clause only works on character patterns.  When dealing with millions of rows, a full-text index can seriously outperform a LIKE clause search using the same search value.  In order to perform a linguistic search with words and phrases, you need to use full-text indexing to get this performance out of your database.  You never know what someone is going to type into a free text box, and full-text indexing, because of its unique indexing of individual pieces of the text, provides an efficient and effective way to quickly return results when searching for free text words and phrases.

    Some of the changes and enhancements are:

    • Full-text indexing of XML data. Woo hoo!
    • You can now run full-text queries against linked servers.
    • Full-text catalogs have integrated backup, restore and recovery capabilities.
    • Greatly improved speed of full-text search performance and index building performance.
    • Data definition languages statements for creating and altering full-text indexes.  If you were using the system stored procs before, not to fear, they still exist, but have been depreciated.
    • Now you can use sp_detach and sp_attach_db to move full-text catalogs.
    • You can now include multiple columns in your full-text searches, instead of the one-or-all approach we are familiar with.
    • Pre-computed ranking optimizations when using a FREETEXTTABLE query, also with improved ranking algorithms.  No more on-the-fly, costly rankings.

    Lots of other enhancements too.  For more information, see this MSDN article.

  • Reflecting back on the greatest job in the world

    It is wonderful to be a developer. I've spent the last 11 years doing the whole jack-of-all-trades thing. Everything from telephony to Clipper, multi-terabye RAIDs for Sql Server databases to Visual FoxPro windows apps, Perl to COM, networking to .Net web apps. Oh, and everything inbetween too.

    I’ve learned more than I could have ever imagined, and I don’t know squat.  I’ve met some really great and intelligent people, and some people who aren’t so great. 

    I love reading books on development, design patterns, languages, methodologies and I love to spread the knowledge.  I love teaching.  I think I’m good at it, and I present topics pretty well.

    I’m definately a coder.  I love to code all day long.  I like trying new things, examining MSIL, and trying something else.  I like taking ideas and putting them to work.  I like being successful.  I love to produce results that make people happy.  I like to produce desired deliverables accurately and with maximum value.

    I love being a developer.

    So what is the best job in the world?  Every single night, right before her bedtime, my 22 month old daughter runs around the living room and gathers up all her books.  She stacks them up all on the ottoman in front of my chair.  She climbs up on me, squeezing herself down between me and the side of the chair.  She cross her legs, holds her hands, looks at her books and then looks up at me.  She’ll then point at her books, not saying a word, waiting patiently for me to pick the first one up.  We then read each and every one of them.  Sometimes I sing them, sometimes I use funny voices.  She points to things and tells me what they are.  “Chichen!” She’ll say.  “What does a chicken say?” I’ll ask her.  “BOK! BOK!”  We’ll do that with the half dozen or so animals she knows.  She tells me what shapes and colors and animals she sees.

    That is the best job in the world.  Reading to my daughter.  Every day.  I love it more than anything.  Even if it were only for 5 minutes, those 5 minutes reading, just her and I, are better than years worth of my love for being a developer.

  • Cancelled my trip to DevCon 2005 in Dallas

    I had a personal situation come up today and I won't be going to DevCon in Dallas this week.  Actually, you won't hear from me until next week.  See ya then!

    P.S.   Apologies to all those I was going to meet up with.
  • Some managed code analysis tools

    In response to a comment on this post, here are couple of source code analysis tools for managed code:

    • NDepend – Free - NDepend analyses .NET assemblies of an application and generates design quality metrics.
    • Complexity Analyzer –  Costs Money - Automatically compute the complexity factors for your methods
    • CCMetrics –  Free - A utility for determining the cyclomatic complexity of any .Net binary
    • CRPlugin – Free - Requires DxCore, which you have if you use CodeRush or Refactor!
  • My Cyclomatic Complexity Thresholds

    When anaylizing some cyclomatic complexity (measures the number of linearly-independent paths through a program module), I was thinking to myself about where I want my thresholds to be.  Where to I say “this is simple enough” or “I definately need to refactor this”.

    So here is my conclusion:

    • 1–10  Simple enough.  Don’t change.  Little risk involved.
    • 11–20  Should consider refactoring.  Moderate risk involved.
    • 21–40  Definate refactoring needed here.  Risk is too high.
    • > 41  What was I thinking?  Throw this away and start over.

    I won’t find anything in the greater than 41 range, but if I were to find anything, I’d definately throw it away.

  • SQLCLR UDF Returns a Truncation Exception

    So I have this SQLCLR UDF that returns my name, “Raymond Lewallen”, that I use for testing purposes.  I was changing some code to work with the latests bits of VS2K5, and discovered something that has changed.

    Lets say I had this in Sql Server:

    Sql function, from .Net assembly, that returns my name

    CREATE FUNCTION GetName()
    RETURNS NVARCHAR(20)
    AS EXTERNAL NAME IdentityAssembly.PersonalInfo.MyName

    That returns “Raymond Lewallen”, as expected.  But now let us change the length of the return value.

    Sql function, from .Net assembly, that returns my name

    CREATE FUNCTION GetName()
    RETURNS NVARCHAR(10)
    AS EXTERNAL NAME IdentityAssembly.PersonalInfo.MyName

    Now, prior to the April CTP release of Sql2k5, this would return “Raymond Le”.  You get data that has been silently truncated.  That was the expected behavior.  But now, after installing the April CTP, I no longer get truncated data.  Now I get a ‘Truncation Exception’ reported.

    However, if I do this:

    T-Sql function that returns my name

     CREATE FUNCTION GetName()
    RETURNS NVARCHAR(10)
    AS
    BEGIN
      RETURN N'Raymond Lewallen'
    END

     It still returns “Raymond Le”.  The T-Sql still silently truncates the data.  Only the SQLCLR UDF returns the truncation exception.  So how you expect your functions to behave, whether they return truncated data or exceptions when data is going to be trunctated, may dictate how and where you write your functions.

  • Reader Poll: Which agile methodology have you adopted?

    How many of you are using XP?  If not, have you adopted any particular agile methodology into your team?  Which one?  If you have time, why?  What do you like about XP, or the agile methods you use?  What do you dislike?
  • Syllabus for Extreme Programming Workshop/Seminar in Oklahoma City

    Here is the syllabus for the workshop/seminar on Extreme Programming to be located in downtown Oklahoma City in mid July.

    Extreme Programming Seminar/Workshop – Level 100

    Values, Principles and Practices of Extreme Programming

    Click here to register for this event in Oklahoma City on July 21st, 2005

     

    Click here to register for this event in Oklahoma City on July 26th, 2005

     

    8:30 AM – 9:00 AM: Arrival

    9:00 AM: Introducing Extreme Programming

    9:35 AM: Sufficient resources- the assumptions

    9:55 AM: Break

     

    10:05 AM: The values of XP

    10:30 AM: The principles of XP

    11:15 AM: Break

     

    11:25 AM: Roles in XP

                The Role of the Customer

                The Role of the Developer

                The Role of the Coach

     

    11:55 AM: Lunch Break

                There are numerous restaurants in the Oklahoma City downtown area.  Finding food will be no problem.  However, due to the absence of “fast food”, I have allotted 1 hour and 15 minutes for lunch.  All restaurants are within walking distance.  We will break early if possible, because the afternoon has little room for adjustment.

     

    1:10 PM: XP Programming Practices

    1:10 PM: Business Practices

    1:30 PM: Coding Practices

    2:00 PM: Break

    2:10 PM: Developer Practices

    3:15 PM: Break

     

    3:25 PM: Artifacts and Events

                Planning - Story Cards

                Planning - Task Cards

                Bullpen

     

    4:00 PM: Adopting XP

     

    4:30 PM - ?: Discussion/Continuing Workshop Project

  • $1500 video card? Are you kidding me?

    A video card on SALE for almost $1000.00!?!?! Who's buying this stuff?  Retail price is $1499.99.
More Posts Next page »

Our Sponsors

Free Tech Publications