3 ms·
I'm dreaming of a C with only pointers that has an optional VM (with and without GC) and namespaces, string and stream included. You can cook your own (C++, WA
by bullen 4y ago
I'm dreaming of a C with only pointers that has an optional VM (with and without GC) and namespaces, string and stream included.
You can cook your own (C++, WASM and Java), but if it was standardized and cross compatible.
Also curious why so many dislike streams?
- wyldfire 4y ago> I'm dreaming of a C with only pointers that has an optional VM (with and without GC) and namespaces, string and stream included. It'd be really nice to be able to trigger some scope-exit behavior, too, IMO.
- bullen 4y agoDo you mean for Exception handling?
- alcover 4y agoMaybe parent hinted at what GCC extensions like __cleanup__ variable attribute do.
- wyldfire 4y agoIndeed: maybe not a full "RAII" kind of feature but at least something simple that allows the author to specify (around the same place where a resource allocation happened, e.g.) that some other symmetric behavior should take place on any scope exit point.
- bullen 4y agoHm, ok my take on this is unexperienced; I come from Java and only learned C++ recently: I would like to have heap inspection tools which a VM would give you. Then you can remove the VM if/when you need performance and have profiled memory enough.
- cookiengineer 4y agoAren't you describing golang? Golang is basically C with pointers, and still very very static in its programming paradigms.
- deleted 4y ago[deleted]
- samanator 4y agoGolang only has a GC, it doesn't have an option to manage memory in other ways. Were you referring to unsafe pointers and calls to Cgo?
- cookiengineer 4y ago> Golang only has a GC, it doesn't have an option to manage memory in other ways. But as far as I understand golang's memory internals, they still offer you to use the copy-based stack directly ("var some SomeStruct;") or to allocate things directly on the heap (via "new(SomeStruct) / make(SomeStruct)". I might be wrong about this, but this is what I understood from casually reading the spec [1]; while they never mention stack or heap specifically and describe it more as memory being allocated at run time, which kind of hints to a copying garbage collector underneath. But they also seem to implement a mark and sweep mechanism [2] so I'd say it's a hybrid GC, similar to how ECMAScript VMs work these days. Nevertheless you're right with the argument that it doesn't offer a way to manage memory yourself, which I think is a good thing. Technically you could use "C.malloc()" and "C.free()" though. > Were you referring to unsafe pointers and calls to Cgo? Yeah, I was kind of referring to the possibility to implement C-interface adapters using CGO (the internal "C" and "unsafe" packages). Personally I would only use C APIs if there's no way around them, though, and keep as much code in golang as possible. [1] https://go.dev/ref/spec#Allocation https://go.dev/ref/spec#Allocation [2] https://github.com/golang/go/blob/master/src/runtime/mgc.go#L439-L456 https://github.com/golang/go/blob/master/src/runtime/mgc.go#...
- Mawr 4y ago> But as far as I understand golang's memory internals, they still offer you to use the copy-based stack directly ("var some SomeStruct;") or to allocate things directly on the heap (via "new(SomeStruct) / make(SomeStruct)". Those are equivalent calls, you can't explicitly choose to allocate on the stack/heap. Conceptually there's no distinction between the stack and heap in Go, you just allocate whatever memory you want and the runtime handles cleanup for you. In practice the compiler will perform escape analysis to place everything it can on the stack, but that's an implementation detail, you don't get to explicitly choose when allocating. At best you can get the escape analyzer to show what it thinks escapes to the heap and try to coax it to allocate on the stack instead.
- pjmlp 4y agoHave a look at D.
- bullen 4y agohttps://en.wikipedia.org/wiki/List_of_programming_languages https://en.wikipedia.org/wiki/List_of_programming_languages I think I'm not going to like it because I want something that is foundational = works everywhere, is stable everywhere and has all features everywhere (f.ex linux 32-bit on ARM) But I will give it a fair shoot.
- alcover 4y ago> C with only pointers Interested in what you meant by that.
- vitaminCPP 4y agoAt the moment, Zig and Rust are the most exciting places to look, IMO.