Sergio and the sigil

Partial list of sessions for Chicago Code Camp

Posted by Sergio on 2009-04-19

We're happy to announce the first partial list of talks selected for the Chicago Code Camp. We hope there's a good mix of various different technologies and that it could spark even more interest in the event.

There are still a good number of time slots undecided for this event. If you want to submit a talk, you can do that until Saturday the 25th of April. The event will be on May 30th.

AuthorTitleAbstract
Curtis Mitchel Rails-like development using ASP.NET This is a discussion about .NET tools geared towards making your development life easier in ASP.NET. We will discuss and compare these tools with the default Rails technology stack.
Dean Wampler Better Ruby through Functional Programming Functional Programming (FP) has become popular as the most robust way to write concurrent applications. Functional ideas improve code in other ways, like reducing coupling between "elements" and eliminating some "surprises" that occur when objects are mutable. We'll discuss the key ideas in functional programming and the functional features that Ruby already supports. We'll describe how best to use these features and how to work around the missing functional features.
Your will learn:
1) What is Functional Programming (FP)?
2) How FP addresses several programming challenges faced today, like concurrency.
3) How FP improves the overall robustness of Ruby code.
4) Ruby's support for FP: what's supported and what isn't.
5) Practical tips for applying FP ideas in your Ruby code
Derik Whittaker Guarding your code with Code Contracts It is a common practice to put checks into our code to help ensure quality. Historically these checks have come in the form of if/then statements where you were attempting to guard against data out of range data. Although the if/then method works reasonably well, it only solves half our problem. These checks guard against only data coming into a method, not the data coming out of a method. Fortunately for us, there is a project coming out of Microsoft, named Code Contracts, which will help to solve this problem. Code Contracts provides a language-agnostic way to express coding assumptions in .NET programs. In this session we will take a look at how you can utilize Code Contracts within your codebase to take your code quality to the next level.
Eric Smith TDD for the iPhone Currently, the iPhone is the hottest platform for mobile development, with everyone wanting to develop on it. Test Driven Development is a proven technique for developing high-quality software, but isn’t encouraged by the iPhone development platform. Open Source developers have stepped in, creating Unit Test Libraries for the iPhone. We’ll show you how to get started, run your first tests, put tests in your build, and touch on advanced techniques like mock objects and dependency injection. Perfect for the Agile Developer looking to get started on iPhone.
After a brief introduction Eric and I will perform a code “Kata” on the iPhone, writing Conway’s Game of Life. Afterwards we will tell the story of the how the application was built with some code snippets, explaining the steps along the way so they can be repeated by the attendees. Finally this presentation ends with a demo, and a victory lap.

Learning outcomes

  • Setting up Unit Tests on Mac
  • Writing Unit Tests
  • Getting tests in your build
  • Making mocks and using protocols
  • Injecting dependencies into your application at the last minute.
Jim Suchy iPhone on Rails You don't have to use Objective-C and Xcode in order to build a killer application for the iPhone. With the full-featured Safari browser, building web applications that act like a native iPhone application is not only possible, but it can be easy to do. We will take a sample Rails application and make it sparkle on the iPhone.
Jim Suchy TDD and JavaScript JavaScript has earned a special, dark place in most programmer’s hearts as it is a necessary evil for making the web experience dynamic. You are test-driving your JavaScript, aren’t you? If not, why not? If the reason is that you don’t know how, or haven’t taken the time to learn the various testing frameworks, then this session is for you. We will explore the various testing frameworks and test-drive a small bit of functionality using the presenter’s favorite.
Len Smith Get rolling with NHibernate All the cool kids are using NHibernate. Come find out what all the buzz is about. We'll see how NHibernate can make your domain model beautiful, your application perform better and facilitate Rapid Application Development.
Len Smith jQuery Magic jQuery makes working with the DOM, AJAX and events easy, fun and magical. We'll get started with an overview of jQuery and examples of integrating jQuery into existing applications in both ASP.NET and ASP.NET MVC.
Micah Martin Ruby Kata and Sparring All respectable software craftsmen make efforts to keep their coding claws sharp. And solely working 9-5 on business applications will dull one's whit. In this session we will broaden your coding horizons with some Ruby Kata and test your skills will some Ruby Sparring.
With Ruby Kata we will code known solutions to simple problems all the while being mindful of our steps and striving to write code of the best possible form.
Ruby Sparring will put your skills up against your peers. Exercises will be presented and your solutions will be compete against those of other participants. The challenge may be to solve a problem in the fewest lines of code, or to build a warrior program that will fight with others in Core Wars fashion.
Michael Hall Introduction to AOP with PostSharp Starting with an example of how things are done using normal techniques. Then install PostSharp and then step by step refactor to using Aspects to replace things like logging, validation, security and/or transactions. Finally give a brief history of the PostSharp product and references to more info and alternative toolsets.
Narayanan Kulasekar "Tools to build an effective Extract, Transform and Load (ETL) process" The biggest and most complex aspect of a data warehouse project is to gain understanding of data in all the source systems that you are dealing with. The next thing is coming up with an auditable and repeatable Extract, Transform and Load (ETL) process to bring all the data from your source systems into the data warehouse. Various studies have identified ETL to consume about 80% of a total data warehouse project effort. This presentation will talk about some of the best practices and scripting techniques that can be handy in making your data warehouse development less painful and more methodical.”
Perry Hertler TDD in the Real World This is an in depth TDD presentation that involves a lot of real-time coding.
The session will start with a high level overview of TDD then move to an example that involves TDDing a design and implementation of a simple story. The presentation will then cover some TDD tips, benefits, weaknesses, and finally compare TDD to TAD (test after development).
The coding part of this presentation can be done in either Java or C#. If it is decided that the presentation would be of use to Code Camp, please respond with a language preference.
Scott Seely Introduction to Google App Engine (GAE) It provides services to handle web requests, store data, and cache values across the server farm. The platform language of choice is Python. It supports several web libraries, including the very popular Django. In this talk, we will build a photo storage application that takes advantage of the caching, data storage, and the web platform features in GAE.
Sean Blanton Trends in Continuous Integration and Software Delivery You have all this great code, but how do you get it out to the real world with some degree of quality? Developers are relying on increasingly sophisticated infrastructure for build, test and delivery automation.Sean will present the latest on Subversion, CVS, Git and commercial file control tools, and how build and workflow automation speed application delivery and align with Agile development. Other topics to be presented are: distributed development, shared library management, scaling development and delivery processes to larger organizations, and the concept of software resiliency.
Tim Barcz Regular Expressions for the .NET Developer Many developers suck at Regular Expressions, don't be one of them. You will leave this session with a better understanding of regular expressions, from how to read them to how to write them effectively. Never again will RegEx stand in your way.

The Code Camp will be a great event. If you haven't registered yet, what are you waiting for?

RSVP

Language Envy - Juicy, a simple webserver

Posted by Sergio on 2009-04-13

Many times when I'm writing JavaScript code with Ajax calls I don't have an URL to call and get the data yet. Or sometimes I have an URL that gives me valid data and I need to test the code against invalid data or some other variation that I don't have handy.

WEBrick

In these situations, instead of creating a temporary ASP.NET application, I learned to love using Ruby and the adorable simplicity of WEBrick. Imagine that I needed an URL that simulated latency on the server.

require 'webrick'
include WEBrick

server = HTTPServer.new( :Port => 2000 )

server.mount_proc("/getData"){|req, res|
  res.body = "{result: 'ok', accountId: 123}"
  res['Content-Type'] = "application/json"
  delay = req.query['delay'] || "0"
  sleep(delay.to_i)
}

trap("INT"){ server.shutdown }
server.start

After running the script I can open use the URL http://localhost:2000/getData?delay=5 in my Ajax call and, after a delay of five seconds, the JSON string {result: 'ok', accountId: 123} will be returned. The server will stay there, in a console window, running until I kill it with CTRL+C.

I could add more mount points on that server for as many test URLs as I wish. I find this incredibly practical.

I wish there was something as simple in .NET

Well, I couldn't find anything as easy in .NET. The few offerings I found were not as straight forward. Some of the alternatives are distributed in .msi files, which makes them less convenient, especially for integration testing or JavaScript unit testing (which is my end goal.)

Hello Juicy

Envy sometimes makes you move forward. I played around with sockets and the HTTP protocol and ended up with a library that looks promising. See that same code written using the Juicy.DirtCheapDaemons.Http.HttpServer class, a.k.a. the Juicy Web Server.

using System;
using System.IO;
using System.Threading;
using Juicy.DirtCheapDaemons.Http;

  class Program
  {
    static void Main(string[] args)
    {
      HttpServer server = new HttpServer{ PortNumber = 2000 };
      server.Start();

      server.Mount("/getData", 
        (req, resp) =>
          {
            resp.Output.Write("{result: 'ok', accountId: 123}");
            resp["Content-Type"] = "application/json";
            var delay = int.Parse(req.QueryString["delay"] ?? "0");
            Thread.Sleep(1000 * delay);
          }
      );

      Console.WriteLine("Press enter to stop server");
      Console.ReadLine();
      server.Shutdown();
    }
  }

There are a few things more that can be done with HttpServer.

//mounting virtual path with a lambda (shown in previous example)
server.Mount("/virtual/path", (req, resp) => DoSomethingWith(req, resp));

//mounting virtual path to serve static files
server.Mount("/virtual/path", @"c:\some\directory");

//hiding a virtual path
server.Mount("/virtual/path/subdir", new ResourceNotFoundHandler());

As it is, HttpServer supports only GET requests. The plan is to add more support (for features that make sense in a unit testing scenario) with time.

I obviously don't envision Juicy becoming a full-fledged web server that I can recommend using in a live web site. But I can see it being helpful in the scenarios I've just described and for testing in general.

I'm sold. Where can I get it?

This project is hosted at GitHub: http://github.com/sergiopereira/juicy/tree/master, where you can download the source directly or even clone the repository :

c:\projects>git clone git://github.com/sergiopereira/juicy.git

Blocked .js files keep biting me

Posted by Sergio on 2009-04-03

This is a tip for those working with JavaScript (and possibly other types of files) that is freely available for download. For the nth time in the last few months I spent an unnecessary amount of time trying to find a problem in my code that wasn't really there.

Windows keeps track of the files you save to your hard disk which came from the Internet. Maybe you have seen this problem when you try to open a CHM file that you downloaded and see that it opens to a blank page. The same type of thing happens with JavaScript files that you download. Let's see what happened to me today.

First I downloaded the latest version of QUnit and saved to my application's directory. I did this the usual way, as shown in the image below.

Then I proceeded to use the downloaded testrunner.js file in my HTML page, via a <script src="testrunner.js"></script> tag. When I tried to open my HTML page, I was not expecting to see the particular error shown below.

I started to look for common problems: Did I save the file in the right place? Did I spell its name right? Did I mispell the function name? Did I miss a dependency? No, no, no, and no. All looked good.

That's when I remembered that the file might have been flagged by Windows. I opened its properties dialog and, sure enough, there it was, the infuriating Unblock button.

Ah, that's easy. I just clicked it and refreshed my page. Wah-wah! Problem persists. I tried typing the .js url in the address bar and saw this 401 error message from IIS, not 404.

That told me that there was still something messed up with file access. I checked the file's permissions, comparing to an older .js file in the application. The new one did not grant access to local users, so I added Read access to local users.

Now it works. Depending on how your IIS and/or ASP.NET security is configured, you may not need this last step (e.g. if the process identity already has admin rights, in which case I salute you, brave friend.) The system at hand was a Win2008-x64 installation with the default IIS/ASP.NET settings.

This problem seems to happen to me every other week and I still did not develop the reflex to take care of it right when I download the file. On the other hand, I'm getting better at remembering about it when I see stuff like "function not defined" in an error message.

JavaScript: Avoid the Evil eval

Posted by Sergio on 2009-03-31
This post is part of a series called JavaScript Demystified.

I'm pretty sure by now you have heard at least once that eval is evil. Some nuggets from Eric Lippert's post:

if you are considering using eval then there is probably a better way
People, eval starts a compiler.

I'm also pretty sure I don't need to tell you that anytime you have an explicit eval() in your code, there's a good chance it's there because you're not taking JavaScript seriously yet.

//mandatory square brackets notation example
//------------------------------------------
var myObject = new MyObject();
var prop1 = eval( 'myObject.' + somePropertyName ); // BAD!
var prop2 = myObject[ somePropertyName ]; // Better

That's not the end of all eval()

At this point some people might be feeling relieved: "Phew! That was easier than it sounded. Getting rid of eval is a piece of cake." Well, I'm not going to say it's significantly harder than that, but we're not done prunning eval() from our code just yet.

You see, eval() is like that coward opponent that sneaks in the dark to attack you from behind. Let's find some of eval's favorite hiding places.

There's a time when you need a timer

Two very popular JavaScript functions used to create timers are setTimeout() and setInterval(). Here's how you still find code being written to use them.

function doSomething(someValue){
	//...
}

setTimeout("doSomething('3 seconds elapsed. Time is up.');", 3000);

As it turns out, this is just another occurrence of eval() revealing how incompetent we can still be in this programming language. Here's a better way to write that code.

setTimeout( function(){ 
                doSomething('3 seconds elapsed. Time is up.');
            }, 
            3000);

Thank God I didn't know functions had constructors

The other secret place that eval() likes to hang out is in the Function constructor. Fortunately this isn't exactly a popular way of creating functions. I'll say it: I didn't even know about this constructor until less than a couple of years ago.

So, in case you don't know what I'm talking about here, I'll show you how to use the function constructor just to imemdiately tell you to not do it.

var sum = new Function('op1', 'op2', 'return op1 + op2;');
var result = sum(10, 20); // ==> 30

The above code is roughly equivalent to the explicit eval() usage below.

eval("var sum = function (op1, op2) { return op1 + op2; }");
var result = sum(10, 20); // ==> 30

We don't come up with the need to use the function constructor often, but I'll admit that when we do, it's usually hard to replace it with another way that doesn't use eval().

Minor update: I was doing some snooping around with Firebug and Reflector and found that WebUIValidation.js (embedded in System.Web.dll) does use eval() in some ways that I just pointed out to be unnecessary. If that is of any comfort to anyone that has done the same in the past, there you have probably the largest deployment of misused eval() I know of.

Talk - JavaScript at Rockford .NET

Posted by Sergio on 2009-03-18

Next Tuesday, March 24th I'll give a JavaScript talk at the Rockford .NET user group.

This talk will be basically the same one I gave for the LCNUG back in December.

The few opportunities I had to give this talk were highly rewarding. It's priceless to see developers realizing how mistakenly they had been using JavaScript, and finally being able to understand why "that bug" was happening in their pages.

So, if you live in the area and think there must be something about JavaScript that you're just not getting, please try to stop by and ask your questions.

JavaScript - Beyond the Curly Braces

One of the greatest problems with JavaScript is its superficial syntax resemblance of C-style languages. We call it the curse of the curly braces.

That is also a very large source of frustration for developers trying to learn JavaScript beyond the basics. Thinking that JavaScript is somehow related to Java or even "It's almost like C# but a little simpler" is an unfortunate and common occurrence that can only lead to trouble.

In this session we will analyze some of the fundamental differences between JavaScript and C#/Java. We will highlight the pitfalls that can trap us and the appropriate workarounds for them.

Time permitting and if there's interest we will take a look at Idiomatic JavaScript, which will help us understand how JavaScript is being written these days. Learning about this will also help you when trying to read the source code or even the documentation and samples for popular JavaScript libraries like jQuery, Prototype, YUI, etc.