Carmack about static analysis

James Miller james at aatch.net
Mon Feb 13 01:42:03 PST 2012


I find that dynamic typing is useful sometimes and static typing other
times. Certainly dynamic (duck) typing is useful for scripts and
similar, and static typing is certainly better for writing code that
is especially picky about its values. I liken it to the way I write
code in PHP, the front-end stuff is written to cover 90% of the use
cases, and I hope that it doesn't fail (it shouldn't unless they do
try to break the site), but if it does, I hear about it because people
are going to submit tickets about it. For any backend code, crons for
example, I always write super-tight double and triple-checked code
because there's not going to be a pissed customer immediately on my
ass if something fails.

I find that given the choice, I'd prefer static typing, since it
matches the way I reason about code, "This function takes two integers
and a string and returns a string", but being weighed down by types
for small programs is annoying.

On 11 February 2012 13:59, bearophile <bearophileHUGS at lycos.com> wrote:
> Jonathan M Davis:
>
>> I just can't stand the idea that whether an if statement is true or not could
>> change the type of a variable (e.g. it's set to a string in one branch and an
>> int in the other).
>
> You have found something that sometimes I like to do in Python, that I can't do in D, a reduced example:
>
>
> import std.stdio;
>
> int findSolution() {
>    return -2;
> }
>
> void main() {
>    int x = findSolution();
>    writeln(x >= 0 ? x : "Solution not found.");
> }
>
> There are of course ways to perform to do the same in D too, but for me this is the most natural way to express that intent.
>
>
>> I consider dynamic typing to be a _huge_ negative. It may
>> be fine for short scripts and the like, but I'll never write anything serious
>> using a dynamically typed language if I can avoid it.
>
> If you try to add static typing to something like the Mathematica Language (that is a Lisp variant) you produce something that's probably unusable for those exploratory programming / mathematical purposes.
>
> Racket has recently added a Typed Scheme, it uses gradual typing. You are able to add types to some functions of your program, and to use very specific types or more general ones as type constraints. They have even added a way to perform dynamic typing in C# (and it's way more than just having a variant type, they have had to change many things to implement it). I think the programming world is moving a bit toward a mix of static and dynamic typing (and a mix of functional and imperative/OOP programming).
>
> Bye,
> bearophile


More information about the Digitalmars-d mailing list