3 ms·
Swift is like JavaScript/TypeScript only if you don't know Swift that well... They are so different, only very superficial comparisons of syntax would lead to
by hellofunk 7y ago
Swift is like JavaScript/TypeScript only if you don't know Swift that well...
They are so different, only very superficial comparisons of syntax would lead to such a statement.
- bobbylarrybobby 7y agoRight, both have sort of C-style syntax. That’s pretty much the beginning and end of their similarities.
- _bxg1 7y agoI don't know Swift that well, but this was my immediate impression when I spent a couple hours with it (and I've used C, C++, Java, C#, Python, etc.). The array/dictionary literal syntax (especially dictionaries) was probably the main thing. Lots of languages have similar array syntax (though fewer have the auto-grow behavior), but I can't think of another C-like language with first-class, dedicated dictionary syntax. C-likes also don't often have first-class functions/closures, or named function parameters (JS doesn't technically have the latter, but it effectively does with object destructuring; this is one of the syntax niceties Swift added). I didn't mean to imply they had an overall similar set of features, so much that someone who's comfortable with TypeScript would have a pretty easy time warming up to Swift, which matters on the web.
- hellofunk 7y agoSyntax is ultimately a fairly minor aspect of languages. The reference and value semantics, the memory management, the type system, the language runtime, these are what really create a development experience in a particular language. And they are on nearly opposite sides of the spectrum between Swift and JavaScript. If you are only superficially doing something in the language, a somewhat trivial project or just experimenting, then they might seem more similar than they really are.
- paavohtl 7y ago> C-likes also don't often have first-class functions/closures I think C is the only remaining C-like language not to have first-class functions. And there are compiler extensions for that too.
- _bxg1 7y agoMy understanding is that in cases like Java and C++, the lambdas aren't truly first-class; they come with limitations. I could be wrong.
- hellofunk 7y agoThat's true about Java but not C++. C++11 introduced true lambdas, but Java's idea of lambdas is rather laughable by comparison and nowhere near as flexible.