Hacker News new | ask | show | jobs
by Dwedit 700 days ago
When you write a procedure that has to maintain an internal state between calls, changing it into a class makes sense. As for the name, you change the verb (write) into a noun (writer), and you now have a name for the class.

C# will silently create hidden closure classes for you when you use lambdas or yield.

2 comments

Just know that if you do this, you’re injecting statefulness in the center of wherever it was this procedure was being used. If your entire system already has statefulness everywhere, nobody will bet an eye. But if you want to have any chance at creating a functional core or island, it’s the opposite of what you should be doing.
When you write a procedure that has to maintain an internal state between calls, stopping what you're doing and switching to functional programming makes sense.