 |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Forum and Wrox.com Feedback section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|

March 30th, 2011, 02:40 PM
|
|
Registered User
|
|
Join Date: Mar 2011
Posts: 17
Thanks: 4
Thanked 1 Time in 1 Post
|
|
Some code samples in WROX books are bad.
When I pay $60 for a book on VB .NET or any other programming language in Visual Studio, I expect the code supplied to work when both the Option Explicit and Option Strict are set to TRUE. At the very least Option Explicit should be set to TRUE. It is bad practice to write any program where these are set to FALSE. WROX books should not be teaching bad coding practices. WROX needs to have a policy consistent with this and it needs to communicate this requirement vigorously to their authors. I wasted a lot of time trying to figure out what kind of an object "item" is. Declaring it as an "object" only sets up a late binding condition when one isn't necessary. Learning the "item" object type is part of what the reader needs to learn; this is a situation that WROX books need to avoid.
It would be useful to hear what other readers think about this issue.
|

March 30th, 2011, 04:09 PM
|
 |
Wrox Staff
Points: 18,059, Level: 58 |
|
|
Join Date: May 2003
Posts: 1,906
Thanks: 62
Thanked 139 Times in 101 Posts
|
|
Can you tell us what book, what chapter this is about?
__________________
Jim Minatel
Associate Publisher, WROX - A Wiley Brand
Did someone here help you? Click  on their post!
|

March 30th, 2011, 04:55 PM
|
|
Registered User
|
|
Join Date: Mar 2011
Posts: 17
Thanks: 4
Thanked 1 Time in 1 Post
|
|
Improving Code Samples from WROX
Quote:
Originally Posted by jminatel
Can you tell us what book, what chapter this is about?
|
The book is "Professional Visual Basic 2010 and .NET 4", Chapter 10 "ADO .NET and LINQ", page 424. There are two issues: one is fixed in the explanation right after but I didn't know that and so I wasted a lot of time trying to type in the code without errors.
The second issue is the undefined variable "item" which should have been followed by "As title"; this is not fixed in the explanation.
The author should also alert the reader to references and imports that are necessary for the code to work. This is done in the explanation that follows but it would have saved a lot if the alert is provided before the reader enters the code. It seems that authors try to add a little suspense for interest sake. But readers of computer books are not looking for suspense; they just want to learn the subject. When they want suspense, they'll read a mystery novel instead.
I would not be surprised if there are similar issues throughout the rest of the book; I went straight to Chapter 10 in order to learn about LINQ. That's why I say that good coding examples should be an enforced WROX policy.
The bottom line is that the authors of WROX books need to be more considerate of their readers, whose skill level will range all over the spectrum.
|

March 30th, 2011, 05:09 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
I don't have the book so I can only guess, but could it be that the example is using the new Type inference system? Consider this example:
Code:
Class Person
Public Sub New()
End Sub
End Class
Class TestApplication
Private Sub MethodName()
Dim somePerson = GetPerson()
End Sub
Private Function GetPerson() As Person
Return New Person()
End Function
End Class
Despite what it looks like, the somePerson variable *is* strongly typed as a Person and not as an Object as the compiler infers the type of the variable based on the value that is assigned to it. Since GetPerson returns a Person, the somePerson variable is typed as a Person as well with this code.
This code works with Option Explicit and Option String set to On, as long as Option Infer is On as well.
Cheers,
Imar
Last edited by Imar; March 30th, 2011 at 05:53 PM..
|

March 31st, 2011, 04:49 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Just did some digging in the source code and indeed the example you're referring to is using type inference.
Consider this:
Code:
Dim query As Table(Of title) = dc.titles
For Each item In query
Console.WriteLine("{0}: {1}",
item.title_id,
item.title)
Next
Here, item *is* a title instance and not an Object. That's why you get IntelliSense when you type item and then a dot. Additionally, you can see the type of the item variable by hovering your mouse over item in the line with For Each. You see a popup telling you that item is, in fact, a title instance.
Type inference is explained in Chapter 1, page 18 and further. Stuff like Option Explicit and Option Infer are described in detail there as well.
LINQ in .NET relies heavily on type inference, mainly because of the dynamic nature of queries and anonymous types.
So, if you want to hear "what other readers think about this issue", I'll say you're being a bit too harsh on this book and the code examples. The example you're referring to is technically correct, and shows best practices when it comes to type inference in queries. If you don't like the syntax of type inference, you can always add "As title" to the code to make it more explicit, but it's certainly not neded to write type-safe code.
Hope this helps.
Cheers,
Imar
Last edited by Imar; March 31st, 2011 at 04:51 AM..
|
|
The Following User Says Thank You to Imar For This Useful Post:
|
|

March 31st, 2011, 08:22 PM
|
|
Registered User
|
|
Join Date: Mar 2011
Posts: 17
Thanks: 4
Thanked 1 Time in 1 Post
|
|
Book Sample Code Issue
Hi Imar,
I have your Beginning ASP .NET 4 etc book. Also thanks for taking the time to look at this issue.
You said that the code provided in the book of issue is:
Dim query As Table(Of title) = dc.titles
For Each item In query
Console.WriteLine("{0}: {1}",
item.title_id,
item.title)
Next
But in the book the verbiage between "query" and "=" is not there. I just think that is should have been.
The other part regarding Option Infer I was not aware of and thanks for the explanation. My difficulty was due to not starting the book with chapter one; I went straight to LINQ in chapter 10. I was basically interested in that before attempting to read a book devoted to it. However, your explanation was short and sweet and could have been provided at the beginning of the LINQ section in the book. Because Option Infer was added specifically due to LINQ, it probably should have been reviewed at the beginning of the LINQ section or at least the reader should be asked to return to chapter 1 page 18 and review the compile options.
I don't know but when you write a book for WROX, do you consider the possibility that the reader may skip ahead?
I went straight from VS2005 to VS2010, so I had never tried LINQ until now.
So perhaps I was too harsh. Perhaps I should have read the first chapter first.
Thanks,
Mangel
Last edited by mangel; March 31st, 2011 at 08:26 PM..
|

April 1st, 2011, 03:05 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Quote:
|
But in the book the verbiage between "query" and "=" is not there. I just think that is should have been.
|
You can add it there, but you don't have to. The same principle applies:
Code:
Dim query = dc.titles
would work fine. dc.titles is a Table(Of Titles) and thus when the compiler sees this, it types query as a Table(Of Titles). So, the code in the book should compile just fine and when you hover your mouse over query it should tell you the type.
The code in the download is slightly different and does include the As clause.
Quote:
|
Because Option Infer was added specifically due to LINQ, it probably should have been reviewed at the beginning of the LINQ section or at least the reader should be asked to return to chapter 1 page 18 and review the compile options.
|
Yes, I agree. That would certainly make sense....
Quote:
|
I don't know but when you write a book for WROX, do you consider the possibility that the reader may skip ahead?
|
It depends on the book I guess. My Beginning books are meant to be read from start to end. I do add forward and back references where appropriate. With a reference type of book things would be different.
I think it's a fine balance. If you need to repeat some stuff in every chapter, you may get the opposite effect where people don't like the fact the same information is repeated over and over again ;-)
But in your case, a reference in the LINQ chapter to the compiler options and an explanation of type inference would have been useful.
Cheers,
Imar
|
Similar Threads
|
| Thread |
Thread Starter |
Forum |
Replies |
Last Post |
| SQL Books from wrox |
carumuga |
All Other Wrox Books |
1 |
January 2nd, 2008 05:23 PM |
| Wrox Books |
stu9820 |
Wrox Book Feedback |
3 |
February 6th, 2004 12:11 PM |
| Older books from Wrox |
Barath |
Wrox Book Feedback |
0 |
January 19th, 2004 08:03 PM |
| Wrox Books Online |
sivko22 |
Forum and Wrox.com Feedback |
3 |
December 3rd, 2003 12:34 PM |
| Old books from WROX |
sAiNz |
Pro JSP |
0 |
July 31st, 2003 10:40 PM |
|
 |