6
jestdotty
29d

wait, people call JavaScript code gross but this is C? wtf

Comments
  • 7
    The C looks fine, but the Rust code looks cursed. Stockholm syndrome most likely.

    Edit: Would rather do this in C++.
  • 10
    Actually 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++.
  • 4
    C 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.
  • 18
    I 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.
  • 1
    @lorentz lol, you are savage man!
  • 6
    Both looks ugly, I prefer Brainfuck
  • 4
    Those 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
  • 2
    What's gross about the C code?
  • 2
    @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
  • 3
    @lorentz My first reaction reading it was aargh memory leak.
  • 2
    @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!"
  • 2
    @Demolishun Hmm... kill everyone, steal the useful stuff, set the rest on fire. Actually that sounds strangely familiar.
  • 2
    @donkulator Chicago, you were thinking of Chicago.
  • 0
    I 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.
  • 1
    @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.
  • 1
    You 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.
  • 1
    and 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.
  • 0
    Well g, u might have to declare it as a class in c so u can input the different variables yourself.
Add Comment