Hacker News new | comments | show | ask | jobs | submit login

    // JavaScript code generated by DuoCode
    GetBestMove = function(board, player, winner)
That line will garbage the global scope..



The C# function is global, so the compiled Javascript function is global. Feels to me like the most correct compilation of the C# code.

(Consider: the C# code has no main function, so, if we hid the GetBestMove definition from the rest of the webpage, it would never get called. The optimal Javascript compilation would be an empty string, and that's clearly not valuable.)


I'm confused. C# doesn't even support global functions. In your example, it's a static private member of the AI class. Why is it wrong to generate

    var AI = {
        GetBestMove: function(....) { ... },
        ...
    };
?

Another thing, I had someone tell me once that according to Erik Meijer (of LINQ and Rx fame), years ago, Microsoft tried a C#-to-JS compiler too. It worked, but they had good reasons to drop the project anyway. Did you ever hear about that, do you know Microsoft's reasons for doing TypeScript instead? Are they still valid?


The project was Volta from Microsoft Live Labs. It was a technology preview but appears to have been canceled. There is also Script# by Nikhil Kothari from the .NET Platform group.


Hmm, I don't know C#; the method wasn't encapsulated in a class, so I assumed it was some kind of global. It could be that this isn't an actual input/output sample, but rather just one method of a compiled class.


Not sure what you mean, you mean it will cause the global scope to be garbage collected, because it will not. It will cause GetBestMove to never be garbage collected though, which is probably ok.


He probably meant to put stuff into the global scope is garbage. As in a 'bad idea', not GC.




Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact

Search: