Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I agree that changing object state and having side effects should be avoided, but you can achieve both immutability and encapsulation very easily with C#:

    public record Thing()
    {
        private string _state = "Initial";
        public Thing Change() => this with { _state = "Changed" };
    }


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: