blog.vorpal.cc

Hi! My name is David Hogue. I write code in Bend, Oregon.

November 1, 2007

Points to consider when evaluating a JavaScript framework

Filed under: — David @ 4:13 pm

I found How to choose a JavaScript framework » d’bug (via Ajaxian). In it the author brings up several things to consider when evaluating a framework.

It’s somewhat related to my earlier post on looking for a comparison of JavaScript frameworks, and his was posted just a day before mine.

It’s not the comparison table I was looking for, but if I ever get around to making that table I’ll certainly use some of the points mentioned in it. I think most of the article could apply to any framework developer tool, not just JavaScript frameworks.

JavaScript syntax hightlighters

Filed under: — David @ 11:34 am

I found some really cool code editors and syntax hightlighters written in JavaScript and I thought I’d share.

The best I’ve found so far is CodePress. It supports many languages, hightlights as you type, adds line numbers, and seems the most reliable.

CodeMirror is another one I found. While it isn’t as polished as CodePress, he describes how he went about creating it which I found helpful and interesting (especially the bit about the maniacal gnome.)

EditArea is another impressive one, but I haven’t looked into it too much.

CodeArea 2 has an example editing html, but I can’t read any of the text around it since it is not written in English. It’s a .cz domain, the Czech Republic, where the speak Czech apparently.

Also, while looking for editors, I stumbled across a vi clone in JavaScript. It is impressively complete. It’s almost as cool as DHTML Lemmings.

Edit 11/2/07 1:33PM: removed funky font tags.

October 31, 2007

So many JavaScript libraries!

Filed under: — David @ 5:22 pm

Just looking around for some JavaScript libraries to use in some new code, I came up with all these libraries:

  1. Prototype
  2. jQuery
  3. MochiKit
  4. MooTools
  5. script.aculo.us
  6. Dojo
  7. Ext JS
  8. ASP.NET AJAX Control Toolkit
  9. The Yahoo! User Interface Library (YUI)
  10. SimpleJS

I haven’t been able to find a decent comparison of the different frameworks (what they do, compatibility, download size). I might come up with my own table soon if I can’t find anything.

I have used the ASP.NET AJAX Control Toolkit1, YUI, and Prototype so far. I think those three are compatible, but I’m not sure. (What I should say is nothing has broken from using the three libraries in a single app.)

Does anyone out there have any good comparisons between all the major libraries?

  1. ASP.NET AJAX Control Toolkit with ASP.NET AJAX are two different things btw. I’ve just been calling the whole thing msajax just because the naming is so ambigous

October 17, 2007

Trying to disprove some .net string memory usage myths

Filed under: — David @ 12:39 pm

I’ve run into a few string/constants myths repeatedly and I thought I’d try to disprove them. Myth 1: constants use less memory. Myth 2: inline strings are always bad. Myth 3: String.Empty doesn’t create an object while “” does.

I’m just running a bunch of different pieces of code and dumping memory statistics before and after to measure. The trimmed output of sos’s !dumpheap -stat command are included after each line.

Thanks to Pale Musings for the sos memory leaks article.

Contents

Steps to reproduce:

  1. Create console app.
  2. Go to project properties, enable unmanaged debugging.
  3. In main add (changing the first line each time)
  4. string value = "span";
    Console.WriteLine(value);
    Console.ReadKey(true);

  5. Put breakpoints on lines 1 and 2.
  6. Run app with debugger (F5).
  7. In the immediate window type .load sos
  8. In the immediate window type !dumpheap -stat
  9. Run to next breakpoint (F5).
  10. In the immediate window type !dumpheap -stat
  11. Compare output from dumpheap.
  12. Change line 1 and repeat.

Simple inline string

code: string value = "span";

before:

      MT    Count    TotalSize Class Name
...
790f9244     2038       129792 System.String
Total 2085 objects

after:

      MT    Count    TotalSize Class Name
...
790f9244     2038       129792 System.String
Total 2085 objects

Enum to lower case string

code: string value = HtmlTextWriterTag.Span.ToString().ToLower();

before:

      MT    Count    TotalSize Class Name
...
790f9244     4825       264628 System.String
Total 4875 objects

after:

 Count    TotalSize Class Name
...
790f9244     4932       267760 System.String
Total 5177 objects

Second enum to string

I thought the above might be unfair. Maybe I was counting memory usage from loading the System.Web assembly or the HtmlTextWriterTag for the first time.

code: span.ToString().ToLower();

before:

      MT    Count    TotalSize Class Name
...
790f9244     4825       264628 System.String
Total 4875 objects

after:

      MT    Count    TotalSize Class Name
790f9244     4932       267760 System.String
Total 5177 objects

Constant defined in the same class

code: string value = span; (span is a constant of the class)

before:

      MT    Count    TotalSize Class Name
...
790f9244     2038       129792 System.String
Total 2085 objects

after:

      MT    Count    TotalSize Class Name
...
790f9244     2038       129792 System.String
Total 2085 objects

Using the same string repeatedly inline

code: string value = "span";
string value2 = "span";
string value3 = "span";
string value4 = "span";
string value5 = "span";

before:

      MT    Count    TotalSize Class Name
...
790f9244     2038       129792 System.String
Total 2085 objects

after:

      MT    Count    TotalSize Class Name
...
790f9244     2038       129792 System.String
Total 2085 objects

Two different inline strings

code: string value = "span a";
string value2 = "span b";

before:

      MT    Count    TotalSize Class Name
...
790f9244     2039       129828 System.String
Total 2086 objects

after:

      MT    Count    TotalSize Class Name
...
790f9244     2039       129828 System.String
Total 2086 objects

Appending constants with +

code: string value = span + a;
string value2 = span + b;
(span, a, b are constants)

before:

      MT    Count    TotalSize Class Name
...
790f9244     2039       129828 System.String
Total 2086 objects

after:

      MT    Count    TotalSize Class Name
...
790f9244     2039       129828 System.String
Total 2086 objects

Quote quote (“”)

code: string value = "";

before:

      MT    Count    TotalSize Class Name

790f9244     2038       129784 System.String
Total 2085 objects

after:

      MT    Count    TotalSize Class Name
...
790f9244     2038       129784 System.String
Total 2085 objects

String.Empty

code: string value = String.Empty

before:

      MT    Count    TotalSize Class Name
...
790f9244     2037       129764 System.String
Total 2082 objects

after:

      MT    Count    TotalSize Class Name
...
790f9244     2037       129764 System.String
Total 2082 objects

Conclusion

So: using inline strings is no better than constants as far as memory or performance are concerned. Enums are worse than constants or inline. String.Empty did save me one object instance and a whole 20 bytes.

For readability and maintainability, constants can help. Personally I find code where everything is a constant even if it is only used once annoying, but that’s just me :)

There’s probably other pages on the net that go into exactly why this all is. At the moment I’m too lazy to go searching for them. Go ahead and open the code in reflector to see what it’s getting compiled to if you want.

The actual difference in any of these is probably so small you’ll never notice it, so go with whatever is easiest and most readable for you.

October 16, 2007

Was looking for some cell phone apps, found a web browser instead.

Filed under: — David @ 10:42 pm

A while ago I was looking for an application that would run on my phone that I could could use to connect to this blog. I wasn’t planning on using it much, but I thought it’d be useful for jotting down notes for later. I thought there ought to be a few that could connect to a blogging api. I even found a few that claimed to, but I never got them to work.

You know what I found? My phone’s web browser. I finally realized that I could just connect with the browser and have all the same features available as if I were at my desk. I don’t know why it took me so long to realize that, but it did.

And then, just today: I wanted to check the temperature before going out. “There must be a ton of weather apps out there” I thought. I started searching for one. And then I realized something. I could just type 97701 temp into Google and it would give me exacty what I wanted.

Anyway, I’ve just come to realize how I can do most anything online with nothing more than a web browser. Nothing revolutionary, just an observation.

By the way I wrote and posted this entire post from my phone’s browser, just because I can.

October 15, 2007

I Just Fixed an Odd Timeout Error With Our CruiseControl.net/NAnt/WatiN Setup

Filed under: — David @ 12:32 pm

The problem:

I have this project I’m working on that uses WatiN 1 to test an asp.net site. For some reason some tests would fail with a timeout trying to find an element or waiting for an element to show up after an UpdatePanel postback. It would go through about half the test before stopping, it was able to open the browser, click buttons, type text, etc.

I couldn’t figure it out. I ran the tests from the command line with NAnt, but they all worked then. They all worked when I ran them from localhost. I put [Ignore] attributes on most of the tests, I used MSE 2 looking for deadlocks. I couldn’t figure it out for the longest time.

The Solution:

Finally I went to Windows Update on the build server. I thought maybe my workstation has some patch that is not on the server yet. When I got there it told me that due to being on the internet zone, instead of the trusted zone, it couldn’t do it’s stuff. This got me thinking an eventually I went to the url the tests were hitting and that wasn’t in a trusted zone either.

Adding the urls to the local intranet zone fixed all my problems. I’m not sure if the security was restricting WatiN or the msajax library. I’d suspect the ajax stuff just because it seems like WatiN isn’t going to be restricted by IE’s security features.

  1. WatiN is a tool to write tests for web applications by controlling an Internet Explorer window.
  2. MSE: Managed Stack Explorer. It will connect to a .net process and give a stack trace of where it is currently.

« Previous PageNext Page »