Why book and source code not same?

Why book and source code not same?

Old forum URL: forums.lhotka.net/forums/t/9667.aspx


volkans80 posted on Sunday, October 24, 2010

I bought VB2008 book but source code and book is not same. I download source code at apress.

For example:

Book-Page 516-ValidRole Method in Assignment Class:

Public Function ValidRole(Of T As IHoldRoles)( _
  ByVal target As T, ByVal e As RuleArgs) As Boolean
  Dim role As Integer = target.Role
  If RoleList.GetList().ContainsKey(role) Then
    Return True 

Else
    e.Description = "Role must be in RoleList"
    Return False
  End If
End Function

But source code is :

 Public Function ValidRole( _
       ByVal target As Object, ByVal e As RuleArgs) As Boolean
        Dim role As Integer = CType(target, IHoldRoles).Role
        If RoleList.GetList.ContainsKey(role) Then
            Return True
        Else
            e.Description = "Role must be in RoleList"
            Return False
        End If
    End Function

RockfordLhotka replied on Sunday, October 24, 2010

Both approaches are valid, so you can go either way. In a sense, you are getting a bonus because you now have examples of the two valid implementations :)

The answer to your actual question may not be satisfying, but here it is. Writing a book of this size is ridiculously complex, and prose is extremely difficult to debug (I'm still waiting for the 'compile' menu option in Word). While the author, reviewers and publisher try their best to keep everything perfectly in sync, the reality is that the book is written over a period of months, and then it takes months for the publishing process itself to occur, and then things like source code are put on the web site.

If this is the only thing out of sync I'd be shocked.

In any case, you can find much more current code on www.lhotka.net/cslanet/download.aspx - the 2008 code is, of course, over 2 years old at this point, so it just represents a snapshot in time from back then. A lot of interesting things have happened since 2008 - Silverlight, ASP.NET MVC, Windows Phone 7, etc.

volkans80 replied on Wednesday, October 27, 2010

I am reading book and I am rewriting Project Tracker myself. I am adding source code to my project where source code is not in book. But there is some errors with this method.

For above example when write this code then error occur: Error 9 Overload resolution failed because no accessible 'AddRule' can be called with these arguments

Maybe I don't know how to write this code for your code in book.

Protected Overrides Sub AddBusinessRules()

      ValidationRules.AddRule(AddressOf Assignment.ValidRole, RoleProperty)

End Sub

RockfordLhotka replied on Wednesday, October 27, 2010

If you are using the generic ValidRole implementation, then you need to use the generic AddRule() overload too. This is where the actual type information originates so it can flow into the rule.

volkans80 replied on Wednesday, October 27, 2010

Thanks for your replies. I think I must study more.

Copyright (c) Marimer LLC