godot-swift icon indicating copy to clipboard operation
godot-swift copied to clipboard

Code style guide question

Open SpectralDragon opened this issue 3 years ago • 4 comments

Why your examples and docs code using C# style guide instead of swift way

https://google.github.io/swift/

or

https://github.com/raywenderlich/swift-style-guide

SpectralDragon avatar Jul 07 '21 09:07 SpectralDragon

I imagine this has to do with following closely to Godot's APIs for game developers using Godot that also want to use Swift (not to be confused with Swift developers that want to use Godot).

I assume this will change a bit over time, though.

alicerunsonfedora avatar Jul 08 '21 18:07 alicerunsonfedora

can you give specific examples?

tayloraswift avatar Jul 12 '21 17:07 tayloraswift

can you give specific examples?

It took me a minute to realize, but I think they're referring to the sample bits of code used in the documentation.

As a example, currently, we have this on the README:

final 
class MySwiftClass:Godot.NativeScript
{
    var foo:Int = 5
    
    init(delegate _:Godot.Unmanaged.Spatial)
    {
    }
    func bar(delegate _:Godot.Unmanaged.Spatial, x:Int) -> Int 
    {
        self.foo * x
    }
    
    @Interface 
    static var interface:Interface 
    {
        Interface.properties 
        {
            \.foo <- "foo"
        }
        Interface.methods 
        {
            bar(delegate:x:) <- "bar"
        }
    }
}

extension Godot.Library 
{
    @Interface 
    static var interface:Interface 
    {
        MySwiftClass.self <- "MyExportedSwiftClass"
    }
}

Where most Swift style guides would write the same code as:

final class MySwiftClass: Godot.NativeScript {
    var foo: Int = 5
    
    init(delegate _: Godot.Unmanaged.Spatial) {}
    
    func bar(delegate _: Godot.Unmanaged.Spatial, x: Int) -> Int {
        self.foo * x
    }
    
    @Interface static var interface: Interface {
        Interface.properties {
            \.foo <- "foo"
        }
        Interface.methods {
            bar(delegate: x:) <- "bar"
        }
    }
}

extension Godot.Library {
    @Interface static var interface:Interface {
        MySwiftClass.self <- "MyExportedSwiftClass"
    }
}

alicerunsonfedora avatar Jul 12 '21 19:07 alicerunsonfedora

Exactly ^ gave me the impression that some non-Swift programmer made the Swift plugin - which is impressive :p btw I really hope @kelvin13 can keep up the effort and make this mature - thank you!

hyouuu avatar Jul 12 '21 22:07 hyouuu