• 0 Posts
  • 58 Comments
Joined 2 years ago
cake
Cake day: September 2nd, 2023

help-circle


  • There are use cases. Like containers where the pointer to the object itself is the key (for example a set). But they are niche and should be implemented by the standard library anyway. One of the things I hate most about Java is .equals() on strings. 99.999% of times you compare strings, you want to compare the contents, yet there is a reserved operator to do the wrong comparison.





  • In C, goto is basically a necessity though. There is really no good way of error handling.

    Options:

    1. Using goto
    void func(void *var) {
        void * var2 = malloc();
        if var == Null {
            goto err;
        }
    
        do_something();
    
    err:
        free(var2);
    }
    
    1. Early returns:
    void func(void *var) {
        void * var2 = malloc();
        if var == Null {
            free(var2);
            return;
        }
    
        do_something();
    
        free(var2);
    }
    
    1. Skipping with conditionals:
    void func(void *var) {
        bool error = false;
        void * var2 = malloc();
        if var == Null {
            error = true;
        }
    
        if !error {
            do_domething()
        }
    
        free(var2);
    }
    
    1. Early return + cleanup function.
    void cleanup(void *var2) {
        free(var2);
    }
    
    void func(void *var) {
        void * var2 = malloc();
        if var == Null {
            cleanup(var2);
            return;
        }
    
        cleanup(var2);
    }
    

    Option 1 is really the only reasonable option for large enough codebases.

    Option 2 is bad because duplicate code means you might change the cleanup in one code path but not some other. Also duplicate code takes up too much valuable screen space.

    Option 3 has a runtime cost. It has double the amount of conditionals per error point. It also adds one level of indentation per error point.

    Option 4 is same as option 2 but you edit all error paths in one single place. However, this comes at the cost of having to write 2 functions instead of 1 for every function that can error. And you can still mess up and return while forgetting to call the cleanup function.

    You must also consider that erroring functions are contagious, just like async ones. I’d say most of the time a function is propagated upwards, with very few being handled just as it ocurrs. This means that whichever downside your option has, you’ll have to deal with it in the whole call stack.








  • I don’t know whatever that language is doing is called, but it’s not reference counting. It’s doing some kind of static code analysis, and then it falls back to reference counting.

    If you call that reference counting, what stops you from calling garbage collectors reference counting too? They certainly count references! Is the stack a reference count too? It keeps track of all the data in a stack frame, some of it might be references!


  • I don’t know what you read on my reply. But your reply makes no sense.

    Let me rephrase it if you prefer:

    Claiming that Rusty’s borrow checker is reference counting is hugely misleading. Since the borrow checker was made specifically to prevent the runtime cost of garbage collection and reference counting while still being safe.

    To anyone unaware, it may read as “rust uses reference counting to avoid reference counting, but they just call it borrow checking”. Which is objectively false, since rust’s solution doesn’t require counting references at runtime.

    I don’t know what mutable string or any of the other rant has to do with reference counting. Looks like you’re just looking to catch a “rust evangelist” in some kind of trap. Without even reading what I said.



  • It’s more than 10 years old. It has stable syntax, big standard library, big library ecosystem, plenty of rust programs already in production.

    If by “evolving” you mean “changing”, I don’t think that is an issue at all. At most, they add features. They don’t change or remove. And with the editions system, it should be no issue.

    If by “evolving” you mean “improving”, then I don’t see how that could ever be an issue.


  • No.

    A stack overflow is a symptom, not the illness. A fork bomb is an illness.

    Software coming from the mathematical point of view, assummes it has infinite resources. However, a real computer has many resources that are finite.

    CPU time is finite. Memory amount is finite. There is a finite number of network ports. And so on.

    A stack overflow just means: “you have run out of this resource called ‘the stack’”. The stack is a region of the memory. Each thread of each process has 1 stack, and it is not infinite in size. This program will cause a stack overflow because it is infinitely recursive, and each function call will consume a bit of the stack.

    A forkbomb is not the end of a finite resource. A fork bomb is a program that uses “forking” to rapidly consume system resources. A fork bomb might cause a stack overflow. Or an out of memory issue. Slow the computer a lot. Or if the OS has a hard limit for process amount, it might reach that limit.


  • I do enjoy cleaning code a lot.

    When I work on shitty code I’m always thinking about how shitty it is and thinking on how a different design would make it much easier.

    When you clean the code, you’re implementing that perfect design you were thinking of all that time. And you know from that point on you’ll be thinking less about how shitty the code is.

    If your only task is to clean code and you’re not gonna work on that codebase afterwards, it’s not as rewarding though.