Friday, December 7, 2007

The Myth of Dynamic Typing?

My last post has also got me thinking about a different idea (dynamic programming paradigms), and I have begun to think about this topic as programming languages versus scripting languages. I personally prefer programming languages, but I can't deny the power of scripting languages. I've often heard that the power of scripting languages comes from dynamic typing and the ability to give any variable of any type to a function and let it do it's thing. But I think this is flawed logic, because at some point the type becomes fixed and the appropriate algorithm must be used to handle this data. So dynamic typing is just a convenience for the programmer that abstracts away a piece of the truth. And now you have to ask yourself, "Why couldn't this same mechanism be done with templates, functional programming, and other mechanisms in a programming language?" The correct answer is that there's no reason it couldn't be.

I think that the problem is not that the programming languages are compiled, statically typed, or any of the other non-sense that you always hear, but the problem is simply what we expect from them. We expect a language like C/C++ to be low-level, operating system agnostic, and portable without any of the "mess" of GUIs, rendering capabilities, etc. But we expect a language like MATLAB/Python to be high-level, operating system agnostic, and portable with all of the "power" of GUIs, rendering capabilities, etc. Each of these paradigms definitely has it's own pros/cons, but I just think that the divide that exists between the two doesn't necessarily have to be as big as it is right now.

This also brings up the real topic that I am actually interested in, "Why can't databases (and their results) be statically-typed?" Why can't I do something like this:

struct Transaction
unsigned int id; //Primary Key
Date date;
DecimalValue amount;
std::string description;

struct BudgetCategory
unsigned int id; //Primary Key
std::string name;
DecimalValue budgeted_spending;
PaymentType frequency;

struct Transaction_BudgetCategory
unsigned int transaction_id; //Foreign Key(
unsigned int budgetcategory_id; //Foreign Key(

auto_type category_sums =
SELECT, sum(Transaction.amount)
FROM Transaction_BudgetCategory, Transaction

Obviously I'm talking about a whole new language/paradigm, but why couldn't you do something like that? The compiler could figure out the appropriate types and create the appropriate structure for you. I know that this is kind of what LINQ is trying to do, but my understanding is that with LINQ you have to create your own structures to store the results in, and why can't the compiler just do it for you?

Maybe I'm just dreaming or not seeing the drawbacks to something like this, but I still think it'd be cool.

No comments: