On Mon, Oct 1, 2012 at 5:58 PM, Gustavo Machado <[email protected]> wrote:
> Rick, that's super interesting however I've said "most", and there's no
> reference to these type of optimizations in TypeScript. It even says "in
> any browser, in any host", so who will perform those optimizations? Looks
> like TypeScript is not. Actually, this:
>
> Greeter.prototype.greet = function(a: string) {
> return "Hello, " + a;
> }
>
> Translates to this:
>
> Greeter.prototype.greet = function (a) {
> return "Hello, " + a;
> };
>
> So no +1 for TypeScript in this case :)
>
TypeScript definitely does not perform the optimization. The optimizations
are performed by the runtime.
Your example is essentially the same thing as the one I gave, so I dont
know what point you're trying to make. If you had this in your code:
(new Greeting()).greet(1);
The TS compiler would throw an exception and tell you to fix the argument
being passed, which means you'd change it to:
(new Greeting()).greet("1");
Now a runtime can look at your API and the function body of greet, then
look at the calls and determine that _yes_ it will always be called with a
string. This will allow the runtime to then perform explicit string
optimizations (whatever those might be).
Rick
>
> Gus
>
>
> On Mon, Oct 1, 2012 at 6:36 PM, Rick Waldron <[email protected]>wrote:
>
>>
>>
>> On Mon, Oct 1, 2012 at 5:15 PM, Gustavo Machado <[email protected]>wrote:
>>
>>>
>>> For less sophisticated developers (most people, and most of the VS
>>>> market), the compiler errors will remove much debugging frustration and
>>>> allow them to focus on creating rather than debugging.
>>>>
>>>>
>>> It also allows them to focus on "creating" instead of understanding what
>>> they are doing. Take the sample on the playground for instance:
>>>
>>> constructor (message: string) {
>>> this.greeting = message;
>>> }
>>>
>>> will translate to:
>>>
>>> function Greeter(message) {
>>> this.greeting = message;
>>> }
>>>
>>> If you can only handle string, should you not be doing a check and
>>> writing a proper message? What will happen to javascript users that consume
>>> your code generated with TypeScript? It's not a huge gain IMO, and a few
>>> CONS:
>>>
>>> - only get intellisense in VS (a gigantic IDE which will handle from
>>> databases, to manual tests).
>>> - TypeScript seems to be making the code longer to type and less
>>> readable instead of shorter/better (like others do).
>>> - yet another language/dependency on your project.
>>> - most of the type-related things could be handled gracefully with
>>> comments.
>>>
>>
>> You can't get runtime optimizations with comments.
>>
>>
>> Take a look at this example:
>>
>> function f( a ) {
>> return "Hello Number " + a;
>> }
>>
>> // Say you called it like this, of course it will work,
>> // but the runtime won't necessarily optimize
>> // because you've given it no information about what
>> // it CAN optimize. Besides, you really wanted a string.
>> f(1);
>>
>>
>> // So enforce it...
>> function f( a: string ) {
>> return "Hello Number " + a;
>> }
>>
>> // throws on compilation
>> f(1);
>>
>> // Which would encourage you to go back to your code
>> // and make it a string:
>> f("1");
>>
>> // Now it passes the compilation and this is what it outputs:
>> function f(a) {
>> return "Hello Number " + a;
>> }
>> f("1");
>>
>> The point is that it made you think about what you were passing to the
>> function.
>>
>>
>> The above example is fairly contrived and I'm sure that most runtimes
>> will figure that specific case out and optimize just the same, but allow it
>> to serve as a simplified example case.
>>
>>
>> Rick
>>
>>
>>
>>
>>>
>>> Gus
>>>
>>> --
>>> Job Board: http://jobs.nodejs.org/
>>> Posting guidelines:
>>> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
>>> You received this message because you are subscribed to the Google
>>> Groups "nodejs" group.
>>> To post to this group, send email to [email protected]
>>> To unsubscribe from this group, send email to
>>> [email protected]
>>> For more options, visit this group at
>>> http://groups.google.com/group/nodejs?hl=en?hl=en
>>>
>>
>> --
>> Job Board: http://jobs.nodejs.org/
>> Posting guidelines:
>> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
>> You received this message because you are subscribed to the Google
>> Groups "nodejs" group.
>> To post to this group, send email to [email protected]
>> To unsubscribe from this group, send email to
>> [email protected]
>> For more options, visit this group at
>> http://groups.google.com/group/nodejs?hl=en?hl=en
>>
>
> --
> Job Board: http://jobs.nodejs.org/
> Posting guidelines:
> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
> You received this message because you are subscribed to the Google
> Groups "nodejs" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/nodejs?hl=en?hl=en
>
--
Job Board: http://jobs.nodejs.org/
Posting guidelines:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en