Jump in the discussion.

No email address required.

Okay so what the frick exactly is Rust and why does anyone use it over any other language?

Jump in the discussion.

No email address required.

1. Ugly trannified version of C

See this cockchopped method to read a file:

pub fn read<P: AsRef<Path>>(path: P) -> io::Result<Vec<u8>> {
  fn inner(path: &Path) -> io::Result<Vec<u8>> {
    let mut file = File::open(path)?;
    let mut bytes = Vec::new();
    file.read_to_end(&mut bytes)?;
    Ok(bytes)
  }
  inner(path.as_ref())
}

:vulgar: :marseyconfused:

vs similar in C (not 1 to 1 but also reading a file):

int main(void)
{
/* declare a file pointer */
FILE    *infile;
char    *buffer;
long    numbytes;
 
/* open an existing file for reading */
infile = fopen("test.dat", "r");
 
/* quit if the file does not exist */
if(infile == NULL)
    return 1;
 
/* Get the number of bytes */
fseek(infile, 0L, SEEK_END);
numbytes = ftell(infile);
 
/* reset the file position indicator to 
the beginning of the file */
fseek(infile, 0L, SEEK_SET);	
 
/* grab sufficient memory for the 
buffer to hold the text */
buffer = (char*)calloc(numbytes, sizeof(char));	
 
/* memory error */
if(buffer == NULL)
    return 1;
 
/* copy all the text into the buffer */
fread(buffer, sizeof(char), numbytes, infile);
fclose(infile);

/* confirm we have read the file by
outputing it to the console */
printf("The file called test.dat contains this text\n\n%s", buffer);

/* free the memory we used for the buffer */
free(buffer);
 
return 0;
}

Pointers (*) are the one weird syntax thing, once you understand them it's very simple. Rust version has like 15 weird syntax things you need to understand in one tiny code block. As a straight White man, I refuse.

2. The Rust Developer Code of Conduct entitles you to free HRT for life :marseytransflag2:

Jump in the discussion.

No email address required.

Anyone who advocates for C/C++ as a good general purpose language is either a 150 IQ turboneurodivergent, or has never had to read code written by the former group.

Jump in the discussion.

No email address required.

OS development is only for 150 IQ turboneurodivergents so it works out

Jump in the discussion.

No email address required.

Those '150 IQ' neurodivergents still making software with memory bugs tho

Jump in the discussion.

No email address required.

Idk what's so hard. Memory is basically infinite nowadays. It won't be long until 128gb laptops hit the market. Just don't free and you won't have any memory bugs.


https://i.rdrama.net/images/1735397835BTbCkGwWb5B-VQ.webp

Jump in the discussion.

No email address required.

:marseytruthnu#ke:

Jump in the discussion.

No email address required.

:#marseyagree:

Jump in the discussion.

No email address required.

If you want a general purpose language, just use f***ING csharp or Java like an actual human

Rust is just dog shit ugly c+ that holds your hand like some kinda gay :marseytrain: UK state strag shit


dude bussy lmao

Jump in the discussion.

No email address required.

>csharp or Java

>actual human

:#marseyreluctant:

I've been meaning to learn rust but I can't say I have an educated opinion of it aside from hating rust evangelists. I do want a performant compiled language that isn't C/C++ though. What I really want is C++, but not a giant pile of unreadable shit waiting to shoot you in the foot because you didn't neurodivergently RTFM about some obtuse edge case.

Go is based and probably the best language for most systems code that isn't extremely performance sensitive but I have no data to back that up.

Jump in the discussion.

No email address required.

Go is fantastic for their unyielding support for backwards compatibility and static compilation.

It's amazing to know you can bump the Go compiler up on a schedule and everything "Just works" and then all you need to do is deploy a SINGLE binary, it's glorious :marseywholesome:

The people hating on Rust are memeing, it's a great language and has a bright future. I know multiple people using it in prod and who love it.

Jump in the discussion.

No email address required.

Rust also makes double checking and bug fixing easier due to having a more descriptive compiler and memory unsafe portions being explicitly declared. Its pretty nice.

Jump in the discussion.

No email address required.

:marseyfemboytalking:

Jump in the discussion.

No email address required.

Rust is absolutely fantastic for getting like 80% of C++ performance for 20% of the effort. Really great for larger projects esp if you need the performance.

Jump in the discussion.

No email address required.

:marseytrans2talking:

Jump in the discussion.

No email address required.

80% performance? Rust compiles down via LLVM just like C++ so you can get 100% of C++ performance if you're even slightly smart about things (maybe 30% of the effort rather than 20%).

Jump in the discussion.

No email address required.

:marseyeggirltalking:

Jump in the discussion.

No email address required.

lol no generics

Jump in the discussion.

No email address required.

At this point fricking Python is faster the Java. C# is fine I just find the compilation from source process insane vs C++. with C++ you just type make and it works but with c# you have to put in 20 different command line flags.

Jump in the discussion.

No email address required.

I fricking hate Java so much dude. I have nothing against C# other than Microsoft=bad (and incompatible with all of my machines)

Jump in the discussion.

No email address required.

I do want a performant compiled language that isn't C/C++ though.

Zig is pretty good, it's closer to C than C++.

Jump in the discussion.

No email address required.

Keep moving zigger, this is a rust neighborhood

https://i.rdrama.net/images/1739514574_hYAeONobIDSKg.webp

Jump in the discussion.

No email address required.

I guarantee that you don't write any code that actually needs performance. Just use literally anything else, it won't matter.

Jump in the discussion.

No email address required.

Most people don't build anything where performance matters, they just think they do. At least not at a systems level where the difference between C++ vs Python is actually relevant.

I'm a senior and I don't think I've written truly performance sensitive code since I was an intern (I/O path kernel code), and that got abandoned before making it to prod (RIP).

I went through a phase in grad school where I reimplemented everything in my LeedCode history with janky C++ and inline assembly so I could snag the 100th percentile. Completely useless exercise but it was fun :marseydramautist:

Jump in the discussion.

No email address required.

>grrrr I don't like unreadable garbage with edge cases you need to look up

>Rust

:surejan:


dude bussy lmao

Jump in the discussion.

No email address required.

garbage collection

Jump in the discussion.

No email address required.

Not sure why you'd start a greenfield Java project when you could at least use Kotlin.

Jump in the discussion.

No email address required.

Reported by:

It's hilarious how bug-ridden your short C code snippet is.

1. buffer contents aren't null-terminated properly, so printf will always do an out of bounds read. This is exactly the kind of bug that Rust is meant to prevent. BTW, even if it was terminated properly, it's generally a mistake to assume that an input file doesn't contain null bytes, you should instead use a function that takes the input size.

2. fseek and ftell are broken by design and they will not work with files larger than 2GB on the platforms where sizeof(long) == 4, e.g. Windows (both 32-bit and 64-bit) and 32-bit Linux.

3. The code doesn't check for ftell and fseek errors and potentially treats the error sentinel value (long)-1 as a filesize and passes it to calloc and fread.

Jump in the discussion.

No email address required.

Sure, here's a better version that addresses all 3*: https://stackoverflow.com/a/54057690 (this just limits file size, if you for some reason need to load large files in memory at once: https://wiki.sei.cmu.edu/confluence/display/c/FIO19-C.+Do+not+use+fseek%28%29+and+ftell%28%29+to+compute+the+size+of+a+regular+file (since you probably don't need this, just do it in chunks: https://stackoverflow.com/a/11792512))

*Well, looks like it still doesn't error check ftell. Imagine they do.

Remains perfectly readable unlike Crust.

Jump in the discussion.

No email address required.

What if you put a comment above each line?

pub fn read<P: AsRef<Path>>(path: P) -> io::Result<Vec<u8>> {
  // define a local helper function because GPT told me to
  fn inner(path: &Path) -> io::Result<Vec<u8>> {
    // open file for reading
    let mut file = File::open(path)?;

    // create a dynamically sized buffer to hold file contents
    let mut bytes = Vec::new();

    // read data into the buffer
    file.read_to_end(&mut bytes)?;

    // give buffer to the caller
    Ok(bytes)
  }

  // satisfy type system (I didn't go to college)
  inner(path.as_ref())
}
Jump in the discussion.

No email address required.

The syntax being confusing is to me specifically about, in order:

  • P: AsRef (P seems like a generic type like Java? But who knows what AsRef is doing here, is that just a pointer? Why isn't P reused, could it be? I'm guessing that P is now a generic type for a pointer to a Path?)

  • -> io::Result (is io a library, like C++? Why do I need to wrap my return vector in an io::Result? Is this like JS Promises? Nothing is manually returned, what is the return vector, bytes?)

  • path: &Path (is this dereferencing path?)

  • let mut file (is mut just saying file is non-const and can be redefined? Is that not the default like in every other language? Why is it needed here since file is never redefined? That leads me to suspect it actually means something else, if so wtf?)

  • File::open(path)? (wtf is the ? doing here? Is :: both how you refer to library types like io::Result and how you call static methods like File::open?)

  • Vec::new() (wait I thought this was a strongly typed language? Why is just a generic Vec allowed? Is there some default "bytes" type?)

  • (&mut bytes)? (so was bytes actually a pointer, and this is dereferencing it? I was assuming mut meant non-const when declaring variables, wtf is it doing here, also again wtf is the ? doing here)

  • Ok(bytes) (I guess Ok probably returns whatever you give it? Tbf your comment here does imply an answer to this one)

  • inner(path.as_ref()) (I'm left suspicious that "ref/AsRef" isn't just a pointer, because doesn't Rust just have normal * syntax for pointers too? Also wait, read takes in a ref to a path, right? But then it calls inner with path.as_ref. Wtf, isn't it now a pointer to a pointer, then dereferenced in inner automatically with path: &Path, resulting in path being a pointer in inner? If so is this intentional??? Maybe File::open expects a pointer to a Path and not a Path?)

Could I answer all these questions with some learning and research? Yeah ofc. But I refuse, trannies should try again and make their language less obtuse.

Jump in the discussion.

No email address required.

language bad because I'm too r-slurred to google beginner questions

Jump in the discussion.

No email address required.

Beginners to a language shouldn't need to go down a dozen weird syntax rabbit holes to completely understand every part of something as basic as reading a file. KISS

Jump in the discussion.

No email address required.

ahhhh namespaces ahhhhhh algebraic types my head nooooooooooooo

Jump in the discussion.

No email address required.

More comments

:#marseyserioushatfact:

You should be able to write code day 1 that looks like it works (but will actually corrupt your data)

Jump in the discussion.

No email address required.

More comments

This is one of the worst posts I have EVER seen. Delete it.

Jump in the discussion.

No email address required.

Your entire argument is basically "ChatGPT generated some shit that I don't understand and I'm too lazy to read a tutorial/book." It's fascinating that with your level of knowledge, you think you're entitled to having an opinion.

"I should be able to understand this without learning!!!" Yeah, just like you wrote broken C code that you thought you understand. You don't even seem to have a good grasp of C and C++, and yet expect to magically know Rust. The questions about basic syntax and error handling could be easily answered by skimming through a few chapters of "Programming Rust".

Also, the code is complicated because the inner wrapper is entirely pointless.

This code is fully equivalent to the original version:

pub fn read<P: AsRef<Path>>(path: P) -> io::Result<Vec<u8>> {
    let mut file = File::open(path)?;
    let mut bytes = Vec::new();
    file.read_to_end(&mut bytes)?;
    Ok(bytes)
}

Second of all, you "wrote" a generic function that takes arguments of multiple types (path objects/strings). If we simplify it to taking just strings, it would look like this:

pub fn read(path: &str) -> io::Result<Vec<u8>> {
    let mut file = File::open(path)?;
    let mut bytes = Vec::new();
    file.read_to_end(&mut bytes)?;
    Ok(bytes)
}
Jump in the discussion.

No email address required.

>Also, the code is complicated because the inner wrapper is entirely pointless.

wrong

Jump in the discussion.

No email address required.

Elaborate

Jump in the discussion.

No email address required.

More comments

Just read the book and my r-slurred choices will make sense!!!

:wingcucks#:

:gigachad2: : :dukenuk#emtldr:

Jump in the discussion.

No email address required.

>"understands" C pointers

>frightened and confused at pass-by-reference

Jump in the discussion.

No email address required.

Yeah that one's on me, pretty much same as C/C++, been a while since I've touched either :marseyderp:

Jump in the discussion.

No email address required.

With colons, the type comes after the variable name. With that, most of your syntax confusion goes away.

P: AsRef

P is of type "AsRef"

path: &Path

path is of type "&Path", which is a reference to an object of type Path

mut is deeper than just const or non-const. By default, the variable and all its internal components are const. mut gives you the ability to call functions that reassign some internal variable that's part of the outer thing you're calling on.

? is a shortcut for "unwrap or return an error" for the Result monad in rust

Jump in the discussion.

No email address required.

By default, the variable and all its internal components are const

:pepereeeeee: I HATE IT

Good explanations tho ty :marseythumbsup:

Jump in the discussion.

No email address required.

!codecels He should've used D

Jump in the discussion.

No email address required.

ONLY use languages approved by Walter Bright!

Jump in the discussion.

No email address required.

It's hilarious how bug-ridden your short C code snippet is.

I don't think it's hilarious

Jump in the discussion.

No email address required.

kek C-huds rekt

Jump in the discussion.

No email address required.

Factcheck: This claim is 100% true.

Jump in the discussion.

No email address required.

C tards are relics of a dying world. All a la mode programmers know this.

Jump in the discussion.

No email address required.

The fricking rust is fricking unreadable to me, the fricking C is fricking straightforward. Why does the fricking rust one need an inner function, b-word? Totally bizarre.

Jump in the discussion.

No email address required.

I dont think it does

Jump in the discussion.

No email address required.

>stackoverflow or gemini

Call it

Jump in the discussion.

No email address required.

You definitely don't need that fancy templating in the Rust version unless you're trying to be fancy or write a really nice API or something.

Just take a Path ref ffs

Jump in the discussion.

No email address required.

You will NEVER be a woman.

Jump in the discussion.

No email address required.

:#marseyagreefast:

Jump in the discussion.

No email address required.

Source?

Jump in the discussion.

No email address required.

Why the frick are you writing in C and not C++. Disgusting code.

Jump in the discussion.

No email address required.

https://i.rdrama.net/images/1739504513NtvUMznF980UHA.webp

Jump in the discussion.

No email address required.

Bring it motherlover!

https://i.rdrama.net/images/1739507397JCpCmdeCRX-K2g.webp

Jump in the discussion.

No email address required.

:lowqualit#ybait:

Jump in the discussion.

No email address required.

Imagine understanding any of this, if you want to read a file why not just USE YOUR EYES? Zoomers smh.

Jump in the discussion.

No email address required.

PHP chads keep on winning

echo file_get_contents(file);

Jump in the discussion.

No email address required.

Further detranified it for you. See all that whitespace to the right of your code? That's empty space waiting to be filled.

int main(void)
{
	/* declare a file pointer */
	FILE    *infile;
	char    *buffer;
	long    numbytes;
 
	infile = fopen("test.dat", "r");       // open an existing file for reading 
	if(infile == NULL)  return 1;          // quit if the file does not exist 
	fseek(infile, 0L, SEEK_END);     numbytes = ftell(infile);    // Get the number of bytes
	fseek(infile, 0L, SEEK_SET);	     //  reset the file position indicator to the beginning of the file
	buffer = (char*)calloc(numbytes, sizeof(char));        //  grab sufficient memory for the buffer to hold the text
	if(buffer == NULL)  return 1;        // memory error
	fread(buffer, sizeof(char), numbytes, infile);    // copy all the text into the buffer
	fclose(infile);
	printf("The file called test.dat contains this text\n\n%s", buffer);     // confirm we have read the file by outputing it to the console
	free(buffer);     // free the memory we used for the buffer
	return 0;
}
Jump in the discussion.

No email address required.

:marseygigachad#talking:

Jump in the discussion.

No email address required.

System programming language like c/c++

It's (in)famous for having a strongly opinionated compiler that doesn't allow you to write memory unsafe code.

It has a few nice thing like a good build system through cargo and an algebraic type system. That said the ecosystem is still not as all encompassing as c++ and fighting the borrow checker to compile your code can be tedious

Jump in the discussion.

No email address required.

Cargo is also a package manager which is great. It's the C++ equivalent of conan and cmake merged into one, but it's coherent and not shit. Conan makes me want to commit terrible acts of violence, and it's still the best C++ package manager around - although maybe you could argue that most conan issues are really packaging issues because the people writing C++ packages for it are actual subhuman r-slurs.

Jump in the discussion.

No email address required.

what the frick exactly is Rust

Overhyped language for people that can't code just like Go.

Jump in the discussion.

No email address required.



Link copied to clipboard
Action successful!
Error, please refresh the page and try again.