Today I had a little aha moment. If anyone asked me yesterday about AI tools integrated into their editor, I would say its a bad idea. Ask me today, I would still say its bad idea. :D Because I don’t want to rely on AI tools and get too comfortable with it. Especially if they are from big companies and communicate through internet. This is a nogo to me.

But since weeks I am playing around with offline AI tools and models I can download and execute locally on my low end gaming PC. Mostly for playing with silly questions and such. It’s not integrated in any other software, other than the dedicated application: GPT4All (no it has nothing to do with ChatGPT)

I’m working on a small GUI application in Rust and still figure out stuff. I’m not good at it and there was a point where I had to convert a function into an async variant. After researching and trying stuff, reading documentation I could not solve it. Then I asked the AI. While the output was not functioning out of the box, it helped me finding the right puzzle peaces. To be honest I don’t understand everything yet and I know this is bad. It would be really bad if this was a work for a company, but its a learning project.

Anyone else not liking AI, but taking help from it? I am still absolutely against integrated AI tools that also require an online connection to the servers of companies. Edit: Here the before and after (BTW the code block in beehaw is broken, as certain characters are automatically translated into < and & for lower than and ampersand characters respectively.)

From:

    pub fn collect(&self, max_depth: u8, ext: Option<&str>) -> Files {
        let mut files = Files::new(&self.dir);

        for entry in WalkDir::new(&self.dir).max_depth(max_depth.into()) {
            let Ok(entry) = entry else { continue };
            let path = PathBuf::from(entry.path().display().to_string());
            if ext.is_none() || path.extension().unwrap_or_default() == ext.unwrap() {
                files.paths.push(path);
            }
        }
        files.paths.sort_by_key(|a| a.name_as_string());

        files
    }

To:

    pub async fn collect(&self, max_depth: u8, ext: Option<&str>) -> Result {
        let mut files = Files::new(&self.dir);

        let walkdir = WalkDir::new(&self.dir);
        let mut walker =
            match tokio::task::spawn_blocking(move || -> Result {
                Ok(walkdir)
            })
            .await
            {
                Ok(walker) => walker?,
                Err(_) => return Err(anyhow::anyhow!("Failed to spawn blocking task")),
            };

        while let Some(entry) = walker.next().await {
            match entry {
                Ok(entry) if entry.path().is_file() => {
                    let path = PathBuf::from(entry.path().display().to_string());
                    if ext.is_none() || path.extension().unwrap_or_default() == ext.unwrap() {
                        files.paths.push(path);
                    }
                }
                _ => continue,
            }
        }

        files.paths.sort_by_key(|a| a.name_as_string());

        Ok(files)
    }
  • GetOffMyLan@programming.dev
    link
    fedilink
    arrow-up
    0
    ·
    3 months ago

    I love using ai to assist with programming.

    I often use it for boring stuff like mass refactoring or generating regex or SQL.

    I wouldn’t use it to write big chunks of code, more to figure out how to do things.

    It’s like an interactive docs that I can ask follow up questions to.

    • Lucy :3@feddit.org
      link
      fedilink
      arrow-up
      0
      ·
      3 months ago

      “mass refactoring or generating regex or SQL” sounds a lot like “big chunks of code” tho. SQL and especially regex is stuff you need to write yourself in order to really understand it.

      • GetOffMyLan@programming.dev
        link
        fedilink
        arrow-up
        0
        ·
        3 months ago

        Regex is very rarely big and SQL is often just to figure out the best way to query something.

        Refactoring is usually something like rewrite these 10 c# classes into records.

        I do understand it. I just don’t want to bother writing it. I can validate the output easily. Works out much quicker overall and often catches edge cases I may not have thought about.

        • nebeker@programming.dev
          link
          fedilink
          English
          arrow-up
          0
          ·
          3 months ago

          If you’re interested in learning more about SQL, throwing EXPLAIN at your query and the AI’s version may be really interesting.

          I’m usually perfectly happy trusting my ORM, but even then it’s really helpful to dig a little deeper to figure things out, both in development and in production.

    • Lucy :3@feddit.org
      link
      fedilink
      arrow-up
      0
      ·
      3 months ago

      “mass refactoring or generating regex or SQL” sounds a lot like “big chunks of code” tho. SQL and especially regex is stuff you need to write yourself in order to really understand it.