Lurker News

Comments (191) 32 threads

Show all comments

Showing thread 1 of 32

chrismorgan3 replies#
I’m impressed/fascinated/horrified by the way it parses a string into a type with a variant of template literal syntax—though it looks like the parsing is probably very fragile. I’m curious why that functionality was added to the language.

The end result is actually pretty approachable.

phpnode1 reply#
it's a bit fragile only due to my laziness, it could be done properly if this were a serious project.
3np1 reply#
How would it be done if done properly?
phpnode#
same mechanism, just deal with more edge cases. e.g. whitespace isn't really trimmed correctly at the moment, it doesn't handle escaping quotes in strings and so on. I did think about trying to match postgres's grammar but it's a lot of work and probably implementing a PEG first would make it easier.
nicoburns1 reply#
> I’m curious why that functionality was added to the language.

I think it's because there are a whole bunch of APIs in javascript where there is a function like `.get("foo")` that internally calls a function called `getFoo` or similar. And this functionality allows such functions to be accurately typed. It basically allows strong typing for stringly typed functions (which are pretty common in dynamic languages)

ianhorn1 reply#
Stringly typed functions frustrate me to no end. Tooling for programming gets better every year, yet stringly typed code is so resistant to any of those improvements. Pycharm at some point had to add SQL tools in python strings for gods sake. That kind of weird deep special casing is everywhere with strings drive behavior. Why use a class (inspectable) when a dictionary, a function, and an if statement (opaque) will do?
AlphaSite#
I think they implemented a generic nested language framework (whose real name eludes me).