3 ms·
Maybe mentioning it in the same breath as Javascript rubbed you the wrong way, but Java _is_ pretty dynamic. Object being a valid write destination for any ref
by Banana699 5y ago
Maybe mentioning it in the same breath as Javascript rubbed you the wrong way, but Java _is_ pretty dynamic.
Object being a valid write destination for any reference means the VM has to maintain type information in all objects (small 'o'), which is a distinctively dynamic thing to do. I mean, simply declare all variables to be Object and you can see a faint shadow of a python-like class system lurking underneath the static types. The fact that nobody does this (I hope!) is of no use to the VM, the semantics say it must do this.
All object allocations are on the heap (and only ever moved to stack if escape analysis proves they could), all methods are dynamically dispatched. Hell, even class loading (i.e. linking libraries) is done at startup, which means you can recompile libraries without re-linking the client code which uses them.
- pjmlp 5y agoI can do similar stuff with C++, so it is a dynamic language now?
- Banana699 5y agoThe reference Python interpreter is implemented in C, does that invalidate the common sense observation that python is dynamic while C is static ? What counts is the default zero-effort mode. Sliding into "All languages are turing complete so all distinctions are meaningless" territory is very rarely helpful for conversations. Sure C++ offers you both stack and heap allocations, virtual and ordinary methods, static types and std::any for values of unknown/irrelevant runtime type. But the default zero-effort thing to do is to use statically-typed stack-allocated objects with non-virtual methods. Java only offers two of these things and one of them needs to be explicitly stated upfront. And, furthermore, Java's runtime still maintains the full machinery needed to do dynamic typing and dynamic method dispatch (the final modifier on methods is purely a promise to javac, the JVM has no concept of a method call that doesn't involve looking up the class it refers to and potentially all of its superclasses), it doesn't matter that you don't use it, your calling code or called code might, and the specification says that it can. C++ objects compile to dumb bit buckets that contain exactly what's asked of them and nothing more. No matter what you do, you can never have all class types in C++ share a common ancestor, and the ones you can will know nothing about their parents unless specifically asked to with 'virtual', they can only remember this when allocated on the heap.
- pjmlp 5y agoYeah, because there isn't such thing as C++ language runtime, RTTI, dynamic_cast<>() and loading C++ classes via shared objects. /s
- Banana699 5y ago>RTTI, dynamic_cast<>() I don't get the snark, these things are only allowed for virtual-method-containing classes, something I explicitly mentioned and said it doesn't count because it's not on by default, not idiomatic to be on by default, doesn't exist in binaries or at runtime when not in the source, and is extremly limited compared to the rich metadata every java object hold no matter what you do or say (so even objects of final classes have it). >loading C++ classes via shared objects A capability of the underlying operating system, which _is_ a "runtime", just not a standard or required part of the language, and shared objects or dynamic libraries know a tiny drop of water about their source compared to the ocean of metadata in every .class file and the runtime representation of them. >C++ language runtime What does that even mean in this context ? I have heard it said to refer to the standard library, which is ridiculous in our context because it's neither required (let alone mandatory) part of the language nor carries information or controls execution of the calling code like the java runtime does. I have heard it being said to refer the variant of C++ that Microsoft runs on the CLR, which might as well be C# in this context. The closest thing would be the Exception Handling Mechanism and the runtime info it requires, but that's again extremely limited compared to what java does and a qualitatively different thing. Dumb tables of pointers or return addresses can never be comparable to the very rich representation of types and other metadata about code that the JVM or the CLR does.
- deleted 5y ago[deleted]
- pjmlp 5y agoFirst of all, an ISO C++ compliant implementation can run bare metal, there isn't any requirement that an OS must exist, that is the whole point of a systems programming language. Secondly a C++ runtime is responsible for running all global variable contructors and destructors, handling exceptions, soft floating operations, loading shared libraries on demand for dynamic linking (depending on OS capabilities or bare metal), how new/delete translation into the underlying OS/MMU. As for the metadata, so when I use static reflection in C++, either via template metaprogramming, or with the features that sadly will only come in C++26, then what? And really I just picked C++ as first example that came into my mind. We can also start discussing Eiffel, Delphi, Swift or Go for example, with their rich type information, dynamic dispatch, rich runtimes, and native compilation model, so they are also dynamic?