Re: Why is java considered a language for "web" or "internet" programming?




Mishagam wrote:

By the way, some interpreted/dynamically typed languages, perform comparably well to the old, "fastest language", C. Lisp, for example.

I assume this is the sentence your comment is about?

But all scripting languages will still work with integer as object, will be still in bytecode, and will be I assume at the least 10 times slower, I would think more like 50 time slower.

I am very curious as to where you have this information from, please provide some references.

But in any case, you would be right in that writing a number cruncher in a dynamically typed language is not very smart or efficient (I would use C. If you want real number crunching performance, such as in weather forecasting, Fortran would be your friend). Most applications are not number crunchers and therefore the claim is not very relevant.

I assume what you think is happening is that whenever a variable is used the interpreter has to run through a large if-then-else statement to decide the data type and that that is what will take time. But this is not so, at least not for perl.

When perl stores a number in a variable it also decides the data type of the variable and stores that information as well. So when you use a variable in an expression, it first recognises the context as being an numerical operation and performs a bitwise test to check the data type of the variable. This is done by accessing a memory address, which is cached in L1 cache). If the data type is correct for the context, the operation proceeds as normal. If not, a conversion is performed. So the penalty is a couple of clock cycles. This does not add up to much in a typical application, because of how modern processors work today.

A small perl internals tip, when a numerical variable is used in a string context and the value is converted to string, the converted string is cached in the variable object so as to not have to perform the conversion again later on. I don't think java or any statically typed languages does that. This is also true for the reverse case.

You should not focus on micro-optimalisations alone. There are many benefits and disadvantages of any language, what you need to look is the overall performance, and you might also want to include the programmer performance and maintenance performance into the equation.

tom
.



Relevant Pages

  • Re: VB6, VB2005, or Something Else?
    ... Do not confuse language issues with implementation issues. ... which automatically convert to any native data type. ... conversion if you pass an integer to a function needing a string. ... always be platform sensitive to some degree. ...
    (microsoft.public.vb.general.discussion)
  • Re: VB6, VB2005, or Something Else?
    ... When using a string within MS Basic for example you do not know how it is maintained nor should you. ... I more referred to the variables which don't have a specified type, which automatically convert to any native data type. ... That is perhaps a language issue, rather a COM issue, but let's say - this data types are behaving like a COM variant in C++. ... But the main reason is that the platforms are very different and need different coding to get the most out of them. ...
    (microsoft.public.vb.general.discussion)
  • Re: Static vs. Dynamic typing (big advantage or not)---WAS: c.programming: OOP and memory management
    ... runtime of the language attempt to convert the rvalue to something ... (or attempt to interpret the string as a number?) ... A warning in 1) is pointless: if the programmer knows what he's doing, ... conversion might fail; ...
    (comp.object)
  • Re: Static vs. Dynamic typing (big advantage or not)---WAS: c.programming: OOP and memory management
    ... runtime of the language attempt to convert the rvalue to something ... (or attempt to interpret the string as a number?) ... A warning in 1) is pointless: if the programmer knows what he's doing, ... conversion might fail; ...
    (comp.programming)
  • Re: What does Val return?
    ... that the data type of the returned value will automatically converted ... Dim myString as String ... so I suspect that the initial return of the Val function ... I'm not sure it's worth writing an explicit CLng conversion. ...
    (microsoft.public.word.vba.general)