MetaProgramming [and high level generic functionality in general] easier and simpler because you don't have Nanny State typing system complaining
That's wrong. I'm more confident that my abstractions are rock-solid (i.e., don't leak) when I use static types. But, ultimately, how well a language facilitates abstraction is a property of the whole design, rather than the type system (or lack thereof). There are both static and dynamic languages that lend themselves to abstraction (e.g., Haskell and Racket), as well as static and dynamic languages that don't (e.g., C and JavaScript).
90% of whether the abstractions will "leak" is about their design and not programming language implementation. If you are doing some "framework that does everything with minimal user input, like it's some kind of AI", then it's probably going to leak no matter what.
But when it comes to the implementation of something smaller, for example a 500-5000 lines long "tool" that uses metaprogramming techniques. If you write that and come 2 months later to "add some new requirement" to it, then with a dynamic language (or a statically typed language where you are using dynamic techniques) the whole thing will be easier to understand, and change a part in it to see how it behaves. With a static language you might change one small thing and get arcane compile errors in unrelated parts of the code. It's also very likely that the code will have a lot of boilerplate declarations, and that you might have to change them one by one to satisfy the compiler (even if the relevant change for the extra requirement was localized). This might sound easy, but if the compiler keeps giving the wrong errors, and you are still waiting to actualy program what you are supposed to, and you suspect that the compiler might force you to make global changes in the entire code over something that is supposed to be independent, you can lose your flow and be less productive in general.
90% of whether the abstractions will "leak" is about their design and not programming language implementation.
I'm not saying that it's impossible to make abstractions that don't leak in dynamic languages. Only that I find it easier in statically typed ones. Which specific statically typed language depends on the nature of the abstraction:
If I need to make the internal representation of values impossible to inspect by clients (e.g., not expose that heaps are implemented as, say, pairing heaps), then I want ML-style type abstraction.
If I need to control the usage of ephemeral resources (i.e., prevent leaks or uses-after-free), then a substructural type system (e.g., Rust's) is the right tool for the job.
Of course, other abstractions fit dynamic languages better:
If I want to use a language construct that isn't implemented in any existing programming language, but I don't want to implement a whole programming language from scratch, then the most sensible choice is using Racket's macro system, with its excellent facilities for syntax transformation while respecting variable scope. (Unlike Common Lisp or Clojure's defmacro, which is an abomination.)
If you are doing some "framework that does everything with minimal user input, like it's some kind of AI", then it's probably going to leak no matter what.
In general, I try to keep my goals modest. IMO, there's too much brokenness in the “little simple stuff” that ought to be perfect because everyone relies on it everyday, like standard library collections and algorithms. So I'm primarily working on that.
If you write that and come 2 months later to "add some new requirement" to it, then with a dynamic language the whole thing will be easier to understand, and change a part in it to see how it behaves.
By “understand”, you mean by “guess by trial and error”? I don't like that much.
With a static language you might change one small thing and get arcane compile errors in unrelated parts of the code.
The great benefit of static typing, properly done, is that it enables local reasoning about code. When I'm implementing a module, I don't need to care about anything else - I only bother type-checking the current module, and any other module that depends on it will only be fixed when I'm done with it.
It's also very likely that the code will have a lot of boilerplate declarations, and that you might have to change them one by one to satisfy the compiler (even if the relevant change for the extra requirement was localized).
My primary language of choice is Standard ML. I don't need to write many type annotations - only for consistency checking purposes at module boundaries. Type inference does 95% of the job.
This might sound easy, but if the compiler keeps giving the wrong errors,
By definition, a type error in a Standard ML program is a programmer error. The language's semantics assigns no meaning to untyped programs.
and you are still waiting to actualy program what you are supposed to, and you suspect that the compiler might force you to make global changes in the entire code over something that is supposed to be independent, you can lose your flow and be less productive in general.
My measurement of productivity is how long it takes me to write a flawless program. As in, no bugs. As mentioned above, my goal is to implement very simple stuff, but do it perfectly.
The great benefit of static typing, properly done, is that it enables local reasoning about code. When I'm implementing a module, I don't need to care about anything else - I only bother type-checking the current module, and any other module that depends on it will only be fixed when I'm done with it.
Well I don't think dynamic languages necessarily prohibit that. And the point was that type inference can get confused over something stupid and the compiler will show the error in some unrelated part of the code, it depends on the language though (afaik even a simple callback being syntactically wrong in c sharp can sometimes make the compiler show something unrelated)
But here is some other even more trivial example of how writing something "data driven" almost necessarily involves making some part of the code dynamic, and sometimes you'd better expand that part of the code.
Suppose that you have an orm that produces sql queries and only uses static techniques. Then using a filter makes it necessary that you will add an adaptation method that must change every time the filter or the schema changes, and which can be harder to compose with other transformations. And then using a simple "order by criterion" might need you doing the above, plus to add extra dummy fields in classes or something. Which makes the classes more difficult to understand and generally turns a large part the code, that could be automated in 20 minutes with an easy to use expansion point from which you could do things by hand, into boilerplate code, extra stuff on classes, and probably a more cumbersome way to override the above. Which is why most ORM frameworks will just give you the option to use a string expression. And it's not just some isolated case, a majority of the techniques that can reduce the code size using metaprogramming involve stuff like the above.
Well I don't think dynamic languages necessarily prohibit that.
Dynamic languages make it hard to delimit abstraction boundaries, so “focus on one thing at a time” is much more difficult to apply, at least if you care about the total absence of errors like I do.
And the point was that type inference can get confused over something stupid and the compiler will show the error in some unrelated part of the code, it depends on the language though (afaik even a simple callback being syntactically wrong in c sharp can sometimes make the compiler show something unrelated)
That's C#'s problem. The lack of structural types beyond generics indeed causes a lot of pain.
Suppose that you have an orm that produces sql queries and only uses static techniques. Then using a filter makes it necessary that you will add an adaptation method that must change every time the filter or the schema changes, and which can be harder to compose with other transformations.
ORMs themselves are ugly, because they attempt to reconcile fundamentally incompatible technologies:
The relational model is first-order, objects are higher-order.
The relational model emphasizes data, object-orientation emphasizes operations.
Relations (tables or queries) expose their internal structure, objects hide it.
Relations can be manipulated algebraically, objects have identity so few algebraic/equational laws hold, if any.
By the way, there exist (statically typed, of course) languages that integrate your database schema into the type-checking process, so your application never falls out of sync with the database. See: http://impredicative.com/ur/
Which is why most ORM frameworks will just give you the option to use a string expression. And it's not just some isolated case, a majority of the techniques that can reduce the code size using metaprogramming involve stuff like the above.
Yeah I tried to use the F Sharp one that had a type provider which automatically typed the whole database, and automatically typed every single sql select statement, but I abandoned it since it couldn't easily be used for dynamic queries, I mean without that functionality what's the freaking point?
And the fact that there is an orm mismatch doesn't really say anything about whether certain operations are easier to do without static typing, I assume you just incidentally wrote that.
but I abandoned it since it couldn't easily be used for dynamic queries, I mean without that functionality what's the freaking point?
Type providers aren't at all what I was talking about. And type providers themselves aren't really a fully static solution anyway. In Ur/Web, SQL queries a part of the syntax of the language, which is fully understood by the parser and type checker. Things like joining incompatible columns or using a column as if it had a different type than it actually has, these things are ruled out at compile-time.
And the fact that there is an orm mismatch doesn't really say anything about whether certain operations are easier to do without static typing, I assume you just incidentally wrote that.
Easier to do wrong? Yes. Easy to do right? I'm not so sure. I work on a gigantic ERP system where nested queries that join data from 10-15 tables aren't uncommon. If you want to get these things right, there's no practical solution other than static typing.
Lol 10-15 tables is gigantic? I work in a shitty ass erp related system and the average report query involves around 8 tables. I never saw the need for "static typing in sql queries", static typing might be needed in programs that rely on state mutation and reusing the same variables a lot, or when there are too many options that must be handled differently and you have to use something like the "agebric data types", or if there are rapid schema changes, but with retrieving relational data the first two don't make sense, and the 2nd can be handled without using too much pointless "safety" related bs.
I don't like and I'm not ever gonna bother the kind of code and model behind things like what you are linking, they are basically taking simple iterations over a dictionary's keys and turning it into something convoluted for essentialy little benefit. Unless it's supposed to be an entire language and not just for retrieving relational data, in which case it would make some sense.
static typing might be needed in programs that rely on state mutation and reusing the same variables a lot,
Like Haskell programs?
or when there are too many options that must be handled differently and you have to use something like the "a[l]gebr[a]ic data types",
Case-analysis arises in literally every program. You can't write a non-infinite loop without it. So a disciplined way to perform case-analysis is very much a necessity.
or if there are rapid schema changes,
Even without schema changes, static types can help you prevent things like, for example, joining tables using the wrong foreign keys.
but with retrieving relational data the first two don't make sense, and the 2nd can be handled without using too much pointless "safety" related bs.
How do you check, for 100% sure, that a function covers all the relevant cases? How do you check that the client of an abstraction doesn't depend on implementor choices that the the latter never intended to advertise?
I can't ensure 100% that a function does take care of all the cases, and I might indeed need to use something like the algebric data types if I really need to ensure correcntess, but I don't see how those techniques have any application with data retrieval specifically (bad sql commands will easily fail anyway), and they can also be difficult to use for some "data driven" parts of a program that might parse user input from somewhere and use it as a command, like with the order by key example I wrote above.
8
u/[deleted] Jun 12 '16
That's wrong. I'm more confident that my abstractions are rock-solid (i.e., don't leak) when I use static types. But, ultimately, how well a language facilitates abstraction is a property of the whole design, rather than the type system (or lack thereof). There are both static and dynamic languages that lend themselves to abstraction (e.g., Haskell and Racket), as well as static and dynamic languages that don't (e.g., C and JavaScript).