Hacker News new | ask | show | jobs
by cx1000 2960 days ago
Hypothesis 1: All successful dynamically-typed programs eventually grow large enough to get rewritten or retrofitted with static types.

Hypothesis 2: All successful statically-typed languages eventually grow large enough to have a dynamically typed scripting language embedded in them.

https://twitter.com/munificentbob/status/988555364252631040

3 comments

I don't see a contradiction here. (speaking as a Python and Haskell user):

1 - dynamic languages, while granting great freedom, make it easy to shoot yourself in the foot with simple typing bugs, so we cope by adding type checking

2 - many (most?) static type systems are not expressive enough to type some programs, so people embed dynamic solutions to build the stuff they need.

Haskell is pretty decent at typing most stuff I want, but it makes me think about it up front, which is nice sometimes, but not always. Python lets me build stuff quickly and work out the design as I go, but it's hard to make sure everything works as intended. I wish there was something that let me bodge things together, but then constrain them with types when I need to...

Python 3.6 introduced type checking as an option, so you can hack something together in Python, then add types later.
Type hints aren't checked or enforced by the compiler. They're really just special-syntax comments to help the developer (or IDE, as the case may be). I wouldn't call this "type checking".
You can run a type-checking tool (e.g. mypy) which will tell you if you've made any type errors.

Since Python has no 'compile' step, type-checking takes the place of compiling in other languages.

I'm using the type annotations from `typing` in a Python 3.5 project I'm working on, but only as a form of documentation. Unfortunately mypy doesn't work for me – the project heavily uses a namedtuple-style sum type library, and I haven't found a way to make the types it generates work with mypy.

(iirc mypy has builtin support for namedtuple, but doesn't really support other types generated at runtime)

I'm surprised nobody has mentioned Greenspun's tenth rule: https://en.m.wikipedia.org/wiki/Greenspun%27s_tenth_rule
That's probably because it has been quoted enough times to come to provoke nausea, and is just wrong.
While I see a lot of examples of 1), I can't think of one for 2). Which successful statically-typed language has that?
Lua is an example for the C-type languages, and Groovy is an example for Java.
Beanshell is another example for Java, and did it before Apache Groovy did. Beanshell added features like optional typing and terse property syntax to Java, then Groovy extended Beanshell by adding closures to Java. Java has made these scripting languages less relevant lately because of more recent features like lambdas and inferred types.
C++ and JavaScript in the browser that you're using to read this would be a good example of #2.
For 2, I should have said "programs written in statically-typed languages". Oops.

Examples are most text editors: emacs (elisp), Sublime Text (Python), Vim (VimScript), Atom (JavaScript). Many games and game engines: World of WarCraft (Lua), Unreal (UnrealScript), SCUMM, etc.

I'm guessing you meant these hypotheses to seem paradoxical (i.e., dynamic code bases are rewritten in static languages to improve maintainability; static code bases are rewritten in dynamic languages to improve maintainability), but I don't think they are.

Dynamic codebases are rewritten in static languages to improve maintainability and code quality; programs written in static languages include an interpreter as a feature that supports user-defined programs, e.g., a browser's JS engine or emac's text editor and also for specialty domains where code quality is less important than developer velocity and the static language of choice is unnecessarily painful (games).

Assuming I didn't misrepresent your thesis, does this seem more or less accurate to you?

No, I actually didn't intend them to be paradoxical.

My feeling is that statically-typed languages and dynamically-typed languages are each better suited for certain kinds of problems. The former gives you better performance, long-term maintainability, and scales to larger programs. The latter gives you a faster iteration loop, is easier to learn, and is easier to dynamically load.

I think what happens is that any sufficiently large program covers so many different requirements that eventually different parts of the program are best implemented in different styles of language.

If you start statically-typed, you eventually get bogged down by the slow compile-reload cycle, need to dynamically load user-defined code, or what to express parts of the program in something higher level or more declarative. So you end up embedding a scripting or configuration language.

If you start dynamically-typed, eventually your program grows to the point that you either can't maintain it or it isn't fast enough, so you end up trying to bolt a type system onto your existing code or rewriting parts of it in a statically-typed language.

I think the costs for the latter are usually higher than the costs for the former, so I tend to lean towards starting statically-typed, but that's also because I'm comfortable using types.

Ah, thanks for clearing that up. I forgot compilation can take a while. I used to write C++, but the only compiled language I've worked seriously with in the last several years has been Go, which tends to compile in about the same time it takes a Python program to load its imports.
UnrealScrip is explicitly said to be both statically typed and inspired by Java a lot[0][1]. It just had lots of language features dedicated to the game, like networking, state machines, being preemptively multitasked, integration with the editor, etc.

Lua is of course popular and the topic of using it in games has been done to death: Love2D, Grim Fandango, Don't Starve, Cry Engine, Garry's Mod, etc.

Eve Online supposedly uses Stackless Python and I've seen Vampire the Masquerade Bloodlines (early Source engine) use Python.

Valve's wiki lists Squirrel, Lua, Python and Gamemonkey and they are all dynamic but I think Squirrel is the top language there.

I've also seen Angel Script in HPL1 (the Penumbra series by frictional) but it's another static scripting language and it markets this as a feature.

Unity of course has its C# 'scripts' which are static and I found the idea of scripting in such a behemoth of a language very novel when I've first seen it (yes, UnityScript has dynamic capabilities but it has static ones too and most of the users seem to be with C#).

SCUMM (and Z machine and similar) is a very weird case because it seems more like a script in the sense of a scene play (and the S might stand for script but they were naming utilities after gross stuff like CYST, MMUCUS, etc. so it might be shoehorned), not actual programming language, it's tied to the engine/game/genre/assets way more strongly than even Unreal Script was but I didn't do anything with SCUMM so I can't actually say for sure what would happen if you wrote something that didn't make sense (like tell a table to walk somewhere or reference an object or animation or something else that doesn't exist).

Many Naughty Dog games (including Crash Bandicoot games on PS1 which is frankly insane) also used their own Lisp inspired by Scheme called GOOL and then GOAL but I'm not sure how dynamic it was.

There's also a subtle line between embedding a language to make yourself scriptable and making yourself a library written in mix of C, C++ and that language and there is an interesting article on that[3].

GIMP also includes (or used to?) something related to Scheme/Lisp and has a system in place to support multiple scripting languages at once and calls between any of them called Procedural DataBase. Adobe Lightroom includes Lua too.

Id tech engines apparently used another language/technique each major engine version and I don't know the specifics of it at all.

I'm quite interested in the topic of extending applications (and specifically games) in various scripting languages, plugin systems, etc. but I'd not say all static programs grow dynamic scripting capabilities since AngelScript, Pascal Script (:D), Unreal Script and C# are all static 'scripting' languages and scripting in general is about 'scripting' (as in - small or big bits of code that is easy to change and safe to experiment with modifying a larger program in small or big ways), not necessarily dynamic programming (e.g. you could in theory every viably have Lua scripts in a larger Python program or even AngelScript scripts in a Python program to really mix it up and script a dynamic program with a static scripting language). You could also extend a C or C++ program with traditional 1990s/2000s style 'plugins' written in almost anything that can get the required ABI out into a dll/so and load, unload, reload, etc. those at runtime without stopping the main program.

[0] - https://wiki.beyondunreal.com/UnrealScript

[1] - https://api.unrealengine.com/udk/Three/UnrealScriptReference...

[3] - https://twistedmatrix.com/users/glyph/rant/extendit.html

Maybe not languages but certainly frameworks, like Qt and many others, offer a dynamic language layer on top of the C++ or other static language.
Though more "inferred" types rather than dynamic types, scala does allow you to do:

  val s = "String"
Rather than the more strict:

  val s:String = "String"
Type inference has nothing to do with dynamic typing.
I had no idea what you were talking about, so I did my own research (ie - googled "type inference vs dynamic typing") and I stand corrected.

https://herbsutter.com/2008/06/20/type-inference-vs-staticdy...

C and C++ are the basis for Python (CPython) and JavaScript, respectively. Lua was written in C.
I can't think of 2 as written.

But big, successful programs will often do (2).

C# has had a dynamic type built in for years now. It's literally a dynamically typed language embedded within the statically typed C#,which grew out of the work on gradual type systems.
dynamic is just based on COM variant type, before .NET even existed.
C#'s dynamic type has nothing to do with COM.
It shows you never had to implement COM interfaces for Visual Basic Variant type via the IDispatch interface.

https://msdn.microsoft.com/en-us/library/windows/desktop/ms2...

The way dynamic is implemented is exactly following the same idea using DynamicObject instead of IDispatch.

https://docs.microsoft.com/en-us/dotnet/api/system.dynamic.d...

And if you actually bother to read MSDN documentation, one of the use cases for dynamic was to simplify COM automation interop.

https://blogs.msdn.microsoft.com/srivatsn/2008/02/04/dynamic...

https://docs.microsoft.com/en-us/dotnet/csharp/language-refe...

C# `var` syntax, ExpandoObject and the rest of System.Dynamic
C# `var` variables are statically-typed, not dynamically.

Not having to write down the type isn't the same as the type not being determined at compile time, which is what "static" means.