Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does not work with functions not in global scope #8

Open
goatslacker opened this issue Feb 9, 2012 · 8 comments
Open

Does not work with functions not in global scope #8

goatslacker opened this issue Feb 9, 2012 · 8 comments

Comments

@goatslacker
Copy link
Contributor

But you knew that already :)

@Ejhfast
Copy link
Owner

Ejhfast commented Feb 9, 2012

It actually does. See the new example on the readme. Though I agree that the syntax for making the declaration is not ideal:

MyObj = {
    //+ MyObj.test_fun :: Number -> Number -> Number
    test_fun:function(num1, num2){
        return num1 + num2;
    }
}

@Ejhfast Ejhfast closed this as completed Feb 9, 2012
@Ejhfast
Copy link
Owner

Ejhfast commented Feb 9, 2012

Also, if you are looking through your fork, you may want to update things... I've already pushed some fairly significant changes/fixes.

@goatslacker
Copy link
Contributor Author

Oh no I saw that in examples/test.js I'm talking about the private functions inside a closure.

Example:

(function () {
  // no way to access concat automatically :(
  // but TypedJS throws an error!
  //+ concat :: String -> String -> String
  function concat(a, b) {
    return a + b;
  }
}());

I was thinking about this and perhaps there's two ways to attack this problem.

  • Use TypedJS along with your unit tests.
  • Allow one to call a single automated test from wherever.

@goatslacker
Copy link
Contributor Author

This is especially an issue for people who write JavaScript programs that don't leak any global variables and their public interface is limited.

@Ejhfast
Copy link
Owner

Ejhfast commented Feb 9, 2012

Oh, ok. That's a thornier problem. And the private scoping pattern is pretty common... I'll give it some thought.

@Ejhfast Ejhfast reopened this Feb 9, 2012
@goatslacker
Copy link
Contributor Author

A crazy idea to have automated tests and private functions:

  • You parse the JS
  • Turn all the functions global in a typedjs sandbox
  • Assign them new names (in case of collisions)
  • Find/replace all references to those functions with their new names
  • Create the test suite with the new functions and signatures mapped to them
  • Run the automated tests
  • return results

@Ejhfast
Copy link
Owner

Ejhfast commented Feb 9, 2012

That's not so crazy, really. Proxino's error-detection product did something similar. We got a lot of flack for it from developers, but people might not care so much in this case (since TypedJS is for testing, not production code).

@goatslacker
Copy link
Contributor Author

I wrote it and it's working pretty ok. I haven't done the assigning of new names or find/replace all references yet but for now it works for functions which don't call other functions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants