Archive

Archive for the ‘Programming’ Category

Cappuccinno

September 15, 2010 Leave a comment

I’ve been working on familiarizing myself with various JavaScript frameworks and methodologies over the past few weeks at work. I recently came across the Cappuccino framework. While I had seen this in the past, I never really tried it out. Well, last week I actually started poking around with it. 🙂

The basic idea of the framework is to provide a platform for building web-based applications. That means it’s a library nothing like jQuery where you pick and choose what elements of jQuery you want, Cappuccinno is an all-or-nothing solution.

The thing I found most interesting was that the JavaScript you write is actually written in a language they call Objective-J. At its heart, it is Objective-C for JavaScript. This is pretty compelling as in theory you could more easily port an exisiting Cocoa application for the web. In practice, this is a long ways out as there is a lot of the underlying framework missing.

I did find writing the Objective-J code very familiar as I’ve used Objective-C in the past. Is this the new way to write web apps? I don’t know… definitely needs some work to before it truly becomes a v1 product, but it has potential.

Some might cringe that it abstracts the “HTML-ness” away from the web, but I don’t necessarily think that is a bad thing.

The most interesting thing about Cappuccinno, to me at least, is there Atlas project. It’s basically Interface Builder for JavaScript, which I find very interesting. They also have tools to convert your Nib files to Cib (basically a Cappuccino Nib file) files which allow you to load up UI that way.

It’s definitely a framework you should look into if you are developing a new web-app from scratch. It obviously doesn’t have the widespread use like jQuery does, but that’s not always a bad thing.

Categories: JavaScript, Programming

HTML5 Canvas and Dashed Lines

September 7, 2010 19 comments

I’ve been spending a lot of time with HTML5’s new Canvas tag, and I have to say, I’m quite excited with it. The gratification you can get with a small set of code rendering some images is great! It’s nothing like what you need to get going in C++ and OpenGL or even XNA – pure, simple, and of course, very limited.

Canvas is currently so limited that you cannot even draw a simple dashed line! Straight lines, no problem.

This is clearly a problem that needs fixing and luckily enough, I have just a solution. 🙂

So, how might we go about adding this functionality. Quite simply! Thanks to the ability for JavaScript’s prototypical nature, and maybe more accurately, it’s dynamic nature, we can extend the functionality of the Canvas object so that we can make our new functionality look like it’s built-in.

Ok, so how do we get started? First we need to define our protype code. I’ve created a new JavaScript file called canvas.js to where we’ll put our code.

CanvasRenderingContext2D.prototype.dashedLineTo = function (from, to, pattern) {}

That adds the ‘dashedLineTo’ function to our canvas protype.

Next we need to actually implement the function. I’m not going to actually go through and explain it all, but the idea of the code is to use the pattern parameter to define the length of each dash and each space, in alternating order, for your dashed line.

CanvasRenderingContext2D.prototype.dashedLineTo = function (fromX, fromY, toX, toY, pattern) {
  // Our growth rate for our line can be one of the following:
  //   (+,+), (+,-), (-,+), (-,-)
  // Because of this, our algorithm needs to understand if the x-coord and
  // y-coord should be getting smaller or larger and properly cap the values
  // based on (x,y).
  var lt = function (a, b) { return a <= b; };
  var gt = function (a, b) { return a >= b; };
  var capmin = function (a, b) { return Math.min(a, b); };
  var capmax = function (a, b) { return Math.max(a, b); };

  var checkX = { thereYet: gt, cap: capmin };
  var checkY = { thereYet: gt, cap: capmin };

  if (fromY - toY > 0) {
    checkY.thereYet = lt;
    checkY.cap = capmax;
  }
  if (fromX - toX > 0) {
    checkX.thereYet = lt;
    checkX.cap = capmax;
  }

  this.moveTo(fromX, fromY);
  var offsetX = fromX;
  var offsetY = fromY;
  var idx = 0, dash = true;
  while (!(checkX.thereYet(offsetX, toX) && checkY.thereYet(offsetY, toY))) {
    var ang = Math.atan2(toY - fromY, toX - fromX);
    var len = pattern[idx];

    offsetX = checkX.cap(toX, offsetX + (Math.cos(ang) * len));
    offsetY = checkY.cap(toY, offsetY + (Math.sin(ang) * len));

    if (dash) this.lineTo(offsetX, offsetY);
    else this.moveTo(offsetX, offsetY);

    idx = (idx + 1) % pattern.length;
    dash = !dash;
  }
};

To use this code, just include your new canvas.js script file in your .html file in a script tag, and voila!

  <script type="text/javascript" src="canvas.js"><script>

If you know of a better way to do this, be sure to let me know!

Update: So, maybe I should have tested that version. 🙂 Updated the code to actually work and not rely on some other pieces of a library I’m working on.

Categories: HTML5, JavaScript, Programming

.NET Framework 4 Beta 2 Install Errors?

October 19, 2009 Leave a comment

If you’re like me and you run both Windows and OS X, you might find yourself in a odd predicament if you try to install Visual Studio 2010 Beta 2 – it may not install!!!

It turns out there is a fairly ridiculous bug in the .NET Framework 4 Beta 2 setup. The basics is that it tries to find a drive to extract out the setup file (why the current drive isn’t good enough is beyond me) and extract out the files there… well, on my setup with Bootcamp that gives me a 160GB partition with OS X and an 80GB partition for Windows. Well, the setup finds the E drive (I have Snow Leopard so I can read HFS drives in Windows) which is my OS X drive and the drive with the most free disk space. Next it tries to extract itself out to it but fails as the HFS partition is read-only.

The workaround is fairly easy to do and the bug should be fixed by the time RTM comes. To fix it, simply remove the drive letter mapping from your OS X drive in Windows, install the .NET Framework 4 Beta 2, and then add the drive letter back to your OS X partition.

After that, all should be happy. 🙂

Categories: Programming

Clang!

September 6, 2009 Leave a comment

If you haven’t read the Ars Technica review of Snow Leopard yet, you should do it!! It’s got a great break-down of the new features and even talks about the changes to the development environment. After seeing the breakdown of the new compiler shipped (Clang LLVM) with Snow Leopard, I fired up Xcode 3.2 and opened up my Plexer source code.

Build and Analyze… waiting, 17 issues!!! Oops!

Here’s a quick shot of one of the issues that it found:

Clang at Work

So I’m sure all of you seasoned Objective-C programmers are laughing out there at me right now, but what can I say, I’m still learning this whole retain-count memory management. 🙂

Needless to say, I was astounded that the compiler was able to figure this out for me. This will obviously be extremely handy for all of those new Objective-C programmers (and even veteran) that forget to release that memory when you’re done with it.

Clang is able to find other types of issues as well, like coding standards violations. For instance, I had a message named withName:(NSString*) and Clang realized that I was returning an instance and control of the memory and that my message name didn’t start with ‘copy’, ‘new’ or ‘alloc’.

Overall, I was actually quite impressed at what Clang was able to do. So yeah, if you have Snow Leopard and you’re a developer, you should definitely switch your projects to use the Clang compiler (unless your projects are C++, Clang doesn’t currently support that language).

For more Clang information, check it out here: http://clang.llvm.org/.

Busy Little Bee

I know, I know… it’s been a while. At least I can say that I’ve been working on some stuff though! 🙂

As some of you know, I stopped work on the Macurial project as the more I got into it, the more I started thinking that this may be a conflict of interest as my company produces tools for source control and I even work in the developer division. Maybe I should have realized this earlier… oh well.

Never fear though, I’ve been hard at work on another project though. Read more…

Haskell and Functional Programming

March 28, 2009 5 comments

So for some reason I’ve decided to dive into functional programming as I never really learned much about it other than scratching the surface at college with Lisp. I’ve started off with Haskell and have been going through the book Real World Haskell. It’s a decent book, but the best part is the online version is free. =)

Initially there were some cool things, like pattern matching for methods, but I’m starting to lose interest… I’m having a real issue wrapping my head around the real world benefits of using Haskell (or any functional language). I mean, the syntax of the language is nice, some of the concepts are interesting, but I don’t know, maybe I’m missing something.

Side note: I originally picked Haskell because I knew it ran fine on both Windows and OS X. However, I just did some research and found out that F# works with Mono on OS X, so I might see about testing the waters over there.

Well… off to check out an F# presentation to see if it can convince me. 😉 http://channel9.msdn.com/pdc2008/TL11/

Categories: Programming

Silverlight 3

March 21, 2009 6 comments

The beta of Silverlight 3 is out (http://silverlight.net/getstarted/silverlight3/default.aspx), and I have to say, I’m fairly impressed by what is in there. My favorite feature is the OOB (Out of Browser) capabilities that are built-in. Sure, this is essentially a click-once implementation on steriods, but that fact that it works on both Windows and OS X makes be happy (for those that don’t know, I use OS X a lot at home).

I’ve been working and planning a cross-platform app for a good amount of time now. I have prototypes of various pieces of the application, but in order to truly be cross-platform I’ve had to use C++ and OpenGL (yeah, there are other options, but this is one of the easier for me). I don’t really want my app to be a web-application, however, SL 3 is making me re-consider a lot about the project.

Now one of the requirements of my project is to be able to rendering large numbers of 3D models on screen… this is one of the possible deal breakers for me. SL 3 still doesn’t “support” 3D, but all that really means is that I need to write the library or make use of existing ones like Kit3D (which I’d love to check-out, but codeplex.com is down and has been down for the whole day, COME ON MICROSOFT!).

Another possible showstopper is the lack of local file system access. One of the limitations of the OOB is that you get an isolated storage area under the web context. This is possibly the most crucial piece. I have been thinking of ways around it though, network storage is a possibility (haven’t validated it is actually supported in SL 3 yet) and might actually be an interesting workflow with the project.

Well… that’s all for now. If you haven’t checked out SL 3 yet, go check it out. It’s looking pretty sweet. 🙂

(fine print: I work at Microsoft and I also work on products to build Silverlight apps.)

Categories: Programming