Hacker News new | ask | show | jobs
by mtdewcmu 4387 days ago
A closure is syntactic sugar for a function plus a struct. Sometimes I think they would be a useful addition to C. But these kinds of things never turn out to be as useful as they seem at first.
1 comments

That's true in a hand-wavey sense, but it ignores that function+struct means you have to define new types, include those types everywhere your closure is used, manage the lifetime and scope of those types, etc. etc.

I would argue the opposite: these things are actually way more useful than they seem at first. The fewer things the language makes you think about, the more you can focus on what you're trying to actually do.

It's true literally.[1] If the language was designed around closures that's one thing. In C, it would be one language paradigm too many.

If you want a language with closures, and all you have is C, the time-honored solution is to write an interpreter and give the interpreted language closures. That is a good way to go.

[1] http://matt.might.net/articles/compiling-scheme-to-c/