JS Strict Data Types - Released

We at Ajaxonomy are happy to announce the release of the first library in the Ajaxonomy Developer's Toolkit. The library is called JS Strict Data Types and attempts to provide a way to maintain strict data types in JavaScript. Strict data types are proposed in the next version of JavaScript, however it is hard to say when you will actually be able to use it in all browsers. So, JS Strict Data Types is an attempt to allow the use of strict data types now.

The library is very easy to use. Simply include the small 7K (uncompressed) js file in your web page or application and then you can start defining variable data types strictly through the methods used in the below example.

MyVar1 = new Int(12); //Creates an Integer variable MyVar2 = new Float(2.54); //Creates a Float variable MyVar3 = new String("Some Text"); //Creates a Sting variable MyVar4 = new Boolean(true); //Creates a Boolean variable

The library uses various methods to maintain the strict data type (if you choose not to use the methods in the library strict data types may not continue to be maintained). The below shows a few of the mathematical methods that are available in the library.

MyVar1.add(5); MyVar1.sub(2); MyVar1.mult(10); MyVar1.div(7);

Since there are quite a few methods that are used to guarantee that strict data types it is recommended that you read the documentation before using the library.

This beta 1.0 release of the library is released under the GNU Lesser GPL. So, it can be used for personal and commercial use. Because of this go ahead and use the library in other libraries or any JavaScript project.

You can see a demo page that uses the library and displays the results here.

You can download the library here.

You can go to the projects Google Code page here.

You can read the projects documentation here.

Strict data types?

Perhaps I should be a bit more descriptive with my criticism :)

I understand the appeal of strict data types, especial when working with larger teams where you want to absolutely ensure the right data is passed in. I can also see how it may save time by allowing you not to have to check the data to see if it's typed correctly yourself.

However in general I view it as a bad introduction.
One of the greatest powers of JavaScript is it's loose typing. It's ability to pass whatever around, and have vars be assigned virtually anything at any time.

I guess one problem is JS is being more and more commercialized and mainstreamed. People tend to want to introduce concepts from one of the most commercialized languages, Java.

Some people would argue with me that "You don't have to use it if you don't want to, but now it's available for those people who do want it."

Well, that doesn't make it right. Now in a few years I might come across some JS code that uses it and I won't have the flexibility that I've learned to love in JavaScript.

Languages shouldn't be a kitchen sink of all ideas and concepts from all languages. They should be exist in their own bucket.

...and have vars be assigned virtually anything at any time.

Actually, I think that this is rarely done, if for no other reason than readability. In fact, one of the many optimizations being incorporated into the current generation of JavaScript engines basically consists of "caching" the evaluated type of a variable so that its type does not have to be re-evaluated each time it is used. If JavaScript frameworks continue to grow at the rate that they currently are, having "type safety" in the development process may turn out to be a real boon for certain people.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <pre> <div> <blockquote> <object> <embed> <img> <param>
  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically.

More information about formatting options

This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Copy the characters (respecting upper/lower case) from the image.