Erik Porter's Blog

Life and Development at Microsoft and Other Technology Discussions

News

    August 2003 - Posts

    VB Import Alias

    M. Keith Warren points out that in C#, you can use the using statement to also create an alias to a particular class to save you some typing.  I honestly thought that didn't work, but I'm glad I'm wrong, that's cool.  VB.NET can do the same thing.

    Imports

    cfg = System.Configuration.ConfigurationSettings

    Thought I'd also mention another way the using statement can be used in C# (but unfortunately has no equivelant in VB.NET) to automatically dispose of a variable when you're done (when the block of code ends).

    using (SqlConnection con = new SqlConnection())
    {
        
    // do something with con
    }

    Even if you declare the variable outside of the parens, it will still call Dispose on “con” after the last curly brace.  You can also declare as many variables inside the using parens seperated by commas as you want and they will all be disposed of afterwords for you.

    Jimmy Nilsson *subscribed*

    Frans posted a link to a post from Jimmy.  He talks about “why“ being more important than “how“ and “what“.  I love this guy already!  Bet you never would've guessed that from some of my other entires!  ;)  *subscribed*

    HC Gets Internationalized

    Just thought this was pretty neat.  Ran across an article I did like...a million years ago...ok, just over a year ago on DotNetJunkies, except, not in English!  :-|

    Integrare Macromedia Flash MX e Microsoft ASP.NET

    I love you Google!  :D

    Roaming Online Identity

    So I was talking to Brian on MSN about Robert's entry and about some of the new features that the new ASP.NET Forums have implemented and are working on implementing such as newsgroup access in the forums.

    Brian then mentioned how he hated how long DNS takes to propigate throughout the world, especially on a new domain and totally I agreed.  I then got to thinking about how DNS works and I was reminded of an idea I had, so whether Brian wanted to hear about it or not, he did and now, whether you want me to post about it or not, I'm gonna!  :P

    .NET My Services was a total flop.  If you're not familiar with it, it was an initiative to get centralized data on people.  High Scores, Contact Lists, Calendars, Credit Cards, Windows Settings, Favorites, etc and then all linked into Passport, so any machine you were on, would act as if it new who you were, as well as a million other cool things.  Well, all the big companies Microsoft was hoping would jump on didn't and it went back to the drawing board.  Hell, I don't even know if they're going to go through with the concept at all now.  I haven't heard anything about it since PDC 2001.  So the big reason it flopped was because people didn't want their data being mediated by Microsoft.  Nobody seemed to feel safe about that concept, let alone Passport on top of all of that!  My next thought was, OK, so Microsoft will probably rework it to work more like a hive, where each company mediates their own data and then all of them would be linked through Passport or something like that.  Personally, I'd imagine companies would feel a bit better since they're in charge of it, but think about it; Who knows the software all of that is built on better?  Company A, B & C or the company that created it and maintains it, Microsoft.  Yah, so even still, I can't see something like that working out.  Just imagine the first big company that got hacked, because they messed up something.  Of course they'd blame it on Microsoft.

    So this kind of different idea pops into my head.  What about DRM (Digital Rights Management)?  Right now, the concept may be based around who owns what files and who can view what files, etc, but what if it could also be based around data as well?  Now, hold that thought and let's get back to the idea of how DNS works.  When you request an address to be resolved, your computer goes out to the closes DNS server (the one your IP is setup to use) and says, do you know what IP i should be using for this address?  If it doesn't know, it goes off to it's closes DNS and asks the same question.  Again and again, until one returns the IP and it is then cached at each machine back up the line all the way back up to the computer that made the original request.  If the request is made again, it goes to the nearest DNS server that knows the answer.  Side note: This is great, but horribly slow now that the internet is huge.  Anyone got a better idea?  ;)  So anyway, back to the idea at hand, what if your personal information worked in the same manner?  Don't get clouded in the details, just think concepts.  So what if when I requested for some personal data, say...all of my contacts, my computer would go out to the nearest computer (sort of P2P like) and say...do you have it?  Ok, no...go to the next closest computer, etc until it either finds the data or makes it back to a central server somewhere and gets it there, caches it around all the paths it took to get there.  Next request, grabs it from the cache, but with some sort of time checker to make sure it's the most recent data.  Now, before you freak out about “holy crap, everyone could get at my personal data...i don't think so, bub!“, remember the first thing I mentioned...DRM.

    Now step back into the shoes of a hacker and imagine if you would find it that much fun and exciting to try to hack data that was already sitting on your machine.  Nothing to spoof, nothing to “break into“.  True, there's still be the challenge of actually getting into the data and accessing it, but half the fun wouldn't be an issue anymore.  That's a good thing!  This scenario is also assuming DRM gets to be as secure as retinal scans:  You'd basically have to kill someone to get access (Demolition Man comes to mind  ;)).  I think things like P2P are great, but what have they done so far?  Allowed us to share files?  What's the next step?  The next big evolution!  This scenario is just one thing I've been thinking a bit about lately.

    Just more ideas and thoughts from yours truely.  Good idea?  Not ever possible?  Other thoughts, good or bad?  Have I lost my marbles?  If anything, did it at least get you thinking a bit?  ;)

    For those of you cynical people out there who think I think this should have happened yesterday regardless of security and the like, again, this is just me blabbin' about ideas that pop into my head, so don't go crazy or anything!  ;)

    Posted: Aug 11 2003, 12:02 AM by HumanCompiler | with 4 comment(s)
    Filed under:
    CommandBehavior.SingleRow

    I'm working on a chapter on ADO.NET and am going through documentation to make sure I have everything perfect and I came across something I hadn't noticed before.  I'm sure I'm the last yahoo to see this, but hopefully not, since the point of this post is to help anyone that hasn't seen this option yet, but often times I need something halfway in between ExecuteScalar and ExecuteReader.  You know, those times when you want to return more than one field, but the DataReader seems like overkill since you know you will only be returning one row every time.  An example of this is say, looking up a User to get some settings about them back.  The typical, “SELECT * FROM Users WHERE ID = @ID” type of thing.  You know there's only going to be one row ever.

    I'm not sure if I'm the only one, but I've only ever really used CommandBehavior.CloseConnection to have the connection automatically closed when the DataReader is closed.  Well, back to my scenario about only needing one row of data.  There's also CommandBehavior.SingleRow, which is actually optimized for only one row, which is exactly what I need!  Way to go Microsoft, sorry I didn't notice this before!  *hits head on desk*.  Now I can go back and find where i'm only ever going to have one row returned and use this for a little peformance gain, which is always good!  :)

    Posted: Aug 10 2003, 07:34 PM by HumanCompiler | with 6 comment(s)
    Filed under: ,
    RSS...Authentication...and why?

    Just sitting here thinking, man...it would be so nice if I could subscribe to a feed from my bank.  See in my RSS aggregator every time a new transaction occurs in my bank account.  Or maybe also one for my investments, so I can see when a purchase or sale goes through or maybe when any of my stocks goes through the roof or through the floor.  Sure, I could sign up to be notified from through e-mail or something like that, but it would be a lot nicer to know everything going on from my aggregator.  The problem is though, how do I get access to that content?  How does the provider know who I am?  Right now, RSS is all anonymous and doesn't care who you are.  Does ATOM/ECHO/PIE have it in its specs for any sort of authentication, so a person could get customized content?  Maybe an employee vs. a customer could get different content instead of having two different places a person would have to blog from.  What about security?  Sensative data...SSL?

    The next part of my thought though is why did we go backwards?  Is this idea of “pull only” data really the best way?  Is it more efficient in the grand scheme of it all over a “pull” technology?  Better question yet, is the idea of “pulling” data down to me, going to be enough in the future?  What if I'd like to be notified on my cell phone when there's a new Microsoft security bulletin for example or an important message to my boss's blog, how will my phone be notified?  It's not exactly efficient to have it constantly going out on the net and “pulling” from a server to see if there's anything new.  Wouldn't it be a better model to have the data pushed down to my cell phone when necessary.  Wouldn't it be better to have all the news i like to read down to me instead of me pulling it down constantly.  Maybe that's just not the way web servers are geared towards.  But if that way makes more sense, “efficiency aside”, then why do web servers work the way they work.  It seems to me like there are just too many things done today because “that's just how it's done”.

    So as I tend to do, this entry really just provides a lot of questions.  I'm not saying my thoughts are the right thoughts or anything even resembling something coherent, but hopefully I'm not the only one that wonders why we've gone back to “pull” instead of “push”.  Is it just because that was the easiest way right now?

    Ok, I'll stop!  ;)  I could probably ramble for hours and get nowhere!  :P

    Posted: Aug 10 2003, 05:29 PM by HumanCompiler | with 16 comment(s)
    Filed under:
    ASP.NET ToolBox

    Scott Mitchell has started a great new resource called the ASP.NET ToolBox.

    Check out his post on it for more information on it, where he got the idea and how you can help out!

    Posted: Aug 10 2003, 02:55 PM by HumanCompiler | with 5 comment(s)
    Filed under:
    Who Loves Naming Conventions? *raises hand*

    I've been posting about naming conventions lately and of course have been finding that as usual, most people think I am a big idiot!  It's cool everyone, I already knew that...so there!  :P

    But look, it's another thread on the subject and so happens to be on a subject I've been preaching on for a while, dealing with naming Stored Procedures, so I have a lot of respect for Phil posting this one and a damn good reason for doing it other than just a personal preference!

    On that note also, who out there prefixes their database Table names out there with something like “tbl”?  Come on now...who out there does it?  I've seen it before and I HATE it!  ;)

    Posted: Aug 07 2003, 09:56 PM by HumanCompiler | with 11 comment(s)
    Filed under:
    MSDN's RSS Feeds Suggestion

    Another free idea from yours truely.  Someone needs to create a better RSS feed for MSDN.  Maybe one that goes out and consumes all of them, filters through them, stripping out duplicates, adding categories, etc, so for example the last entry that just showed up 5 times in my SharpReader, would only show up ONCE, but just be under 5 different categories.  I'm sure there are a lot of us out there that are not only interested in one subject on MSDN.

    I'd do it myself, but don't have the time or hosting to take care of it.

    Hey Microsoft...want to take this one?  ;)

    UPDATE

    My mission in blogging is to actually make sure everyone knows what a big idiot I really am.  As soon as I posted this, I then thought...wait, is that what the “Just Published” feed is for?  Everything?  True, it could still be modified to help us “choose our content a bit better”, but that would be closer than I thought it was for...so I journey to the MSDN site and have been staring at it for at least 5 minutes now and I don't see the actual list of feeds listed anywhere.  I see the RSS link button “thingie”, but I can't find the list.  It's official I am the worlds biggest idiot!

    Posted: Aug 07 2003, 01:23 PM by HumanCompiler | with 4 comment(s)
    Filed under:
    VB.NET: Dynamic Arrays

    Matthew Reynolds' great tip reminded me of something especially for everyone using VB.NET.

    This is probably common knowledge for people who have been using VB.NET for quite a while, but for those just moving from VB6, dynamic arrays can be a major performance pitfall when migrating.

    Under the covers, when you call ReDim Preserve MyArray(5), VB.NET will actually take the array as it stands before that statement, create a copy of it with the additional positions needed (or a smaller size), then destroy the original copy.  This is because there really isn't such a thing as a “dynamic array“ in .NET.  This is what the ArrayList was invented for (well, probably for many other reasons too).  Take this typical VB6 scenario that you might be used to, that you then use in VB.NET:

    Private Function GetMyArray() As SomeClass()
         Dim MyArray() As
    SomeClass

         For i As Integer = 0 To
    MyData.Count - 1
              ReDim Preserve
    MyArray(i)

              MyArray(i) = New
    SomeClass
              With
    MyArray(i)
                   .ID = i
                   .Name = "blah " & i.ToString
              End
    With
        
    Next

        
    Return
    MyArray
    End Function

    Now think about making a copy of the array under the covers for every item in your loop?  Imagine working with 1000 items?

    My tip:  DO NOT USE THEM!  When you don't know the exact number of positions that you are going to need, use the ArrayList and use Matthew's tip to “export“ a strongly typed array from the ArrayList.  AFAIK, dynamic arrays were only written for backwards compatibility and don't even exist in C#.

    This is so much fun to take a break from writing to write more...of all things!  :-\

    UPDATE

    It's too early in the morning.  I posted how you might do it the “bad” way, but didn't post how you should do it instead...so here's how I would recommend rewriting the previous code example...

    Private Function GetMyArray() As SomeClass()
         Dim MyArray As New
    ArrayList
         Dim CurrentItem As
    SomeClass

         For i As Integer = 0 To
    MyData.Count - 1
              CurrentItem = New
    SomeClass
              With
    CurrentItem
                   .ID = i
                   .Name = "blah " & i.ToString
              End
    With

             
    MyArray.Add(CurrentItem)
        
    Next

        
    Return DirectCast(MyArray.ToArray(GetType
    (SomeClass)), SomeClass())
    End Function

    This will perform much faster!

    /me passes out...

    More Posts Next page »