[swift-evolution] Rewrite imported C function signatures
Carlos Rodriguez Dominguez
carlos at everywaretech.es
Sat Mar 26 05:37:18 CDT 2016
Well, the difference is that the compiler could produce a warning or error with fixit to indicate the developer that an alternative signature to the originally C imported one is available. This way, code ports should gain much readability, while not requiring much effort from the developer to make use of the newer signature.
El 26 mar 2016, a las 5:53, Brent Royal-Gordon <brent at architechies.com> escribió:
>> As you can observe, that old-style signature is highly error prone, does not comply with swift guidelines, it is difficult to understand, etc. My opinion is that there should be some syntax to rewrite the signature to avoid those issues. For instance, a possible syntax could be:
>>
>> #mapsignature(socket(_:,_:,_:)->Int32)
>> func socket(domain:SocketDomain, type:SocketType, protocol:SocketProtocol) -> socket_t? {
>> let result = socket(domain.rawValue, type.rawValue, protocol.rawValue)
>> if result == -1 {
>> return nil
>> }
>> else{
>> return result
>> }
>> }
>
> What's wrong with just overloading it like this without hiding the original? That way you can start by directly porting (perhaps even mechanically converting) the code and later refine it to use the nicer Swift-style overload.
>
> --
> Brent Royal-Gordon
> Architechies
>
More information about the swift-evolution
mailing list