welcome to my blargh

now with 88.333% more desu. repeating of course.

This is what it looks like when JavaScript development goes bad.

Loading mentions Retweet

Filed under  //   javascript   programming  
Posted December 8, 2009
// 0 Comments

Lists in C# versus Java

Here's how you create and iterate over a list in C#:

Now, here's that same code in Java:

As you can see, the Java code is a bit more verbose. While C# defines its List class as a strongly typed class, Java treats its own as a very generic collection that requires you to cast elements as you access them. Also, C# does some synaptic sugar with its "foreach" statement that automatically accesses the iterator and loops through the collection.

Loading mentions Retweet

Filed under  //   c#   java   programming  
Posted December 7, 2009
// 1 Comment

Getting Some Armory Info

Just something I'm working on. More details later. ;)

Loading mentions Retweet

Filed under  //   programming   world of warcraft  
Posted October 6, 2009
// 0 Comments

Quickie: Preventing Default Link and Button Behavior with jQuery

Real simple: by calling the preventDefault() method on the event, you can stop a link from taking a user away or a button from posting back. This is a routine task for providing controls for your web app. You will use this all the time.

Going a bit further, you can put in some code to execute:

Loading mentions Retweet

Filed under  //   jquery   programming  
Posted October 6, 2009
// 0 Comments

How Much Is Too Much?: The Quality Balancing Act

Over the last few days I've been studying Lua in order to start developing some AddOn ideas for World of Warcraft. Lua is a very lightweight OO language used for embedding in other software to provide scripting and customization features.

A feature of Lua called "varargs" caught my eye. In a nutshell, it allows you to define a function with a variable number of arguments. This is similar to C# or Java, however in those languages you pass in arguments to the main method via a strongly typed array (ie String[] args). Before the "..." or varargs operator, you can pass in any number of named arguments that must be passed to the function. It looks like this:

What's this? A super loosely typed language that has the gall, the unmitigated lunacy to allow completely random and optional arguments instead of relying on that old cornerstone of OO thought, overloading? That was my initial reaction. But after a while, I started thinking about the possible reasons behind a feature like this and why it actually was a correct design. It started with my friend making the following observation.

As analytical thinkers, programmers value accuracy and perfection above all else. We are obsessed over the perfect algorithm, the perfect design. We want our software to be accurate to the hundred trillionth and have a rock solid design that will be robust yet flexible. However, in this quest for perfection, we sometimes lose sight of what's important: getting the job done. While quality is important in all things, it's equally important to meet the needs of the user.

At my previous job after a merger, we adopted PHP as the official development language after years on Classic ASP. As a .NET developer, I was aghast at some of the fast and loose liberties our new coworkers took with web development and the loosely typed features of the language. During a discussion over the merits of strong typing someone said, "Sure, strongly typing's great if you're working for Mission Control". For a while I was puzzled, didn't these folks want to make the most robust, rock solid software? Well yes, to a point. The fact that I overlooked was that web development is more about new features faster. In an e-Commerce system, it's important to be correct, but money only goes to two decimal places. What language can't do that accurately?

More recently, I worked on a small port of a URL shortener that I call Chorty. Trying to come up with a way to create a random 4 character identifier was a bit of a challenge. I wanted to make the system never run out of possible combinations ever. The computer scientist in me was taking over. Eventually though I realized two things:

1) This is not going to be the next TinyURL.
2) Knowing #1, I think nearly two million possible combinations is perfectly fine.

In fact, all one would have to do to expand the possible combinations is increase the length by a character or two. And this is extremely easy to do in the code, so problem solved. We don't like to admit to ourselves that our software will never be perfect, but that's the truth. We will always have to revisit code and sometimes good enough is perfectly OK.

In the case of Lua, the obvious intention isn't to create a rock solid language that can launch a rocket into space. The design of Lua is intended to provide a very fast, very flexible language for rapid scripting. I don't think my World of Warcraft AddOn needs accuracy to the hundred trillionth. As developers, we need to know when our software performs reasonably enough to fit the problem at hand and leave it at that.

Loading mentions Retweet

Filed under  //   programming  
Posted September 30, 2009
// 0 Comments

Anonymous types and System.Web.Mvc.JsonResult issue?

Wow, this is driving me utterly insane. Take a look at the two versions of this code:

Pretty simple right? I left out some stuff for brevity, but I have a very simple subclass defined called JsonJob into which I copy the properties from the Linq Object.

Version 2:

So, more brief. Selects data using Linq, returns an anonymous type which I push out as a JsonResult.

Technically these two should work the same way. Why does Json() care about type? But it seems that for me, anonymous types create malformed Json or something. Here's my AJAX request using jQuery:

Again, pretty simple. But if I use Version 2, the error callback is triggered every time (with no error defined!).

Of course everyone says This Doesn't Happen For Me (tm), but that's no help.

Loading mentions Retweet

Filed under  //   asp.net mvc   programming  
Posted September 25, 2009
// 1 Comment

Some daily notes on learning ASP.NET MVC

- You don't need a view for every controller action. For instance you can return a JsonResult for Ajax requests.

 
- When using jQuery to post AJAX requests, it's easiest to use $.getJSON because it automatically creates the JSON object for you. Otherwise you can use: var x = Eval(data); to get a hold of a json object.
 
- Very low need for custom routes so far, unlike other MVC frameworks I've used. The default seems to work fine for most needs.

- Data can be returned to a page two ways: Through ViewData collection (good if you have multiple sources of data), or through the Model.

 
- View Data needs to be cast to it's proper type before you use it. Makes things sort of messy.
 
- Return data to the model via 'return View(object);' in the controller. Make sure to modify the Inherit declaration at the top of the view: "System.Web.Mvc.ViewPage<List<MvcApplication1.Data.Job>>".

Loading mentions Retweet

Filed under  //   asp.net mvc   programming  
Posted September 24, 2009
// 0 Comments

How I Deploy Code

I use two (three?) tools on a daily basis to build and deploy code.

1. Robocopy
2. MSBuild
3. Windows PowerShell

Robocopy is a newer command line directory replicator available out of the box in Windows Server 2008 and up as well as Vista and up. You can get it for XP and Server 2003 as part of the Windows Resource Kit as well. Basically you point it to a directory to copy from and a directory to copy to and it will copy the entire contents of said directory. That in itself isn't enough to warrant much praise, but it also includes robust facilities for retrying copying in the case of network or disk failure.

Before developing my new build and deploy process, I would routinely use the Publish Website wizard in Visual Studio to copy my application to a local directory, then used windows explorer to copy the files to the production share. Needless to say, this is not a good way of doing things. For one, the windows explorer copy function sucks. It sucks a lot. It doesn't care what's newer or older or the status of the network or disk. If you're 1 minute away from finishing an hour long copy (not unusual for an Explorer copy) and the network goes kaput, you're screwed -- try figuring out where it left off. Robocopy will detect the problem and pause, retrying a configurable amount of times. It's also much, much, much faster than an Explorer copy due to the fact that it skips overwriting files that are older or the same age than the ones in the destination. It also seems to be written from the ground up to be faster at copying files.

I can't lavish enough praise on Robocopy. It's really a must have tool for Windows developers.

MSBuild is basically Microsoft's version of 'make' or 'ant'. It's a configurable utility to build .NET applications from the command line which can be scripted and customized. Personally I don't use a lot of the functionality, and in fact, I could probably get away with just batch scriping the csc compiler, but using MSBuild lets me set up different targets in case I want to clean or force a rebuild (I normally always just rebuild).

PowerShell is what the command line in Windows should be: a scriptable interface much like the Bash shell on Linux systems. It's not something that I can't live without, but I like it for the colored output and larger default window.

So, how do I use all three of these together? Batch scripts. Yep, the humble batch script:

This is my BuildFull script. It calls MSbuild to clean and then rebuild my entire solution, then Robocopy to copy the built web app to a deploy directory. You could even point a local instance of IIS to the deploy directory to do a final end to end test or whatever. Notice I have Robocopy set up to exclude a bunch of junk such as the subversion folders, build folders, cache files, configuration files, project files, user-specific settings, debug databases, etc. I also ignore all source code; we don't need it.

And here's my deploy script. It copies files from my local deploy directory to the production share. Since we have a load-balanced server, I then make sure both shares are up to date by copying one to the other including the Web.config file in case I manually deployed it.

A lot of people think there's some sort of mystic art to making the perfect build and deploy routine when there just isn't. Setting up scripts to handle your deployments is an absolutely necessity to keeping your sanity.

Loading mentions Retweet

Filed under  //   programming  
Posted September 21, 2009
// 0 Comments

Oh uh, you fucked up your SVN repo with a bad commit. Fix it.

So you deleted a bunch of files, or moved things around and checked in a bad revision. You need to do a "reverse merge".

1) Revert to the last known good revision.
2) Do a svn merge -r HEAD:revision#
3) Commit.

In my case, I had deleted my local copy of trunk thinking I could get a copy of the last known good revision and commit that. Won't work. I had to update, reverse merge, then commit.

The beauty of source control is that as long as you have what you need checked in, you can always find a way to fix your boo boos.

Loading mentions Retweet

Filed under  //   development   programming   svn  
Posted September 4, 2009
// 0 Comments

The most retarded IE bug ever

(seriously, who thought this was a good idea?)

Loading mentions Retweet

Filed under  //   programming  
Posted September 1, 2009
// 0 Comments