by noncoml · 2y ago · 0 comments
Edit: Yes, it does write some code that is "close" enough, but in some cases it is wrong, in others it doesn't not do exactly what asked. I.e. needs supervision from someone who understands both the requirements, the code and the problems that may arise from the naive line that the LLM is taking. Mind you, the most popular the issue, the better the line LLM is taking. So in other words, IMHO is a glorified Stack Overflow. Just as there are engineers that copy-paste from SO without having any idea what the code does, there will be engineers that will just copy paste from LLM. Their work will be much better than if they used SO, but I think it's still nowhere to the mark of a Senior SWE and above.
use std::fs::File;
use std::io::{self, BufReader, Read};
fn read_file_character_by_character(path: &str) -> io::Result<()> {
// Open the file in read-only mode.
let file = File::open(path)?;
// Create a buffered reader to read the file more efficiently.
let reader = BufReader::new(file);
// `chars` method returns an iterator over the characters of the input.
// Note that it returns a Result<(char, usize), io::Error>, where usize is the byte length of the char.
for char_result in reader.chars() {
match char_result {
Ok(c) => print!("{}", c),
Err(e) => return Err(e),
}
}
Ok(())
}
fn main() {
let path = "path/to/your/file.txt";
if let Err(e) = read_file_character_by_character(path) {
eprintln!("Error reading file: {}", e);
}
}(Also, the comment about the iterator element type is inconsistent with the code following it. Based on the comment, `c` would be of type `(char, usize)`, but then trying to print it with {} would fail because tuples don't implement Display.)
use std::fs::File;
use std::io::{self, Read};
fn read_file_character_by_character(path: &str) -> io::Result<()> {
let mut file = File::open(path)?;
let mut contents = String::new();
file.read_to_string(&mut contents)?;
for c in contents.chars() {
println!("{}", c);
}
Ok(())
}
fn main() {
let path = "path/to/your/file.txt";
if let Err(e) = read_file_character_by_character(path) {
eprintln!("Error reading file: {}", e);
}
}- It should be generating `path: impl AsRef<Path>` to be properly generic.
- It's not setting a nonzero exit code on error.
- Edge case handling is a vital property for production-usable tools at scale. I'm wondering if it can yet special case situations such as creating a conditional compilation version for Linux that uses the splice syscall when the arguments are 2 file handles.
the typing of code is the easy part even though it's a part a lot of folks are somewhat addicted to.
the things which have far more value are applying value judgements to requirements, correlating and incorporating sparse and inaccurate diagnostic information into a coherent debugging strategy, and so on. there will come a time when it can assist with these too, probably first on requirements distillation, but for more complex debugging tasks that's a novel problem solving area that we've yet to see substantial movement on.
so if you want to stave off the robots coming for you, get good at debugging hard problems, and learn to make really great use of tools that accelerate the typing out of solutions to baseline product requirements.
use std::fs::File;
use std::io::{self, Read};
use std::str::from_utf8;
fn read_file_character_by_character(path: &str) -> io::Result<()> {
// Open the file in read-only mode.
let mut file = File::open(path)?;
let mut buffer = [0; 4]; // UTF-8 character max byte length
let mut temp_buffer = vec![];
while let Ok(bytes_read) = file.read(&mut buffer[..1]) { // Read byte by byte
if bytes_read == 0 { // End of file
break;
}
temp_buffer.push(buffer[0]);
if let Ok(s) = from_utf8(&temp_buffer) {
if s.chars().count() == 1 { // Complete character read
print!("{}", s);
temp_buffer.clear(); // Clear temp buffer for next character
}
}
}
Ok(())
}
fn main() {
let path = "path/to/your/file.txt";
if let Err(e) = read_file_character_by_character(path) {
eprintln!("Error reading file: {}", e);
}
}You're going to have to buffer at least a little, to figure out where the USV / grapheme boundary is, depending on our definition of "character". To me, a BufReader is appropriate here; it avoids lots of tiny reads to the kernel, which is probably the right behavior in a real case.
To me, "read character by character" vaguely implies something that's going to yield a stream of characters. (Again, for some definition there.)
Also I just asked Claude and Gemini and they both provided an implementation that matches the “bytes to UTF-8” rust docs. Assuming those are right,LLMs can do this (but I haven’t tested the code).
But I think that AI coding will upset this equilibrium by reducing the quality even more, and significantly enough that users will very much notice - and for many of them it will push things into "what I need doesn't work most of the time" category. And then there will be payback.
Then again, I am an optimist.
We can't hope to compete with something that can edit all the files in less than 5 minutes.
If you're not at least trying to plan what your life will look like under these circumstances then you're doing yourself a disservice.
But, for most of the debates I've seen, I don't think it the answer matters all too much.
Once we have models that can act as full senior SWEs.. the models can engineer the models. And then we've hit the recursive case.
Once models can engineer models better and faster than humans, all bets are off. Its the foggy future. Its the singularity.
This is such an extremely bullish case, I'm not sure why you'd think this is even remotely possible. A Google search is usually more valuable than ChatGPT. For example, the rust utf-8 example is already verbatim solved on reddit: https://www.reddit.com/r/rust/comments/l5m1rw/how_can_i_effi...
I'm not saying that the whole "robots building better robots" thing is a pipedream, but given where things are today, this is not something that's going to happen soon.