Archives

Archives / 2006 / June
  • From the Peculiar Ideas Departament: Compilr

    Say you're away from home and just have to compile some lines of code to prove a theory, how do you do? Easy: browse to http://www.caller.me.uk/Compilr/, type or paste your lines and the code is compiled in a far and away server. It sounds like a strange proposition to me, but who knows, may be there are reams of programmers with Internet access that don't have a compiler at hand... Where's the money in the site? Advertising of course (Google is now generating some really weird spawn.) For the time being, they offer you C#, VB.NET, C, and Fortran compilers. Come to think of it, if they offer a few exotic languages like Lisp, Prolog, or APL, I may very well give it a try...

    Read more...

  • Kerberos, NTLM, PKI, SSL, roles, AzMan, DACL, impersonation, etc. in .NET

    You would imagine that topics like authentication (who you are) and authorization (what you are allowed to do), should be by now: a) solved and easily explained; b) standardized. In truth, the latter is a little more truth than the former, but at any rate if you want to understand these subjects you face a real alphabet soup and an entangled concept diversity, with each such concept apparently entitled to a tome by itself. Being 2006, authentication and authorization are still complex and not well understood topics, and, as a consequence, more than a few systems re-invent (poorly and weakly) the wheel.

    Well, this article, even though a little bit long, explains in a pretty detailed and decent way many of these concepts. Furthermore, it shows how to implement standard authorization and authentication solutions with the .NET Framework. Recommended reading.

    Read more...

  • .NET in Linux (and something about numerical analysis)

    Every few months news emerge about the Mono project: spearheaded by Miguel de Icaza in order to have a Linux .NET implementation that would allow to more easily create Windows like applications in Linux, Mono has managed to implement a good C# compiler, most of the BCL (ADO.NET included) and a pretty reasonable ASP.NET 1.1, but it has failed to have a production-level Windows Forms implementation (they are moving ahead, but Microsoft goes much faster.) A couple of years ago I got enthusiastic about Mono, but now I see (sadly) that it's stalling (even though it was acquired by Novell, or may be exactly because of that [;)]).

    While visiting the Mono site I found (again) dnAnalytics, an open source project trying to implement a standard set of numerical methods libraries (stuff like matrix manipulation, differential equations, etc.) in C#. It runs OK in Mono and also in the official .NET (although it doesn't use the new abilities in .NET 2.0), it could be of use for those of you working on numerical analysis.

    Read more...

  • Beta version of Ruby.NET compiler just released

    I just got an e-mail announcing the "preliminary Beta release of the Gardens Point Ruby.NET compiler" (what's that? an alpha? an untested beta?) One part of the announcement caught my eye, though:

    Our implementation is not yet fully complete, but it is the only Ruby compiler that we know of for either the .NET or JVM platforms that is able to pass all 871 tests in the samples/test.rb installation test suite of Ruby 1.8.2.

    So, go grab your preliminary Beta here.

    Read more...

  • Complete Visual Studio Team System shortcut keys listing

    Reading this blog entry, I remembered of the times when my younger brother Alex was the capo of PowerBuilder 6: just to impress you, he would put the mouse in his shirt pocket and then banged through the IDE just with the keyboard with amazing speed and dexterity. Well, it so happens that you can do the same with Visual Studio, only that we are so spoiled by the mouse that we never learnt how to drive VS without one. Almost a year ago, Jeff Atwood wrote a VS macro that generates a nice Web page with all the keyboard shortcuts available, I installed the macro, run it, and uploaded the shortcuts page ready for you to download and check here (the link is in Spanish, don't worry, just press the Download button.) So, any unexpected and useful shortcut there?

    Read more...

  • What Every Dev Must Know About Multithreaded Apps

    Pay attention to this few lines of code:

    class Calculator {
        private static int m_TotalCount;


        public void DailyCut(int
    limit)
        {
            m_TotalCount = 0;
            while
    (m_TotalCount != 0 && m_TotalCount < limit)
            {
                // some process
                m_TotalCount++;
            }
        }

        // other methods
    }

    Let's focus in just one of the several silly things of the sample: after setting m_TotalCount to 0, we immediately check whether m_TotalCount is different from zero, which will never be true, so the process inside the loop will never be executed. Obvious, right?

    Now, what would you do if you find out that the process, however infrequently, does get executed? A bug in .NET? Bill Gates? Well, far more plausible is that we are facing a concurrency problem: if several execution threads run through the Calculator class, then may be some method inside thread Y changes the value of m_TotalCount, right when thread X is between the assignment and the while, improbable but possible.

    This is an example of the bad things that can happen in multi-threaded environments, that's why it is recommended that we rookies better stay away from these waters, but at the same time multi-threaded programming offers several tempting advantages and, besides, with the generalization of multi-core and multi-process machines, it's going to be an unavoidable fact of life. That's why we better learn the ways and means of multi-threading and a good starting point is this nice article by Van Morrison that won an Excellence Award from the Society for Technical Communication. A very short and recommended reading.

    Read more...

  • TechEd 2006 *live* presentations

    TechEd 2006 started yesterday (and I finally didn't make it). Oh well, thanks to the Internet we can be up-to-date and much closer than not-being-there, for example we can watch the keynote delivered on Sunday afternoon and some other "home made" videos recorded in situ. We can also watch a webcasts series to be done live at TechEd from June 12 to June 16. See you at the Virtual TechEd!

    Read more...

  • .NET Framework 3.0

    Today, as Ecuador was beating Poland in the World Cup (way to go Ecuador!), Somasegar was announcing that what was previously known as WinFX (WCF, WPF, WF) plus other technologies like WCS (formerly Infocard) are an integral part of .NET Framework 3.0. Furthermore, *all* these components will be available for Vista, 2003 Server, and XP. I think it's time we download Beta 2.

    While in the subject, my +1 to the idea that Indigo, Avalon, Infocard are far better names than WCF, WPF, WCS, etc.

    Read more...

  • Friendly Web sites, design patterns, and metacognition

    First of all, you just have to love the guys that created these register policies:

    Isn't that all what you expect from a Web community member? Who needs lawyers anyway? Before you start laughing, note that JavaRanch gets millions of entries in its forums every month and they have won a Jolt Productivity Award on the Web Site and Developer Networks category twice in a row. When you know that, you are not surprised that these same guys created the Head First book series, of which I started to read Head First Design Patterns today, a book where, for example, the possibilities of the decorator pattern are illustrated in this way:

    Does that chap looks like an object decorator or what? Wink [;)] The authors use in funny ways the results of metacognitive research (that is, the research on how people learn), so you will laugh while you learn. Now, the authors write all of their examples in Java (nothing is perfect Stick out tongue [:P]), but luckily a good soul already translated the samples to .NET Cool [H]. Recommended reading.

    Read more...

  • Datasets are not for everything (and neither XML)

    First of all, let me tell you that datasets are wonderful, especially if you have to do CRUD operations on relational records. But that doesn't mean they are always the best choice. Ditto for XML. With the obvious statement out of the way, let me tell you this little tale:

    My pal Sandra needed to execute a process except for a group of operations, moreover, this group of "forbidden" operations could be changed at runtime. So, to begin with, Sandra defined an XML file with the forbidden operations:

    <ForbiddenOperations>

      <Operation>Destroy</Operation>

      <Operation>Kill</Operation>

      <Operation>Maime</Operation>

    </ForbiddenOperations>

    Then, she populated a dataset with the contents of the XML file:

    DataSet dataSet = new DataSet();

    dataSet.ReadXml(@"..\..\ForbiddenOperations.xml");

    And now, she could execute the process, except for forbidden operations, like so:

    DataTable operationsTable = dataSet.Tables[0];

    DataRow[] foundRows = operationsTable.Select("Operation_Text='" + operation + "'");

    if (foundRows.Length == 0)

    {

      // It isn't a forbidden operation, so do the process

    }

    It works, and it uses just a few lines of code. OTOH, it's terribly inefficient. To begin with, reading an XML file to populate a dataset demands a lot of resources and the file becomes a semaphore. Furthermore, the Select() method scans the table linearly, interpreting the expression for every row. If the table has many rows or the process is invoked many times, the response time will suffer noticeably.

    Which is the alternative? First, let's put the forbidden operations in the App.config file:

    <appSettings>

      <add key="forbiddenOperations" value="Destroy,Kill,Maime"></add>

    </appSettings>

    Then, populate a string dictionary with those operations:

    string[] forbiddenOperations = ConfigurationSettings.AppSettings["forbiddenOperations"].Split(',');

    StringDictionary forbiddenOperationsDictionary = new StringDictionary();

    foreach (string operation in forbiddenOperations)

    {

      forbiddenOperationsDictionary.Add(operation, operation);

    }

    And finally, you can execute the process, except for forbidden operations, like so:

    if (!forbiddenOperationsDictionary.ContainsKey(operation))

    {

      // It isn't a forbidden operation, so do the process

    }

    The first and last parts are more compact than in the first solution, even though the second part takes more lines. But the whole process is far more efficient and fast.

    So, even though datasets are great, don't use them for everything, in particular don't use them as a dictionary or a cache, if you want to find objects or records by a certain key it's far better to use a dictionary. Ditto, for XML.

    Read more...

  • C# Expression Evaluators

    Warning: this is not the usual code sample ready to be cut and pasted in your homework due for tomorrow.

    OTOH, if you are one of those guys that just have to understand why and how you can implement an expression evaluator in C#, then boy has Chuck Jazdzewski some interesting information for you. Chuck likes to propose interesting problems/challenges (often useless yet fascinating) and then discuss at detail various approaches to the problem, in the case of expression evaluators, Chuck offers us four alternatives:

    1. The classic procedural solution (√° la plain old Visual Basic)
    2. The object oriented solution (at the best 199x Smalltalk/Java style)
    3. The visitor pattern solution (for the guys one stair above average Java or C# programmers)
    4. The layered solution using partial classes (for the neoteric programmers using C# 2.0 or VB.NET 2005)

    As I said, don't expect a complete solution ready to be run but some pseudo-code and an interesting discussion of pros and cons. It may not help you with tomorrow's homework but it sure will help you impress the geek gal on the next cubicle.

    Read more...

  • The Art of Project Management

    Today I'm going to make an obvious point: the stars in a software project are the programmers (well, the architects a little bit too [;)]) no doubt about it. But the scenario is not unlike that of a music concert: the stars are the singers and musicians for sure but in order for the concert to be a success you require of far more people in many different fields, some of them totally unrelated to music.

    In order for a software project to be a success you require users, domain experts, IT people, testers, etc. And above all, you require project managers, this is a job hated poorly understood by programmers: a manager is a pointy haired boss utterly clueless about the fine art of programming.

    As I said, the stars are the programmers, but just as a concert produced by musicians is doomed to be a failure, a software project made only by programmers will be a nightmare. To avoid such chaos, to have everything ready for the programmers to write their masterpiece and let the users ecstatic, we need a great project manager.

    So what is it that a project manager is supposed to do? The answer is neither short nor simple, so it's great when a witty and candid book on the subject appears: The Art of Project Management, written by Scott Berkun, which got a Jolt Productivity Award in the Books General category. A recommended reading, for programmers and managers alike.

    Read more...

  • Programmer fonts, do they matter?

    May be I pay attention to silly things, but some fonts are easier to read than others and if you keep writing or reading code during hours and hours, the font that you use may very well affect your productivity (just a theory Geeked [8-|], besides, far more ridiculous stuff has made it's way in the Internet). Anyways, this is a code section with the standard Visual Studio font (Courier New Size 10):

    The Consolas font was created for Windows Vista but you can download and install it for Visual Studio 2005, at size 10 it looks like this:

    Note how more code fits in the same region and, IMHO, it's somewhat more readable. Finally, the Anonymous font was born in the Mac but you can download it free for Windows. The same code section in a smaller size (9 point) looks like this:

    Before Consolas debut, Anonymous was the one that I used. There are many fonts for programmers available (free, expensive, nice, silly, ...) What do you think? What font do you prefer for code? Does it even matter?

    Read more...