6 ms·
Hypothesis 1: All successful dynamically-typed programs eventually grow large enough to get rewritten or retrofitted with static types. Hypothesis 2: All succe
by cx1000 8y 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 https://twitter.com/munificentbob/status/988555364252631040
- dudul 8y agoWhile I see a lot of examples of 1), I can't think of one for 2). Which successful statically-typed language has that?
- cx1000 8y agoC and C++ are the basis for Python (CPython) and JavaScript, respectively. Lua was written in C.
- philwelch 8y agoLua is an example for the C-type languages, and Groovy is an example for Java.
- vorg 8y agoBeanshell 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.
- outworlder 8y agoI can't think of 2 as written. But big, successful programs will often do (2).
- naasking 8y agoC# 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.
- pjmlp 8y agodynamic is just based on COM variant type, before .NET even existed.
- naasking 8y agoC#'s dynamic type has nothing to do with COM.
- pjmlp 8y agoIt 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/ms221608(v=vs.85).aspx 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.dynamicobject?view=netframework-4.7.2 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-dispatch-in-c/ https://blogs.msdn.microsoft.com/srivatsn/2008/02/04/dynamic... https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/dynamic https://docs.microsoft.com/en-us/dotnet/csharp/language-refe...
- naasking 8y agoThat's not why the dynamic type was created, that was just one side benefit. The dynamic type grew out of the IronPython effort which grew into the DLR in order to better support dynamically typed languages on the CLR, by having reusable polymorphic inline caching for efficient dispatch. COM integration with the CLR has existed since the beginning, which I used quite extensively many years ago, they just took advantage of the DLR to make it easier.
- kentosi 8y agoThough 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"
- dudul 8y agoType inference has nothing to do with dynamic typing.
- kentosi 8y agoI 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-staticdynamic-typing/ https://herbsutter.com/2008/06/20/type-inference-vs-staticdy...
- hellofunk 8y agoMaybe not languages but certainly frameworks, like Qt and many others, offer a dynamic language layer on top of the C++ or other static language.
- munificent 8y agoFor 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.
- weberc2 8y agoI'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?
- munificent 8y agoNo, 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.
- deleted 8y ago[deleted]
- cgdub 8y agoC++ and JavaScript in the browser that you're using to read this would be a good example of #2.
- NegativeLatency 8y agoC# `var` syntax, ExpandoObject and the rest of System.Dynamic
- umanwizard 8y agoC# `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.
- NegativeLatency 8y agoJava, ScriptEngineManager https://docs.oracle.com/javase/7/docs/api/javax/script/ScriptEngineManager.html https://docs.oracle.com/javase/7/docs/api/javax/script/Scrip...
- uryga 8y agoI 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...
- Tijdreiziger 8y agoPython 3.6 introduced type checking as an option, so you can hack something together in Python, then add types later.
- DonaldPShimoda 8y agoType 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".
- Tijdreiziger 8y agoYou 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.
- uryga 8y agoI'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)
- tcbawo 8y agoI'm surprised nobody has mentioned Greenspun's tenth rule: https://en.m.wikipedia.org/wiki/Greenspun%27s_tenth_rule https://en.m.wikipedia.org/wiki/Greenspun%27s_tenth_rule
- gkya 8y agoThat's probably because it has been quoted enough times to come to provoke nausea, and is just wrong.