Coffeehouse Post

Single Post Permalink

View Thread: is managed code faster than native?
  • User profile image

    , Bass wrote

    It can't be that complicated to do a search for places a function is called? That's O(n lg n) on the size of the code base at best?

    For functions with instructions where each parameter is indirected from a type-fix point you have at least O(nmv) to resolve the function. If function lengths are independent of codebase size and type indirection grows with lg(n), this is O(n^2 lg(n)) at the very least, and that's assuming that the type of the parameter passed to the argument is transparently obvious what the type is. And as soon as you get a recursion loop or calls from external libraries the answer becomes undecidable ( pow($v, $n) { return ($n == 1)? 0 : pow($v,$n-1)*$v; } has indeterminate type to the compiler).

    I don't agree with letting code be more verbose to help the compiler. Isn't the point of programming languages to take needless complexity from the programmer? If we wanted to tell the computer everything, we'd be using assembly language.

    You assume that the types add verbosity to the language just to get performance gain. Static types let you discover problems with your code as well. Telling my compiler that I intend to return an array of doubles from this function and it being able to tell me that foo("2", 1)[0] is a double, not an array of doubles is something that helps me keep typos, errors and knock-on effects of changing internal functions (which potentially affects the correctness of the callers) to a minimum.

    Essentially static types are a really basic set of unit tests. They say "Hey - this function is going to return a double. So unit test it so that it can never return an array, or a file pointer".

    But unlike unit tests, it's a complete set of unit tests. The unit test covers all inputs and guarantees that the function will return something useful.

    I've done Java for awhile professionally.

    I feel sorry for you. Java is a terrible language, and I see how if you think all statically typed languages are like Java and all dynamic ones are like Ruby why you'd think that static languages suck. However, before you condemn all static languages, I'd like to point out that not all of them are so retarded and verbose for so little benefit.