3 ms·
"Using" -- a poor choice of keyword. It has been used for many years in languages like C++, C# (and now Rust) for namespace manipulation. Using the same keyword
by colonwqbang 3y ago
"Using" -- a poor choice of keyword. It has been used for many years in languages like C++, C# (and now Rust) for namespace manipulation. Using the same keyword to declare an object destructor becomes confusing.
For a language like Typescript which borrows so much of its syntax from C/C++ it would be best to either make the same syntax mean the same thing, or instead make up new syntax. Call it "with" or "defer", or something else instead.
Also the syntax "Symbol.dispose" to denote a symbol seems overly verbose. Why not use a single prefix character like Lisp/Ruby ":symbol".
- jraph 3y ago"with" was already taken by a misfeature of JavaScript, so… I too thought they were introducing something related to the "using" of C++, but the keyword does not seem too bad, in the context of a code, it's very readable. What would you suggest? As for Symbol, it's a JavaScript feature. I bet it was introduced like this so symbols could be polyfilled, so adopted more easily, without making the lack of support a syntax error - i.e. no need to transpile this. A bit verbose, but bearable, and probably easier to parse for a human than a colon. Too much of such terse syntax rapidly makes the code harder to read and more difficult to look up for a novice, or possibly even for someone experimented..
- BjorksEgo 3y ago"Using" is used for the same purpose in C# tries to keep keyword symmetry with https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/statements/using https://learn.microsoft.com/en-us/dotnet/csharp/language-ref...
- BjorksEgo 3y ago*Which Typescript tries to keep keyword symmetry with
- linkgoron 3y agoTypeScript is just implementing a stage 3 JavaScript feature. It's not their own invention.
- frutiger 3y agoIt’s not, though the author and champion of the TC39 proposal is a Microsoft employee and has generally championed features that have a close analogue to those from C# (eg. cancellation tokens).
- colonwqbang 3y agoAh, I didn't realise that. It seems typescript wasn't the first language to use the verb "use" inconsistently :) https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/using-directive https://learn.microsoft.com/en-us/dotnet/csharp/language-ref... https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/statements/using https://learn.microsoft.com/en-us/dotnet/csharp/language-ref...
- sergiotapia 3y agoNah I remember back in 2012 when I wrote C# we used `using` to indicate "dispose of this as soon as it's out of scope". Like for filereaders or streamreaders, if I remember right.
- paulddraper 3y agoThe C# keyword for this feature is in fact, "using". And the choice was made by JavaScript. TypeScript is honoring that.