1. Avoid declaring page class variables as STATIC. This creates all kinds of confusion, because they end up shared across the whole application for every rendering of that page. A coworker of mine did this and we kicked it around for a few minutes before I convinced her to use VIEWSTATE or SESSION as a persistence mechanism.
2. Don't assume pressing enter will cause a BUTTON object to get a click event when you are inside of a textbox. A POSTBACK, yes, but a button click no. I trap that event and send it to the button in a javascript snippet, but am sure there are other ways to do it as well.
3. Use the AS casting technique for object variables. If you use the double parens (DataSet) for example, and the object is not hydrated, an exception will be thrown. Using the AS (myThing AS DataSet) for example, the Framework will convert your object to NULL. Traditional cast or a CONVERT function is the way for Value types.
4. In C# use the USING wrapper around DISPOSABLE types. For example :
Using (SQLConnection myConnection = new SQLConnection) {
bunch of code
}
// This is just cool and the right way to get disposal. I am new to this style.
5. And read this somewhere in Google, but useful for maintaining sanity, forget all about using .EQUALS for comparing VALUE types. It reads badly and runs slower because the system looks all around for an overridden implementation of the EQUALS comparison function.
6. Use STRING.EMPTY or use STRING.LENGTH for comparison to string variables instead of the dreaded double-quotes. Performance, Localization and readability.
My $0.02 on some things I am seeing lately, if I may be so bold.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment