News for hackers. Stuff that matters.
Re:Context: The Missing Feature of Programming Languages by duped on Monday March 25, 2024 @11:12AM (#39817309)
LISPs had dynamic scoping for this decades ago and it fell out of fashion. I think a large part of that is because in practice it turns the code into spaghetti, and you can make it much simpler by just adding the "context" as a function argument. No special language features needed.
Re:Context: The Missing Feature of Programming Languages by rtz121 on Monday March 25, 2024 @12:40PM (#39818441)
Dynamic scope is still very useful for some things. But it's certainly way over-used in a lot of the old Emacs libraries for example.
Re:Context: The Missing Feature of Programming Languages by jdougan on Monday March 25, 2024 @10:03PM (#39823571)
When everything is scoped dynamically, it is indeed a problem. If you only have a handful of things with a clear syntactic mechanism to indicate when they are being used? Much clearer.

I impkemented a slow version of contexts in Smalltalk, just to see how bad it was. Where it shone was in places where you can't pass a context as an arg (eg. binary math operators) either for compatibility reasons or because passing the context would be too noisy.

Re:Context: The Missing Feature of Programming Languages by duped on Tuesday March 26, 2024 @12:10AM (#39824209)
I disagree it's clearer, because it's a spooky action at a distance. An analog are thread locals, which have the same characteristics of a dynamically scoped variable.

I've found dynamic scoping useful so few times I can count them on one hand, and while it's an intriguing feature, I think it makes a lot of sense to use a more explicit abstraction. For example, you shouldn't need dynamic scoping for overloading binary operators - you should have a more clear method that takes a context as an argument instead.

Context is external state, and it's extremely surprising when a fundamental operator like "+" modifies it.