6 ms·
I’ve been leaning more towards a dual language approach recently. A language with tight integration with C like Lua, or Gambit, that makes it easy to drop down
by Decabytes 3y ago
I’ve been leaning more towards a dual language approach recently. A language with tight integration with C like Lua, or Gambit, that makes it easy to drop down to C. C gets treated like a block of unsafe Rust code, and you keep as little of the code base in C as is necessary
- dualogy 3y agoWhat I never get about the huge Lua popularity in C/C++ land is how people manage the mental switch between 0-based and 1-based indexing. Or is this tunable from the VM/JIT-hosting side? Because if I were to use Lua-the-language standalone, I'd lose all my "mental automatics" for real basic arraying/looping stuff that serve in day to day in the non-Lua workloads of C/++, Go, the occasional TypeScript etc.
- defrost 3y agoIt might be because I'm old and grew up with carpentry and fence and post around a paddock real life problems but there's no switch if you seperate the two as two distinct things. If you make a pigeon hole row of boxes, box number 1 has an index of 1 and an offset of 0 (from the origin mark). C arrays are syntactic sugar for origin based offsets, Fortran arrays are indexed by element number. In C arr[i] is equivalent to i[arr] is equivalent to arr + i and to i + arr.
- rwbt 3y agoThis is what I've been thinking lately i.e. C and Lua (throw in LuaJIT too if speed is needed). But I've found out that using functional parts of modern C++ (bear with me) as a higher level language with C underpinnings also works very well. But you need tremendous discipline to do it successfully. For eg - using only C POD structs, no constructors, no exceptions, no inheritance, limited template usage etc. Some would say a very C style C++ with a lot of syntax sugar.
- dualogy 3y agoThat's how any C++ stuff of mine goes, "given the chance", ie. the self-contained, private/hobbyist stuff. With structs instead of classes you still have the convenience of instance methods (rather than just mynamespace_funcname funcs), statics, even namespaces (hardly necessary with methods and statics), yet can avoid inheritance and the whole public/protected/private noise (public by default, otherwise structs and classes are exactly equivalent in C++) except for the rare case where it does seem beneficial over a simple field.
- rwbt 3y agoI also stopped writing destructors (because eventually that leads to writing move constructors); instead now just use a unique_ptr to wrap resources (covers most of the cases) or a simple scope_exit (ala "defer"). Turns out separating ownership and lifetime really helps to write much better C++ code for me. These simple rules coupled with great modern C++ syntax sugar like lambdas, tuples and 'auto' along with the basic data structures in it's standard library makes it a breeze.
- nine_k 3y agoWhat you describe feels like a good way to write code for the Arduino platform.