Lazycoder

23May/085

Modern JavaScript Development: Reflection in JavaScrpt

Sometimes you want to find out what members an object exposes. There's a pretty simple way to do this. A simple for-in statement.

CODE:
  1. for(var member in obj){ alert(member); };

No really, that's it. No "imports" or "using" statments. No complicated classes to memorize, no unwrapping or casting. Just for-in over an object. One caveat, this will show you ALL of the objects members and it doesn't distinguish between members declared directly on the objects and members inherited through the objects prototype. What if you just want to find the methods on an object? I've created two helper functions that will return just the methods(functions) of any JavaScript object.

CODE:
  1. Object.prototype.getAllMethods = function(){
  2. var memberArray = new Array();
  3. for (var method in this) {
  4. if (typeof this[method] == 'function') {
  5. memberArray.push(method);
  6. };
  7. };
  8. return memberArray;
  9. };
  10.  
  11. Object.prototype.getOwnMethods = function(){
  12. var memberArray = new Array();
  13. for (var method in this) {
  14. if (typeof this[method] == 'function' && this.hasOwnProperty(method)) {
  15. memberArray.push(method);
  16. };
  17. };
  18. return memberArray;
  19. };

In the getOwnMethods function we use the hasOwnProperty function to discriminate between methods declared in the object and methods inherited through the prototype.

21May/083

Technology Round Table Podcast – “Hello World” Edition

Technology Round Table Podcast - "Hello World" Edition - Jon Galloway: ""

We've let the cat out of the bag! Our first podcast is up. I had a lot of fun recording it. When Jon proposed the idea, I thought it was a great idea. I love the geek dinners/lagers/get togethers where we just let the conversation flow. That's kind of the feel I wanted our podcast to have. I never realized just how much we rely on visual cues during a conversation to tell when it's our turn to speak. We're working out a system to keep us from talking over one another.

One thing I did notice when I listened to the podcast. At one point, it almost sounds like I'm asking Rob Conery to justify his job at Microsoft. That's the furthest thing from my mind. Rob is doing a great job on the MVC team and his MVC Storefront screencasts are mandatory watching if you plan on using the ASP.NET MVC framework or are just trying to get your feet wet with Test Driven Development. I've never had the pleasure of meeting Rob, but I've heard he's a super groovy guy.

Assuming there is a lot of interest in this, we hope to set up a site, blog, action figures, etc... So go have a listen and leave a comment somewhere we can find it.
Edit: Here's a Direct Link to the Podcast
20May2008 - SP1 - Twitter - ORM - Ninject.mp3

P.S. Honestly Microsoft, an IFrame to embed SkyDrive content? What is this, 1999? Party over, oops, out of time.

Filed under: General 3 Comments
20May/083

Twitter’s down

So I'm starting to look at alternatives to Twitter. Right now, I'm looking at FriendFeed. It has the same Friend/Follower model that Twitter does. It integrates with a lot of other services. But can it handle the load? It's being developed by some ex-Googlers who worked on GMail, GMaps and Oracle.

Eric over at Internet Duct Tape has put together some great Greasemonkey scripts that make working with FriendFeed a little easier.

So how would this work. Well, if you have a blog, you just set it up in FriendFeed. You can also post messages directly in FriendFeed. If you already have a Pownce or Jaiku account, you can add those into your profile and post to them as you normally would.

The one thing I think FriendFeed is missing right now is a way to directly message one of your friends/followers. You can reply to messages they've posted, but you can't really initiate a conversation with anyone.

List of FriendFeed clients:
Twhirl - Recently added support for FriendFeed.
Alert Thingy - Best name ever for a desktop notification application.
MySocial247
Feedalizer

Filed under: General 3 Comments
20May/085

Why can’t you declare a static method in an interface?

I've stated on Twitter a couple of times that I'd like to be able to declare static methods as part of my interface. My reasoning is: If an interface defines a contract in my code, why can't a static method be part of that contract?

CODE:
  1. public interface ITryStatic {
  2.     static void Foo();
  3.     void Bar();
  4. }

I found a great answer over in this forum.

In both Java and .NET, classes can only inherit from one class but a class can implement multiple interfaces. So consider the following code.

CODE:
  1. public interface ITryStatic {
  2.     static void Foo();
  3. }
  4.  
  5. public interface ITryAnotherStatic {
  6.     static void Foo();
  7. }
  8.  
  9.  
  10. public class Whoops : ITryStatic, ITryAnotherStatic {
  11.     public static void Foo() { printline("Foo"); }
  12. }
  13.  
  14. ITryStatic staticWhoops;
  15. staticWhoops.Foo(); //which one does it try? It doesn't matter since there's no code to run.
  16. ((Whoops)staticWhoops).Foo(); //Sure, but it defeats the purpose of using an interface.

Essentially the answer is: The compiler tries to run the code specified by the static method in a class. Since an interface doesn't provide an implementation details, there is nothing to run. You could, if the compiler would let you, cast the interface to the concrete type that's actually being represented. But that defeats the purpose of declaring an using an interface.

I do wonder if type inference could be used to route around this problem?

15May/084

RIAs are a platform play, AIR is a platform of standards

RIA == platform play

Neal Ford has a great post here highlighting how the new enthusiasm for Rich Internet Applications is an attempt by the big vendors to capture the kind of platform marketshare that the Win32 API had back in the 90's.

Which brings us around to the current hotness, Rich Internet Applications (RIA). Ever wonder why Adobe and Microsoft are slugging it out for that space? And Sun is running along behind with JavaFX saying "Wait, we want to fight too!". It's the new platform play. We've dealt with the pain of writing good looking web applications so long that when someone comes along and shows pretty pixels, we swoon. Yes, you can create beautiful applications using Silverlight and Flex. And Sun showed some awesome demos of JavaFX at JavaOne. But, if you write an application in one of those tools, you've bought a platform. You are no longer in a standards space. You can't take a Silverlight application and port it to Flex without a rewrite. Same goes with JavaFX. Whoever wins the RIA war has the new dominant web platform, just like Win32 back in the day. Sounds like a good reason for big companies to pour resources into the effort.

Bringing up that Web-based applications are standards based highlights the unique position that Adobe has with it's AIR platform. You can use FLEX/Flash to create your RIA in AIR, but you can also use web standards markup and script to create an RIA. But even if you use Flex, the compiler and SDK are available under the Mozilla Public License. JavaFX will be available under the GNU General Public License'>GPL once it is released. Adobe even opened up the Flash player. My point being that even though there isn't a standard in place for those technologies, the format is open enough and allows people to build their own implimentations of those technologies.

Filed under: General 4 Comments
14May/080

links for 2008-05-14

Filed under: Links No Comments