←back to thread

84 points mkalioby | 1 comments | | HN request time: 0s | source
Show context
maweki ◴[] No.42192775[source]
Embedding functionality into strings prevents any kind of static analysis. The same issue as embedding plain SQL, plain regexes, etc..

I am always in favor of declarative approaches where applicable. But whenever they are embedded in this way, you get this static analysis barrier and a possible mismatch between the imperative and declarative code, where you change a return type or field declaratively and it doesn't come up as an error in the surrounding code.

A positive example is VerbalExpressions in Java, which only allow expressing valid regular expressions and every invalid regular expression is inexpressible in valid java code. Jooq is another example, which makes incorrect (even incorrectly typed) SQL code inexpressible in Java.

I know python is a bit different, as there is no extensive static analysis in the compiler, but we do indeed have a lot of static analysis tools for python that could be valuable. A statically type-safe query is a wonderful thing for safety and maintainability and we do have good type-checkers for python.

replies(4): >>42193389 #>>42194000 #>>42194121 #>>42196401 #
eddd-ddde ◴[] No.42194121[source]
I disagree. You'll be surprised to hear this, but source code... is just a very big string...

If you can run static analysis on that you can run static analysis on string literals. Much like how C will give you warnings for mismatched printf arguments.

replies(1): >>42194391 #
maweki ◴[] No.42194391[source]
You might be surprised to hear that most compilers and static analysis tools in general do not inspect (string and other) literals, while they do indeed inspect all the other parts and structure of the abstract syntax tree.
replies(1): >>42195260 #
eddd-ddde ◴[] No.42195260[source]
I know, but that's the point, if you can get a string into an AST you can just do the same thing with the string literals. It's not magic.
replies(3): >>42195362 #>>42196090 #>>42196502 #
1. scott_w ◴[] No.42196090{3}[source]
Not in the standard language functions. If you wanted to achieve this, you have to write your own parser. That parser is, by definition, not the language parser, adding a level of difficulty to proving any correctness of your program.

There's a reason the term "stringly-typed" is used as a criticism of a language.