4 ms·
I am a beginner to programming language implementation. I have a JIT compiler that compiles a language that looks similar to Javascript. My favourite languages
by samsquire 3y ago
I am a beginner to programming language implementation. I have a JIT compiler that compiles a language that looks similar to Javascript.
My favourite languages are Python, Java and C.
I have written 2 Rust programs. I am not sure I understand C++ "forward" and Rust's lifetimes with the apostrophe. Any explanations would be helpful.
Async Rust, traits all seem hard to understand to me. I would like to understand them better.
I like C programming because it feels simple.
With Rust it feels that everything is a fight, I haven't yet got the mental model to design Rust programs. I think I need to design programs as trees.
I can deal with * symbols and &.
I find into(), forward hard to understand.
I find C++ template syntax hard to understand, things like unique_pointer.
- sillysaurusx 3y agoDo you mean C++ forward declarations? If so, it’s basically an entry in the linker table. A placeholder of sorts. You can’t reference something without it being known, so you have to make it known first. Where C++ gets weird is that you can’t instance something without it being fully known (the full definition needs to be visible). This is rooted in the .cpp / .h header split, which as far as I know is pretty unique to C.
- samsquire 3y agoThis function I don't understand: https://en.cppreference.com/w/cpp/utility/forward https://en.cppreference.com/w/cpp/utility/forward It has something to do with references and lvalues.
- foota 3y agostd::forward (and reference collapsing rules, which are related) is imo one of the most complicated parts of C++. Generally, the idea is that it's there to implement "perfect forwarding". Essentially, being able to accept and pass to another function any type of parameter without coercing it to something like a const reference, which can be inefficient, or limit the way a caller can use your function. I'm not trying to gate keep, but if you don't understand unique pointers and templates in general, you're a long way from needing or being able to make use of perfect forwarding imo. You don't need perfect forwarding outside of generic wrapper type code, and in most code you can just accept a specific type of object (e.g., value types or const references). If you want to understand it you should start with learning value categories, move semantics, and templates, and then try to learn perfect forwarding.
- samsquire 3y agoThe bit between the < and > I find hard to understand. In C++ behaviours are named, like in some C++ code coroutines there is a template that looks like: template <is_task task_t> The is_task looks like an if statement.
- foota 3y agoMy impression is that coroutines aren't super stable today, but what you're seeing there is a C++20 "concept", essentially, a way to restrict the types accepted by a template. E.g., the is_task part is a concept that requires the template parameter type task_t to meet some criteria. Normal template code looks like: template <typename T> Where you can also choose to use the class keyword instead of typename. C++20 isn't very widely used though, so this isn't something you're likely to run into in anything other than cutting edge code. If you want you can read about them here: https://en.cppreference.com/w/cpp/language/constraints https://en.cppreference.com/w/cpp/language/constraints but you're probably better not using concepts at least at first. In general, https://en.cppreference.com/ https://en.cppreference.com/ is a very high quality source for learning, although it's very dry as well.