← Home ← Back to /g/

Thread 106001388

74 posts 20 images /g/
Anonymous No.106001388 [Report] >>106001409 >>106001433 >>106001526 >>106001864 >>106002024 >>106002128 >>106002684 >>106003062 >>106003714 >>106003916
Brutal.
Rust btfod once again.
Anonymous No.106001409 [Report]
>>106001388 (OP)
there's two jokes here
- that guy primarily uses OCaml, where types are even more complex than this
- that guy for his current job uses C++ which is... lol...
Anonymous No.106001433 [Report] >>106001468
>>106001388 (OP)
I know nothing about rust
but if that's idiomatic I imagine it can't be that hard to parse once you know what you're doing
Anonymous No.106001468 [Report] >>106001612 >>106001967 >>106006396
>>106001433
>I know nothing about rust
it kinda shows
the problem is not whether something can be read or not
but how easy it is
this is brainfuck. a hello world.
>+++++++++[<++++++++>-]<.>+++++++[<++++>-]<+.+++++++..+++.[-]
>++++++++[<++++>-] <.>+++++++++++[<++++++++>-]<-.--------.+++
.------.--------.[-]>++++++++[<++++>- ]<+.[-]++++++++++.


and this is the same in C
#include <stdio.h>

int main(void)
{
fprintf("hello world\n);
}


both can and have been written by a human
which one would you rather work with?
Anonymous No.106001526 [Report] >>106001568 >>106001576
>>106001388 (OP)
ok, but how often are you trying to implement a function as complicated as try_map? Those are the kinds of functions the library implementers spend weeks on and once they're finished, 100,000 programmers will all use it for decades.
Anonymous No.106001568 [Report] >>106001576 >>106001585 >>106001603
>>106001526
>try_map
>complicated
such is the power of rust
creating problems out of thin air
Anonymous No.106001576 [Report]
>>106001568
>>106001526
which is exactly ops picrel's point btw
the absolute state of crabs
Anonymous No.106001585 [Report] >>106001594
>>106001568
you're being retarded
Anonymous No.106001594 [Report] >>106001749
>>106001585
if you exclude syntactical concerns
and the bells and whistles

tell me what goes on in try_map
i want you to write it / say it out loud so that you understand the enormity of this
Anonymous No.106001603 [Report] >>106001610 >>106001617 >>106001648
>>106001568
yes, implementing map in a dynamic language like javascript where you just throw shit at the wall and see what sticks is fucking simple. when you want to have the exact same flexibility as javascript while simultaneously getting provable safety, it requires complication in the type system.
Anonymous No.106001610 [Report]
>>106001603
it's almost as if having you cake and eating it too isn't trivial
Anonymous No.106001612 [Report]
>>106001468
wow that top one looks really user-friendly, I could have a tiny keyboard and still write code
Anonymous No.106001617 [Report] >>106001648
>>106001603
>provable safety
which goes only as far as static analysis can go without being an impact on the runtime
if only it was a silver bullet, you would at least have a leg to stand on
Anonymous No.106001648 [Report]
>>106001603
>>106001617
btw
the more you defend and push rust
the less likely it is that it will be refined into something usable
Anonymous No.106001718 [Report]
wow, this entire thread is one asshat with Rust derangement syndrome.
Anonymous No.106001749 [Report] >>106001881
>>106001594
Not the guy you're originally responding to, and I suppose "complicated" would not have been his best word choice. But I'll describe what's going on here.

try_map is a method over arrays.
It takes as argument a function f that can fail in some way.
If f fails at all, it returns the first error given by f
Otherwise it returns a new array with f applied to all elements over the original array.

Basically it's just map, but it can fail. The complexity comes from the fact that it's generic. What type of array does it apply over? Arrays of any element (T) and any size (N). What type of function can it take as argument? Anything, even a closure that mutates its closing environment. The function returns type R, which can be any kind of "error" data type. Option, Result, something else... doesn't matter. As long as it implements the Try trait.
Anonymous No.106001864 [Report] >>106001892 >>106002013
>>106001388 (OP)
what's up with this type system masturbation?
does optimized rust even beat optimized C/C++ with those extra type analysis?
and I'm ignoring compile times.
Anonymous No.106001881 [Report] >>106001906 >>106002076 >>106002083 >>106002150 >>106003932
>>106001749
yeah like i said
its unnecessarily complicated
and the complexity emerges from the language
heres an implementation of try_map in c for comparison
int try_map(void *array, int (*function)(void *), size_t elem_size , size_t size)
{
while (size--)
{
int error;
if (error = function(array)) // if non equal to 0, short circuits
return(error);
array -+ elem_size;
}
}


its not bigger that rusts' synopsis alone by much
as for the generic part theres tricks to be played
like name mangling through macros
or encoding the type with the data so that you support heterogenous arrays
or even adding a parameter for your iterator
which you could keep a pointer to within your structures if you wanna be fancy
possibilities are endless
but the complexity then emerges from the machinery
not from the syntax
as it should be
bc otherwise its the definition of fighting the language
thats why i dont like rust and think its a bad product
they had a complex idea with encoding good practices into the synatx but its doesnt mean its good
they offset the job of static analysis to the memory of the user. which is extremely lazy, as a product
Anonymous No.106001892 [Report]
>>106001864
>does optimized rust even beat optimized C/C++
theyre on par, you can do raw asm with both
and you cannot do faster than asm
Anonymous No.106001906 [Report]
>>106001881
>as a product
*for a product
Anonymous No.106001967 [Report] >>106001997 >>106006396
>>106001468
Well, the bottom one won't compile...
Anonymous No.106001997 [Report]
>>106001967
ah shit
i forgot the closing "
as in
printf("hello world");
and in the other code its
array += elem_size
not
array +- size

im baked, indulge me
also thats why testing often is a good practice
Anonymous No.106002013 [Report] >>106002023
>>106001864
The ideal with all of this is for a program to work as intended if it compiles. The point isn't to try to squeeze out extra performance.
Both Rust and modern C++ paradigms try to strive for zero cost abstractions, which compile to nearly the same thing in many cases. Rust's compiler uses a lot of LLVM plumbing that was made for C++, so that makes sense.
One advantage Rust has over C++ is zero size types. The minimum size of a struct in C++ is one byte.
Anonymous No.106002023 [Report] >>106002030
>>106002013
>One advantage Rust has over C++ is zero size types.
???
how do you use em?
Anonymous No.106002024 [Report]
>>106001388 (OP)
Rust seems like a language you use to masturbate your own ego, not to get the job done.
Anonymous No.106002030 [Report] >>106002041
>>106002023
>zero size types
they're basically compile time tags afaik
Anonymous No.106002041 [Report]
>>106002030
and thats the thing:
tags for what if datasize is 0?
curious
Anonymous No.106002076 [Report] >>106002086
>>106001881
>look how simple C is when you throw out all the type safety
the inner working of the mind of a cnile.
Anonymous No.106002083 [Report] >>106002093
>>106001881
shit like this and retards like you are the reason why congress is working on legislation to make C illegal.
Anonymous No.106002086 [Report]
>>106002076
type safety is between your ears, crab
but if you need childproof, then thats what you get i guess
Anonymous No.106002093 [Report] >>106002197
>>106002083
>immediate panic upon seeing void *
autism is a hard handicap
Anonymous No.106002128 [Report] >>106002139
>>106001388 (OP)
You mean a language with a strong type system that errs towards static dispatch by genericizing behaviors (like C++) requires significant type information?
I mean, how retarded are people? Legitimately. This isn't dynamic dispatch untyped garbage full of implicit casts and conversions here. What do you expect?
Anonymous No.106002139 [Report]
>>106002128
>What do you expect?
for it not to look like someone stepped on it
Anonymous No.106002150 [Report] >>106002203
>>106001881
Anon, you could have at least shown a C++ comparison. Fucking void* isn't generic, and reliance on it over a proper type system is why std::sort in C++ is faster than qsort in C.
Anonymous No.106002190 [Report]
Also, your code implies that the error type I want is an int error code. What if I want my error to be a string? What if I want it to be a tagged union that has different object types depending on the type of error it is? try_map isn't just generic over the type of the array and the return type of the function, but also over the type of the error.
Anonymous No.106002197 [Report] >>106002211 >>106002250
>>106002093
just write it in fucking assembly, cnile. that "code" is completely worthless, with zero utility. but you're just so gosh darn proud of it because it exists at the threshold where your intelect is able to comprehend it somewhat.
Anonymous No.106002203 [Report] >>106002375
>>106002150
>qsort
lamao
also im too lazy to look over the code. im sure theres more to it than just types
probably a width thats a parameter in one version when the other does name mangling or has dynamic dispatch with width-specific variants for each case
also also
theres quite a few ways to make void * either type safe
or no-cost generic. where you dont use void * but do macro magic force inlines
or generic but at a cost with function pointers
i know you like your types
but i like simple more than i like types (and dont get me wrong, i like em too. but fuck complexity emergent from the framework. id rather deal with a complex machine)
Anonymous No.106002211 [Report]
>>106002197
>total meltdown
ywabj
(you will always be jealous)
Anonymous No.106002224 [Report] >>106002261
can't you omit a lot of that type bs?
Anonymous No.106002250 [Report] >>106002275 >>106002280
>>106002197
>because it exists at the threshold where your intelect is able to comprehend it somewhat
Sums up people who write code in C without a valid reason (of which there aren't any anymore, since we entered the era of python on microcontrollers.)
Anonymous No.106002261 [Report]
>>106002224
>can't you omit a lot of that type bs?
yeah, by switching to c or javascript. no more scary type safety.
Anonymous No.106002275 [Report] >>106002292 >>106002303
>>106002250
>Sums up people who write code in C without a valid reason (of which there aren't any anymore, since we entered the era of python on microcontrollers.)
*wet fart noises*
what do you think gpgpu shit is written in?
>omf but cuda
rly? have you looked at the actual code?
https://github.com/NVIDIA/cuda-samples/blob/master/Samples/5_Domain_Specific/Mandelbrot/Mandelbrot_cuda.cu
Anonymous No.106002280 [Report]
>>106002250
>when your industrial control system does a mark-and-sweep for half a second
Anonymous No.106002292 [Report] >>106002309
>>106002275
tl;dr
Anonymous No.106002303 [Report] >>106002336
>>106002275
this code doesnt need types whats wrong ywith ou
Anonymous No.106002309 [Report] >>106002328 >>106002359
>>106002292
its c
without solid c skills dont even try gpgpu bc its C only now you work with 3 memory pools with different properties each, and everything is asynchronous. kindof, depends on the exact model of your card to make things even more spicy
Anonymous No.106002328 [Report] >>106002341
>>106002309
>its c
template <class T>


nigga you dumb as hell.
Anonymous No.106002336 [Report]
>>106002303
its not abt types its about c
otherwise in prod code you will need to remember what is where because given how it all w orks your data will be interleaved in arrays
and youre gonna have to keep track of everything separetely in your host machine because you communicate with your gpu via buffers
and with interleaved data your returns are gonna be the equivalent of void *'s

in gpgpuland theres no concession towards gay homo concepts like 'type safety'
everything is basically a void *
you better keep your ducks in a row
Anonymous No.106002341 [Report] >>106002755
>>106002328
i refuse to acknowledge anything that was released after C99
Anonymous No.106002359 [Report] >>106002388
>>106002309
tl;dr
Anonymous No.106002375 [Report] >>106002389 >>106002393 >>106002411 >>106002419
>>106002203
>i like simple more than i like types
You might like Bash then. Only one data type: string.
Anonymous No.106002388 [Report] >>106002395
>>106002359
no bathrooms for fake women at nvidias
rust is persona non grata
Anonymous No.106002389 [Report]
>>106002375
string is an unnecessary abstraction over bits
Anonymous No.106002393 [Report] >>106002758
>>106002375
one might say it's stringly-typed
Anonymous No.106002395 [Report]
>>106002388
tl;dr
Anonymous No.106002411 [Report]
>>106002375
youre right
i use it and i like it
im not good at it, by no means
but i manage to write whatever i need
rn i run a bash script to control my gpus fans
i needed the functionality of seeing current temp, max temp and to control the fan speed
Anonymous No.106002419 [Report]
>>106002375
cap.
bash has hashmaps, arrays and integers too.
Anonymous No.106002684 [Report] >>106002753
>>106001388 (OP)
People be talking about C++ being ugly and bloated, then come up with this shit as a replacement?
Yeah nah
Anonymous No.106002753 [Report]
>>106002684
it's clear that the rust "council" sees C++ as an aesthetic goal. of course C++ is now copying rust, so we're only going to see new heights of autistic nonsense with some of the worst syntax imaginable.
Anonymous No.106002755 [Report]
>>106002341
yes but full compiler support is still limited. 26 years later. you basically get what overlaps with c++ and thats it
Anonymous No.106002758 [Report]
>>106002393
heh
Anonymous No.106002983 [Report]
Rust "people" make me not like or want to use Rust. Simple as.
Anonymous No.106003062 [Report]
>>106001388 (OP)
In C# it's just
Anonymous No.106003714 [Report]
>>106001388 (OP)
disgusting syntax character vomit
i continue to maintain that the only person who knows how to design good programming languages is Anders Hejlsberg
Anonymous No.106003762 [Report] >>106003880 >>106003894
Bros you're bashing a language when you're barely writing a proper sentence in English. What's wrong with you fucking autists?
Anonymous No.106003880 [Report]
>>106003762
go back, phoneposting fag
Anonymous No.106003894 [Report] >>106003902 >>106003908 >>106003913
>>106003762
Rust "bashers" are third worlders that got filtered by the BC. I rarely ever see a pajeet using Rust and it's by design.
Anonymous No.106003902 [Report]
>>106003894
real languages dont have symbols in types
Anonymous No.106003908 [Report]
>>106003894
Not a jeet but I hate rust because only the faggiest of faggots seem to heavily endorse and advocate for it. I would rather use D. I don't even care if rust is good or not; but I do know that only faggots seem to endorse it.
Anonymous No.106003913 [Report]
>>106003894
nah. we still have our dicks. makes a big difference apparently
Anonymous No.106003916 [Report]
>>106001388 (OP)
What i hate about modern languages is that they all focus on how code shouldn't interact with other code rather than how it should.
Anonymous No.106003932 [Report] >>106003996
>>106001881
> array -+ elem_size;
>-+
what the fuck is that?
Anonymous No.106003996 [Report]
>>106003932
NOP
Anonymous No.106006396 [Report]
>>106001468
>>106001967
>this is so clear, it can be written and read by a human
>it's incorrect though
AHHAHAHAHAHAHAHAHAHA
NICE ONE FAGGOT