• 0 Posts
  • 126 Comments
Joined 1 year ago
cake
Cake day: September 2nd, 2023

help-circle
  • I hate both of them. The first one is very clunky with all the ". The second one is not self-docummenting at all, and it makes some enums impossible.

    For example, you can’t represent:

    enum A {
        B(u32)
        C(u32)
        D
    }
    

    It would be

    A {
        | u32
        | u32
        | ()
    }
    

    Also, the pipe is very awkward to type, specially depending on keyboard layout. Since it’s a rare character. If you need to separate between enums and struts and really don’t want to use the enum and struct keywords, you can use different delimiters, like:

    A [
     u32,
     u32
    ]
    
    B {
     u32,
     u32
    }
    

  • In my experience, nobody really knows what OOP is, everyone has a different definition.

    Most of the “OOP” features are implemented in languages that are not OOP. The only one that is to me an OOP-exclusive feature is class-inheritance. So IMO OOP=class inheritance.

    There is plenty of criticism about inheritance, specially among rust lovers. Since rust implements other features associated with classes, except class inheritance. Such as: methods (and self keyword), interfaces (traits), default interface method implementation.

    Anti-OOPs usually argue that encapsulation and interface is a much better alternative to class inheritance.

    Some things class inheritance is criticized for:

    Diamond inheritance problem: If there is class A. B and C inherit from A and override its methods. D inherits B and C without overriding them. What implementation should D inherit? B or C? Same happens if only B or C overrides.

    Encourages having multiple layers of abstraction: it’s not uncommon to see huge inheritance chains. MyCustomList -> OrderedVector -> OrderedList and Vector -> List -> Collection -> Iterator. Just by looking at MyCustomList, you don’t know the entire chain, you just see “OrderedVector”. You have to follow many nested links until you can know it all, and then you have to retain that knowledge along with tens of other inheritance chains.

    Not ideal for performance: Inheritance encourages designs where the compiler will need to add a v-table to classes. These tables make implementation of OOP patterns much easier, but they require additional overhead when calling methods. Note that v-tables are not OOP specific, rust needs them also for trait objects. However, rust encourages designs with small amount of trait objects.

    Not as intuitive as claimed: People are taught OOP with simple examples involving real-world objects like: car -> vehicle -> object. However, these situations are rare except in some specific cases like UIs, video games, simulations. In most other cases, you are dealing with concepts rather than objects. And even when you’re dealing with objects, it’s not a clear cut. Sometimes it might happen that bicycle -> car. Even though not intuitive, in some situations this may be a useful inheritance. But when bicycle inherits car, it no longer resembles the inheritance-chain of the real world, so that’s extra work for the brain.




  • C:

    int increment(int i) {
        return (int) (1[(void*) i])
    

    However, if you wanna go blazingly fast you gotta implement O(n) algorithms in rust. Additionally you want safety in case of integer overflows.

    use std::error::Error;
    
    #[derive(Debug, Error)]
    struct IntegerOverflowError;
    
    struct Incrementor {
        lookup_table: HashMap<i32, i33>
    }
    
    impl Incrementor {
        fn new() -> Self {
            let mut lut = HashMap::new();
            for i in 0..i32::MAX {
                lut.insert(i, i+1)
            }
            Incrementor { lookup_table: lut }
        }
    
        fn increment(&self, i: i32) -> Result<i32, IntegerOverflowError> {
            self.lookup_table.get(i)
                .map(|i| *i)
                .ok_or(IntegerOverflowError)
    }
    

    On mobile so I don’t even know if they compile though.


  • This user was not using git though, he was using vs code. That button doesn’t say “git reset” it says “discard all changes”. And btw, what it does is “git clean”, which is something that git can do.

    Just below the button there is a list of all the changes. In his case, there were 3000 changes of the type “file creation”. Discarding a file creation can only be made one way: deleting the file.

    Anyway, this user is presumably in his learning phase, I would not assume that he knows what git reset or git restore actually do.


  • There is a warning. IIRC it says “are you sure you want to discard all changes? This action is unreverisble”. In the context of version management. Creating a file is a change. And just below the button to discard all changes is the list of changes. In that list he could’ve seen 3000 changes of the type “file creation”, when you discard a file creation, it means to undo the creation, which is a deletion.

    The button days what is going to do. There is a warning about what it’s going to do. And there is a list of the exact changes it’s going to undo.

    The only way to avoid this from happening is to not have the button exist. In that case, the users that actually want to discard all changes would be unable to do so.



  • I don’t even know why people ITT are blaming the IDE and completely ignoring this.

    When you learn git, you do so on a dummy project, that has 5 files which are 10 characters long each.

    An IDE is not made so you can’t break things, it is tool, and it should let you do things. It’s like complaining that Linux will let you delete your desktop environment. Some people actually want to delete your desktop environment. You can’t remove that option just because someone can accidentally do it by ignoring all the warnings.


  • calcopiritus@lemmy.worldtoProgramming@programming.devOn "Safe" C++
    link
    fedilink
    arrow-up
    16
    arrow-down
    1
    ·
    2 months ago

    And unfortunately, this means that WG21, the C++ committee, has to take action because people are demanding it

    Why does this mean that they have to take action? Why do they need to make C++ memory safe?

    C++ was not designed to be memory safe. If you try to make C++ memory safe, you’ll have to break retro compatibility. If you’re going to break retro compatibility, can you say it’s still C++? Or another language called C++2? At that point, why not just use another language that was designed from the start to be memory safe?

    The action that should be taken is to completely avoid starting any new project in C++, and let the language die. A programming language is nothing more than a tool, once the tool no longer works, you search for another that does.

    C++ should go the way of fortran and cobol. The only development of C++ should be done is to maintain existing huge codebases that would be too expensive to rewrite.




  • Editor/IDE, whatever. People claim both about jetbrains.

    If you want a purely editor-thing:

    Whatever vscode does with Ctrl+D (I don’t know the name). Ctrl+D is probably the hotkey I use most in vscode (probably more than Ctrl+S), yet CLion doesn’t have that. I’ve searched multiple times the whole settings for it.

    Those two examples are just the ones that most recently occurred to me, it has a lot more issues. For example the lack of a staging area. You can’t “git stage” in CLion.

    And I don’t think that the git integration is free from criticism. Git integration is one of the most important features of IDEs. It’s absolutely valid to criticize it.

    The autoformatter also doesn’t work correctly when developing in remote. Which means that unless I want my PRs to have thousands of lines of whitespace changes, I can’t use the auto formatter.

    Now I don’t know if this is a CMake issue or CLion. But at one point It was "#include"ing a struct from a header file I had deleted 1 hour previous to the build failing. The only way to fix that was to create the file again and delete it again.

    These complaints might seem small. But put together they are hours of wasted time that you don’t expect from the “best” of something.


  • Don’t need to go all the way there. I always heard that jetbrains make the best editors. Yet when my job forced everyone to use CLion I saw that it was just a lie. The editors aren’t good, they are just expensive.

    There are 2 easy examples:

    1. Remote developing sucks. Loading a remote cmake project takes ages. Yet if you remove the temp directory it’s almost instantaneous. Except when you do it too often and clion refuses to sync the files, then you’re fucked because there isn’t a “sync” button, it only happens automatically.

    2. The commit log is awful. It doesn’t by default show you the commit/branch you’ve checked out, it shows the chronologically most recent commit. There’s no “go to checked out commit” button either, you have to write the hash in the search field. Which btw the search is trash. If you write 6 of the characters of the hash it shows “there are no results”, yet when you write the 7th, suddenly your commit appears.





  • I don’t know why you are being so rude. I thought it was the rust community that was known for being toxic?

    It’s not my opinion on what the unsafe keyword means. That’s its purpose. Nobody ever wants to write unsafe code on purpose. The unsafe keyword was created to allow safe programs to be created in rust that wouldn’t be accepted by the strict rust compilers.

    In a Venn diagram, there are 2 circles: safe programs (1) and programs that are deemed safe by the rust compiler (2).

    Circle 2 is smaller than circle 1 and entirely contained inside it. However, there is no reason to not let people write programs from circle 1 that aren’t in circle 2. The unsafe keyword exists to enable programmers to write those programs in rust. However, it comes with a warning, now the programmer is the one responsible for making the program inside circle 1.