Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
Demolishun35063221dThe C looks fine, but the Rust code looks cursed. Stockholm syndrome most likely.
Edit: Would rather do this in C++. -
lorentz15183221dActually the C example should have a destructor too, because automatic resource management like all good things (and, frankly, most bad things too) was introduced to systems programming by C++.
-
lorentz15183221dC is an IR to me. I'd never write anything more than examples directly in it, but if you target it with a transpiler you're inherently compatible with every platform in existence.
-
lorentz15183221dI guess the difference is that most idiotic design choices in C are rooted in how computers used to work, whereas the idiotic design choices in JavaScript are rooted in how JavaScript works.
-
Hazarth9530221dThose are not even equivalent, but I guess close enough to make a point.
C++ and std::vector would make it pretty much identical, but pure 98 C.. yeah . You gonna have to get low level, but at the same time with that C code you know 100% what It's doing, whats the size of the memory, how fast it will be accessed, where the data lives.. everything.. complete control... While that Rust Code probably uses dynamically resizable arrays, which already adds some mistery regarding constructing, destructing and allocation logic. Not much, but It's there, and It abstracts all of the low level details. Which is good 99% of the time, but yknow -
lorentz15183221d@jestdotty wdym there are no generics in C at all. Eventually Rust is supposed to get a Numeric trait, until then, it's N: Copy + Add + Sub + Ord + Eq + Sized + 'static + WhateverYouNeed
-
Demolishun35063220d@donkulator if people treated all problems in software engineering like a pirate would. The profession would be so much more interesting and fun: "Aargh! There be memory leaks in these waters!"
-
donkulator3087220d@Demolishun Hmm... kill everyone, steal the useful stuff, set the rest on fire. Actually that sounds strangely familiar.
-
nike-6218dI was about to ask what is so gross about plain english.
But then i decided not to ask.
Somebody carefully explain this post (the original post of the thread) to me. -
lorentz15183218d@nike plain English would be "a layer stores a sequence of real numbers initialized to zeroes".
The rust version says "a layer contains a vector of float. The main way to prepare a layer is by providing a size, in which case the layer will contain that many zeroes".
The C version says "a layer contains a reference to a float and a size. initialize_layout is a function that accepts a reference to a layer and a size, replaces the reference to float in the layer with a reference to new uninitialized space for the specified number of consecutive floats, and replaces the number in the layer with the size."
There's no structure in C at all. Until you read the function body you can only suspect that the pointer is supposed to be pointing to an uninitialized layer, that the pointer inside a layer is an array, or that the array is owned by the layer. Even after reading it, you still don't know whether there are other ways to initialize a layer and whether the array can be null. -
lorentz15183218dYou may argue that my comparison is unfair because initialize_* is a convention just like new, but
1. it's not a language-wide convention, only one of many conventions, new is a language-wide convention.
2. no tool will tell you that the function exists, you have to read the library source or hope it's written down somewhere in REAL plain English.
You can also argue that the sole pointer argument to initialize_* is obviously supposed to be uninitialized, but the function could equally likely expect the struct to be initialized and instead initialize the floats in the buffer. -
lorentz15183218dand I bet that there's a soft requirement in the C version to manually initialize the buffer before calling another library function because it's full of Infinity and NaN by default.
-
nike-6218dWell g, u might have to declare it as a class in c so u can input the different variables yourself.
Related Rants
wait, people call JavaScript code gross but this is C? wtf
rant
rust
gross
javascript
c