News for hackers. Stuff that matters.
Re:TypedJS: Sanity Check your JavaScript by secoif on Wednesday February 08, 2012 @04:17AM (#3565866)
Please don't use non-commercial licences: you are greatly limiting the number of people who can afford to contribute to your project.
Re:TypedJS: Sanity Check your JavaScript by spacemanaki on Wednesday February 08, 2012 @08:05AM (#3566367)
Furthermore I don't think CC licenses are meant to be used for code: http://creativecommons.org/software
Re:TypedJS: Sanity Check your JavaScript by timothya on Wednesday February 08, 2012 @01:24AM (#3565419)
Interesting, but if I wanted to get this sort of validation I'd just use Google's Closure Compiler. It supports validating types and also lets you do things like casting variables to different types. And the annotation method is pretty clear, flexible, and easy to understand.
Re:TypedJS: Sanity Check your JavaScript by silentOpen on Wednesday February 08, 2012 @05:28AM (#3566002)
Re:TypedJS: Sanity Check your JavaScript by glymor on Wednesday February 08, 2012 @02:59AM (#3565679)
At first glance this is a fuzz generator not a type checker.
Re:TypedJS: Sanity Check your JavaScript by silentOpen on Wednesday February 08, 2012 @02:54AM (#3565665)
What is the license that is free for non-commercial use? Static type checking is nice but implementation in a non-statically-type-checked language is unfortunate.
Re:TypedJS: Sanity Check your JavaScript by cromwellian on Wednesday February 08, 2012 @05:05AM (#3565957)
I think Closure Compiler is a lot more useful than this. You get type checking, but you also get best of breed optimization/minification too.

You don't get the automatic runtime test generation stuff, but that's more along the lines of an add-on utility like Quickcheck/Scalacheck.

Re:TypedJS: Sanity Check your JavaScript by zoka on Wednesday February 08, 2012 @04:04AM (#3565836)
The add_all() function as presented on their web page is wrong,instead of adding the array elements it just returns the last one.

Line 180 should be: count += num_arr[i];

Moreover naming accumulation variable for sum "count" is totally counter intuitive.

Re:TypedJS: Sanity Check your JavaScript by TeamMCS on Wednesday February 08, 2012 @03:30AM (#3565753)
Interesting idea but I'd hate to maintain that.
Re:TypedJS: Sanity Check your JavaScript by wyuenho on Wednesday February 08, 2012 @03:56AM (#3565816)
How much performance hit would it costs, and is there a companion tool that I can remove only those comments with types?
Re:TypedJS: Sanity Check your JavaScript by tbassetto on Wednesday February 08, 2012 @08:16AM (#3566404)
I never saw someone using "nil" in JavaScript (even in a comment). I guess the author has a Ruby background.
Re:TypedJS: Sanity Check your JavaScript by perfunctory on Wednesday February 08, 2012 @03:33AM (#3565761)
From their home page example

if(obj.valid === true) {

I would flag this line as an error.

Re:TypedJS: Sanity Check your JavaScript by inimino on Wednesday February 08, 2012 @05:09AM (#3565969)
Why? obj is specified by the type annotation to be an object with a property 'valid' that is a Boolean, so what's the problem?
Re:TypedJS: Sanity Check your JavaScript by perfunctory on Wednesday February 08, 2012 @06:01AM (#3566065)
I just don't like this style very much. It's better to write

if (obj.valid) {

Re:TypedJS: Sanity Check your JavaScript by reginaldo on Wednesday February 08, 2012 @06:10AM (#3566091)
Sometimes, and I mean just sometimes, it is better to just use ===. For instance, I recently wrote some code where a variable has a value of type Number, but I use "false" to signal the absence of such value (in the sense that the value is not available yet). In that case, I have to use stuff like if(x !== false), because "0" is a valid value in that context.
Re:TypedJS: Sanity Check your JavaScript by nilved on Wednesday February 08, 2012 @06:16AM (#3566099)
`if (foo)` and `if (foo === true)` aren't equivalent.
Re:TypedJS: Sanity Check your JavaScript by Hovertruck on Wednesday February 08, 2012 @10:25AM (#3566846)
According to the TypedJS annotation for the function they are. The function definition says that obj.valid has to be a boolean, so any other type of falsy input (0, undefined, null, etc) should never be provided as an argument here.
Re:TypedJS: Sanity Check your JavaScript by inimino on Wednesday February 08, 2012 @06:08AM (#3566088)
Sure, I agree it is poor style. I guess I assumed because of the context you were saying you would expect the type checker to flag it as an error.
Re:TypedJS: Sanity Check your JavaScript by darkxanthos on Wednesday February 08, 2012 @08:46AM (#3566478)
While uglier === is much more specific and enforces types... Which seems germane here.
Re:TypedJS: Sanity Check your JavaScript by kevingadd on Wednesday February 08, 2012 @03:58AM (#3565821)
It would be more interesting if you could also use the annotations to type-check at runtime (optionally). That way if the annotations diverged from the actual code, you'd find out.