Re: [swift-users] Justification for Swift Design Decisions?

2017-10-31 Thread Austin Zheng via swift-users
To expand on this, most (if not all) the proposals in the list of proposals
on GitHub (https://github.com/apple/swift-evolution/tree/master/proposals)
have a "Rationale" link to a mailing list archive post by one of the Swift
core team members explaining why a certain decision was reached. Those are
probably worth looking through. Some of the simpler and less controversial
proposals have almost no explanation, but the larger and controversial
proposals have extensively written-up rationale posts.

Best,
Austin

On Tue, Oct 31, 2017 at 12:25 PM, David Sweeris via swift-users <
swift-users@swift.org> wrote:

> Specifically WRT to double quotes for characters, the Commonly Rejected
> Changes doc (https://github.com/apple/swift-evolution/blob/master/
> commonly_proposed.md) says, "Swift takes the approach of highly valuing
> Unicode. However, there are multiple concepts of a character that could
> make sense in Unicode, and none is so much more commonly used than the
> others that it makes sense to privilege them. We'd rather save single
> quoted literals for a greater purpose (e.g. non-escaped string literals)."
>
> Otherwise, off the top of my head I'm not sure. If it's a particularly
> controversial decision, there's a fair chance it's come up on the
> swift-evolution list, though, so maybe search its archives?
>
> Hope that helps,
> - Dave Sweeris
>
> > On Oct 31, 2017, at 8:52 AM, Michael Rogers via swift-users <
> swift-users@swift.org> wrote:
> >
> > Hi, All:
> >
> > I’m giving a presentation on Swift this weekend, and am trying to find
> justification for some of the design decisions that they made. Is there
> anything out there that goes into the detail of this? Like … why did the
> use “ for characters, or \() for String interpolation?
> >
> > Thanks,
> >
> > Michael
> > ___
> > swift-users mailing list
> > swift-users@swift.org
> > https://lists.swift.org/mailman/listinfo/swift-users
>
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users
>
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] can we express "does not conform to a particular protocol"?

2017-07-03 Thread Austin Zheng via swift-users
I'm pretty sure solutions like the one you proposed are impossible, 
unfortunately :(. The compiler has to choose the static override at compile 
time, but it can't tell until runtime whether the type conforms to `Equatable` 
or not (because of retroactive conformance).

It's also not possible to use the as or is dynamic casting machinery to work 
with `Equatable`, because of the use of the `Self` type in its requirements.

A feature that the community has expressed interest in, "generalized 
existentials", may allow you to implement a function that does what you want.

Best,
Austin


> On Jul 3, 2017, at 5:00 PM, David Baraff via swift-users 
>  wrote:
> 
> I’m searching for the simplest way to write a function
>   func maybeEqual(_ lhs:T, _rhs:T) -> Bool
> 
> where it returns lhs == rhs if T is equatable, and false, otherwise.
> I tried
> 
> func maybeEqual(_ lhs:T, _rhs:T) -> Bool {
> return false
> }
> 
> func maybeEqual(_ lhs:T, _ rhs:T) -> Bool {
> return lhs == rhs
> }
> 
> but that doesn’t work.  Is there a way to express a type not matching 
> something?
> Alternately, how can I write this?
> 
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Removed discussions in doc for Swift 4. Why?

2017-06-12 Thread Austin Zheng via swift-users
The currying syntax was removed in Swift 3 (see
https://github.com/apple/swift-evolution/blob/master/proposals/0002-remove-currying.md).
I'm not aware, though, of any proposal in the pipeline to remove variadic
arguments, so it's not clear why the book should have removed discussion
about them.

Austin

On Mon, Jun 12, 2017 at 11:02 AM, tuuranton--- via swift-users <
swift-users@swift.org> wrote:

> From
>
>
> https://developer.apple.com/library/content/documentation/
> Swift/Conceptual/Swift_Programming_Language/RevisionHistory.html#//apple_
> ref/doc/uid/TP40014097-CH40-ID459
>
>
> "Removed discussion of variable function arguments and the special syntax
> for curried functions."
>
>
> Why?
>
>
> I tried variable function arguments and they seem to work fine in Xcode 9.
> Didn't try currying yet, however.
>
>
> Are these features being phased out?
>
>
>
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users
>
>
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] There is a way to see pending features or discussions in complexity order?

2017-06-12 Thread Austin Zheng via swift-users
Hi Mariano,

If you want to contribute, you should create an account at the bug tracker
at https://bugs.swift.org/. You can then look for bugs marked with the
`StarterBug` tag, which are simple tasks or enhancements that are
explicitly called out as appropriate for new contributors.

If you just want to look through all the proposals and their current
status, you can visit https://apple.github.io/swift-evolution/. Note that
proposals are arranged in chronological order.

Best,
Austin


On Mon, Jun 12, 2017 at 11:17 AM, Mariano Cornejo Herrera via swift-users <
swift-users@swift.org> wrote:

> Of course but I'm new in language development so I want to start from less
> complex stuff, learn and then help with more complex stuff, that's why I
> want to know if there is a place where all the pending features are ordered
> according to the complexity
>
> On Mon, Jun 12, 2017 at 12:08 PM Quinn "The Eskimo!" via swift-users <
> swift-users@swift.org> wrote:
>
>>
>> On 11 Jun 2017, at 09:02, Mariano Cornejo Herrera via swift-users <
>> swift-users@swift.org> wrote:
>>
>> > There is a way to see pending features or discussions in complexity
>> order?
>>
>> I’m not sure what you’re asking for here.  Are you looking for some way
>> to contribute to the Swift open source efforts?
>>
>> Share and Enjoy
>> --
>> Quinn "The Eskimo!"
>> Apple Developer Relations, Developer Technical Support, Core OS/Hardware
>>
>>
>> ___
>> swift-users mailing list
>> swift-users@swift.org
>> https://lists.swift.org/mailman/listinfo/swift-users
>>
>
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users
>
>
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Why is static a keyword?

2017-05-11 Thread Austin Zheng via swift-users
`class` and `static` in classes have subtly different meanings, if I recall
correctly. A `class` declaration can be overriden in subclasses; a `static`
one can't.

Best,
Austin

On Thu, May 11, 2017 at 10:04 AM, Zhao Xin via swift-users <
swift-users@swift.org> wrote:

> No. I think it is just a compromise.
>
> Zhaoxin
>
> On Fri, May 12, 2017 at 1:01 AM, Adrian Zubarev <
> adrian.zuba...@devandartist.com> wrote:
>
>> I don’t think this is the answer that was asked for. I bet it’s more a
>> technical question from the internal point of of view.
>>
>>
>>
>> --
>> Adrian Zubarev
>> Sent with Airmail
>>
>> Am 11. Mai 2017 um 18:59:58, Zhao Xin via swift-users (
>> swift-users@swift.org) schrieb:
>>
>> In Swift, you use `static in struct and enum` and `class in class`. For
>> example,
>>
>> struct Foo {
>>
>> static func bar() {
>>
>>
>>
>> }
>>
>> }
>>
>>
>> class ClassFoo {
>>
>> class func bar() {
>>
>>
>>
>> }
>>
>> }
>>
>>
>> Another the `class func bar()` can replace to `static` as well. Here the
>> `static` and `class` are equal in functions of classes.
>>
>>
>> And `class` is a keyword.
>>
>>
>> class ClassFoo2 {
>>
>> static func bar() {
>>
>>
>>
>> }
>>
>> }
>>
>>
>> Zhaoxin
>>
>>
>>
>> On Fri, May 12, 2017 at 12:17 AM, Jose Cheyo Jimenez via swift-users <
>> swift-users@swift.org> wrote:
>>
>>> I was expecting static to be a builtin. Does anybody know why it must be
>>> a keyword?
>>>
>>> Background. https://bugs.swift.org/browse/SR-4834
>>>
>>> ___
>>> swift-users mailing list
>>> swift-users@swift.org
>>> https://lists.swift.org/mailman/listinfo/swift-users
>>>
>>>
>> ___
>> swift-users mailing list
>> swift-users@swift.org
>> https://lists.swift.org/mailman/listinfo/swift-users
>>
>>
>
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users
>
>
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] (no subject)

2017-03-12 Thread Austin Zheng via swift-users
The source code on GitHub _is_ full and complete.

Check out 
https://github.com/apple/swift/blob/master/stdlib/public/core/Collection.swift#L1336-L1338
 

 for the implementation of `count`. RandomAccessCollection inherits from 
BidirectionalCollection, which inherits from Collection.

Best,
Austin

> On Mar 12, 2017, at 10:45 PM, Don Giovanni via swift-users 
>  wrote:
> 
> I understand swift is open source. However, i can't seem to find the complete 
> source code in GitHub. For example, RandomAccessCollection protocol has a 
> property count default implementation but upon looking through the source 
> provided in 
> GitHub:https://github.com/apple/swift/blob/master/stdlib/public/core/RandomAccessCollection.swift
>  
> 
> the implementation of the count property is not provided. This is just one of 
> the many examples where code provided to us in GitHub is incomplete. Where do 
> we get the complete source for RandomAccessCollection protocol as an example? 
> Thanks.
> 
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Swift and Xcode along with Playgrounds is full of bugs

2016-09-13 Thread Austin Zheng via swift-users
Hi Shyamal,

Please share with us the SLA you signed with Apple that guarantees you any 
level of paid support with regards to Swift, or alternatively an invoice that 
shows us how much you paid for a license to use the Linux port of Swift.

Best regards,
Austin

> On Sep 13, 2016, at 7:24 PM, Shyamal Chandra via swift-users 
>  wrote:
> 
> Hi Shawn,
> 
> Could you give me examples of what I said was clearly "unprofessional"?  Two 
> months for a bug because open source is "do it yourself".  This sounds like a 
> crappy support team by a large multinational company that open sources 
> non-functional Linux ports of its language.  I gave clear examples and bugs 
> so I don't understand why you are getting defensive and hammering me with the 
> "unprofessional" word.  First, address the issues and the bugs; I gave you 
> clear examples and you circumvent those issues and flag the post because you 
> don't want to confront that the tooling is buggy and flaky.
> 
> I believe that a company of Apple's stature is unprofessional when they 
> deliver buggy code to their customers that they pay money for.  Before you 
> respond to this message, please address the bugs that I hyperlinked and the 
> forum question problem.  You are wasting my time.
> 
> Thanks!
> 
> Best,
> 
> Shyamal Chandra
> shyam...@gmail.com 
> Linkedin: http://www.linkedin.com/in/shyamalc 
> 
> Phone: 620-719-9064
> 
> On Tue, Sep 13, 2016 at 9:16 PM, Shawn Erickson  > wrote:
> You message are really coming across with an unprofessional tone. I 
> understand you are frustrated but folks inside and outside of Apple have been 
> working their butts off and frankly deserve a little more civility.
> 
> Anyway, the Linux side of things is very much an open source - do it yourself 
> - type of thing at this time. I am sure folks would love to have the issues 
> and short coming addressed but need folks to step forward.
> 
> If you would like to talk specifics about swift issues you are having a fair 
> number of folks are on this list and possibly could help.
> 
> Also note Apple folks are likely a little burned out right now with all of 
> the crazy work closing out - as best they could - on Swift 3 and Xcode 8, 
> etc. so they may not be the quickest to respond.
> 
> -Shawn
> On Tue, Sep 13, 2016 at 6:53 PM Shyamal Chandra via swift-users 
> > wrote:
> I am not arguing; I am bringing up defect in the Apple way of handling bugs 
> for Swift, Xcode, and Playgrounds.  Am I supposed to wait for eternity?
> 
> On Tuesday, September 13, 2016, Jens Alfke  > wrote:
> 
>> On Sep 13, 2016, at 6:27 PM, Shyamal Chandra > wrote:
>> 
>> Do you really think that is a viable option again?
> 
> No, you’re right. Reporting bugs is clearly the least viable option, except 
> for all the other options* (like arguing on mailing lists.)
> 
> —Jens
> 
> * With apologies to Winston Churchill
> 
> 
> -- 
> Sent from Gmail Mobile
> ___
> swift-users mailing list
> swift-users@swift.org 
> https://lists.swift.org/mailman/listinfo/swift-users 
> 
> 
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Syntax for extending a struct conforming to a protocol with constraint

2016-07-10 Thread Austin Zheng via swift-users
You can't do this yet, but it's on the roadmap: 
https://github.com/apple/swift/blob/master/docs/GenericsManifesto.md#conditional-conformances-
 


Austin

> On Jul 9, 2016, at 10:54 PM, 褚晓敏 via swift-users  
> wrote:
> 
> Hello, every one. I want to extend a struct to conform to a protocol, while 
> it’s itself a generic and needs a constraint. So I wrote this: (Swift 3)
> 
> ``` swift
> struct Polynomial {
>   //definition goes here
> }
> 
> extension Polynomial: CustomStringConvertible where Field: 
> CustomStringConvertible {
>   //implementation goes here
> }
> ```
> 
> Then I receive an error message from the compiler:
> Extension of type 'Polynomial' with constraints cannot have an inheritance 
> clause
> 
> This is the only way I know to do this(theoretically), but unfortunately it 
> doesn’t work.
> 
> So, how can I achieve this? What syntax should be employed?
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] object.self?

2016-07-09 Thread Austin Zheng via swift-users
Yes, as far as I know 'foo' and 'foo.self' are equivalent. I don't actually
know why the latter exists, except in analogy to "T.self".

There was a mistake in my response; the metatype of 'foo' is not
'foo.self', it is 'foo.dynamicType' (or whatever new form dynamicType is
going to take in Swift 3).

On Sat, Jul 9, 2016 at 2:27 PM, Rick Mann  wrote:

>
> > On Jul 8, 2016, at 09:45 , Austin Zheng  wrote:
> >
> > Hi Rick,
> >
> > If you have a type (let's call it "T"), you can use it two ways:
> >
> > * As a type, or part of a type, like such: "let x : T = blah()"
> > * As a value, just like any other variable, function argument, property,
> etc.
> >
> > In the second case (type-as-value), you need to append ".self" to the
> type name according to the grammar:
> >
> > "let x : Any.Type = T.self"
> >
> > There was a "bug" in Swift 2.x where you could sometimes use just "T",
> without the ".self", in certain cases (in particular, when you were passing
> in a type-as-value to a function with one unlabeled argument). That bug has
> since been fixed.
> >
> > As for types-as-values: Swift allows you to treat a type as a normal
> value, which means you can do whatever you want with it: pass it to
> functions and return it from functions, store it in properties or
> variables, etc. If you have one of these types-as-values (called
> 'metatypes'), you can do certain things like call static methods or
> initializers on them, use them to parameterize generic functions, etc.
>
> Thanks, Austin. I'm familiar with all this in Swift. What threw me was
> that "subclassObject" was an instance, not a class.
>
> > However, to get back to your original question, the `.self` in that
> switch statement actually isn't necessary and you should really just be
> switching on the value of subclassObject itself, not the value of its type.
>
> I would have thought so, but the response to this answer was something
> along the lines of "I never know when to use the object or its self."
>
> To me, for an instance, foo an foo.self should be equivalent in all
> respects (shouldn't it?).
>
> >
> > Best,
> > Austin
> >
> >
> > On Fri, Jul 8, 2016 at 9:38 AM, Rick Mann via swift-users <
> swift-users@swift.org> wrote:
> > I just saw a question which brought up something I didn't know about.
> Apparently sometimes you have to call object.self in a place that looks
> like you should just use "object." What does this usage mean?
> >
> > for subclassObject in objects {
> > switch subclassObject.self {<--- Here, why not
> "subclassObject" alone?
> > case is Subclass1:
> > doSomethingWith(subclassObject as! Subclass1)
> >
> > case is Subclass2:
> > doSomethingWith(subclassObject as! Subclass2)
> >
> > case is Subclass3:
> > doSomethingWith(subclassObject as! Subclass3)
> >
> > default:
> > break
> > }
> > }
> >
> > Thanks,
> > Rick
> >
> > > On Jul 8, 2016, at 08:15 , Dan Loewenherz via swift-users <
> swift-users@swift.org> wrote:
> > >
> > > To my knowledge, you can’t do exactly what you’re trying to do, but
> this is close:
> > >
> > > for subclassObject in objects {
> > > switch subclassObject.self {
> > > case is Subclass1:
> > > doSomethingWith(subclassObject as! Subclass1)
> > >
> > > case is Subclass2:
> > > doSomethingWith(subclassObject as! Subclass2)
> > >
> > > case is Subclass3:
> > > doSomethingWith(subclassObject as! Subclass3)
> > >
> > > default:
> > > break
> > > }
> > > }
> > >
> > > On Fri, Jul 8, 2016 at 10:11 AM, Nate Birkholz via swift-users <
> swift-users@swift.org> wrote:
> > > This looks like it doesn't work (swift 2.x), but wanted to be sure
> it's not supported:
> > > class Superclass {}
> > > class Subclass1 : Superclass {}
> > > class Subclass2 : Superclass {}
> > > class Subclass3 : Superclass {}
> > >
> > > let sc1 = Subclass1()
> > > let sc2 = Subclass2()
> > > let sc3 = Subclass3()
> > >
> > > let objects : [Superclass] = [sc1, sc2, sc3]
> > >
> > > for subclassObject in objects {
> > > switch subclassObject {
> > > case let object = subclassObject as? Subclass1:
> > > doSomethingWith(object)
> > > case let object = subclassObject as? Subclass2:
> > > doSomethingWith(object)
> > > case let object = subclassObject as? Subclass3:
> > > doSomethingWith(object)
> > > default:
> > > return
> > > }
> > > }
> > >
> > > This gives an error, expecting a colon (:) after object on every case.
> > >
> > > I wanted to be sure I wasn't missing something in my syntax (nor some
> obvious-to-others reason this isn't supported) before going to swift
> evolution.
> > >
> > >
> > > --
> > > Nate Birkholz
> > >
> > > ___
> > > swift-users mailing list
> > > swift-users@swift.org
> > > https://lists.swift.org/mailman/listinfo/swift-users
> > >
> > >
> > > 

Re: [swift-users] object.self?

2016-07-08 Thread Austin Zheng via swift-users
Hi Rick,

If you have a type (let's call it "T"), you can use it two ways:

* As a type, or part of a type, like such: "let x : T = blah()"
* As a value, just like any other variable, function argument, property,
etc.

In the second case (type-as-value), you need to append ".self" to the type
name according to the grammar:

"let x : Any.Type = T.self"

There was a "bug" in Swift 2.x where you could sometimes use just "T",
without the ".self", in certain cases (in particular, when you were passing
in a type-as-value to a function with one unlabeled argument). That bug has
since been fixed.

As for types-as-values: Swift allows you to treat a type as a normal value,
which means you can do whatever you want with it: pass it to functions and
return it from functions, store it in properties or variables, etc. If you
have one of these types-as-values (called 'metatypes'), you can do certain
things like call static methods or initializers on them, use them to
parameterize generic functions, etc.

However, to get back to your original question, the `.self` in that switch
statement actually isn't necessary and you should really just be switching
on the value of subclassObject itself, not the value of its type.

Best,
Austin


On Fri, Jul 8, 2016 at 9:38 AM, Rick Mann via swift-users <
swift-users@swift.org> wrote:

> I just saw a question which brought up something I didn't know about.
> Apparently sometimes you have to call object.self in a place that looks
> like you should just use "object." What does this usage mean?
>
> for subclassObject in objects {
> switch subclassObject.self {<--- Here, why not
> "subclassObject" alone?
> case is Subclass1:
> doSomethingWith(subclassObject as! Subclass1)
>
> case is Subclass2:
> doSomethingWith(subclassObject as! Subclass2)
>
> case is Subclass3:
> doSomethingWith(subclassObject as! Subclass3)
>
> default:
> break
> }
> }
>
> Thanks,
> Rick
>
> > On Jul 8, 2016, at 08:15 , Dan Loewenherz via swift-users <
> swift-users@swift.org> wrote:
> >
> > To my knowledge, you can’t do exactly what you’re trying to do, but this
> is close:
> >
> > for subclassObject in objects {
> > switch subclassObject.self {
> > case is Subclass1:
> > doSomethingWith(subclassObject as! Subclass1)
> >
> > case is Subclass2:
> > doSomethingWith(subclassObject as! Subclass2)
> >
> > case is Subclass3:
> > doSomethingWith(subclassObject as! Subclass3)
> >
> > default:
> > break
> > }
> > }
> >
> > On Fri, Jul 8, 2016 at 10:11 AM, Nate Birkholz via swift-users <
> swift-users@swift.org> wrote:
> > This looks like it doesn't work (swift 2.x), but wanted to be sure it's
> not supported:
> > class Superclass {}
> > class Subclass1 : Superclass {}
> > class Subclass2 : Superclass {}
> > class Subclass3 : Superclass {}
> >
> > let sc1 = Subclass1()
> > let sc2 = Subclass2()
> > let sc3 = Subclass3()
> >
> > let objects : [Superclass] = [sc1, sc2, sc3]
> >
> > for subclassObject in objects {
> > switch subclassObject {
> > case let object = subclassObject as? Subclass1:
> > doSomethingWith(object)
> > case let object = subclassObject as? Subclass2:
> > doSomethingWith(object)
> > case let object = subclassObject as? Subclass3:
> > doSomethingWith(object)
> > default:
> > return
> > }
> > }
> >
> > This gives an error, expecting a colon (:) after object on every case.
> >
> > I wanted to be sure I wasn't missing something in my syntax (nor some
> obvious-to-others reason this isn't supported) before going to swift
> evolution.
> >
> >
> > --
> > Nate Birkholz
> >
> > ___
> > swift-users mailing list
> > swift-users@swift.org
> > https://lists.swift.org/mailman/listinfo/swift-users
> >
> >
> > ___
> > swift-users mailing list
> > swift-users@swift.org
> > https://lists.swift.org/mailman/listinfo/swift-users
>
>
> --
> Rick Mann
> rm...@latencyzero.com
>
>
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users
>
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Bls: Re: Swift to Javascript

2016-06-22 Thread Austin Zheng via swift-users
If you want something supported by Apple, the procedure is to propose it on the 
swift-evolution list. However, Swift has a very specific set of development 
priorities right now, so they are almost certainly not going to accept any new 
proposals for compiler backends or transpilation support for at least several 
months.

Austin


> On Jun 21, 2016, at 11:20 PM, Mr Bee  wrote:
> 
> I know there are some JS compilers, but I prefer something that is officially 
> supported by Apple.
> 
> 
> –Mr Bee
> 
> 
> Pada Rab, 22 Jun 2016 pada 12:45, Austin Zheng
>  menulis:
> The great thing about Swift being open-source is that anyone can help make it 
> a better language!
> 
> Here's a good starting point: 
> https://kripken.github.io/emscripten-site/index.html 
> 
> 
> Best,
> Austin
> 
>> On Jun 21, 2016, at 9:44 PM, Mr Bee via swift-users > > wrote:
>> 
>> Hi all, 
>> 
>> I wish I will be able write web app using Swift instead of JavaScript. It 
>> would be wonderfull if we could develop desktop app, mobile app, server-side 
>> app, and web app, all using Swift. It will be complete.
>> 
>> Is it possible that someday in the future we would be able to compile Swift 
>> code into JavaScript? Something that's like Microsoft's TypeScript. *finger 
>> crossed*
>> 
>> What do you think? Hello, Mr Chris Lattner? Are you listening?
>> 
>> Regards,
>> 
>> –Mr Bee
>> 
>> ___
>> swift-users mailing list
>> swift-users@swift.org 
>> https://lists.swift.org/mailman/listinfo/swift-users
> 

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Swift to Javascript

2016-06-21 Thread Austin Zheng via swift-users
The great thing about Swift being open-source is that anyone can help make it a 
better language!

Here's a good starting point: 
https://kripken.github.io/emscripten-site/index.html 


Best,
Austin

> On Jun 21, 2016, at 9:44 PM, Mr Bee via swift-users  
> wrote:
> 
> Hi all, 
> 
> I wish I will be able write web app using Swift instead of JavaScript. It 
> would be wonderfull if we could develop desktop app, mobile app, server-side 
> app, and web app, all using Swift. It will be complete.
> 
> Is it possible that someday in the future we would be able to compile Swift 
> code into JavaScript? Something that's like Microsoft's TypeScript. *finger 
> crossed*
> 
> What do you think? Hello, Mr Chris Lattner? Are you listening?
> 
> Regards,
> 
> –Mr Bee
> 
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Swift Binary Size vs. Obj-C

2016-06-15 Thread Austin Zheng via swift-users
Sorry, I totally missed the part where you mentioned the runtime libs.

I assume you're compiling your Objective-C code using the `-Os`
optimization level? Unfortunately, it doesn't seem like swiftc has any
flags for trading off speed and binary size. Part of the size discrepancy
is almost certainly due to the immaturity of the compiler.

This is probably only valid for the roughest of OOM estimates, but
LinkedIn's iOS app is 135 MB (don't know how it breaks down in terms of
assets vs code), and is almost entirely implemented in Swift. It's not much
to go off, but it might provide you with a starting point.

If any of your company's engineers are at WWDC, you might want to have them
ask the engineers during the developer tools labs.

Best,
Austin


On Wed, Jun 15, 2016 at 5:16 PM, Seth Friedman via swift-users <
swift-users@swift.org> wrote:

> Thanks for the quick reply. You guys are right on part of it; the runtime
> libraries are causing the majority of the increase. I thought the Swift
> runtime libraries were supposed to only take up 4.5 MB though? Did they
> increase with Swift 3? If I add up all of the libraries, they take up a
> total of 22.88 MB in the binary. About how big would they be if I had
> Bitcode turned on?
>
> That said, the actual Swift binary is still larger. In my table view
> example, the Objective-C binary is 144 KB and the Swift binary is 201 KB. 
> *That's
> still a 40% increase*. Obviously it's much harder to test a large-scale
> app, but I'd like to know the percentage increase to expect if we were to
> migrate to Swift.
>
> On Wed, Jun 15, 2016 at 5:04 PM Saagar Jha  wrote:
>
>> Yep, I just took a simple app and opened up the ipa. 90% of it is the
>> “Frameworks” directory containing the Swift frameworks libSwiftCore.dylib,
>> libSwiftDarwin.dylib, etc.
>>
>>
>> On Wed, Jun 15, 2016 at 3:43 PM Seth Friedman via swift-users <
>> swift-users@swift.org> wrote:
>>
>>> Hi all,
>>>
>>> I've seen a ton of blog posts written about all of the cool and exciting
>>> things about Swift, but I haven't see anything really about the downsides
>>> (besides the occasional post about pain points with interoperability).
>>> What's of biggest concern to me when considering migrating my company's app
>>> from Objective-C to Swift is binary size. Swift binary size seems to be
>>> several times larger than Objective-C, and I'm curious what data there is
>>> in the community to support this suspicion.
>>>
>>> For some quick data points, I created a single view controller project
>>> in Obj-C and one in Swift, turned off bitcode to get a better idea of what
>>> the binary size on device would be, and archived them. I did this in Xcode
>>> 8 Beta 1 using Swift 3 so that I'd make sure to get any binary size
>>> improvements in Swift 3.
>>>
>>> The Obj-C IPA file was 639 KB. The Swift IPA file was *23.6 MB*. I know
>>> that the Swift runtime libs are about 4.5 MB, but subtracting that, the
>>> Swift IPA file is still *30x bigger than the Obj-C equivalent*. Next, I
>>> tried adding a simple table view controller, a Person model with a first
>>> and last name, and a data source that puts the first and last names in the
>>> table view in an attempt to make a functioning app. However, the binary
>>> sizes were about the same (the Obj-C one actually decreased to 635 KB).
>>>
>>> When we're talking about binary sizes this small, it's not a big deal,
>>> but my company's app is currently 81 MB, about 35 MB of which is code, and
>>> the rest is assets. If the code part of the binary size increases by orders
>>> of magnitude like this, we'll go way over the 100 MB cellular limit that
>>> Apple has set. This is also a really bad experience for customers in
>>> emerging markets like China and India that have poor connections.
>>>
>>> Can anyone confirm or deny that Swift binary size is orders of magnitude
>>> larger than Objective-C? I'm looking for the specific increase we'll see to
>>> take to my management in order to make a justification for whether it's
>>> worth it for our customers.
>>>
>>> Thanks!
>>>
>>> Seth Friedman
>>>
>>>
>>> ___
>>> swift-users mailing list
>>> swift-users@swift.org
>>> https://lists.swift.org/mailman/listinfo/swift-users
>>>
>> --
>> -Saagar Jha
>>
>
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users
>
>
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Swift Binary Size vs. Obj-C

2016-06-15 Thread Austin Zheng via swift-users
Swift binaries are so massive currently because there's no ABI stability,
therefore the runtime and support libraries must be packaged with every
application. This should change in the future.

Best,
Austin

On Wed, Jun 15, 2016 at 3:43 PM, Seth Friedman via swift-users <
swift-users@swift.org> wrote:

> Hi all,
>
> I've seen a ton of blog posts written about all of the cool and exciting
> things about Swift, but I haven't see anything really about the downsides
> (besides the occasional post about pain points with interoperability).
> What's of biggest concern to me when considering migrating my company's app
> from Objective-C to Swift is binary size. Swift binary size seems to be
> several times larger than Objective-C, and I'm curious what data there is
> in the community to support this suspicion.
>
> For some quick data points, I created a single view controller project in
> Obj-C and one in Swift, turned off bitcode to get a better idea of what the
> binary size on device would be, and archived them. I did this in Xcode 8
> Beta 1 using Swift 3 so that I'd make sure to get any binary size
> improvements in Swift 3.
>
> The Obj-C IPA file was 639 KB. The Swift IPA file was *23.6 MB*. I know
> that the Swift runtime libs are about 4.5 MB, but subtracting that, the
> Swift IPA file is still *30x bigger than the Obj-C equivalent*. Next, I
> tried adding a simple table view controller, a Person model with a first
> and last name, and a data source that puts the first and last names in the
> table view in an attempt to make a functioning app. However, the binary
> sizes were about the same (the Obj-C one actually decreased to 635 KB).
>
> When we're talking about binary sizes this small, it's not a big deal, but
> my company's app is currently 81 MB, about 35 MB of which is code, and the
> rest is assets. If the code part of the binary size increases by orders of
> magnitude like this, we'll go way over the 100 MB cellular limit that Apple
> has set. This is also a really bad experience for customers in emerging
> markets like China and India that have poor connections.
>
> Can anyone confirm or deny that Swift binary size is orders of magnitude
> larger than Objective-C? I'm looking for the specific increase we'll see to
> take to my management in order to make a justification for whether it's
> worth it for our customers.
>
> Thanks!
>
> Seth Friedman
>
>
>
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users
>
>
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Discrepancy between sharing internal Swift symbols with Obj-C when in an app vs a framework target

2016-06-04 Thread Austin Zheng via swift-users
This is probably a solution to a different issue, but what happens if you 
declare your "should be visible from Objective-C" swift methods as 'dynamic'?

Austin

> On Jun 4, 2016, at 11:55 AM, Jens Alfke via swift-users 
>  wrote:
> 
> 
>> On Jun 4, 2016, at 11:29 AM, Kevin Lundberg via swift-users 
>> > wrote:
>> 
>> However objc code inside the same framework as the swift code in question 
>> should ideally be able to see internal swift symbols as well, as they are 
>> within the same module.
> 
> I agree; I didn’t realize that was your situation. I haven’t tried doing this 
> myself. It sounds like a bug.
> 
> —Jens
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] String Comparisons in Swift

2016-06-02 Thread Austin Zheng via swift-users
You should be able to use ==. 

Are the lengths of your strings the same length? readLine() has a strip 
newlines parameter that is true by default. 

Best,
Austin

Sent from my iPhone

> On Jun 2, 2016, at 12:07 PM, John Myers via swift-users 
>  wrote:
> 
> I've had some difficulty comparing string variables to string constants with 
> ==.  I believe it's always after using a readLine().  Does Swift require a 
> .equals() or a .compareTo(), as other c like languages, or are there 
> invisible characters in my string because of the readLine() which I need to 
> strip out?
> Thanks!
> -- 
> John Myers
> --
> mye...@shawanoschools.com
> 
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] UnsafeMutablePointer vs. UnsafeMutablePointer

2016-06-01 Thread Austin Zheng via swift-users
This shouldn't be something you need to worry about. The mechanism the OS uses 
to handle memory per process is different from the mechanism your process uses 
to allocate memory, and the OS should reclaim all the memory that your app used 
(whether it was 'leaked' or not).

More info: 
http://stackoverflow.com/questions/2975831/is-leaked-memory-freed-up-when-the-program-exits
 


Best,
Austin

> On Jun 1, 2016, at 9:13 AM, Adrian Zubarev via swift-users 
>  wrote:
> 
> I’ve got one more question that bothers me.
> 
> Lets say I’ve got a class that might look something like this:
> 
> class Reference {
>  
> var pointer: UnsafeMutablePointer
>  
> init(integer: Int) {
> self.pointer = UnsafeMutablePointer.alloc(1)
> self.pointer.initialize(integer)
> }
>  
> deinit {
> self.pointer.destroy(1)
> self.pointer.dealloc(1)
> }
> }
> Let talk about ARC here. If I use optionals here and release manually the 
> reference deinit will be called and we’re happy here:
> 
> var reference: Reference? = Reference(integer: 123456789)
> reference = nil
> If I don’t use optionals because I want my value to exist while the 
> application is running, deinit will never be called but my application 
> terminates just fine (SIGKILL?):
> 
> let reference = Reference(integer: 123456789)
> Doesn’t this create a memory leak?
> 
> How do I solve this problem, especially if don’t know whats inside the 
> Reference type (assume I’m a different developer who only has access to the 
> framework but not its implementation)?
> 
> 
> 
> 
> -- 
> Adrian Zubarev
> Sent with Airmail
> 
> Am 23. Mai 2016 um 18:31:43, Jordan Rose (jordan_r...@apple.com 
> ) schrieb:
> 
>> 
>>> On May 21, 2016, at 01:48, Adrian Zubarev via swift-users 
>>> > wrote:
>>> 
>>> I played around with UnsafeMutablePointer and realized one behavior:
>>> 
>>> let pString = UnsafeMutablePointer.alloc(1)
>>> pString.initialize("test")
>>> pString.predecessor().memory // will crash ax expected
>>> pString.predecessor() == pString.advancedBy(-1) // true
>>> pString.destroy()
>>> pString.dealloc(1)
>>> 
>>> where
>>> 
>>> let iInt = UnsafeMutablePointer.alloc(1)
>>> iInt.initialize("test")
>>> iInt.predecessor().memory // will not crash
>>> iInt.predecessor() == iInt.advancedBy(-1) // true
>>> iInt.predecessor().memory = 42 // did I just modified some memory I don't 
>>> own?
>>> iInt.destroy()
>>> iInt.dealloc(1)
>>> 
>>> Is this intended? This is really the case where its unsafe.
>>> 
>> 
>> Dmitri’s answers are all better for this specific discussion, but in 
>> general, “unsafe” in Swift means “if you don’t follow the rules, this may 
>> crash, may silently corrupt memory or do other bad things, may cause other 
>> code to be optimized out or miscompiled, may be harmless”. In this 
>> particular case, it’d be hard to check for the validity of the pointer while 
>> also being fast and binary-compatible with C.
>> 
>> Jordan
>> 
> 
> 
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Unsafe(Mutable)Pointer (suc)predecessor and advancedBy functions

2016-05-26 Thread Austin Zheng via swift-users
This is where it gets tricky.

When you create a chunk of memory using 'UnsafeMutablePointer.memory()' or
'alloc()', it's as if you are programming in C with 'malloc' and 'free'.
The memory you create and the objects you put in that memory don't
participate in ARC - the runtime will not track reference counts or
automatically free the memory. The memory will live on forever unless you
explicitly call 'dealloc()' later.

Using these APIs correctly is quite hard. If you're not careful you can
leak memory (if you lose all pointers before you've had a chance to call
dealloc), or access invalid memory (you called dealloc earlier, but
somewhere else you later access that memory). In a lot of cases a good
thing to do is to wrap your unsafe memory buffer inside a regular Swift
class, only allow the buffer to be accessed or modified through that class,
and have that class be responsible for deallocating the buffer when its
deinit is called. This way, you tie the lifetime of that buffer to your
Swift class and ARC handles the memory management for you.

Best,
Austin


On Thu, May 26, 2016 at 11:19 AM, Adrian Zubarev via swift-users <
swift-users@swift.org> wrote:

> It's also not clear sometimes exactly what "out of bounds" means - for
> example, you might have a big chunk of memory representing an array, and
> then you take a pointer to only part of that memory, representing a slice
> of the array. In this case you can write "out of bounds" of the slice, but
> the pointer type doesn't know that (because you are still within the range
> of the chunk of memory that you got from `UnsafeMutablePointer.memory()`).
>
>
> True story. :D
> Thank you for clarifying that to me, its a good example. Also the new
> pointer that I’ll get here won’t be a slice of an array just because
> `Memory` isn’t a slice. I’ll have to cast the pointer first, but I got the
> point here. ;)
>
> One more thing:
>
> - How does ARC work here when I create a new pointer to one of my
> allocated objects?
> - Do I have 2 strong references to my main piece of memory?
>
>
> --
> Adrian Zubarev
> Sent with Airmail
>
> Am 26. Mai 2016 bei 20:07:36, Austin Zheng (austinzh...@gmail.com)
> schrieb:
>
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users
>
>
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Unsafe(Mutable)Pointer (suc)predecessor and advancedBy functions

2016-05-26 Thread Austin Zheng via swift-users
On Thu, May 26, 2016 at 10:31 AM, Adrian Zubarev via swift-users <
swift-users@swift.org> wrote:

> So theoretically I could build a wrapper type for Unsafe(Mutable)Pointer
> which will be safe to use and never exceed the allocated range!
>
Yeah, if I remember correctly this is actually how the Swift collections
are implemented.

> public func successor() -> UnsafeMutablePointer? {
>
> // return `nil` if out of range
> }
>
>
>1. So why don’t we have safe pointers today?
>2. Any technical reasons or do I miss something here?!
>
> The check for safety imposes a performance cost, which may or may not be
okay.

It's also not clear sometimes exactly what "out of bounds" means - for
example, you might have a big chunk of memory representing an array, and
then you take a pointer to only part of that memory, representing a slice
of the array. In this case you can write "out of bounds" of the slice, but
the pointer type doesn't know that (because you are still within the range
of the chunk of memory that you got from `UnsafeMutablePointer.memory()`).

The way Swift has you do it is that you can do whatever you want with
pointers, but it's up to you to decide exactly what "in bounds" and "out of
bounds" means, and then wrap that all up in a wrapper type with the
appropriate checks. That way you can have the raw performance if you really
need it, and you can have safety otherwise.


>
>

> --
> Adrian Zubarev
> Sent with Airmail
>
> Am 26. Mai 2016 bei 19:14:41, Andrew Trick (atr...@apple.com) schrieb:
>
>
> On May 26, 2016, at 9:59 AM, Adrian Zubarev via swift-users <
> swift-users@swift.org> wrote:
>
> I’ve got one more questions about Unsafe(Mutable)Pointer. I know that I’m
> able to access memory that might not belong to me.
>
> My question is:
>
>-
>
>Can I trust these functions that they will return a pointer to some
>memory when I allocate more than one object AND when I’m moving only inside
>that range?
>
>
> Yes.
>
>
>-
>
>public func successor() -> UnsafeMutablePointer
>public func predecessor() -> UnsafeMutablePointer
>public func advancedBy(n: Int) -> UnsafeMutablePointer
>
>-
>
>UnsafeMutablePointer.alloc(4) when I advance only in range of
>[0,1,2,3] am I safe or could I get a pointer to memory that does not
>belong to me?
>
>
> UnsafeMutablePointer.alloc(N) creates a single object in memory that
> holds N consecutive T values. Each value resides at index*strideof(T.self)
> bytes beyond the allocated pointer where index is valid in the range 0..
> -Andy
>
>
>-
>
>Example:
>
>// imagine this is some memory portion,
>// where x is memory that does not belong to me
>// and 0 is moemory free to use
>
>[…, x, 0, 0, 0 x, 0, x, …]
>
>// now I want to allocate 4 objects
>// variant A:
>
>[…, x, MY1, MY2, MY3, x, MY4, x, …]
>
>// my pointer will sit at `MY1` and if I advance by 2 I'll get `x`
>// can this happen to me?
>
>// variant B:
>// Unsafe(Mutable)Pointer will ensure that I always get memory tied 
> together
>// (or the above functions will skip memory that doesn't belong to me??):
>
>
>[…, x, MY1, MY2, MY3, MY4 x, …]
>
>
> So which is right?
>
>
>
> --
> Adrian Zubarev
> Sent with Airmail
>
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users
>
>
>
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users
>
>
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Robotics with Swift

2016-05-08 Thread Austin Zheng via swift-users
This is great news! I have a BBB and a RC truck I've been meaning to build
a robot out of this summer, and this gives me an option to interface with
the hardware besides the Python interface.

Brad Larson (https://twitter.com/bradlarson) works at a company called
SonoPlot that makes robots for research applications, and I believe he's
written a few blog posts on how switching to Swift made the software
driving those robots more robust (e.g.
http://www.sunsetlakesoftware.com/2014/12/02/why-were-rewriting-our-robotics-software-swift
)

Austin

On Sun, May 8, 2016 at 6:14 PM, Jon Hoffman via swift-users <
swift-users@swift.org> wrote:

> Is there anyone interested in robotics with Swift?  I created a Swift
> library named SwiftyBones (https://github.com/hoffmanjon/SwiftyBones )
> for the BeagleBone Black to connect to the Digital GPIO, Analog IN and PWM
> pins and was interested in feedback on the library by anyone that is
> familiar with programming single board computers like the BeagleBone Black
> or Raspberry PI.  I am especially interested in feedback on the modular
> design and if it helps or hinders development.  I do have a shell script on
> the SwiftyBones github page that helps with compiling projects that has
> multiple source files.
>
> To see how SwiftyBones can be used for robotics, I created a reference
> project using the SwiftBones library.  The github page is here:
> https://github.com/hoffmanjon/SwiftyBones_BuddyBot .  To see the robot in
> action (definitely a work in progress) you can see the video on the latest
> blog post:
> http://myroboticadventure.blogspot.com/2016/05/the-first-robot-programmed-in-swift.html
>
>
> Thanks,
>
> Jon
>
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users
>
>
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


[swift-users] String initializers and developer ergonomics

2016-05-07 Thread Austin Zheng via swift-users
Hello Swift users,

I wanted to run something past you folks and get some opinions/feedback.

About a month ago on Hacker News I saw someone commenting about how Swift's 
string-handling code was unbearably slow (3 seconds to run a code sample, vs. 
0.8 in Java). I asked him to provide the code, and he obliged. Unfortunately, I 
didn't have time to dig into it until this morning. The code in its entirety 
can be found here: 
https://gist.github.com/austinzheng/d6c674780a58cb63832c4df3f809e683 


At line 26 we have the following code:

result.append(begin == eos ? "" : String(cs[begin..

However, the actual initializer being called was this String initializer in the 
Mirror code:

public init(_ instance: Subject)

This seems like a tricky gotcha for developers who aren't extremely familiar 
with both the String and reflection APIs. His code looked reasonable at a first 
glance and I didn't suspect anything was wrong until I profiled it. Even so, I 
only made the connection because I recognized the name of the standard library 
function from poking around inside the source files.

What do other people think? Is this something worth worrying about, or is it so 
rare that it shouldn't matter? Also, any suggestions as to how that code sample 
might be improved would be appreciated - my naive first attempt wasn't any 
better.

Best,
Austin


___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


[swift-users] Capturing references to initializers?

2015-12-10 Thread Austin Zheng via swift-users
Hello Swift users,

I have a question about capturing references to initializers. You can do
the following right now:

struct Foo {
let number : Int
// This type has a single initializer
init() {
number = 10
}
}

let a  = Foo.init  // a's type: () -> Foo

So far so good. Now, let's add in a second initializer:

extension Foo {
init(customNumber: Int) {
number = customNumber
}
}

Now, if you want to capture a reference to one of the initializers, you can
annotate the variable with the explicit function type:

let a : () -> Foo = Foo.init
let b : Int -> Foo = Foo.init

My question involves the case where you have multiple initializers that
take the same arguments and types. How would you capture initializers then?

extension Foo {
init(numberToInc: Int) {
number = numberToInc + 1
}
}

How do I capture a reference to the numberToInc: initializer, versus the
customNumber: initializer?

Best regards,
Austin
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users