Most active commenters

    ←back to thread

    452 points birdculture | 18 comments | | HN request time: 2.045s | source | bottom
    1. GenshoTikamura ◴[] No.43982864[source]
    > Stop resisting. That’s the most important lesson

    > Accept that learning Rust requires...

    > Leave your hubris at home

    > Declare defeat

    > Resistance is futile. The longer you refuse to learn, the longer you will suffer

    > Forget what you think you knew...

    Now it finally clicked to me that Orwell's telescreen OS was written in Rust

    replies(1): >>43983002 #
    2. atoav ◴[] No.43983002[source]
    But it is true. My own biggest mistake when learning Rust was that I tried to torce Object Oriented paradigms on it. That went.. poorly. As soon as I went "fuck it, I just do it like you want" things went smoothly.
    replies(2): >>43984144 #>>43987271 #
    3. rikafurude21 ◴[] No.43984144[source]
    Sounds like an abusive relationship if im being honest. Your programming language shouldnt constrict you in those ways.
    replies(5): >>43984486 #>>43984523 #>>43984615 #>>43984649 #>>43993404 #
    4. lagniappe ◴[] No.43984486{3}[source]
    It helps to understand the cultural ethos of the original rust devs, and the situation that gave rise to it.
    5. jplusequalt ◴[] No.43984523{3}[source]
    >Your programming language shouldn't constrict you in those ways

    Says who? Programming languages come in all shapes and sizes, and each has their tradeoffs. Rust's tradeoff is that the compiler is very opinionated about what constitutes a valid program. But in turn it provides comparable performance to C/C++ without many of the same bugs/security vulnerabilities.

    replies(1): >>43987603 #
    6. hbn ◴[] No.43984615{3}[source]
    Every programming language has constrictions by the nature of having syntax.

    In JavaScript you can declare a variable, set it to 5 (number), and then set it to the "hello" (string), but that's not allowed in e.g. C. Is C constricting me too much because I have to do it in C's way?

    replies(1): >>43986014 #
    7. ModernMech ◴[] No.43984649{3}[source]
    Abusive relationships involve coercion, control, fear, and often violate personal autonomy and consent. One party dominates the other in a harmful way. Using Rust is not harmful.

    Placing restrictions on the programs a programmer can write is not abusive. The rules exist to ensure clarity, safety, performance, and design goals. In an abusive relationship, rules are created to control or punish behavior, often changing capriciously and without reason or consultation. By contrast, Rust is designed by a group of people who work together to advance the language according to a set of articulated goals. The rules are clear and do not change capriciously.

    Abuse causes emotional trauma, isolation, and long-term harm. Rust may cause feelings of frustration and annoyance, it may make you a less efficient programmer, but using it does not cause psychological or physical harm found in abusive relationships.

    8. dgfitz ◴[] No.43986014{4}[source]
    I believe you can do that in C pretty easily with a void pointer, someone correct me if I'm mistaken.

    Should you? Different question entirely.

    replies(2): >>43988260 #>>44003293 #
    9. pessimizer ◴[] No.43987271[source]
    Works that way with learning a spoken language, too. I couldn't learn my second language until I stopped thinking I was supposed to judge whether things in the language were "good" or not. Languages aren't meant to be "good" in a beauty contest sense, they're supposed to be useful. Accept that they are useful because many, many people use them, and just learn them.

    I probably wouldn't have been able to do that with Rust if I hadn't been an Erlang person previously. Rust seems like Erlang minus the high-overhead Erlangy bits plus extreme type signatures and conscious memory-handling. Erlang where only "zero-cost abstractions" were provided by the language and the compiler always runs Dialyzer.

    10. atoav ◴[] No.43987603{4}[source]
    Also: everybody can write a program that does the thing it is intended to do. That is the easy part. The hard part is writing a program that does not do things it isn't intended to do while existing in a ever changing environment and even be subjected to changes of its own source code.

    So the hard part isn't getting code to work, it is ensuring it is only working in the intended ways, even when your co-worker (or your future self) acts like an unhinged, unristricted idiot. And that means using enforced type systems, validation, strict rules.

    If you are a beginner cobbling hobby programs an anything-goes approach to software may feel nice and like freedom, but beyond a certain level of complexity it will land you in a world of pain.

    Any great C programmer whose code I ever had the pleasure of reading has a plethora of unwritten rules they enforce through their heads. And these rules exist there for a reason. When you have a language that enforces these rules for you, that gives you the freedom to dare more, not less, as certain things would be very risky with manual checking.

    It is like the foam pit in extreme sports. While it is certainly more manly to break your neck in ten consecutive tripple-backflip tries, you are going to get there faster with a foam pit where you can try out things. And the foam pit transforms the whole scene, becaus people can now write code that before would crash and burn without feeling restricted. Funny how that goes.

    replies(1): >>43993395 #
    11. quietbritishjim ◴[] No.43988260{5}[source]
    But you can't add 2 void pointers and seamlessly get integer addition if they point at integers or concatenation if they point at strings.

    (You could build your own custom data types that have type metadata in a shared header and an addition function that uses it, but then you're building your own custom language on top which isn't really the same thing.)

    So yes C really does restrict you in some ways that Javascript doesn't.

    replies(1): >>43988476 #
    12. dgfitz ◴[] No.43988476{6}[source]
    That wasn't the constraint I was responding to, you moved the goalposts! :)
    13. freilanzer ◴[] No.43993395{5}[source]
    Restrictions foster creativity, and also free up mindspace to think about your actual problem in more detail.
    14. freilanzer ◴[] No.43993404{3}[source]
    If your compiler does not let you compile garbage code, then it's restricting you, but that's exactly what you want - you don't want to compile something that is incorrect. Rust just enforces more rules than, say, Ruby or C/C++.
    15. int_19h ◴[] No.44003293{5}[source]
    Pedantically speaking, you can't. You can have a variable that points to an integer 5, and then make it point to a character array "hello\0". But the value of the variable is a pointer in both cases.

    Curiously enough, this is also true of Python - just less obvious because it doesn't have any variables that aren't pointers, and most operators perform an implicit dereference.

    replies(1): >>44013551 #
    16. boomlinde ◴[] No.44013551{6}[source]
    > Pedantically speaking, you can't. You can have a variable that points to an integer 5, and then make it point to a character array "hello\0". But the value of the variable is a pointer in both cases.

    Unions may be the better analog here.

    > Curiously enough, this is also true of Python - just less obvious because it doesn't have any variables that aren't pointers, and most operators perform an implicit dereference.

    That's more like an implementation detail than a quality of the language itself. A JavaScript implementation might do the same. For example, values in V8 are all either pointers to the heap except in the case of small (31-bit) integers, and a less optimized implementation might not even make that distinction and allocate everything on the heap. Similarly, a Python implementation might store SMIs directly where the pointer would be, like V8. PyPy uses both tagged pointers/SMIs and may even allocate registers for values.

    replies(1): >>44018547 #
    17. int_19h ◴[] No.44018547{7}[source]
    > Unions may be the better analog here.

    Tagged unions would be, except they aren't first class in C.

    The best analogy here would probably be OCaml polymorphic variants (https://dev.realworldocaml.org/variants.html)

    > That's more like an implementation detail than a quality of the language itself.

    It is not, though, because - unlike JavaScript - the fact that everything is a reference to object, and each object has a unique identity, is explicitly a part of Python semantics, and this is very visible in many cases. It's easy to observe it for "primitive" types as well simply by inheriting from them.

    (OTOH the fact that a given Python implementation might still implement this by using tagged pointers etc is an implementation detail, because it is still required to behave as-if everything was an object).

    replies(1): >>44020135 #
    18. boomlinde ◴[] No.44020135{8}[source]
    > Tagged unions would be, except they aren't first class in C.

    For the originally stated example, 'declare a variable, set it to 5 (number), and then set it to the "hello" (string)', a plain union is just fine.

    > The best analogy here would probably be OCaml polymorphic variants

    It would be, except OCaml is not C.

    > It is not, though, because - unlike JavaScript - the fact that everything is a reference to object

    Evidently, references and pointers are not the same thing, hence it is an implementation detail whether references correspond to pointers.

    > and each object has a unique identity

    Which doesn't necessarily have anything to do with their address. It's an opaque value guaranteed to be unique for an object for the duration of its lifetime.

    Meanwhile, C pointer values aren't necessarily unique for different objects. For example, a pointer to a struct with one or more fields shares value with a pointer to its first field. It's only once you factor in type that pointers uniquely identify a particular object, so they don't exactly correspond to Python's object identity.