4 ms·
I'd have to agree that it's not fully baked but as someone learning it currently, I have to say that it's a pretty awesome language. It fixes a lot of the annoy
by Zaheer 12y ago
I'd have to agree that it's not fully baked but as someone learning it currently, I have to say that it's a pretty awesome language. It fixes a lot of the annoyances I have about other languages and wraps it all together. Things like multiple returns, closures, etc are super handy features that I've wanted in other languages.
Shameless Plug: Check out www.LearnSwift.tips if you're trying to learn. It was born out of my desire to learn Swift and is just a simple curation of resources, tutorials, code samples, etc to learn Swift.
- panzi 12y ago> multiple returns, closures, etc What other new(ish) language in this day and age does not support this? You have closures in e.g. Haskell, Java, C#, Rust, C++, JavaScript, Python and Ruby. You have destructuring/unpacking support for tuples/lists or something similar that can be used for multiple return values in e.g. Haskell, Rust, Python and Ruby. I think there will be destructuring in future JavaScript standards and I don't know about C#. I think a new language that doesn't support these things would be disappointing.
- dfkf 12y agoC# can pass parameters by reference, which is often used to return multiple values from a function. In new C# 6 it will look like this: if (int.TryParse("1234", out int result)) { /* do stuff */ }
- panzi 12y agoIf you count that than so can C/C++/Objective C (via pointers/references). But I like to use tuples and destructuring of tuples more (syntax wise).
- rectangletangle 12y agoWhen you say multiple returns do you mean something like generator functions, functions that return some form of tuple like construct, functions with variable return types, or something else? I haven't looked into Swift much at all, so I'm curious.
- interpol_p 12y agoTuples are used for multiple returns in swift. So a function definition might look like: () -> (Int, String) (Function that takes no parameters, returns an Int/String tuple) Edit: Tuples can also have named parameters, so something like this is possible: () -> (index: Int, name: String) Then the resulting tuple can be accessed by name: //Where x is a tuple returned from the above function x.index x.name
- josephlord 12y agoAs interpol_p says tuples are available. It is also quite possible to return a function or other closure so a generator function is definitely possible. The return type does have to be defined though so there isn't a way to have a variable return type. I suppose you could return something of "Any" type but would you really want to?