Saturday, March 22, 2008

Static vs Dynamic Typing II

After receiving feedback and reading more about it, I'm coming to the conclusion that static vs dynamic typing has more to do with writing code, lines of code, and the benefits of run time checking vs compile time checking. Static and dynamic typing classify values and expressions into types differently. Java is statically typed and Ruby is dynamically typed. It seems like a program written in Java will contain more lines of code then the exact same program written in Ruby. This is because of the type checking. I'm not familiar with Ruby yet, but, supposedly you have the ability to write less code because all of the code dealing with the types of objects and casting will be removed. The run time check seems to give more flexibility when writing the program and dealing with types. Static typing, with compile time checking, allows program errors to be caught earlier and program execution to be more efficient. Dynamic typing, with run time checking, is more flexible although slower running and more prone to program errors.

1 comment:

aaron said...

james just shared this: Part of being a good programmer is learning not to trust yourself

in that article the author writes


2) Turn Assumptions into Compiler Errors

This is most effective when coding in C++. Occasionally I run into a situation where we find certain classes are invalid inputs to a template, function, etc ... The best way to prevent using the type in the wrong context is to turn it into a compiler error. Typically this is accomplished with a combination of macros and templates. It's not pretty, but catching an error at compile time is the cheapest way. You can't ship a bug that doesn't compile.


i think thats a good argument for static typing. it is a lot cheaper to find bugs during compile time. i await a response from austen. :)