Comparing statically typed code with dynamically typed code - costs and benefits

Whatever its merits, Adobe ActionScript 3 presents a unique opportunity to investigate the implications of typed or untyped languages, because it is a fairly strict superset of javascript with all the syntactic benefits / overheads of strict type declarations, declarative casting, etc.

What this makes possible is comparing the same code, written in both directions, and factoring in the syntax of the host language.

This makes me wonder if there is quantitative evidence on the real benefits of strong typing, particularly for compile-time error checking in terms of error rates, programming performance, and code footprint; or are our perspectives entirely based on assumptions and assumptions? Are there any other languages ​​that can be used both ways (other than old-fashioned VB - not a very respected language anyway.)

I have spent considerable time on both languages, but have not finally decided which way I prefer, and I would rather not add to the anecdotal evidence - I am looking for objective information.

0


source to share


6 answers


This is one of the great religious wars in programming, surpassing perhaps only the conflict between one True Editor EMACS and the evil offspring of Satan vi.

Basically, if a program written in a dynamic language is correct, then it can be converted to a statically typed language and still be correct, and vice versa. The advantage of a truly statically typed langfuage is that errors that appear at runtime in a dynamic language can be identified at compile time in a statically typed language.



What is often ignored in these situations, however, is that statically typed languages ​​generally have escape hatches (such as type tricks), and it seems that dynamic languages ​​can use type inference for inference and be treated as statically typed types of an explicitly dynamic expression.

What's really important, under the covers, is the programmer. If the programmer thinks about the program correctly, then it will be correct either in a static or dynamic language. I don't know of any good experimental evidence that one is more productive or more error prone in practice.

+1


source


In my opinion, strongly typed languages ​​such as C # can identify many missed errors at compile time that would not be caught in a fluent typed language and therefore cause a runtime error afterwards. I don't think this is just speculation, as strict compilation can anticipate problems that can subsequently cause run-time errors. This can potentially eliminate most of the types of coding eons that you miss during implementation, but which can be easily found and fixed by the compiler.



+1


source


The meaning of static typing strikes me as very limited if you think that I cannot say that something is true for a piece of software, unless you have a test to demonstrate that it is. If you accept and practice this, then it pretty much doesn't matter if the bugs were found at compile time or during testing.

At this point, I would have preferred the more concise language of the two types of languages, which in my experience were dynamic languages.

The flip side is that static typing really helps you if you're not writing tests. In this case, static typing is probably not enough to make your software work properly.

+1


source


OP and felipecsl are confused about the terminology used when talking about a set of disciplines.

Static Typing means that types are checked at compile time (regardless of compile time in the language). Dynamic Typing means that types are checked as expressions / statements are executed. Strong typing means that you cannot, for example, disallow (distinguish) a pointer to an integer. A weak seal is the opposite of a strong seal. In the meantime, there is no need to worry about it. ”

As far as I know, there is no "strong typing".

Now for someone else to answer the actual question; -)

0


source


The weak type requires more maintenance time. As programs get more complex, more problems arise due to the lack of a compiler to identify obvious problems. Not recommended for large complex projects. I speak from experience.

0


source


Statistically typical language. Have variables and xpressions as fixed types that are explicitly specified by the programmer or inferred. Compiler using this. Info, type checking here will be done at compile time. Whereas dynamically typed langs are fixed their values, but variables and xxpressions arent fixed. Dat facct that when ever an operand is evaluated it will probably return different values, then the type checking is done after the operand has been evaluated. after calculation, but before the operation is performed at runtime

-1


source







All Articles