VB.Net
VB.Net
Where I work, we are in the process of creating a new standards document for our vb.net development efforts. We have been trying to mold ourselves to the industry standards as much as possible. Everyone has been pretty agreeable on everything until we got to the naming conventions portion (specifically regarding the naming of controls). One camp wants to follow the industry trend that says all controls should be named according to it's purpose without identification of type e.g. a text box named "FirstName". The other camp proports the traditional add-a-prefix view citing that the controls you are looking for will be grouped together in intellisense e.g. same text box named "txtFirstName". I am suprised at how passionate people are on this point. I am not trying to stir up a heated debate here, but I would really like to know how others feel on this subject. Give me your feedback. I'd love to hear it.
[This post was originally posted at my DevAuthority.com blog.
http://www.devauthority.com/blogs/dbalzer/default.aspx Go to
http://www.devauthority.com to get your own .Net blog.]
Have you ever needed to save a webform for later use? If so, Eric Wise has come up with a really slick solution for this. Check out his article HERE!
[This post was originally posted at my DevAuthority.com blog.
http://www.devauthority.com/blogs/dbalzer/default.aspx Go to
http://www.devauthority.com to get your own .Net blog.]
Today I was called in to look at an issue where a GridView that had a button column was exhibiting some strange behaviors. Everything was fine until you sorted or paged the GridView. After that, the button columns no longer referred to the correct rows. The rows sorted, but the buttons did not. Short answer was that we found someone had inadvertantly set EnableSortingAndPagingCallbacks to True on the GridView. Setting this to false fixed the problem. Has anyone else experienced this? Why is it causing the button columns not to sort correctly?
[This post was originally posted at my DevAuthority.com blog.
http://www.devauthority.com/blogs/dbalzer/default.aspx Go to
http://www.devauthority.com to get your own .Net blog.]
Yesterday, I posted an article on a problem I was having with trying to insert a null value for a nullable datetime field in sql 2K. Eric Spray sent me an email regarding this issue. He said he couldn't post a comment (thanks to the problems we're having with the content spammers), but wanted to weigh in. I really appreciate his comment and wanted to post it here.
From Eric:
The basic problem is: how to represent a null value when the type does not support null. I have had this debated several times with colleagues, most use your solution by using a designated value to represent null (ie MinValue). I don't like this solution, reason is you are using a valid value. What if another developer or end user wants/needs to use that value, they are SOL. Sometimes the requirements of a project do not allow you to use up a valid entry to represent null. So, my solution is to have a property to manage the null state. I like this solution better because it does not take away valid values. Now lets say you need to restrict the values being entered (ie MyDate <= 1/1/2005). I would still recommend you use the below pattern, that way WHEN the validation requirement changes it will be an easier change.
That's just my $.02
Here is my solution in C#
public class MyClass
{
private DateTime _myDate;
private bool _myDateIsNull = true;//Initialize to true because the value is not set yet
public DateTime MyDate
{
get
{
if(this.MyDateIsNull)
{
throw new NullReferenceException("MyDate is null!");
}
return _myDate;
}
set
{
//Input validation here
if(value <= DateTime.Parse("1/1/2005"))
{
throw new ArgumentOutOfRangeException("Date must be greater than '1/1'2005'");
}
_myDate = value;
_myDateIsNull = false;
}
}
public bool MyDateIsNull
{
get
{
return _myDateIsNull;
}
set
{
_myDateIsNull = value;
}
}
}
<note to self>
I have run into this problem a few times, but for some reason can never seem to remember the resolution. Therefore I decided to note it here for future reference.
When trying to insert a null value for a nullable datetime field in sql 2K, I end up getting the SqlDateTime Overflow error. This appears to be a problem with a difference between the definition of the Date and Datetime datatypes in .net and sql2K.
The way I found to solve this (there may be better and I would love to hear if there are) is:
if myDate = DateTime.MinValue then
myParamater.Value = System.DBNull.Value
else
myParamater.Value = myDate
end if
Please weigh in if you have any additional insight or a better solution, but this does seem to work.
</note to self>
<Rant>
That's Right. I'm asking you, PLEASE STOP USING ERROR HANDLING! At least until you learn to do it properly that is. I'm currently working on some code that a so-called mid-level developer put together. Everywhere I look in the application there are Try Catch blocks. The problem I have is that it looks something like this:
Try
'do something cool here
Catch ex as exception
Throw New ex
End Try
WHAT??? You mean you bothered wrapping your code in a try catch just to throw the exception in the end as is with no other action? WHY? Don't you realize it's going to throw the exception anyways?
</Rant>
Sorry for the rant. I wouldn't be nearly as upset with this from a junior developer, but this guy claims to have 3+ years vb.net experience and continuously tells me how efficient his code is.
I have been following
Eric Wise's blog for a long time now, as of last week I started working with him. I know that I will certainly grow as a developer working with his influence. For my first project I have adopted his Domain Pattern that he blogged about
here. Unlike some of the other patterns I have used, I was able to get up and running with this one in just a couple of hours. It is easy to use and well thought out. I would highly recommend it to anyone looking to adopt a domain manager pattern for their own development efforts.
Have you seen this issue? It can be very frustrating. You set out to create a new project, put in your first page, build, launch IE and BAM!!! ERROR Could not load Type YourNameSpace._Default. OK, OK, so you go and you check all your src references to be sure that they match your Default Namespace. Hmmm, they're all good. You try to just rebuild the solution. No good! Then after an hour of research, someone suggests trying to re-install the DotNetFramework. Why would I want to do that? Everything else is working fine on my machine. No other projects are having this problem. But what the heck... What do you know, it's working now. But I have no explanation as to why. Can anyone else give me an idea what the problem was here? I can't find an explanation for it. I'm just curious.
OK, It's been a while since I've posted, but I just read a post on Jay Kimble's blog that (for those of you familiar with Glenn Beck) made me want to wrap my head in duct tape to keep it from exploding. Not that anything in the post itself drove me to insanity. It's just that I am so sick of the language wars. You can read the post here.
VB.NET and C# are not competition. They are both produced by Microsoft. IMHO the reason Microsoft brought C# into the fold was to give Java developers an easy way to join the .NET ranks. Now, before I get flamed for that statement, let me clarify. I don't have any inside track on Microsoft strategy, but it's pretty clear to see that C# and Java are extremely similar languages and since C# and VB leverage the same power within the .Net Framework, there had to be a purpose.
So if both languages leverage the same power, why the arguments? Well let me float my own theory. I think that a lot of the developers using C# (and the ones making the most noise) are probably former Java Developers who have spent their entire career evangelizing the world of the evils of Microsoft. Now that they are using Microsoft technology, they need to channel that anger to something else. Hmmm... what do they have to compete with now.
Before this post begins another bloody battle in the ongoing war, let me just say this. I'm am not advocating more language comparisons. It's almost all about syntax anyway. If you like C# then I think that's great. If you like VB.Net wonderful. We need to stop letting the world hear us argue over which language is superior and start educating them as to the advantages of the .NET Framework. Which language you use doesn't matter at all. It's all about the framework baby!
The .NET Q&A Blog is now live. It started with an idea that Jay Kimble had to start a blog dedicated to answering questions anyone may have regarding any issue in .NET. The idea is simple, you can go to the blog and use the Contact link on the side to email your issue. The issue then gets stripped of any project specific information (for the protection of the inocent) and posted to the blog for all the other bloggers out there to respond to. The advantage of doing this in a blog is that google seems to index blogs better than forums, so it will be easier for others to find these answers in the future.
Ok, If you have been following Jay Kimble's blog you have read about me and my lack of Object Oriented Programming. It's not that I don't understand what OOP is. It's also not that I don't understand some of the benefits of OOP. My dilema stems from working as a contractor. Two major problems here. First, I have had no-one to mentor me in this area. I lost all professional contact with developers who were better than I about the time my company was embracing .NET and these new technologies. Prior to that I had ample opportunity to learn in the technologies we were using at the time (classic asp, vb 6.0, etc...) but have never had this benefit in the .NET world. The second problem is that now that I'm an independant contractor I have so little time to spend investigating new architecture that I have been afraid to take the leap from my classic coding approach. I am too busy being CEO, Marketing Director, CFO, CTO, Sales Director, DBA, Sr Developer, Grunt Code Monkey, Project Manager, Receptionist, Janitor... ok, you get the idea.
Despite the time crunch I'm facing, I'm getting ready to jump into the OOP pool. I realize that to alieviate some of the time constraints I have, I need to have a more extensive object library. Less coding equals more free time (or more projects one or the other). I'm hoping that some of you may be able to help me with this. I've started a new category here for OOP and hope that all of you will assist me (and hopefully others) in my quest to become Object Oriented. I would like to see it become a tutorial of sorts on OOP. After all, you never know when you may have to maintain my code someday.
My first issue is I need to get into the OOP mindset. I need to get in my head when it's appropriate to write code to do some task inline in the page, and when I should be creating an object to handle this. Please post your suggestions and tips.
I don't know how many of you may have already seen this but it doesn't hurt to get the news out there. I am not looking to take advantage of the offer myself since I already have a XDN Professional membership, but I thought I should get the word out anyway. As a current XDN Memeber, I would highly recomend this to anyone. I mean hey, it's free components and goodies each month for a year! Who can beat that? Anyway, details below:
FREE XDN Professional for .NET Bloggers during May 2004
Mike Schinkel, president of Xtras.Net, made an offer on his personal blog of a free XDN Professional membership (http://www.xtras.net/xdn) during the month of May 2004 for anyone that blogs about .NET frequently. If you are a .NET blogger, see Mike's post for how to get your free XDN membership.