CodeBetter.Com
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @CodeBetter

Karl Seguin

.NET From Ottawa, Ontario - http://twitter.com/karlseguin/

April 2007 - Posts

  • Random: Help with ASP.NET + PerfCounters / MySQL Thoughts / RedGate Rules / Amazon Web Service / CDN / PHP and OO

    Here's just an accumulation of random thoughts I've had over the last couple weeks.

    1.
    First and most importantly, I'm running into the problem where I'm trying to build a monitoring system that hooks into the System.Diagnostics.PerformanceCounter class and logs data (to be used for reporting later on) ever X seconds. The problem I'm running into with ASP.NET is that I don't know, nor can I seem to figure out, the instance name for the specific application. When I'm hooking into the ASP.NET Apps vXXXX, this isn't a problem because it uses the IIS name (_LM_W3SVC_.....Root). However, when I need counters from the Process or .NET XXX objects, the instances show up as the actual process (all I get is w3wp, w3wp#1, w3wp#2). At any given time, I have no clue which process is responsible for which application. IISAPP.vbs doesn't help because that just gives me the PID, which I still can't use.


    2.
    SQL INSERT should support a WHERE clause which actually does an UPDATE for rows matching the WHERE expression. So instead of checking if something exists and doing an IF .. update ... ELSE  insert ..

    You can just do:
    INSERT INTO Users (....) VALUES (...)
       WHERE UserId = 3


    3.
    MySQL Stored Procedure language is based on the SQL:2003 ISO/ANSI standard. Compared to TSQL, it's still very young (as is the entire stored procedure support). My biggest complaint, which might just be a case of complete ignorance on my part, is that variables aren't prefixed. In a normal language, variable prefixing isn't important...but in SQL it's critical because you easily get into conflicts with column names. Take:

    CREATE PROCEDURE GetUserById
    (
       Id INT
    )
    BEGIN

       SELECT Username, Email
          FROM Users
          WHERE Id = Id
    END

    How will MySQL handle that? I don't know. We've simply settled on prefixing all our parameters/variables with an underscore.


    4.
    While we're talking about MySQL..If you are using MySQL, set the sql-mode variable to STRICT_ALL_TABLES. It's a joke that it isn't on by default - and something that's almost impossible to go back and fix. You can learn more here, but implicit behaviour sucks


    5.
    SQL Server doesn't escape my wrath today either. I don't think Microsoft should buy-out RedGate (because that might put an end to a good thing), but RedGates products certainly put a lot of the MS SQL Server client products to shame. The SQL Bundle is stupidly useful...matched only by Resharper.


    6.
    The single biggest problem with the Amazon Web Services is...that someone at Amazon decided to call them Web Services. If you've never heard of AWS,
    what would you think? Another Web 2.0 web service to tie into some Amazon property, like their store, or their search or something. WRONG! AWS S3 is a cheap storage/bandwidth service...and EC2 (which we just love here at Fuel) is an "Elastic Cloud" network which lets us quickly scale computing power at the push of a button. Per hour billing of CPU cycles is very interesting to us, and as it gets easier and easier to do, it'll be a lot more interesting to everyone else too. It'd be great if EC2 ran Windows and they had worked out some great licensing arrangement with Microsoft, but it's such a great service
    we're just not using MS products on there (we might try a mono-solution in the near future though). Microsoft and Google and the thousands of hosting companies are gonna have to adjust.

    7.
    Speaking of Content Delivery, if you are paying too much for bandwidth (like more than $1.00/gb) consider using one of the many newer CDN's out there. We prefer PantherExpress, but there's also CacheFly and Amazon S3. In my experience, you pay A LOT less, get MUCH better customer service and almost as good (in some cases much better) speeds as you do with the 2 big boys of the CDN industry.

    8.
    Can't finish this off without laughing at PHP. I've said it before, and I'll say it again, PHP developers and the PHP team itself just don't get object
    oriented programming. The MySQLi extension is the OO way of connecting to a MySQL database (versus the normal MySQL extension). Not only does MySQLi support a completely procedural way of being used, but check out their documentation on how to use it:

    Example 1417. Object oriented style
    <?php
    $mysqli = new mysqli("localhost", "my_user", "my_password", "world");

    /* check connection */
    if (mysqli_connect_errno()) {
        printf("Connect failed: %s\n", mysqli_connect_error());
        exit();
    }

    printf("Host information: %s\n", $mysqli->host_info);

    /* close connection */
    $mysqli->close();
    ?>

    Notice those crapy mysqli_connect_errno() and mysqli_connect_error() calls? I'm sure the lack of exceptions will make Joel happy, but come on...this just plain out sucks!

  • StructureMap and The Code Wiki Together

    An article I wrote on how to modify The Code Wiki to use Jeremy's StructureMap has just been published on DotNetSlackers. You can see the article it here.

    This is an introductory article on Dependency Injection as a whole and should be a pretty easy read - whether you know The Code Wiki or not.

    There were a lot of best practices I left out of The Code Wiki, such as using a DI Framework,  for fear of over complicating everything. These articles are the outlet I'll use to discuss those features in separately from the main Code Wiki system/book. Hopefully others will also see opportunity to write their own articles about it :)

    Anyways, you'll see how Jeremy's done a great job of making StructureMap painless to use. It's also very flexible (which I didn't really get into).

    Worth mentioning that you can win an XBox360 for writing an article for DNS :) 

    Posted Apr 13 2007, 11:10 AM by karl with no comments
    Filed under:
  • Encapsulation isn't the be all and end all

    Lately I've been getting myself worked up over a thought that most developers use OO almost exclusively to enhance their code's encapsulation. I'm not 100% sure where this thought comes from or if I'm right. It's great that people want to organize their code and and separation of concern, cohesion and information hiding are all really great things, but it's a problem if that's all you think OO offers and go around saying you favor OO programming.

    Part of this stems from some of the interviews we've been doing lately. Everyone has OO on their resume, and they all say they've used it and most say they favor it, but getting them to talk about OO is a painful experience. Even when we lead a bit and talk about  "modeling" with respect to OO, they'll immediately talk about UML or use cases or databases - which all aren't too far off, but I just want someone to start talking about their domain layer and domain problems and stuff.

    An even bigger part of this stems from the Web 2.0 folk. I think it's great that namespaces and inheritance is all the rage in JavaScript-land, it certainly makes it easier for me to use those libraries. But you read some of the docs or some people's blogs and they talk about OO as though it was nothing more than an IKEA shelf organizer.

    Use any tool that makes your code easier to maintain, but that doesn't make you an expert in said tool.

  • Write an article for a chance to win an XBox 360

    DotNetSlackers is running an XBox 360 Giveway where potential authors have the chance to win one of three XBox 360s. You can learn more by visiting the contest page. Personally, I wouldn't give up this chance to win an XBox 360.

    Why is this posted on The Code Wiki tag? Well, I have an upcoming article on The Code Wiki going on DotNetSlackers...i won't be eligible for the prize (since I'm somewhat affiliated with DNS), but it'd be great to see someone else write a Code Wiki article and win an xbox 360.
     

    Posted Apr 05 2007, 08:40 AM by karl with no comments
    Filed under:
  • Announcing The Code Wiki

    I'm excited to announce the release of The Code Wiki - a learning tool to help teach fundamental programming practices. The Code Wiki is both a web-based sample application as well as a completely free eBook.

    I've currently written/released the first two chapters and am hopeful to be able to release a chapter roughly every month (although something tells me I'm going to be disappointed on that one). The two chapters are 24 or so pages, at a full 8.5 x 11, with few graphics and little artificial spacing.

    I'm going after, what I think, is one of the largest .NET audiences out there which also happens to be the worst targeted by tech books. This isn't a reference book like the countless others out there, and it isn't a super-advanced book either. It's squarely aimed at developers who know how to code, but want to learn how to better design their code. I shudder when I hear the word "architect", but I'll use it this one time.

    If you'll forgive me my hubris, I see this entire endeavor as an introduction to Jimmy Nilsson's excellent Applying Domain-Driven Design and Patternsbook, amongst other things. The app/book has a strong focus on important topics like domain design and unit testing, which I'm glad to say seems to be gaining momentum within the .NET community.

    I'm also hopeful that The Code Wiki might be useful for authors/presenters who need a sample application to write/talk about. For example, The Code Wiki doesn't use an O/R Mapper, and there's nothing I'd like to see more than someone writing an article on how to make The Code Wiki leverage NHibernate (or something). (don't worry, if one isn't written by the time I get to it, I do plan on writing one myself).

    There's a lot more to blog about, but for now we'll stick with this simple introduction. I'm anxious to see what people think, and more importantly to learn from the mistakes I've made.

    Check it out at www.thecodewiki.com


     

More Posts

Our Sponsors