Programming thread

Disclaimer: I've written some decent-sized projects in Rust, and quite like the language to the point where I feel the need to defend it here.

Apparently this is necessary because as you see println!() does both line-printing and string formatting, and Rust doesn't natively support variadic functions (functions with an arbitrary/undefined number of parameters), but they can be faked with macros. And rather than just having it be a function which takes a string and an array of strings to do the placeholder replacement with or some other sane alternative, they decided they'd implement it with macros and you can just litter your code with exclamation points and fuck off.
Surely it's better to determine conversion, string formatting, and typecasting at compile-time than at run-time? printf alone has opened up a fuck ton of nasty security vulnerabilities.

Without realizing it, though, you've stumbled upon Rust's biggest flaw: most libraries are built on a mountain of macros and type system magic that makes them impossible to extend. Especially with "safe" wrappers around C libraries, like Rust-SDL2. I'd rather deal with the occasional unsafe function than that dumb shit.

Next, the intermingling of OOP-ish concepts with snake_case. We Ruby now bois. Speaking of which, I'm confused what significance the capitalization has in the namespacing.
namespaces, libraries, and functions are snake_case, types are PascalCase.

And why do we use rand::Rng; but then never actually use Rng anywhere?
Rng is a trait, a collection of functions implemented by many different classes, akin to a Java interface or a Haskell typeclass. The Rng trait covers functions common to all random number generators (thread RNGs, pseudo-RNGs, /dev/urandom/, etc).

In this line:
C-like:
let secret_number = rand::thread_rng().gen_range(1..101);
We create a ThreadRng with the constructor rand::thread_rng, call its gen_range function (which it implements as part of the Rng trait) to get a random number, then silently discard it.

In order to use a trait's functions (gen_range), you have to import the trait (Rng) or the type that implements it (ThreadRng). For some reason, this example doesn't explicitly import the ThreadRng type, so it imports the Rng trait instead.

Had I written this example, I would have done something like this:
C-like:
use rand::rngs::ThreadRng;

fn main() {
    // ...
    // everything in rust is an expression
    // every {} block can return a value
    let secret_number = {
        let rng : ThreadRng = rand::ThreadRng();
        rng.gen_range(1..101)
    };
    //...
}
To explicitly emphasise the creation of the ThreadRng.

let mut guess. The "mut" keyword makes the variable mutable. I don't like the idea of immutable variables because we already have a word for those and it is "constant." JavaScript actually does something right by having separate let and const keywords for variables and constants rather than keyword-stacking.
"Immutable" and "constant" are two different things. Constant values are determined at compile-time; Immutable values are determined at run-time, but not changed after that.

…Fuck me with a shovel. If you pass a variable by reference, it becomes a constant unless you add a keyword to make it otherwise. The fuck?
This is quite literally the point of Rust.

Pointers are scary things. A C function that takes a pointer as an argument can do anything with it - read from it, write to it, create infinite copies and propagate them to other objects or threads. Copies of a pointer can outlive the original data they were pointing to, causing memory corruption or even crashes if you try to write to the "dangling pointer".

Imagine you have a multiplayer game with Player objects dropping in and out of a server. How do you clean up after a player when they leave? Do you switch on a "dead" flag, allowing a dummy Player to take up space in memory? Do you diligently search the game state for dangling pointers to the departing player?

Or do you refrain from creating pointers to Player objects at all, instead referring to them by an ID? If that's the case, why bother having Player objects at all? Why not just represent each player as a row in a database, indexing on the ID? This problem is a thorn in the side of any low-level language with an object system.

With Rust, you can have your objects and eat them too, because there are rules in place to prevent dangling pointers and similar monstrosities:
  • Pointers are explicitly specified as mutable or immutable
  • Functions that take pointer arguments cannot propagate them outside of the function body
  • Multiple mutable pointers to the same data cannot exist at the same time
  • Data structures with pointers in them must be higher on the stack than whatever the pointer points to, unless a Box, Mutex, or other smart pointer is used
It takes a while, but once you get used to them you can write totally memory-safe code, which is a great feeling. No dangling pointers, no memory leaks, no buffer overflows or similar exploits. Don't you see how, for mission-critical software like servers, that would be a great thing? Or how using less brainpower on memory allocation could allow people to write more performant optimized programs?



I know that my autistic rant won't make the language any more appealing to you lot... I just wanted to point out that Rust has a method to its madness. It's a well-thought-out and meticulously designed language; most things that are hard to do in Rust are just transparent wrappers over things that are hard to do in general.

Rust aficionados seem to get a sexual thrill from rewriting perfectly-good software in Rust just so that they can say that they coded it in Rust.
It's a brand name at this point. Rust has a reputation for spawning "X but better" projects (grep but better, GNU find but better, spotify but better). I've tried a few and confirmed that they are in fact better, though I'm hesitant to attribute this to the language itself.
 
@Cryonic Haunted Bullets Thanks for your level-headed response to my intentionally acerbic write-up. I don't completely understand what you wrote about memory safety but I'll defer to your expertise there. Memory safety is something web devs don't worry about so much because the entire world will be destroyed once we're done sending the response anyway (conceptually if not literally) so who cares if we're not using memory quite as efficiently as possible… It was something I think I understood better back when I was getting my degree and doing application programming as part of that, but it's been a while.

Your explanation of the traits cleared up the confusion there. I'm sure that's explained later on in the book but obviously I didn't get beyond the first couple pages while looking for things to complain about.
 
Pointers are scary things.
No, they're not and I'm tired of people pretending, or being too stupid, or being webdevelopers (but I'm repeating myself) to believe otherwise.
Imagine you have a multiplayer game with Player objects dropping in and out of a server. How do you clean up after a player when they leave? Do you switch on a "dead" flag, allowing a dummy Player to take up space in memory? Do you diligently search the game state for dangling pointers to the departing player?
Or maybe I just spend two minutes getting my data model in order instead of flailing around in code like a retard or a webdeveloper (but I'm repeating myself)?

Note: the above exceptionalism is not meant to be an insult to quotee nor Rust, but feel free to send tophats anyway.
 
No, they're not and I'm tired of people pretending, or being too stupid, or being webdevelopers (but I'm repeating myself) to believe otherwise.
pointer_opinion_bell_curve.png




On a related note: I hate /g/ so god damn much. It outdoes even /r9k/ in terms of sheer pettiness, resentment, and hatred of normal successful people. Probably because /g/aboos are so close to what they covet. They spend all day on a computer doing vaguely technical things - $CURRENT_YEAR's most lucrative vocation - and are somehow too stuck-up and autismal to make any money off of it.
 
At the risk of sounding assblasted (I'm not and I like the image): I don't deal with pointers almost at all when doing C++ and when doing C then they're obviously inevitable, but then again I can't imagine where does the "doing pointer arithmetics" meme comes from.

Don't get me wrong, I despise the syntax around pointers, but pretending they're some terrible boogeyman while at the same time using references for everything is either dishonest or ignorant. That's what I meant by (quoting myself) people pretending or being too stupid.

Once again: not an insult or an attack on anyone personally in this thread, rather a general observation on oft repeated misconceptions.
 
@Cryonic Haunted Bullets Thanks for your level-headed response to my intentionally acerbic write-up. I don't completely understand what you wrote about memory safety but I'll defer to your expertise there. Memory safety is something web devs don't worry about so much because the entire world will be destroyed once we're done sending the response anyway (conceptually if not literally) so who cares if we're not using memory quite as efficiently as possible… It was something I think I understood better back when I was getting my degree and doing application programming as part of that, but it's been a while.

Your explanation of the traits cleared up the confusion there. I'm sure that's explained later on in the book but obviously I didn't get beyond the first couple pages while looking for things to complain about.
He's basically saying that pointers are prevented from outliving their pointee by making life time a part of the type system.
Code:
fn print_refs<'a, 'b>(x: &'a i32, y: &'b i32) { // 'a and 'b are the explicit lifetimes of x and y
    println!("x is {} and y is {}", x, y);
}
It's a reasonable way of solving the problem I suppose, but I don't really see why they limit you to a single mutable reference at a time.

The only idea I really like is traits which are basically compile time interfaces, but even then you can do the same thing in C++ using templates. Hell, we even call them traits
C++:
#include <stdio.h>

// Declaration of the BTree trait, specialize to implement
template<typename TNodeHandle>
struct BTreeTraits {
    using THandle = TNodeHandle;

    static bool IsValid(THandle b)=delete;
    static THandle GetLeaf(THandle b, bool lOrR)=delete;
    static THandle SetLeaf(THandle b, bool lOrR, THandle l)=delete;
};

// Create function aliases
template<typename TNodeHandle>
bool IsBTValid(TNodeHandle a) { return BTreeTraits<TNodeHandle>::IsValid(a); }
template<typename TNodeHandle>
TNodeHandle GetBTLeaf(TNodeHandle b, bool lOrR) { return BTreeTraits<TNodeHandle>::GetLeaf(b, lOrR); }
//...

// Use traits in generic algorithm
template<typename TNodeHandle, typename TPred>
TNodeHandle TravelWhile(TNodeHandle h, TPred&& p) {
    while (IsBTValid(h)) {
        auto cmp = p(h);
        if (cmp == 0)
            break;
        else
            h = GetBTLeaf(h, cmp < 0);
    }
    return h;
}


template<typename T>
struct Node {
    T v;
    Node<T>* l,* r;
    Node(int v, Node<T>* l, Node<T>* r)
        : v(v), l(l), r(r) { }
};

// Implement interface
template<typename T>
struct BTreeTraits<const Node<T>*> {
    using THandle = const Node<T>*;

    static bool IsValid(THandle b) { return b != nullptr; }
    static THandle GetLeaf(THandle b, bool lOrR) { return lOrR ? b->l : b->r; }
    static THandle SetLeaf(THandle b, bool lOrR, THandle l)=delete;
};

template<typename T>
struct BTreeTraits<Node<T>*> : public BTreeTraits<const Node<T>*> {
    using THandle = Node<T>*;

    static THandle GetLeaf(THandle b, bool lOrR) { return lOrR ? b->l : b->r; }
    static THandle SetLeaf(THandle b, bool lOrR, THandle l) {
        auto& a = (lOrR ? b->l : b->r);
        auto p = a;
        a = l;
        return p;
    }
};



void Main() {
    Node<int> a{1, nullptr, nullptr},
        b{3, nullptr, nullptr},
        c{2, &a, &b},
        d{4, &c, nullptr},
        e{0, nullptr, &d};
    
    int target = 3;

    TravelWhile(&e, [target](auto a) {
        printf("%d ", a->v);
        return target - a->v;
    });
}
One thing I adore about C++ is how all of these things are emergent behavior; they added templates for the sole purpose of having std::vector, but their users then found all manner of new things it could be used for.


Imagine you have a multiplayer game with Player objects dropping in and out of a server. How do you clean up after a player when they leave? Do you switch on a "dead" flag, allowing a dummy Player to take up space in memory? Do you diligently search the game state for dangling pointers to the departing player?

Or do you refrain from creating pointers to Player objects at all, instead referring to them by an ID? If that's the case, why bother having Player objects at all? Why not just represent each player as a row in a database, indexing on the ID? This problem is a thorn in the side of any low-level language with an object system.

With Rust, you can have your objects and eat them too, because there are rules in place to prevent dangling pointers and similar monstrosities:
Rust lets me OOPSIE all over myself!!!! OOPSIE DOOPSIE OBJECTS EVERYWHERE!!!! Just use the database option, what on earth is wrong with you?

On a related note: I hate /g/ so god damn much. It outdoes even /r9k/ in terms of sheer pettiness, resentment, and hatred of normal successful people. Probably because /g/aboos are so close to what they covet. They spend all day on a computer doing vaguely technical things - $CURRENT_YEAR's most lucrative vocation - and are somehow too stuck-up and autismal to make any money off of it.
Based /g/igachads inducing imposter syndrome in virgin googler nigger cattle :smug:
 
You're going to say I'm a tranny for saying good things about Rust, but it is nice to write. It's syntax is cleaner and more concise. Weirdos who say 'it's slow' are only saying that because the don't know how to do Dev builds that are much faster and don't try to optomise the program (complainers only run release builds). Modules are really good. C++ finally came around to what Java, Ada, Python2 & 3, D, Ruby, Node, Go .... the list goes on ... have all figured out, but C++ has been slow to adopt this idea. The syntax is pretty well balanced. Generics and 'classes' (traits) are a lot more natural then C++ templates. Simple things are faster to do because more complex things have tighter restrictions in Rust, compared to C++ where you need to know a lot going in to get good results out at any level of work. The monads (enums), calling semantics, and closure syntax all get high marks from me. It's a very comfy language to white, which makes having to deal with the eco-system a toss-up.

Cargo is like NPM and it locks you in to using GitHub to host the libraries you want to publish to the public to use. You can put a git URL or a local directly in as the source for the library, but I haven't seen a way to host your own NPM like system and have it work with Cargo. For instance, have your own hosted package repository and have Cargo pull from that for your organization in addition to GitHub and other git sites; I've not seen a standard way to do this.

Some projects are confused on how to get C++ like inheritance to work in Rust. According to the Standard Library, you can use slice methods on Vec because Vec can deference as a slice. Many projects are ignorant to this style and instead create numerous redundant traits that are unnecessary and have the practical affect of hiding methods in the documentation. Guilt of this are, but not limited to, GTK-RS and Druid.

If you're writing Rust for any length of time you'll start to notice that every thing is 3 or more layers of manager structs before you hit a compiler build-in looking though the Standard Library. It's an infectious style that will start to change how you approach much of the software you write.

It's very nice to work with data is Rust, so it's disappointing that their isn't a good GUI lib to go along with stellar serialise-deserialise support. The best I've found so far is Druid, but it's not exactly to my standards; numerous redundant traits that are unnecessary instead of deref.

Rust Core Devs miss-spelled Barrow in the standard Library. It's called Borror; Boerow? What the fuck? That's jank as shit.

I can't stand the people who write the software, so it's impossible to have any sort of community with them. They are all gender-queer delusional narcissists. Realistically this is a problem endemic to working with Americans, but since Rust is an American project and most college-fuck-wits drink soy by the Kilo Liter use Rust you may find this problem a lot too. Trannies are the worst. They are bad at software and acting correct to people. It's no surprise that a lot of FOSS is just a tranny side-show, but it really make getting involved impossible. Why would you want to write software with someone or take patches from someone who is delusional and a law-suit waiting to happen. I don't know anyone who has patients to listen to someone's head-cannon and how they were born in the wrong body and how their an inter-galactic precise nor do I care to. I just need the API to not be jank as shit.

A good number of libraries are not actually implemented in Rust, but are just C FFI which means you're tracing back the brain dead API translation instead of dealing with the Library in its native language. C FFI means you don't get the benefits of using Rust because the C parts aren't held to the standards the compiler applies to your project, so you're just calling in to who know what. Frankly, it seems better to handle those problems on home turf instead of hoping the tranny running the git repo hasn't done the FFI wrong. It's too time consuming to trace the docs back from what they were native and the quality you get on the Rust side is a crap shoot.

Rust hasn't gotten it's ABI shit together so you have phat binaries no matter what. They all have to include the Rust Runtime, where C and C++ include it with a link to a DL or SO. It seems the Rust Core Team in not very motivated to change this. C and C++ have a similar problem with extern C in C++ reducing a lot of the features that you use in C++ from C.

Rust is a nice language. It's community is shit and Americans who are afraid of saying nigger are not worth working with in software. Rust isn't really doing anything new. D and Ada both tried to improve on a lot of common problems in C and C++ and came out in the 2000s and '90s, respectively. Rust would have nuked out of the water D easily. As much as I think Rust is nice, if it came out 10 years earlier then it did, before the West got so gay and tranny, its adoption would be much better. The future for USA and its technology is disappointing any way you cut it.
 
Last edited:
He's basically saying that pointers are prevented from outliving their pointee by making life time a part of the type system.
So linear types?
Anyway, I really don't resent Rust as much as its narrative and user base are insufferable and wrong headed.
The story should be "immutability is the correct default behavior". It should be "memory should always be managed", which means either at runtime with GC or at compile time with ownership tracking. It should be "failure and type conversions are explicit".
Instead it's just ass. It could have been a cool complement to Haskell. I'll just wait for Carp to mature.
 
So linear types?
Anyway, I really don't resent Rust as much as its narrative and user base are insufferable and wrong headed.
Agree. People just find what they like and then start to crank out the rationalisations, the jargon, and the buzzwords all around how great their new flavour of the month is. Actually they just like the language, the same way some people like or dis-like rap or chocolate pudding or beef. The only difference is we don't expect people stomachs to yield to refutation.
The story should be "immutability is the correct default behavior". It should be "memory should always be managed", which means either at runtime with GC or at compile time with ownership tracking. It should be "failure and type conversions are explicit".
This will upset you, but I've never seen a creative enough GC; something that can kill things that it thinks might be no longer needed but are not entirely deferenced and then when that object is discovered to be needed again can be reconstructed. Sort of like real memory: you need something so you remember it, then you don't need it so you forget it, then you discover you need it again and re-learn it. Short of a system that can be more aggressive and some times kill memory that it could still need, I don't see GCs taking over.

It will seem like I'm trying to monopolise the conversation, but I left out Rust Macros. They are also very good. Every time I see #define .... do { ... } while(0); I think this is a fucking ulcer and has really failed to keep up with user's demands. If Rust were to go away and only one thing from it would be merged into C++, it should be the macro system. Rust Macros use a regex like syntax for their parameters, can have a variable number of parameters, and can be used like C++ templates to stamp out types or like functions. <https://veykril.github.io/tlborm/introduction.html>
 
At the risk of sounding assblasted (I'm not and I like the image): I don't deal with pointers almost at all when doing C++ and when doing C then they're obviously inevitable, but then again I can't imagine where does the "doing pointer arithmetics" meme comes from.

Don't get me wrong, I despise the syntax around pointers, but pretending they're some terrible boogeyman while at the same time using references for everything is either dishonest or ignorant. That's what I meant by (quoting myself) people pretending or being too stupid.

Once again: not an insult or an attack on anyone personally in this thread, rather a general observation on oft repeated misconceptions.
I think the real problem is that pointers are specialized tools that allow you to do certain things that you otherwise couldn't, but people treat them like they're the main focus of the language. You basicallyuse a pointer either in order to not reallocate massive chunks of memory or when you have no other choice, but people almost seem to try and replace the concept of a variable itself with pointers.

New devs are afraid of pointers because what they see makes no sense to them, so they must assume it must be extremely complicated. In reality, it truly does make no sense, but they don't know that. They chalk it up to their own inexperience rather than the collective psychosis gripping low level devs.

I think a lot of C++ and especially C devs think that it's still 1987 and every last byte must be saved, so they make these horrifying labyrinths of pointers pointing to pointers rather than just allocating another word or two.

I do arguably unnecessary optimization all the time, it's just what programmers do, but when 50% of your project is asterisks it's time to calm down.
 
I think the real problem is that pointers are specialized tools that allow you to do certain things that you otherwise couldn't, but people treat them like they're the main focus of the language. You basicallyuse a pointer either in order to not reallocate massive chunks of memory or when you have no other choice, but people almost seem to try and replace the concept of a variable itself with pointers.
Pointers aren't specialized tools, they're at the heart of any language that exposes them. You need pointers in order to:
  • Pass anything by reference
  • Do any object-oriented programming at all (methods and inheritance are fundamentally built on top of pointers)
  • Interface with libraries and operating systems
  • Work with strings in any capacity
  • Allocate memory from the heap (not to mention, the heap itself is made up of pointers)
  • Work with any resource whose size isn't predictable at compile-time (file buffers, textures, shaders, etc)
What the hell kind of C/C++ code are you writing where you only have to use pointers once in a while?
 
This will upset you, but I've never seen a creative enough GC; something that can kill things that it thinks might be no longer needed but are not entirely deferenced and then when that object is discovered to be needed again can be reconstructed. Sort of like real memory: you need something so you remember it, then you don't need it so you forget it, then you discover you need it again and re-learn it. Short of a system that can be more aggressive and some times kill memory that it could still need, I don't see GCs taking over.
Why would I be upset? This is a very creative idea, I'm just not sure it applies;
First, generational GC solves an interesting problem - not that you need to re-remember things, but that most things don't need to be remembered for long.
Another aspect of what you mention is CPU cache, where the hot stuff is easily accessed.
Finally, what you want can be implemented by memoizing with a TTL, perfectly doable in a functional language.
 
Pointers aren't specialized tools, they're at the heart of any language that exposes them. You need pointers in order to:
  • Pass anything by reference
  • Do any object-oriented programming at all (methods and inheritance are fundamentally built on top of pointers)
  • Interface with libraries and operating systems
  • Work with strings in any capacity
  • Allocate memory from the heap (not to mention, the heap itself is made up of pointers)
  • Work with any resource whose size isn't predictable at compile-time (file buffers, textures, shaders, etc)
No, that's what you need references for:
  • to pass anything by reference, you pass a reference;
  • ditto, etc.
You can of course argue, that a reference is just a const-pointer (meaning: T* const, not const T*), but that argument is symmetrical - a pointer is a reference in the same way a reference is a pointer. And back again to my post about people being either dishonest or ignorant re: pointers being teh evulz whilst at the same time using inherently reference-based languages.
What the hell kind of C/C++ code are you writing where you only have to use pointers once in a while?
C++11 and further. Move-semantics significantly eased up passing references by, well, passing references instead of pointers. The main reason to use a pointer instead of a reference is in cases where a particular "reference" is optional (you can't have null references in C++, you can have null pointers), where it's initialization is not inherently tied to creation of an object (which should be avoided if possible, RAII FTW) or when you want to switch the reference to another entity.

TL;DR - pointers are non-const references with wacky syntax, let's stop pretending otherwise.
 
  • Agree
Reactions: Marvin
Isn't the real discussion something like smart pointers vs plain C pointers instead of pointers vs no pointers?
Surely Rust has some type of pointer or reference.
 
Isn't the real discussion something like smart pointers vs plain C pointers instead of pointers vs no pointers?
Possibly, but I'd rather not preempt the discussion too much and hijack the thread with unsolicited C++ sperging, unless prompted to do so.
Surely Rust has some type of pointer or reference.
I think the Rust references were already described in this topic, about a page back.
 
No, that's what you need references for:
What are we even arguing about? I think we agree.

In object-oriented languages like C++ and Rust, all class methods take the object's address as an implicit first argument. The object's members are offsets of this address. This is how inheritance and dynamic dispatch work.

To me, a "pointer", is a reference with no attached baggage or qualification. References in managed languages qualitatively different from pointers; it's impossible for a Java or Python reference to segfault, access invalid / deallocated memory, or walk off an array like a C pointer can. This is what I mean when I say that "a pointer is a scary thing": having access to raw pointers opens up a whole new class of oopsies.

1638653575877.png

Isn't the real discussion something like smart pointers vs plain C pointers instead of pointers vs no pointers?
Surely Rust has some type of pointer or reference.
Rust is statically garbage collected. Pointers have to have a smaller scope than the thing they point to.

Valid C++:
C++:
int* a = NULL;
{
  int b = 1;
  a = &b;
}

// oh shit, a points to b, but b no longer exists!

Invalid Rust:
C-like:
let a : &u32 = {
    let b : u32 = 1;
    &b
};

// compiler error: reference lives longer than referent

You can use raw pointers for things like Windows API calls, but only within an unsafe block.
 
  • Informative
Reactions: Least Concern
To me, a "pointer", is a reference with no attached baggage or qualification. References in managed languages qualitatively different from pointers; it's impossible for a Java or Python reference to segfault, access invalid / deallocated memory, or walk off an array like a C pointer can.
That's a bit of a potatoh-potatoe distinction, because you can absolutely crash a program through, for example, null reference (or a multitude of other reasons in shitty dynamic languages like Python), though it's not a "segfault" because, as you have stated, we're dealing with a managed environment. So there'll be some nice exception with a stacktrace instead. [BTW, I love trolling Java weenies by causing NullPointerException and asking them "I thought there were no pointers in Java?!"]

I don't consider this a nitpick, because modern C++ puts, like, 98% (asspull number) of these kind of memory access errors to rest, so most of the remaining bugs are in fact of the logical kind and very much in effect like in those managed languages. If a programmer wants to be super-serious-doubly paranoid, then they can use all sorts of guarded memory accesses (such as .at() instead of operator[]). Hell, most of the "hardening" is achieved by leveraging move-operations on references instead of using pointers and where that's not applicable, dropping a std::unique_ptr or a std::shared_ptr. Which, incidentally, also helps with readability.
This is what I mean when I say that "a pointer is a scary thing": having access to raw pointers opens up a whole new class of oopsies.

View attachment 2774316
Frankly, I don't know what "memory safety" means in the above context. And then again, if someone uses C in 21st century, they get what they deserve. I hope that the fuckton of software in C will be finally replaced, though I believe C++ would be a better choice since the language commitee finally got their heads out their asses ~10 yrs ago.
Rust is statically garbage collected.
I can't afford to use GC, sorry. That's a dealbraker for me.
Pointers have to have a smaller scope than the thing they point to.
I don't dispute that and I applaud Rust for catching such semantic bugs at the language level, but then again - the example provided is moronic.
 
I can't afford to use GC, sorry. That's a dealbraker for me.
Did I say "static garbage collector"? Holy shit, I'm a fucking moron. What I meant to say was RAII. De-allocations are determined at compile time, outside of a few special cases like reference counters. All the goodness of managed memory, none of the GC pauses.

I don't consider this a nitpick, because modern C++ puts, like, 98% (asspull number) of these kind of memory access errors to rest, so most of the remaining bugs are in fact of the logical kind and very much in effect like in those managed languages. If a programmer wants to be super-serious-doubly paranoid, then they can use all sorts of guarded memory accesses (such as .at() instead of operator[]). Hell, most of the "hardening" is achieved by leveraging move-operations on references instead of using pointers and where that's not applicable, dropping a std::unique_ptr or a std::shared_ptr. Which, incidentally, also helps with readability.
So, in other words, the same approach as Rust: bounds checking on collections, move semantics, and shared / unique pointers in lieu of new or malloc. Modern C++ added these features around the same time as Rust was in development, and I'm sure there was significant cross-pollination between the two projects.

It's a matter of whether you prefer the battle-tested C++ ecosystem or the modern functional aspects of Rust. Because I don't use many C++ libraries, and have no experience with the language's newer features, I prefer the latter.

I hope this can be the last reply in this chain, because, holy shit, this is the gayest argument I've ever had on the internet.
 
I think the real problem is that pointers are specialized tools that allow you to do certain things that you otherwise couldn't, but people treat them like they're the main focus of the language. You basicallyuse a pointer either in order to not reallocate massive chunks of memory or when you have no other choice, but people almost seem to try and replace the concept of a variable itself with pointers.

New devs are afraid of pointers because what they see makes no sense to them, so they must assume it must be extremely complicated. In reality, it truly does make no sense, but they don't know that. They chalk it up to their own inexperience rather than the collective psychosis gripping low level devs.
The pointer is one of the most fundamental elements in computer architecture; as the notion that memory can address itself is the way in which dynamism is created and without which computers would be limited to the simplest of numerical calculations. You cannot escape the pointer, you merely hide from int; yet behind the veil of your highfalutin languages it diligently toils to prop up the preposterous abstraction you call "simplicity"!

I think a lot of C++ and especially C devs think that it's still 1987 and every last byte must be saved, so they make these horrifying labyrinths of pointers pointing to pointers rather than just allocating another word or two.

Now observe as I write a hello world with 5000 required dependencies
Fucking wish it was bud



Did I say "static garbage collector"? Holy shit, I'm a fucking moron. What I meant to say was RAII. De-allocations are determined at compile time, outside of a few special cases like reference counters. All the goodness of managed memory, none of the GC pauses.
☝🏿 Here we see computational marxism in action; they will use terms like "static garbage collector" to frame your beautiful RAII as a subordinate version of their godless garbage collection. They do this in order to control the language; TO CONTROL YOUR MIND. Once you accept their programming programming you become unable to separate truth from coding communist lies! Know the signs, be on guard Programing Patriots!
 
Back