Images in this post missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at
Mmmmm...statically typed goodness (updated)

I'm somewhat of a n00b when it comes to object-oriented development and C#, but that is what I've been doing for the past couple of years now. My background is in more procedural type programming languages, like PL/SQL (I did a lot of Oracle development early in my software development career). I've been doing some more web development lately, and one of the things I'm being painfully reminded of is how much I really dislike JavaScript. Why? Because JavaScript is not a strongly statically typed language (its dynamically typed (see "Static vs dynamic typing" here)). The fact that I can declare a variable (or don't really even *have* to declare your variables in JS), but NOT give it a type, can be extremely painful if you're not careful. With a nice, strongly statically typed language like C#, when I declare a variable/object, I have to declare what type of an object it will be...and it will ALWAYS be that kind of object. Always. Until it is destroyed, that is the kind of object it will be. What's so great about that? The fact that I always know what I can and can't do with that object. That's the very thing that makes working with JavaScript so painful. When I declare a variable, I might initialize it as a number. But then, I might set its value later by calling another function. Who knows what kind of data is returned by that function. (Granted, maybe I should by understanding what that function is doing, but if I didn't write the function, it's not always intuitive) I might now be working with a string, or a date. So now, when writing my code, I might try to access a property of that variable, or perform some method/function on it, whatever. In code, it seems just fine. But it's not until I actually run my application (this indicates that its a dynamically typed language) and it pukes all over my JavaScript code giving me an "object does not support this property or method" error that I realize that something is now wrong. But what? What do I need to do to fix it? What can I do or what can I NOT do with this variable now? Its hard to tell.

Yes, I'm sure I've become spoiled by the beauty of the Visual Studio development environment and the wonder that is Intellisense. Yes, I probably also have a LOT to learn about writing good JavaScript code. But despite all of that, I still find JavaScript to be one of the most painful programming/scripting languages I've ever had to work with. Can I get an amen? Anyone have any suggestions for growth in this area?

I need to correct myself here. It was brought to my attention that I used incorrect terminology here. I should have used the term statically typed, when referring to C#, as opposed to strongly typed; and I should have used the term dynamically typed as opposed to weakly typed in reference to JavaScript. I've made corrections above, including the title. Thanks for the correction Foo (sorry, I'd use a more appropriate reference, but that's all you left me).

Cross-posted from my personal weblog at Bob.Yexley.Net.

Posted 09-22-2006 10:03 AM by Bob Yexley



Billy McCafferty wrote re: Mmmmm...strongly typed goodness
on 09-22-2006 11:34 AM

I never had a a strong appreciation of JavaScript until I found years ago.  It's parent site is which has an incredible ensamble of other JavaScript wonders.  But I have to admit my JavaScript has fallen behind since finding telerik UI controls.  In my current application of about 25,000 LOC, I've probably written less than 50 lines of JavaScript...I actually kind of miss it.  (Kind of.)  Now if I could only get a handle on RegEx...someday...someday.

Jayson Knight wrote re: Mmmmm...strongly typed goodness
on 09-22-2006 1:15 PM

Javascript also has some very strange variable scoping issues that can bite you if you're not careful. Orcas is slated to have full intellisense for javascript btw, so that should be a huge boon.

Scott wrote re: Mmmmm...strongly typed goodness
on 09-22-2006 3:01 PM
One project you might want to check out is Script#: It allows you to write C# (strongly typed) which is then converted to JavaScript, and provides a nice developer experience.
Foo wrote re: Mmmmm...strongly typed goodness
on 09-22-2006 3:49 PM
What you described is not "strongly typed", it is "statically typed".. these are 2 totally different things. i tend to MUCH prefer dynamically typed languages to statically typed languages, for a whole slew of reasons.
Bob Yexley wrote re: Mmmmm...statically typed goodness (updated)
on 09-27-2006 3:29 PM

@ Scott:

W O W.  Thanks for the tip about Script# Scott. That looks VERY impressive. I've only had a chance to breeze through the overview of the project, but so far I REALLY like what I see. What I can't seem to figure out is why I've not heard anything about this before now. Seems to be somewhat overlooked.

Sam wrote re: Mmmmm...statically typed goodness (updated)
on 10-12-2006 6:03 PM
I think much of your concern can be traced back to the development environment though. It's a shame to hate on JavaScript when there's really nothing making a JS String object any hard to debug than a .NET System.String. It's the environment. Firefox is a must for JS development. IE just doesn't come close (as far as I've found). It's also good to understand the basics of the language though. JS isn't your average dynamically typed language like Ruby or Python. In fact, I'm tempted to say that it's a weakly _classed_ language (for lack of a better term). JS is a Prototype based language. So where in Ruby you're likely to be dealing with an actual URI object when dealing with a URI, in JS you're dealing with a Decorated Object at best, and probably more generally a plain old String. Don't get me wrong, a Type is what it is, and that doesn't change, but fundamentally that Type is almost always Object in JS. The point is, don't like seeing "[[Object object]]" in IE? Decorate it with your own toString() method. Want Form elements to have a serialize() method? Give it to 'em. Due to browser differences static decoration is sometimes ineffective however (IE doesn't Type DOM Elements, so it doesn't work there). Is JS a great language? I dunno about that. It's a very flexible language though that you can do some really complex things with very easily that would have you writing lots of nastyness in c#. But the potential is often frustrated by browser limitations unfortunately. Plus most implementations are tremendously slow.

Add a Comment

Remember Me?

About The CodeBetter.Com Blog Network
CodeBetter.Com FAQ

Our Mission

Advertisers should contact Brendan

Google Reader or Homepage Latest Items
Add to My Yahoo!
Subscribe with Bloglines
Subscribe in NewsGator Online
Subscribe with myFeedster
Add to My AOL
Furl Latest Items
Subscribe in Rojo

Member Projects
DimeCasts.Net - Derik Whittaker

Friends of
Red-Gate Tools For SQL and .NET


SmartInspect .NET Logging
NGEDIT: ViEmu and Codekana
NHibernate Profiler
Balsamiq Mockups
JetBrains - ReSharper
Web Sequence Diagrams
Ducksboard<-- NEW Friend!


Site Copyright © 2007 CodeBetter.Com
Content Copyright Individual Bloggers


Community Server (Commercial Edition)