30 ms·
I’ve found that binding C++ to a scripting language makes a lot of sense when dealing with safety issues (and other problems). While I have worked on plenty of
by makecheck 10y ago
I’ve found that binding C++ to a scripting language makes a lot of sense when dealing with safety issues (and other problems).
While I have worked on plenty of C++ projects that had sections with performance-critical code or frequently-allocated data structures that need careful control over memory, I have never seen an entire program in this category. For that matter, I probably haven’t seen one with more than 40-50% of the C++ code in this category. Invariably, you start to see people write painful code to do trivial-things-that-are-not-trivial-in-C++, intermixed with the things that might actually benefit from C++.
You can offload a lot of less-critical C++ code, forcing it into a higher-level programming environment where fewer things can go wrong, in a language that is accessible to more programmers.
- catnaroek 10y agoOne big problem with most high-level languages is that their support for automatic resource reclamation is limited to garbage collection, which is grossly inadequate for non-memory resources.
- mingodad 10y agoI did a fork of Squirrel -> SquiLu https://github.com/mingodad/squilu https://github.com/mingodad/squilu because I found the syntax more familiar and also been made with C++ that make create extensions easier than plain C. Then I started adding more and more C/C++ like syntax options with the idea to have a way to develop fast prototypes in a way that could be migrated to C/C++ when performance was not good enough, the idea is to be able to parse and accept C/C++ syntax but without actually inforce it at scripting level (accept discard/warning) and be able to use a real C++ compiler to do the heavy work. Ideally it'll lead to something like Terra http://terralang.org/ http://terralang.org/ or Cxx.jl https://github.com/Keno/CXX.jl https://github.com/Keno/CXX.jl But now Haxe http://haxe.org/ http://haxe.org/ has several advantages that's worth consider.
- pjmlp 10y agoThose languages provide other mechanisms, but people keep ignoring them on this discussions. Besides the usual set of using, with, try-finally, there are higher order functions for those languages that support it. For example, with-file "/pathname" { //fd is only visible and open here } accept-connection { // socket } // .... You just need higher order functions and implicit parameters to be able to do that in your GC language of choice.
- catnaroek 10y agoThe problem is actually remembering to use `using`, `finally`, `with-foo`, whatever. With RAII, I don't need to remember - forgetting to free is literally impossible.
- pjmlp 10y agoRAII only works with global and stack allocated data. You also need to remember to use RAII in every other case. You might also need to implement RAII handle classes in specific use cases.
- catnaroek 10y agoOnce for every struct/class, which is much better than once for every individual resource used.
- pjmlp 10y agoYou don't need to do it for every individual resource used, specially if the language has support for meta-programming. I guess these FP patterns are yet to be widely known.
- gpderetta 10y agoThe biggest difference between RAII and other approaches based on higher order functions and closures is that RAII is bound to object lifetimes, while other approaches are bound to scopes. They compose differently.
- pjmlp 10y agoNot valid when using pointers and references. And then you need to add smart something into the mix. Which is no different than using resources from scoped pools.
- chubot 10y agoBut which scripting language? C++ header are fairly hostile interfaces for wrapping. You end up with either tons of hand-written glue code or littering your header files with annotations so they can be sorta wrapped. Python is not very good as an embedded language (globals and locks). Lua is OK but AFAIK making C++-like classes in Lua is a pain, and the language is a bit annoying for other reasons.
- pjmlp 10y agoIf the API isn't template heavy, a typical solution on Windows is to access C++ via COM, and on Mac OS X via the Objective-C++ runtime. As of Windows 8,it is even easier given the new COM ABI model aka WinRT that all languages that wish to be used must support. You just need the ability to use WinRT projects on the language tools. On mainframes like IBM i, you can take advantage that all languages, including C and C++, compile to a common bytecode to make some wrapper libraries as well.
- _nalply 10y agoWhich reasons?
- chubot 10y agoIIRC, if you make a typo in a var name in Lua, you don't even get an exception like Python -- you just get nil. I'd prefer it to be more strict about errors like that. 1-based indexing. Prototypes rather than classes -- I don't think having to roll your own or research an object system for every project is a good use of time. Lua is a great language implementation, but whenever I try to actually program in it, it feels like an inferior version of Python...
- lmm 10y ago> Python is not very good as an embedded language (globals and locks). Rather than embedding Python in the C++, write the top-level loop in Python and call into the C++ from there.
- bjz_ 10y agoThat's why it's exciting to see libraries like Helix[0], Neon[1], and Rustler[2] that help folks embed Rust into higher level languages safely. Opens lots of possibilities by making even those performance critical sections of code safe for a whole team to hack on. - [0]: https://github.com/rustbridge/helix https://github.com/rustbridge/helix - [1]: https://github.com/rustbridge/neon https://github.com/rustbridge/neon - [2]: https://github.com/hansihe/Rustler https://github.com/hansihe/Rustler