Dave Burke - Freelance .NET Developer specializing in Online Communities

A freelance .NET Developer

.text: lesson in DAAB best practices

It's been a week now during which I got to spend a lot of my time with .text .094.  Someone said early on when ScottW first released .text .093 that it was a study in best practices.  That is so true.

For one of several gains in studying Scott's framework, I picked up a new approach for handling parameters.  You'll find these in the SqlDataProvider project, SqlHelper class.  These parameter methods were not part of my DAAB 2.0 package...but they are now!

Check out this code below.  The economy in this (for guys like me who haven't seen this before) is phenomenal.  I particularly liked the (int) parameter return statement.




Posted: Oct 15 2003, 01:05 AM by daveburke | with 10 comment(s)
Filed under:

Comments

Scott Galloway said:

Because error handling is for wimps! Hmm...I would so wrap that in a try...catch block (even if Joel Spolsky thinks I'm being obscure :-)). Actually, one of my favourite features in DAAB isn't used at all in .TEXT, namely, the SQLHelperParameterCache.GetSpParameterSet...used as follows...

SqlParameter[] sqlParams = SqlHelperParameterCache.GetSpParameterSet(Global.ConnectionString,"pr_Common_GetListItemsWithPermissions");
sqlParams[0].Value = contentType;
sqlParams[1].Value = userName;
sqlParams[2].Value = portalId;
sqlParams[3].Value = sortCriteria;
sqlParams[4].Value = sortDesc ? 1 : 0;
sqlParams[5].Value = startItemId;
sqlParams[6].Value = numItems;

In this way, I save even more typing (oh, and in case you're wondering the performance loss is close to 0.
# October 15, 2003 6:04 AM

Anonymous said:

I think it serves a better example of what *not* to do -- I do my best to never refer to ordinal index positions. I think that's a bad way to write code, even though it is faster than refering to the literal. Steve McConnell in Code Complete refers to people like this as "Bit Chasers" who try to ink out ever last bit of performance over long term maintainability.
# October 15, 2003 6:39 AM

Dave Burke said:

Whoa. Thanks for the example, Scott. I will investigate! That's so great; I post some code that I think is sweet, and you post even better code!

As for anonymous (hey, good point, why no name?), you're right about the index position issue. I spent hours tracking down the fix for my custom .text where I added a parameter to the inparam group which returned the wrong value from the stored proc.
# October 15, 2003 8:15 AM

Scott Watermasysk said:

Scott: Why no error handling?
I want the error to bubble up the layers. No sense in eating the error on this level. In pages/objects where you are using this functionality you will never figure out what is causing the error.

In .95 the only data try's are arround IDataReaders, and it simply uses try/finally to make sure the connection is closed on errors.

Anonymous: "Bit Chasers"
I agree with you. I guess I could build my own command objects instead of using the helper...but in most cases the number of parameters is small and easily managed. I never use positional indexes when working with results...I guess I took the easy way out going in :)

-Scott
# October 15, 2003 8:43 AM

Frans Bouma said:

Hardcoded indexes == best practises? Erm... Did I miss something? :)

Shouldn't that parameter create routine return a parameter instance, which value you can simply return?
# October 15, 2003 8:46 AM

Dave Burke said:

I seem to have mis-named this post...

Scott, I saw the bubbling up effect with the returned param on entering a new post, providing the success/failed message, with the "baseline error occurred" text.

# October 15, 2003 8:51 AM

Ryan Felton said:


Am I missing something? I've been useing the DAAB v2 and I don't see any function For the MakeInParam or MakeOutParam. Is this a custom creation?

# October 15, 2003 12:57 PM

Dave Burke said:

Ryan, I asked ScottW about this through a post to the .text list group, and he said he picked them up along the way, he thinks from the Petshop DAL. They're in the .text .094 source in the SQLHelper class in the SqlDataProvider project.

But from Scott Galloway's comments about, it looks like the daab already has superior parameter handling methods requiring even less typing...
# October 15, 2003 2:38 PM

Scott Galloway said:

ScottW: Fair comment...I have a slightly different approachb - I tend to 'eat' errors and pass up a value which indicates an error (null, 0 or somesuch) - kind of a return code approach...mainly because I expect to have to nitify a user and I like to catch me errors in each layer of the app - so, each higher layer only gets 'clean' data and only has to worry about exceptions from it's own operations. This probably has more to do with my background which is Enterprise development - passing large exception classes between layers is costly (and dangerous if the consuming layer doesn't expect them). But horses for courses I suppose :-).
In the instance where Scott uses an index...umm...yes...you declare an array and refer to a member...that's bad practice how exactly. You're seriously saying you'd rather declare constants or even a enum to indirectly refer to the number '7'?
# October 15, 2003 4:43 PM

Scott Galloway said:

Oh, incidentally, for those who are interested, I posted a version of DAAB 2.0 which is a drop-in replacement for the .TEXT one...means you have access to all the nice 2.0 features (including a couple of bug fixes)...
http://www.mostlylucid.co.uk/posts/497.aspx
# October 15, 2003 4:59 PM
Leave a Comment

(required) 

(required) 

(optional)

(required)