News for hackers. Stuff that matters.
Re:Porting 4.5K lines of C to Go by DelightOne on Saturday August 05, 2017 @05:33AM (#14934950)
Souns like get/set in swift for me. Does it have computed properties too?
Re:Porting 4.5K lines of C to Go by taspeotis on Saturday August 05, 2017 @06:17AM (#14935060)

    public double Area
    {
        get { return Width * Height; }

        set
        {
            Width = Math.Sqrt(value);
            Height = Width;
        }
    }
You can also use expression bodied members (that's the => syntax) with get/set. There's a shorthand if you only need to define the getter (i.e. read-only):

    public double Area => Width * Height;
Re:Porting 4.5K lines of C to Go by DelightOne on Saturday August 05, 2017 @08:28AM (#14935389)
Swift has the same syntax too except the last line.

Have they introducted willSet and didSet too?

Neat stuff, i may try the language out in a future project on windows.

Re:Porting 4.5K lines of C to Go by taspeotis on Saturday August 05, 2017 @09:26AM (#14935554)
There's no direct equivalent to willSet or didSet. The closest equivalent (aside from adding code before/after your own get/set code) might be INotifyPropertyChanged [1]/INotifyPropertyChanging [2]? But they are more for external observers and add a lot of boilerplate to your code. It's possible to manage the boilerplate, however [3].

[1] https://msdn.microsoft.com/en-us/library/system.componentmod...

[2] https://msdn.microsoft.com/en-us/library/system.componentmod...

[3] https://github.com/Fody/PropertyChanged