Yeah you are doing it wrong.

> "Is "192.168.1.4" included in the subnet "192.168.0.0/16"?" -> No

ChatGPT is not good at numbers or complex maths like this.

> Check whether a widget overflows in flutter

I mean this would be closed as unclear on StackOverflow, but again, this is basically asking ChatGPT to write an entire function. It can do a good stab but it's not going to get it correct.

Copilot isn't for that sort of thing. Let me give you a more realistic autocomplete example from my code:

std::fs::write(&sv_path, sv).expect("error writing top.sv");
std::fs::write(&rs_path, rs).expect("error writing top.rs");
std::fs::write(&cargo_toml_path, cargo_toml).expect("error writing Cargo.toml");
std::fs::write(&cpp_path

It completes `, cpp).expect("error writing main.cpp");` which is actually exactly what I had. I may have used Copilot to write that; I don't remember. The point is it is 100% correct and saved me writing all that. Traditional autocomplete can't compete with that.

However even for "do it all for me" queries it can still be useful. For example I asked:

> I have a C++ process paused in a debugger (lldb). It is consuming a lot of memory. Is there any way I can see what is using the memory? E.g. a heap profiler that can attach to the process?

It got it wrong and told me to run the process under Valgrind. I said:

> Those instructions aren't for attaching to an existing process.

And it told me about the Heaptrack project with can do exactly what I want. I can see why search engines are integrating this asap. Even though it hallucinates, it does that infrequently enough that it's still really useful. I mean it hallucinates frequently but even so it is very useful.

Perhaps a better example is this:

> Write a C++ program to run a child process and send data to its stdin and stdout while it is running.

After 2 more prompts I got it to output the code below. This code is not correct. But the fixes to make it work are relatively minor, and EASILY less work than writing it all from scratch.

In a few years we will look on people that don't use Copilot (or similar) like people that don't use IDEs. They're hurting their own productivity out of principal.

-------

#include <iostream>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <vector>

class ChildProcess {
public:
ChildProcess() : pid(-1), pipefd{-1, -1} {}

~ChildProcess() {
if (pid != -1) {
close(pipefd[1]); // Close write end of the pipe
waitpid(pid, nullptr, 0);
}
}

bool create(const std::string& command, const std::vector<std::string>& arguments) {
if (pipe(pipefd) == -1) {
std::cerr << "Failed to create pipe." << std::endl;
return false;
}

pid = fork();
if (pid < 0) {
std::cerr << "Failed to fork process." << std::endl;
return false;
} else if (pid == 0) {
// Child process
close(pipefd[0]); // Close unused read end of the pipe

// Redirect stdin and stdout to the pipe
if (dup2(pipefd[1], STDIN_FILENO) == -1) {
std::cerr << "Failed to redirect stdin." << std::endl;
return false;
}

if (dup2(pipefd[1], STDOUT_FILENO) == -1) {
std::cerr << "Failed to redirect stdout." << std::endl;
return false;
}

// Convert arguments to a C-style array
std::vector<char*> args;
args.reserve(arguments.size() + 2);
args.push_back(const_cast<char*>(command.c_str()));
for (const std::string& arg : arguments) {
args.push_back(const_cast<char*>(arg.c_str()));
}
args.push_back(nullptr);

// Execute the child process
execvp(command.c_str(), args.data());

// execvp() only returns if there's an error
std::cerr << "Failed to execute child process." << std::endl;
return false;
} else {
// Parent process
close(pipefd[1]); // Close unused write end of the pipe
}

return true;
}

void write(const std::string& data) {
if (pid != -1) {
::write(pipefd[1], data.c_str(), data.size());
}
}

std::string read(size_t numBytes) {
std::string output;
if (pid != -1) {
char buffer[numBytes + 1];
ssize_t bytesRead = ::read(pipefd[0], buffer, numBytes);
if (bytesRead > 0) {
buffer[bytesRead] = '\0';
output = buffer;
}
}
return output;
}

std::string readLine() {
std::string output;
if (pid != -1) {
char buffer;
ssize_t bytesRead;
while ((bytesRead = ::read(pipefd[0], &buffer, 1)) > 0) {
output.push_back(buffer);
if (buffer == '\n') {
break;
}
}
}
return output;
}

private:
pid_t pid;
int pipefd[2];
};

int main() {
ChildProcess childProcess;
std::vector<std::string> arguments = {"arg1", "arg2"};
if (childProcess.create("child_process", arguments)) {
childProcess.write("Hello, child process!");

std::string output = childProcess.read(1024);
std::cout << "Child process output: " << output << std::endl;

std::string line = childProcess.readLine();
std::cout << "Child process line: " << line << std::endl;
}

return 0;
}