<?xml version="1.0" encoding="utf-8"?>
<feed
    xmlns="http://www.w3.org/2005/Atom"
    xmlns:at="http://www.sixapart.com/ns/at"
    xmlns:icbm="http://postneo.com/icbm"
    xmlns:rvw="http://purl.org/NET/RVW/0.2/"
    xml:lang="en">
    <title>Renaissance Programmer</title>
    <link rel="self" type="application/atom+xml" title="Renaissance Programmer (Atom)" href="http://jcoehoorn.vox.com/library/posts/page/1/atom.xml" />
    <link rel="alternate" type="text/html" title="Renaissance Programmer" href="http://jcoehoorn.vox.com/library/posts/page/1/"/>

    <link rel="service.post" type="application/atom+xml" title="Renaissance Programmer" href="http://www.vox.com/services/atom/svc=post/collection_id=6a00c22525ad91604a00c22525ade7549d" />

    <link rel="service.subscribe" type="application/atom+xml" title="Renaissance Programmer" href="http://jcoehoorn.vox.com/library/posts/atom.xml" />

    
    
        
    <link rel="next" type="application/atom+xml" title="Renaissance Programmer" href="http://jcoehoorn.vox.com/library/posts/page/2/atom.xml" />
    
    <link rel="last" type="application/atom+xml" title="Renaissance Programmer" href="http://jcoehoorn.vox.com/library/posts/page/13/atom.xml" />


    <generator uri="http://www.vox.com/">Vox</generator>
    <updated>2008-07-22T19:25:20Z</updated>

    <author>
        <name>jcoehoorn</name>
        <uri>http://jcoehoorn.vox.com/?_c=feed-atom-full</uri>
    </author>

    <id>tag:vox.com,2006:6p00c22525ad91604a/</id>


    
    <entry>
        <title>Idea for Simple Multi-threaded Software</title>
    
    
    
        <link rel="alternate" type="text/html" title="Idea for Simple Multi-threaded Software" href="http://jcoehoorn.vox.com/library/post/idea-for-simple-multi-threaded-software.html?_c=feed-atom-full" />
    
        
        <link rel="service.post" type="application/atom+xml" title="Idea for Simple Multi-threaded Software" href="http://jcoehoorn.vox.com/library/post/idea-for-simple-multi-threaded-software.html?_c=feed-atom-full#comments" />
    
        <link rel="service.edit" type="application/atom+xml" title="Idea for Simple Multi-threaded Software" href="http://www.vox.com/atom/svc=post/asset_id=6a00c22525ad91604a00fad69bbb680005" /> 
                <id>tag:vox.com,2008-07-21:asset-6a00c22525ad91604a00fad69bbb680005</id>
        <published>2008-07-21T16:25:14Z</published>
        <updated>2008-07-22T19:25:20Z</updated>
    
        <author>
            <name>jcoehoorn</name>
            <uri>http://jcoehoorn.vox.com/?_c=feed-atom-full</uri>
        </author>
    
        
        <content type="html" xml:base="http://jcoehoorn.vox.com/?_c=feed-atom-full">
            <![CDATA[
                <div xmlns="http://www.w3.org/1999/xhtml" xmlns:at="http://www.sixapart.com/ns/at">
    
    
        
            
            <p>As multi-core CPUs become more and more common, the ability to write quality software that takes advantage of them will become more important.&#160; The tools currently available are not adequate to this task.&#160; We are seeing a few things emerge to help solve the problem.&#160; One good example is the shift back to web applications hosted on a server.&#160; Web applications automatically run in parallel; each request can get it&#39;s own thread.&#160; However, there&#39;s still a shortage of simple, effective techiques for building parallel software on the desktop.</p><p>I had an idea of one place that where it would be very easy to build a parallel software approach into the programming language, so that developers can take advantage of a multi-core cpu in certain situations without having to do extra work.&#160; This idea is obvious enough that it probably isn&#39;t new to me, but I don&#39;t think I&#39;ve read about it anywhere else and so I wanted to write it out here.</p><p>What I want to do is updated the standard &quot;foreach&quot; loop that&#39;s included in most modern programming languages.&#160; .Net, java, PHP, Python, and more all have this simple loop.&#160; In a for each loop, you specify an operation to be performed on every item in a collection of items.&#160; Current implementations of this loop always run in serial.&#160; Process one item, and when that one is finished get the next and process it.&#160; However, much of the time this could be done in parallel.&#160; My idea is that you could bake this concept into a programming language by making a simple change to your loop declaration.&#160; For example, take this simple C# loop declaration.&#160; Instead of this:</p><blockquote><p><span style="color: #3366ff">foreach </span>(<span style="color: #3366ff">object </span>Item <span style="color: #3366ff">in </span>MyCollection)<br /></p></blockquote><p>Do this:</p><blockquote><p><span style="color: #3366ff">forevery </span>(<span style="color: #3366ff">object </span>Item <span style="color: #3366ff">in </span>MyCollection)<br /></p></blockquote><p>Change just one key word and the compiler knows it can use create separate threads for the contents of the loop.&#160; <span style="color: #3366ff"></p></span><p>Of course, there are situations where these loops should not be run in parallel.&#160; Maybe you need to break early.&#160; Or maybe you&#39;re building a count as you go.&#160; But this should be relatively easy for the programmer to determine, and they can always use the old behavior when needed.</p><p>Are there any languages out there that already implement this concept?<br /></p>
        
    
                <p style="clear:both;">

    <a href="http://jcoehoorn.vox.com/library/post/idea-for-simple-multi-threaded-software.html?_c=feed-atom-full#comments">Read and post comments</a>

 | 

    
    <a href="http://www.vox.com/share/6a00c22525ad91604a00fad69bbb680005?_c=feed-atom-full">Send to a friend</a>

</p>

                </div>
            ]]>
        </content>
    
    </entry>

    
    <entry>
        <title>VB.Net vs C#, Round 2: Partial Namespaces</title>
    
    
    
        <link rel="alternate" type="text/html" title="VB.Net vs C#, Round 2: Partial Namespaces" href="http://jcoehoorn.vox.com/library/post/vbnet-vs-c-round-2-partial-namespaces.html?_c=feed-atom-full" />
    
        
        <link rel="service.post" type="application/atom+xml" title="VB.Net vs C#, Round 2: Partial Namespaces" href="http://jcoehoorn.vox.com/library/post/vbnet-vs-c-round-2-partial-namespaces.html?_c=feed-atom-full#comments" />
    
        <link rel="service.edit" type="application/atom+xml" title="VB.Net vs C#, Round 2: Partial Namespaces" href="http://www.vox.com/atom/svc=post/asset_id=6a00c22525ad91604a00fae8cce237000b" /> 
                <id>tag:vox.com,2008-07-17:asset-6a00c22525ad91604a00fae8cce237000b</id>
        <published>2008-07-17T17:31:25Z</published>
        <updated>2008-07-20T03:22:15Z</updated>
    
        <author>
            <name>jcoehoorn</name>
            <uri>http://jcoehoorn.vox.com/?_c=feed-atom-full</uri>
        </author>
    
        
        <content type="html" xml:base="http://jcoehoorn.vox.com/?_c=feed-atom-full">
            <![CDATA[
                <div xmlns="http://www.w3.org/1999/xhtml" xmlns:at="http://www.sixapart.com/ns/at">
    
    
        
            
            <p>I&#39;ve <a href="http://jcoehoorn.vox.com/library/post/why-i-like-vbnet-over-c.html">talked about this before</a>, and I don&#39;t want to go over the same issues a second time.&#160; However, I recently had a project where I finally spent a few weeks in C#, with no VB work at all.&#160; At last, I had a chance to develop a deeper familiarity with C#.&#160; Maybe I would learn something new.&#160; </p><p>The result?&#160; C# moves closer to VB.Net in my estimation, but doesn&#39;t quite pass it.&#160; All of the short-comings when compared to VB.Net still exist in my mind, but now I&#39;ve had the chance to get a feel for what C# does about them.&#160; I can&#39;t put my finger on it, but there are little things here and there in C# that make up for a lot of what I complained about before.&#160; For example, I still prefer seeing &quot;End If&quot;, &quot;End Sub&quot;, &quot;End Class&quot;, etc to the more ambiguous &quot;}&quot;.&#160; But now that I&#39;ve used C# more it&#39;s not as big a deal.&#160; I like the VB way, but I&#39;m not as handicapped by C# as I was.&#160; The gap is still there, but it&#39;s not as wide.</p><p>The experience did bring one new shorting coming in C# that I didn&#39;t write about before.&#160; VB.Net supports partial namespaces; C# does not.&#160; Let me explain.&#160; Imagine you want to read from a file.&#160; In .Net, that means using the System.IO namespace.&#160; With Visual Basic, System is imported by default and child namespaces are automatically resolved.&#160; So, for example, to see if a file exists I can just say something like this:<br /><blockquote><p><span style="color: #3366ff">If </span>IO.File.Exists(<span style="color: #144692">&quot;foo.bar&quot;</span>) <span style="color: #3366ff">Then </span><br /></p></blockquote>That won&#39;t work in C#.&#160; You have to either type out System.IO.File or add a using directive for System.IO at the top of the file.&#160; Now the IO namespace this isn&#39;t a big deal.&#160; You&#39;re probably going to use the classes from the namespace a dozen times if you use them once, or it&#39;s not a lot to type otherwise.&#160;&#160; It does pollute your intellisense namespace though, and it starts to become annoying when you also need StringBuilder and have to import System.Text but aren&#39;t using anything else from that namespace.&#160; Or maybe you need a single Dataset, but nothing else from System.Data.&#160; You can quickly accumulate several using directives that only exist to support one class declaration.&#160; The point is that the class library heirarchy in .Net is rather flat, and there are a lot of little things you might want that in C# that all require a using directive where VB.Net does not.</p><p><br />So C# doesn&#39;t let you use a partial namespace in a declaration.&#160; Big deal.&#160; Well, this example only illustrates the least of my complaints.&#160; The worst things about what I&#39;ve shown so far are that it leads to a polluted intellisense prompt and that it breaks your flow to have to jump to the top of the page to add the declaration and then jumb back versus simply typing a shorter name.&#160; If this was all there was to it I would just keep my mouth shut and deal with it.&#160; But there are other, more important manifestations.&#160; I&#39;ll give two examples.</p><p>Say you&#39;re working on a project that involves a lot of XML.&#160; You&#39;ll probably import the System.Xml namespace.&#160; In C# you may also need to import one or more of System.Xml.Schema, System.Xml.XPath, System.Xml.Serialization, or System.Xml.Xsl.&#160; And now you&#39;re using a whole bunch of different classes with no reference in the code for which specific namespace each class came from.&#160; In VB.Net you can just preface the class names of classes not directly in the Xml namespace with only the missing child namespace.&#160; For example, if I choose not to import System.Xml.Schema but already have System.Xml I can still just say &quot;Schema.XmlSchema&quot; instead of &quot;System.Xml.Schema.XmlSchema&quot;.&#160; <span style="color: #144692"></p></span><p>That sounds a lot like the same complaint I had earlier, and it usually ends up requiring a little more typing than importing all the namespaces once.&#160; What&#39;s new, though, is that in my opinion this has the potential tomake the code easier to understand.&#160; The specific example of &quot;Schema.XmlSchema&quot; is pretty redundant, but there are plenty of cases where having one level of the namespace with the class would add clarity to the declaration.&#160; This is especially true for junior developers who may not be totally familiar with the framework.&#160; Used correctly, it can provide just a little bit of important context for each of your declarations.</p><p>Now for the next example.&#160; After all, the Xml namespace is pretty well understood.&#160; Also, my XML example wasn&#39;t very good; what do we need the extra context for?&#160; Fair enough.&#160; Let&#39;s look at something even more relevant.&#160; What if you&#39;re working on a project where you want to use a third party library?&#160; In this case, being able to see a small amount of context for each class may have a little more value.&#160; And what if you&#39;ve never used this library before?&#160; </p><p>The <a href="http://sharpdevelop.net/OpenSource/SharpZipLib/">SharpZipLib</a> comes to mind as a reasonable example.&#160; Imagine your project involved using the library to untar some files.&#160; In C# you would import ICSharpCode.SharpZipLib.Tar and then type class names as usuall.&#160; However, there is no help from the IDE in finding out what those classes are without re-typing the entire namespace every time.&#160; This shows one final reason why partial namespaces are useful.&#160; In VB.Net you just import ICSharpCode.SharpZipLib.&#160; Now, if you only type &quot;Tar.&quot; you get an intellisense list of members of that namespace as soon as you hit the period key.&#160; For this reason, I find VB.Net is much easier to work with when learning the ins and outs of a new library.</p><p>In summary, I really like VB.Net&#39;s ability to use partial namespaces in declarations.&#160; There&#39;s probably a more official name for the feature, but I don&#39;t know
it.&#160; It might even be something you can just turn on as an option for a project in
C#, in which case I hope someone will tell me where to find that option.&#160; I think the feature promotes code that is more readable, doesn&#39;t break the flow of the programmer as often, keeps your intellisense namespace clearer, and aids in learning new libraries.</p><p></p><p><br /> </p>
        
    
                <p style="clear:both;">

    <a href="http://jcoehoorn.vox.com/library/post/vbnet-vs-c-round-2-partial-namespaces.html?_c=feed-atom-full#comments">Read and post comments</a>

 | 

    
    <a href="http://www.vox.com/share/6a00c22525ad91604a00fae8cce237000b?_c=feed-atom-full">Send to a friend</a>

</p>

                </div>
            ]]>
        </content>
    
    </entry>

    
    <entry>
        <title>Make your Code as Useful as Possible</title>
    
    
    
        <link rel="alternate" type="text/html" title="Make your Code as Useful as Possible" href="http://jcoehoorn.vox.com/library/post/make-your-code-as-useful-as-possible.html?_c=feed-atom-full" />
    
        
        <link rel="service.post" type="application/atom+xml" title="Make your Code as Useful as Possible" href="http://jcoehoorn.vox.com/library/post/make-your-code-as-useful-as-possible.html?_c=feed-atom-full#comments" />
    
        <link rel="service.edit" type="application/atom+xml" title="Make your Code as Useful as Possible" href="http://www.vox.com/atom/svc=post/asset_id=6a00c22525ad91604a00fad69a3d7d0005" /> 
                <id>tag:vox.com,2008-07-16:asset-6a00c22525ad91604a00fad69a3d7d0005</id>
        <published>2008-07-16T17:35:23Z</published>
        <updated>2008-07-16T20:23:39Z</updated>
    
        <author>
            <name>jcoehoorn</name>
            <uri>http://jcoehoorn.vox.com/?_c=feed-atom-full</uri>
        </author>
    
        
        <content type="html" xml:base="http://jcoehoorn.vox.com/?_c=feed-atom-full">
            <![CDATA[
                <div xmlns="http://www.w3.org/1999/xhtml" xmlns:at="http://www.sixapart.com/ns/at">
    
    
        
            
            <p>I don&#39;t know how many times I&#39;ve seen code similar to the following on programming help forums:</p><blockquote><p><span style="color: #3366ff">Function </span>MyMethod(<span style="color: #3366ff">ByVal </span>InputParameter() <span style="color: #3366ff">As String</span>) As <span style="color: #3366ff">String</span>()<br />&#160;&#160;&#160; <span style="color: #339933">&#39;Do Stuff here that returns a different string array</span><br /><span style="color: #3366ff">End Function</span><br /></p></blockquote><p>That&#39;s okay.&#160; We can make that work just fine.&#160; I mean, it could be worse; they could have used an <em>ArrayList</em>.&#160; But we can do better, too.&#160; Now look at this code:</p><blockquote><p><span style="color: #3366ff">Function </span>MyNewMethod(<span style="color: #3366ff">ByVal </span>InputParameter <span style="color: #3366ff">As </span>IEnumerable(<span style="color: #3366ff">Of</span> <span style="color: #3366ff">String</span>)) <span style="color: #3366ff">As </span>StringCollection<br />&#160;&#160;&#160;&#160;<span style="color: #339933"> &#39;Do stuff here that returns the string collection</span><br /><span style="color: #3366ff">End Function</span><br /></p></blockquote><p>This code is a drop in replacement for the code above.&#160; By that I mean that anywhere you call the first method, you could replace it with the 2nd method and your code will still work.&#160; You don&#39;t have to change anything else except the type of the variable that accepts the result.&#160; So if it works the same, why change?&#160; I mean, it takes a little more thought to read it and therefore you could argue it takes more to maintain.&#160; What do you gain?&#160; The answer is that you&#39;ve just made the function more useful and flexible.</p><p>Let&#39;s start with the InputParameter.&#160; Perhaps right now you have always have a string array when you call it.&#160; But what if later you start working with something like an ArrayList or the generic List(Of String)?&#160; Those will both work with that method right now, with no other changes.&#160; You can even put Xml or datatables through there with a little work.&#160; IEnumerable(Of String) will accept anything that can give you a string in a For Each loop.&#160; So just by changing the type I&#39;ve instantly made the code more powerful.</p><p>Now for the return type.&#160; I could have used IEnumerable(Of String) here as well.&#160; However, in this case that would actually limit the capabilities of the function.&#160; You&#39;d lose the ability to look at values by index.&#160; What I want to do is expand the capabilities of the function.&#160; String() already implies IEnumerable(Of String).&#160; However, by moving from the&#160; array up to a StringCollection I not only keep that ability but gain the ability to easily add or remove items from the collection.&#160; I also get some bonuses like the nice .Contains() and .IndexOf() methods.&#160; So again, I&#39;ve expanded what the function can do, and therefore made it more valuable.&#160; </p><p>For example, you might now be able to use it somewhere that before would have required a separate (but very similar) function.&#160; Or the switch to the new function might save you having to write a for each loop on the return value because of additional capabilities in the collection like the .Contains() method.&#160; It will enable you to get the same work done in less code.</p><p>One other point is that the new version should perform about the same as the old one. There might be a very small loss, but any difference is likely to be minor relative to other considerations in your code.&#160; Certainly falls under the heading of &quot;premature optimization.&quot;</p><p>In general, we can think of IEnumerable(Of String) as a wider type, and StringCollection as a more powerful type.&#160; A good rule of thumb is to accept a wider type for input and return a more powerful type for output.&#160; In this way you will make your code more useful, and in the long run that&#39;s probably a good thing.</p> 
        
    
                <p style="clear:both;">

    <a href="http://jcoehoorn.vox.com/library/post/make-your-code-as-useful-as-possible.html?_c=feed-atom-full#comments">Read and post comments</a>

 | 

    
    <a href="http://www.vox.com/share/6a00c22525ad91604a00fad69a3d7d0005?_c=feed-atom-full">Send to a friend</a>

</p>

                </div>
            ]]>
        </content>
    
    </entry>

    
    <entry>
        <title>The Power of Declarative Code in ASP.Net</title>
    
    
    
        <link rel="alternate" type="text/html" title="The Power of Declarative Code in ASP.Net" href="http://jcoehoorn.vox.com/library/post/the-power-of-declarative-code-in-aspnet.html?_c=feed-atom-full" />
    
        
        <link rel="service.post" type="application/atom+xml" title="The Power of Declarative Code in ASP.Net" href="http://jcoehoorn.vox.com/library/post/the-power-of-declarative-code-in-aspnet.html?_c=feed-atom-full#comments" />
    
        <link rel="service.edit" type="application/atom+xml" title="The Power of Declarative Code in ASP.Net" href="http://www.vox.com/atom/svc=post/asset_id=6a00c22525ad91604a00fad69997260004" /> 
                <id>tag:vox.com,2008-07-11:asset-6a00c22525ad91604a00fad69997260004</id>
        <published>2008-07-11T15:55:55Z</published>
        <updated>2008-07-11T19:58:09Z</updated>
    
        <author>
            <name>jcoehoorn</name>
            <uri>http://jcoehoorn.vox.com/?_c=feed-atom-full</uri>
        </author>
    
        
        <content type="html" xml:base="http://jcoehoorn.vox.com/?_c=feed-atom-full">
            <![CDATA[
                <div xmlns="http://www.w3.org/1999/xhtml" xmlns:at="http://www.sixapart.com/ns/at">
    
    
        
            
            <p>ASP.Net is often mistaken for a simple update to Classic ASP.&#160; Just take ASP, throw in some .Net classes, and you&#39;re done.&#160; You get a better IDE and you might get a small performance boost from using pre-compiled code, but not much else.&#160; Of course, you <em>could </em>use ASP.Net like Classic ASP.&#160; If that&#39;s as far as you go then I suppose everything above would be true.&#160; In fact, one of the nice things about ASP.Net is it&#39;s ability to work with you as your skills grow, and give at least small benefits right away.&#160; But if you stop here you&#39;re missing out on the best parts of the language.</p><p>ASP.Net allows you to be more declarative in how you lay out your page.&#160; If an SQL SELECT query is the classic example of declarative code, than you can think of each server control as a little SELECT query.&#160; It&#39;s a way to declare what you want to the framework and let it worry about how to actually do it rather than listing out every little step.&#160; The advantages of this approach are numerous: your code base is smaller, busy-work is reduced, you see pages from a higher level, you get better separation of concerns for designers and developers...&#160;&#160; I could go on.&#160; You might be surprised to hear that there&#39;s a huge potential performance benefit as well.</p><p>If that thought does surprise you, it shouldn&#39;t.&#160; After all, it&#39;s what makes SQL fast.&#160; Take an SQL cursor, for example.&#160; A cursor is usually the slowest way to accomplish any task in a database.&#160; Why?&#160; Because it&#39;s procedural.&#160; If you can re-write the cursor to use declarative statements you will nearly always see a significant performance improvement.&#160; This is because the database can now use it&#39;s cache and indexes, and even execute the operation in parallel.&#160; The same concept applies to a web page, and for the same reasons.&#160; I don&#39;t know to what extent, if any, ASP.Net applies these concepts.&#160; But it should be theoretically possible. </p><p>First we&#39;ll look at caching/indexing.&#160; With declarative code the server can get a rough picture of what every instance of a page will look like.&#160; It can use this picture to create and cache a pre-loaded version of the page, where all the declared controls and HTML are loaded and put in the intial state defined by the aspx code.&#160; This is a huge improvement, because the amount of work left to do for each request is greatly reduced.&#160; Classic ASP would have to start from the beginning for every single request and work it&#39;s way through all of the page code to be sure of getting the correct result, like any other procedural code.&#160; The ASP.Net environment can take a few shortcuts.</p><p>Now let&#39;s move on to parallelism.&#160; Server controls in ASP.Net ultimately boil down to plain old XML, and every XML document is a tree structure of tags.&#160; The nature of XML means you have a certain amount of independence between siblings at any given level of the tree; the contents of one sibling aren&#39;t really relevant to the contents of another sibling.&#160; That means that each sibling can be processed in parallel.&#160; In practice ASP.Net controls can have code that modifies other parts of the page, so this ability is not absolute.&#160; However, it should be possible for the compiler to analyze the code and build a dependency tree for a page, and in this way get some advantage.&#160; The important thing here is that less procedural code means a more straightforward dependency tree and a greater the potential for parallelism. </p><p>As CPUs with more cores become more and more common a built-in mechanism
to render a page in parallel will become more and more significant.&#160; This is true even though a web server may already utilize multiple cores by&#160; processing separate requests in parallel.&#160; For example, while one node on a page waits for a request to a database to complete, rather than blocking the entire page other nodes can continue to process.&#160; In this way individual requests can still be served faster.</p><p>I need to repeat that I have no idea if these concepts are currently implemented.&#160; I suspect at moment they are not, and it&#39;s a shame if that&#39;s so. But the possibility and potential here is certainly interesting.</p>
        
    
                <p style="clear:both;">

    <a href="http://jcoehoorn.vox.com/library/post/the-power-of-declarative-code-in-aspnet.html?_c=feed-atom-full#comments">Read and post comments</a>

 | 

    
    <a href="http://www.vox.com/share/6a00c22525ad91604a00fad69997260004?_c=feed-atom-full">Send to a friend</a>

</p>

                </div>
            ]]>
        </content>
    
    </entry>

    
    <entry>
        <title>SQL Injection, Part 2</title>
    
    
    
        <link rel="alternate" type="text/html" title="SQL Injection, Part 2" href="http://jcoehoorn.vox.com/library/post/sql-injection-part-2.html?_c=feed-atom-full" />
    
        
        <link rel="service.post" type="application/atom+xml" title="SQL Injection, Part 2" href="http://jcoehoorn.vox.com/library/post/sql-injection-part-2.html?_c=feed-atom-full#comments" />
    
        <link rel="service.edit" type="application/atom+xml" title="SQL Injection, Part 2" href="http://www.vox.com/atom/svc=post/asset_id=6a00c22525ad91604a00fad694856d0004" /> 
                <id>tag:vox.com,2008-06-24:asset-6a00c22525ad91604a00fad694856d0004</id>
        <published>2008-06-24T22:37:46Z</published>
        <updated>2008-07-22T20:35:09Z</updated>
    
        <author>
            <name>jcoehoorn</name>
            <uri>http://jcoehoorn.vox.com/?_c=feed-atom-full</uri>
        </author>
    
        
        <content type="html" xml:base="http://jcoehoorn.vox.com/?_c=feed-atom-full">
            <![CDATA[
                <div xmlns="http://www.w3.org/1999/xhtml" xmlns:at="http://www.sixapart.com/ns/at">
    
    
        
            
            <p>I first wrote about an <a href="http://jcoehoorn.vox.com/library/post/sql-injection.html">SQL Injection</a> attack way back in April.&#160; It died down for a while, but that attack is still going on.&#160; It broadened in scope to even hit some php and ASP.Net sites, and this week I&#39;ve noticed several new requests for assistance.&#160; If you&#39;re wondering how your site would fare, you should check out <a href="http://news.cnet.com/8301-10789_3-9976521-57.html?part=rss&amp;subj=news&amp;tag=2547-1_3-0-5">this article</a>.&#160; <em>Here are the steps to take if you need to fix the issue</em>:</p><ol><li><strong>Take down the site.</strong>&#160; As it stands now, the site is actively serving malware to it&#39;s users.&#160; This is not a situation you want to be in.&#160; You can put up a temporary page to tell the users what is happening, but you should not allow the&#160; site to continue operating until it&#39;s fixed.</li><li>Fix the vulnerabilities that allowed the breach in the first place.&#160; The nature of the attack is that the site will be infected again inside of a week unless the vulnerabilities are closed.&#160; It could be as simple as replacing a single apostrophe with two apostrophes on a few form fields or it could be much more complicated, but it must be done.&#160; The article I linked to above has some tools that can help.</li><li>Fix the database.&#160; Now we can finally begin to undo the damage.&#160; You have a couple options here, including restoring from backup, though that may not be necessary.&#160; Instead, I modified the code used for the attack to help with the cure.&#160; If this seems cryptic it&#39;s because I only changed what was necessary to make it work.&#160; <em>Note that you should not run this code if the database contains valid instances of the text &quot;&lt;script&quot; anywhere:</em></li></ol><blockquote><p><span style="color: #666666">DECLARE @T varchar(255),@C varchar(255) </span><br /><span style="color: #666666">DECLARE Table_Cursor CURSOR FOR select a.name,b.name from sysobjects a,syscolumns b where a.id=b.id and a.xtype=&#39;u&#39; and (b.xtype=99 or b.xtype=35 or b.xtype=231 or b.xtype=167) </span><br /><span style="color: #666666">OPEN Table_Cursor FETCH NEXT FROM Table_Cursor INTO @T,@C </span><br /><span style="color: #666666">WHILE(@@FETCH_STATUS=0) BEGIN </span><br /><span style="color: #666666">exec(&#39;update [&#39;+@T+&#39;] set [&#39;+@C+&#39;]=LEFT([&#39;+@C+&#39;], CHARINDEX(&#39;&#39;&lt;script&#39;&#39;, [&#39;+@C+&#39;])-1)</span><br /><span style="color: #666666">WHERE CHARINDEX(&#39;&#39;&lt;script&#39;&#39;, [&#39;+@C+&#39;]) &gt;0&#39;)</span><br /><span style="color: #666666">FETCH NEXT FROM Table_Cursor INTO @T,@C </span><br /><span style="color: #666666">END </span><br /><span style="color: #666666">CLOSE Table_Cursor </span><br /><span style="color: #666666">DEALLOCATE Table_Cursor</span><br /></p></blockquote><p>Now, finally, you can put the site back up and things should be back to normal.<span style="color: #666666"> </p></span><blockquote><blockquote><p><span style="color: #666666"></span></p></blockquote></blockquote>
        
    
                <p style="clear:both;">

    <a href="http://jcoehoorn.vox.com/library/post/sql-injection-part-2.html?_c=feed-atom-full#comments">Read and post comments</a>

 | 

    
    <a href="http://www.vox.com/share/6a00c22525ad91604a00fad694856d0004?_c=feed-atom-full">Send to a friend</a>

</p>

                </div>
            ]]>
        </content>
    
    </entry>

    
    <entry>
        <title>Firefox</title>
    
    
    
        <link rel="alternate" type="text/html" title="Firefox" href="http://jcoehoorn.vox.com/library/post/firefox.html?_c=feed-atom-full" />
    
        
        <link rel="service.post" type="application/atom+xml" title="Firefox" href="http://jcoehoorn.vox.com/library/post/firefox.html?_c=feed-atom-full#comments" />
    
        <link rel="service.edit" type="application/atom+xml" title="Firefox" href="http://www.vox.com/atom/svc=post/asset_id=6a00c22525ad91604a00fae8c3d337000b" /> 
                <id>tag:vox.com,2008-06-17:asset-6a00c22525ad91604a00fae8c3d337000b</id>
        <published>2008-06-17T18:51:48Z</published>
        <updated>2008-06-17T19:05:30Z</updated>
    
        <author>
            <name>jcoehoorn</name>
            <uri>http://jcoehoorn.vox.com/?_c=feed-atom-full</uri>
        </author>
    
        
        <content type="html" xml:base="http://jcoehoorn.vox.com/?_c=feed-atom-full">
            <![CDATA[
                <div xmlns="http://www.w3.org/1999/xhtml" xmlns:at="http://www.sixapart.com/ns/at">
    
    
        
            
            <p>Don&#39;t forget to <a href="http://www.getfirefox.com">download the new Firefox</a> today.&#160; </p><p>... if you can, that is.&#160; It seems that the folks over at Mozilla vastly underestimated the amount of traffic their world-record try would bring.&#160; At least, the server isn&#39;t responding at the moment, and hasn&#39;t worked for me since the official start time nearly two hours ago.</p><p>You may still be able to get the new version using this link:<br /><a class="jive-link-external" href="http://download.mozilla.org/?product=firefox-3.0&amp;os=win&amp;lang=en-US" target="_newWindow">http://download.mozilla.org/?product=firefox-3.0&amp;os=win&amp;lang=en-US</a></p><p>However, this link isn&#39;t 100% reliable either, and I don&#39;t know if it will get counted towards the record.&#160; I have used to get install the new Firefox on the three systems I use, so if you can&#39;t wait and the link doesn&#39;t work on the first try then give it a few moments and try again.</p><p><strong>Update:</strong>&#160; The site appears to be working again.<br /> </p>
        
    
                <p style="clear:both;">

    <a href="http://jcoehoorn.vox.com/library/post/firefox.html?_c=feed-atom-full#comments">Read and post comments</a>

 | 

    
    <a href="http://www.vox.com/share/6a00c22525ad91604a00fae8c3d337000b?_c=feed-atom-full">Send to a friend</a>

</p>

                </div>
            ]]>
        </content>
    
    </entry>

    
    <entry>
        <title>Excel Column Names</title>
    
    
    
        <link rel="alternate" type="text/html" title="Excel Column Names" href="http://jcoehoorn.vox.com/library/post/excel-column-names.html?_c=feed-atom-full" />
    
        
        <link rel="service.post" type="application/atom+xml" title="Excel Column Names" href="http://jcoehoorn.vox.com/library/post/excel-column-names.html?_c=feed-atom-full#comments" />
    
        <link rel="service.edit" type="application/atom+xml" title="Excel Column Names" href="http://www.vox.com/atom/svc=post/asset_id=6a00c22525ad91604a00fad690d4e60004" /> 
                <id>tag:vox.com,2008-06-12:asset-6a00c22525ad91604a00fad690d4e60004</id>
        <published>2008-06-12T20:51:53Z</published>
        <updated>2008-06-13T13:35:04Z</updated>
    
        <author>
            <name>jcoehoorn</name>
            <uri>http://jcoehoorn.vox.com/?_c=feed-atom-full</uri>
        </author>
    
        
        <content type="html" xml:base="http://jcoehoorn.vox.com/?_c=feed-atom-full">
            <![CDATA[
                <div xmlns="http://www.w3.org/1999/xhtml" xmlns:at="http://www.sixapart.com/ns/at">
    
    
        
            
            <p><span id="intelliTxt">I ran across a request in a forum today to create an 
Excel column name from an index.&#160; It sounds simple, but it&#39;s harder than it 
looks.</span>
<p><span></span><span>The obvious solution here is to think about a column name 
as a base 26 number, with A-Z for digits.&#160; Unfortunately,&#160;it doesn&#39;t quite work 
like that.&#160; The &#39;0&#39; digit is broken.&#160; For example, counting the column names 
from A you wrap around to AA after reaching Z. If this were base 10 it would be 
like counting from 1 to 9 and then getting 11 instead of 10, or counting from 0 
to 9 and then getting 00 instead of 10, depending on whether you treat A as 0 or 
1. So it&#39;s tricky.</p>I thought I could get around that but that it would 
take more work than it&#39;s worth, so I decided to look around online. Surely there 
would be something already out there. What I found was a bunch of 
over-complicated implementations that all break somewhere on one of the 
boundaries I described.&#160; Even the&#160;<a href="http://support.microsoft.com/kb/833402">Microsft support 
example</a>&#160;doesn&#39;t work well.&#160; What a disappointment.</span></p><p><span>So I ended up 
writing a new version after all.&#160;&#160;This one will scale, and it&#39;s not even that 
complicated. I just had to get a little recursive:</span></p><blockquote><p><span style="font-size: small; color: #0000ff">Function</span><span style="font-size: small"> 
ColumnName(</span><span style="font-size: small; color: #0000ff">ByVal</span><span style="font-size: small"> index 
</span><span style="font-size: small; color: #0000ff">As</span><span style="font-size: small"> </span><span style="font-size: small; color: #0000ff">Integer</span><span style="font-size: small">) </span><span style="font-size: small; color: #0000ff">As</span><span style="font-size: small"> </span><span style="font-size: small; color: #0000ff">String<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Static</span><span style="font-size: small"> chars() 
</span><span style="font-size: small; color: #0000ff">As</span><span style="font-size: small"> </span><span style="font-size: small; color: #0000ff">Char</span><span style="font-size: small"> = {&quot;A&quot;c, &quot;B&quot;c, &quot;C&quot;c, &quot;D&quot;c, &quot;E&quot;c, 
&quot;F&quot;c, &quot;G&quot;c, &quot;H&quot;c, &quot;I&quot;c, &quot;J&quot;c, &quot;K&quot;c, &quot;L&quot;c, &quot;M&quot;c, &quot;N&quot;c, &quot;O&quot;c, &quot;P&quot;c, &quot;Q&quot;c, &quot;R&quot;c, 
&quot;S&quot;c, &quot;T&quot;c, &quot;U&quot;c, &quot;V&quot;c, &quot;W&quot;c, &quot;X&quot;c, &quot;Y&quot;c, &quot;Z&quot;c}</span></p><p><span style="font-size: small">&#160;&#160;&#160;&#160;&#160;&#160;&#160; index -= </span><span style="font-size: small; color: #800000">1</span><span style="font-size: small"> </span><span style="font-size: small; color: #339933">&#39;adjust so it matches 0-indexed array rather than 1-indexed 
column</span></p><p><span style="font-size: small; color: #0000ff">&#160;&#160;&#160;&#160;&#160;&#160;&#160; Dim</span><span style="font-size: small"> quotient 
</span><span style="font-size: small; color: #0000ff">As</span><span style="font-size: small"> </span><span style="font-size: small; color: #0000ff">Integer</span><span style="font-size: small"> = index \ </span><span style="font-size: small; color: #800000">26</span><span style="font-size: small"> </span><span style="font-size: small; color: #339933">&#39;normal / operator rounds. \ does integer division, which 
truncates</span><br /><span style="font-size: small">&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="font-size: small; color: #0000ff">If</span><span style="font-size: small"> quotient &gt; 
</span><span style="font-size: small; color: #800000">0</span><span style="font-size: small"> </span><span style="font-size: small; color: #0000ff">Then</span><br /><span style="font-size: small">&#160;&#160; &#160;&#160; &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ColumnName = 
ColumnName(quotient) &amp; chars(index </span><span style="font-size: small; color: #0000ff">Mod</span><span style="font-size: small"> </span><span style="font-size: small; color: #800000">26</span><span style="font-size: small">)</span><br /><span style="font-size: small; color: #0000ff">&#160;&#160;&#160;&#160;&#160;&#160;&#160; Else</span><br /><span style="font-size: small; color: #0000ff">&#160;&#160; &#160;&#160; &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="font-size: small">ColumnName = chars(index </span><span style="font-size: small; color: #0000ff">Mod</span><span style="font-size: small"> </span><span style="font-size: small; color: #800000">26)</span><br /><span style="font-size: small; color: #0000ff">&#160;&#160;&#160;&#160;&#160;&#160;&#160; End</span><span style="font-size: small"> 
</span><span style="font-size: small; color: #0000ff">If</span><br /><span style="font-size: small; color: #0000ff">End Function</span><span style="font-size: small"> </span><br /></p></blockquote>
<blockquote dir="ltr" style="margin-right: 0px;"><p><span><blockquote dir="ltr" style="margin-right: 0px;">

<p><span style="font-size: small">
</span><span style="font-size: small">
</span></p></blockquote><span style="font-size: small"></span></span></p></blockquote><p><span style="font-size: small; color: #0000ff"><span style="color: #000000">That still needs some basic bounds and error checking, but it works well for a quick sample.&#160; It&#39;s only 11 lines 
of code as is appears in my IDE (curse the vox formatter!) so it&#39;s pretty easy 
to follow.&#160; It should perform well too, since it would be very odd have more 
than&#160;one or two recursive calls.&#160; Now hopefully Google can index this page 
better than all those bad implementations I saw out there, but I&#39;m not holding 
my breath.</span></span>

<p dir="ltr" style="margin-right: 0px;"><span style="font-size: small; color: #0000ff"></span>&#160;</p> </p>
        
    
                <p style="clear:both;">

    <a href="http://jcoehoorn.vox.com/library/post/excel-column-names.html?_c=feed-atom-full#comments">Read and post comments</a>

 | 

    
    <a href="http://www.vox.com/share/6a00c22525ad91604a00fad690d4e60004?_c=feed-atom-full">Send to a friend</a>

</p>

                </div>
            ]]>
        </content>
    
    </entry>

    
    <entry>
        <title>Oops</title>
    
    
    
        <link rel="alternate" type="text/html" title="Oops" href="http://jcoehoorn.vox.com/library/post/oops.html?_c=feed-atom-full" />
    
        
        <link rel="service.post" type="application/atom+xml" title="Oops" href="http://jcoehoorn.vox.com/library/post/oops.html?_c=feed-atom-full#comments" />
    
        <link rel="service.edit" type="application/atom+xml" title="Oops" href="http://www.vox.com/atom/svc=post/asset_id=6a00c22525ad91604a00fad68ff2900005" /> 
                <id>tag:vox.com,2008-06-12:asset-6a00c22525ad91604a00fad68ff2900005</id>
        <published>2008-06-12T20:12:33Z</published>
        <updated>2008-06-12T20:12:33Z</updated>
    
        <author>
            <name>jcoehoorn</name>
            <uri>http://jcoehoorn.vox.com/?_c=feed-atom-full</uri>
        </author>
    
        
        <content type="html" xml:base="http://jcoehoorn.vox.com/?_c=feed-atom-full">
            <![CDATA[
                <div xmlns="http://www.w3.org/1999/xhtml" xmlns:at="http://www.sixapart.com/ns/at">
    
    
        
            
            <p>So it&#39;s been a while since my last update.&#160; In truth, I just haven&#39;t felt like writing.&#160; It never fails that the same time I put the update schedule in the title is when I finally cave- though I did make it for several months.&#160; Anyway, I do have a few topics coming, but I don&#39;t know how often I&#39;ll be updating so I took the schedule down. </p>
        
    
                <p style="clear:both;">

    <a href="http://jcoehoorn.vox.com/library/post/oops.html?_c=feed-atom-full#comments">Read and post comments</a>

 | 

    
    <a href="http://www.vox.com/share/6a00c22525ad91604a00fad68ff2900005?_c=feed-atom-full">Send to a friend</a>

</p>

                </div>
            ]]>
        </content>
    
    </entry>

    
    <entry>
        <title>Screen Scraping ASP.Net</title>
    
    
    
        <link rel="alternate" type="text/html" title="Screen Scraping ASP.Net" href="http://jcoehoorn.vox.com/library/post/screen-scraping-aspnet.html?_c=feed-atom-full" />
    
        
        <link rel="service.post" type="application/atom+xml" title="Screen Scraping ASP.Net" href="http://jcoehoorn.vox.com/library/post/screen-scraping-aspnet.html?_c=feed-atom-full#comments" />
    
        <link rel="service.edit" type="application/atom+xml" title="Screen Scraping ASP.Net" href="http://www.vox.com/atom/svc=post/asset_id=6a00c22525ad91604a00fa967556ea0003" /> 
                <id>tag:vox.com,2008-05-14:asset-6a00c22525ad91604a00fa967556ea0003</id>
        <published>2008-05-14T14:47:00Z</published>
        <updated>2008-05-14T14:47:00Z</updated>
    
        <author>
            <name>jcoehoorn</name>
            <uri>http://jcoehoorn.vox.com/?_c=feed-atom-full</uri>
        </author>
    
        
        <content type="html" xml:base="http://jcoehoorn.vox.com/?_c=feed-atom-full">
            <![CDATA[
                <div xmlns="http://www.w3.org/1999/xhtml" xmlns:at="http://www.sixapart.com/ns/at">
    
    
        
            
            <p>I consider myself to be pretty good at scraping web sites.&#160; I&#39;ve been able to get into sites others thought where impossible.&#160; I&#39;ve even made it through some pretty tricky login verification.&#160; My tool of choice to accomplish this is VB.Net and a simple class I&#39;ve written that re-implements much of System.Net.Webclient, and extends it to support a few additional functions.&#160; Unfortunately, I&#39;m not ready to release that class here yet- there are still some issues with it I want to work out first.</p><p>The real key to scraping a web site isn&#39;t the technology, anyway.&#160; Scraping a given page, once you have it,
is and always will be rather trivial.&#160; It&#39;s when you&#39;re scraping a site where you
may have to make several requests in sequence to get the server to create the page
you want that things can get tricky.&#160; With that in mind, the key to successfully scraping a web site is simply to study client source for the site until you can accurately reproduce http requests that are the same or sufficiently similar to those issued by a web browser under the command of a normal user.&#160; This may mean parsing some very nasty javascript now and then, but that&#39;s they way it works.&#160; Of course, there are tools that can help with this, but when it comes down to it you usually just need to be able to read the code.</p><p>Today I was helping someone scrape an ASP.Net site.&#160; This was my first time scraping ASP.Net, which surprised me considering it&#39;s my web platform of choice.&#160; I was also shocked to discover that ASP.Net can be unusually difficult to scrape.&#160; Perhaps in hindsight I should have known this, but it caught me unaware this morning.&#160; </p><p>You see, ASP.Net pages include a few extra things by default that must go with every request.&#160; The hidden __ViewState field, for example.&#160; The server normally does some basic validation on the application state, so just sending an empty view state may not cut it.&#160; Also, most server controls send requests using very cryptic IDs via an __doPostBack() javascript function.&#160; It&#39;s actually quite difficult to follow.&#160; More than that, since it&#39;s so easy to push the work for simple controls to the server, it&#39;s very easy to obfuscate what a particular link is really doing.&#160; So easy that you may even end up hiding things&#160;by accident.</p><p>I figure after I get a little more experience scraping these pages I&#39;ll discover there&#39;s a trick to it, and once you know the trick they may even turn out to be easier.&#160; In fact, I would expect that knowing a site uses ASP.Net would allow you to make certain assumptions about what fields you need to submit and how to submit them. </p><p>So if you have a web site and you want to protect it from scrapers, well... there&#39;s really not much you can do.&#160; Once a page is sent to a web browser a smart programmer will always be able to decipher it.&#160; But you could do worse than to choose ASP.Net.<br /></p>
        
    
                <p style="clear:both;">

    <a href="http://jcoehoorn.vox.com/library/post/screen-scraping-aspnet.html?_c=feed-atom-full#comments">Read and post comments</a>

 | 

    
    <a href="http://www.vox.com/share/6a00c22525ad91604a00fa967556ea0003?_c=feed-atom-full">Send to a friend</a>

</p>

                </div>
            ]]>
        </content>
    
    </entry>

    
    <entry>
        <title>The End is Near</title>
    
    
    
        <link rel="alternate" type="text/html" title="The End is Near" href="http://jcoehoorn.vox.com/library/post/the-end-is-near.html?_c=feed-atom-full" />
    
        
        <link rel="service.post" type="application/atom+xml" title="The End is Near" href="http://jcoehoorn.vox.com/library/post/the-end-is-near.html?_c=feed-atom-full#comments" />
    
        <link rel="service.edit" type="application/atom+xml" title="The End is Near" href="http://www.vox.com/atom/svc=post/asset_id=6a00c22525ad91604a00f48d13e0d80001" /> 
                <id>tag:vox.com,2008-05-05:asset-6a00c22525ad91604a00f48d13e0d80001</id>
        <published>2008-05-05T19:28:11Z</published>
        <updated>2008-05-05T19:34:08Z</updated>
    
        <author>
            <name>jcoehoorn</name>
            <uri>http://jcoehoorn.vox.com/?_c=feed-atom-full</uri>
        </author>
    
        
        <content type="html" xml:base="http://jcoehoorn.vox.com/?_c=feed-atom-full">
            <![CDATA[
                <div xmlns="http://www.w3.org/1999/xhtml" xmlns:at="http://www.sixapart.com/ns/at">
    
    
        
            
            <p>Get out your tinfoil hats.&#160; It turns out that a small part of Windows was <a href="http://blogs.msdn.com/oldnewthing/archive/2008/05/05/8459022.aspx">written by a machine</a>.&#160; You have to read through&#160;most of a rather boring post to see what I&#39;m talking about, and if you blink you might even miss it, but it&#39;s there.&#160; This isn&#39;t an official Microsoft&#160;statement, but it&#160;is an officially sanctioned blog of a senior Microsoft engineer.&#160; I&#39;m sensationalizing this more than a little, but I&#39;m sure there are those who will see this as a sort of slippery slope and wonder where it ends.</p>
        
    
                <p style="clear:both;">

    <a href="http://jcoehoorn.vox.com/library/post/the-end-is-near.html?_c=feed-atom-full#comments">Read and post comments</a>

 | 

    
    <a href="http://www.vox.com/share/6a00c22525ad91604a00f48d13e0d80001?_c=feed-atom-full">Send to a friend</a>

</p>

                </div>
            ]]>
        </content>
    
    </entry>

</feed>


