Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

C vs Rust

Name: Anonymous 2015-02-13 1:07

C:
int main(int argc, char **argv) {
int r;
if(argc > 1) {
r = atoi(argv[1]);
} else {
usage();
exit(EXIT_FAILURE);
}
}


Rust:
fn main() {
let argv: Vec<Result<String,OsString>> = std::env::args()
.map(|x| x.into_string())
.collect();

let r = match argv.get(1) {
Some(x) => match x.parse::<i32>() {
Ok(v) => v,
Err(_) => {
show_usage();
panic!()
},
},
None => {
show_usage();
panic!()
}
}
}


Type explosion is to be expected. Do notation could have been used to keep the control logic as clean as C, but Rust is not HASKAL and never will be anything like HASKAL and you're an asshole for wanting to write readable code you filthy shit fuck.

Name: Anonymous 2015-02-23 22:54

>>80
How is flipped function composition related to OOP?

Name: Anonymous 2015-02-23 23:31

>>81
Write some code that uses it and the answer will be staring you in the face.

Name: Anonymous 2015-02-23 23:58

>>82
Objects followed by methods are not function composition, ``faggot''.

Name: Anonymous 2015-02-24 0:13

>>83
not understanding this most basic thing

Name: Anonymous 2015-02-24 0:30

>>84
That isn't what he said!

Name: Anonymous 2015-02-24 18:58

>>82
Are you talking about chained method calls, where methods of foo all return foo? Because that's not function composition.

Name: Anonymous 2015-02-24 19:05

>>79
You drunk or something? You wrote the type for (.), not (&).

Name: Anonymous 2015-02-24 19:11

>>80
No, you idiot, it's for those who like readable code. Haskell is riddled with direction-inverting operators like

<- -- Hebrew
>>= -- White
<< -- Hebrew
($) -- White
(.) -- Hebrew


that make expressions impossible to decode because the control flow in them starts in an unobvious place and changes direction several times. So I just find it saner to choose one direction and settle with it instead of having to visually parse unreadable shit like

x <- (f g) . (h . j. z $ i) $ y >>= return (f . m << negro)

Name: Anonymous 2015-02-24 19:41

>>79
Moreover, the lens (&) is just reversed function application

(&) :: a -> (a -> b) -> b

https://hackage.haskell.org/package/lens-4.7/docs/Control-Lens-Lens.html

Name: Anonymous 2015-02-24 19:46

Name: Anonymous 2015-02-24 20:00

>>90
This isn't flip (.), this is OOP-style method application and it will not work in point-free style.

Name: Anonymous 2015-02-24 20:44

>>90
Why didn't they call it (|>)? It's pictographic and they even point out that's what Ft-hoocrtpoe uses for it. Caml |> O does it too.

Name: Anonymous 2015-02-24 20:52

Name: Anonymous 2015-02-24 21:12

>>93
That's a really silly reason, considering that & ought to be an even more frequently taken name.

Name: Anonymous 2015-02-24 21:17

>>93
What a waste. That's just a specialized form of something like a & and seq and they wasted multiple combinators on this junk.

Name: >>95 2015-02-24 21:18

s/and seq/append/seq/g

Name: Anonymous 2015-02-24 22:05

░░░░░░▄▀▒▒▒▒░░░░▒▒▒▒▒▒▒▒▒▒▒▒▒█
░░░░░█▒▒▒▒░░░░▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒█
░░░░█▒▒▄▀▀▀▀▀▄▄▒▒▒▒▒▒▒▒▒▄▄▀▀▀▀▀▀▄
░░▄▀▒▒▒▄█████▄▒█▒▒▒▒▒▒▒█▒▄█████▄▒█
░█▒▒▒▒▐██▄████▌▒█▒▒▒▒▒█▒▐██▄████▌▒█
▀▒▒▒▒▒▒▀█████▀▒▒█▒░▄▒▄█▒▒▀█████▀▒▒▒█
▒▒▐▒▒▒░░░░▒▒▒▒▒█▒░▒▒▀▒▒█▒▒▒▒▒▒▒▒▒▒▒▒█
▒▌▒▒▒░░░▒▒▒▒▒▄▀▒░▒▄█▄█▄▒▀▄▒▒▒▒▒▒▒▒▒▒▒▌
▒▌▒▒▒▒░▒▒▒▒▒▒▀▄▒▒█▌▌▌▌▌█▄▀▒▒▒▒▒▒▒▒▒▒▒▐
▒▐▒▒▒▒▒▒▒▒▒▒▒▒▒▌▒▒▀███▀▒▌▒▒▒▒▒▒▒▒▒▒▒▒▌
▀▀▄▒▒▒▒▒▒▒▒▒▒▒▌▒▒▒▒▒▒▒▒▒▐▒▒▒▒▒▒▒▒▒▒▒█
▀▄▒▀▄▒▒▒▒▒▒▒▒▐▒▒▒▒▒▒▒▒▒▄▄▄▄▒▒▒▒▒▒▄▄▀
▒▒▀▄▒▀▄▀▀▀▄▀▀▀▀▄▄▄▄▄▄▄▀░░░░▀▀▀▀▀▀
▒▒▒▒▀▄▐▒▒▒▒▒▒▒▒▒▒▒▒▒▐

Name: Anonymous 2015-02-24 23:48

░░░░░░░░▄▄▄▄▄
░░░░░░░░▀▀▀██████▄▄▄
░░░░░░▄▄▄▄▄░░█████████▄
░░░░░▀▀▀▀█████▌░▀▐▄░▀▐█ Have u ever
░░░▀▀█████▄▄░▀██████▄██ went fast?
░░░▀▄▄▄▄▄░░▀▀█▄▀█════█▀
░░░░░░░░▀▀▀▄░░▀▀███░▀░░░░░░▄▄
░░░░░▄███▀▀██▄████████▄░▄▀▀▀██▌
░░░██▀▄▄▄██▀▄███▀░▀▀████░░░░░▀█▄
▄▀▀▀▄██▄▀▀▌████▒▒▒▒▒▒███░░░░▌▄▄▀
▌░░░░▐▀████▐███▒▒▒▒▒▐██▌
▀▄░░▄▀░░░▀▀████▒▒▒▒▄██▀
░░▀▀░░░░░░▀▀█████████▀
░░░░░░░░▄▄██▀██████▀█
░░░░░░▄██▀░░░░░▀▀▀░░█
░░░░░▄█░░░░░░░░░░░░░▐▌
░▄▄▄▄█▌░░░░░░░░░░░░░░▀█▄▄▄▄▀▀▄
▌░░░░░▐░░░░░░░░░░░░░░░░▀▀▄▄▄▀
░▀▀▄▄▀

Name: Anonymous 2015-02-24 23:50

>>98
No.

Name: Anonymous 2015-02-25 0:24

>>99
Nice dubs.

I believe I got dubs too!

CHECK EM

Name: Anonymous 2015-02-25 0:27

>>97
Cool Doctor Who meme, Superwholockian.

Name: Anonymous 2015-02-25 0:42

>>101
What are you talking about, palindrome-kun?

Name: Anonymous 2015-02-25 1:04

JACKSON 5*20+3 GET

Name: Anonymous 2015-02-25 19:03

>>100-99
Double dubs!

Name: Anonymous 2015-02-27 18:48

Take malloc and free out of C, add some static analysis for bad pointer usage and you have 98% of the benefit of Rust

Name: Anonymous 2015-02-28 4:13

>>105
Take malloc and free out of C, add some static analysis for bad pointer usage
What is C++ new/delete and smart pointers?

Name: Anonymous 2015-02-28 11:36

>>106
new/delete are malloc/free + constructors/destructors respectively. Smart pointers look like they incur unavoidable runtime overhead.
Also you should really check your grammar.

Name: Anonymous 2017-01-19 14:25

>>9
Here's the assembler code generated by rustc for the standard Hello World program:

core::fmt::Arguments::new_v1:
push rbp
mov rbp, rsp
mov rax, rdi
mov qword ptr [rbp - 24], rax
mov qword ptr [rbp - 32], r8
mov qword ptr [rbp - 40], rcx
mov qword ptr [rbp - 48], rdx
mov qword ptr [rbp - 56], rsi
mov qword ptr [rbp - 64], rdi
mov qword ptr [rbp - 16], 0
mov rax, qword ptr [rbp - 64]
mov rcx, qword ptr [rbp - 56]
mov qword ptr [rax], rcx
mov rdx, qword ptr [rbp - 48]
mov qword ptr [rax + 8], rdx
mov rsi, qword ptr [rbp - 16]
mov qword ptr [rax + 16], rsi
mov rsi, qword ptr [rbp - 8]
mov qword ptr [rax + 24], rsi
mov rsi, qword ptr [rbp - 40]
mov qword ptr [rax + 32], rsi
mov rdi, qword ptr [rbp - 32]
mov qword ptr [rax + 40], rdi
mov rax, qword ptr [rbp - 24]
pop rbp
ret

drop:
push rbp
mov rbp, rsp
mov qword ptr [rbp - 8], rdi
pop rbp
ret

example::main:
push rbp
mov rbp, rsp
sub rsp, 64
lea rdi, [rbp - 56]
lea rcx, [rip + ref.0]
xor eax, eax
mov r8d, eax
mov rsi, qword ptr [rip + example::main::__STATIC_FMTSTR]
mov rdx, qword ptr [rip + example::main::__STATIC_FMTSTR+8]
call core::fmt::Arguments::new_v1
lea rdi, [rbp - 56]
call std::io::stdio::_print@PLT
add rsp, 64
pop rbp
ret

example::main::__STATIC_FMTSTR:
.quad ref.2
.quad 1

ref.0:

str.1:
.ascii "Hello, World!\n"

ref.2:
.quad str.1
.quad 14


This is from the compiler explorer site, on my Linux VM the output is even more horrific (to the point that it's too large to post here). In both cases I'm pretty sure it's the latest version of the compiler, 1.14.0. I'm not that experienced with assembly, but it looks to me like it's using 64 bytes of stack space, which is ridiculous for such a trivial program.

For comparison, GCC 4.4.7 with optimization off produces the following Hello World code:

.LC0:
.string "Hello, World!"
main:
push rbp
mov rbp, rsp
mov edi, OFFSET FLAT:.LC0
call puts
mov eax, 0
leave
ret


>>82,84
OOP is based on partial application, not function composition. Converting a.hax(&a, 5) (C style) to a.hax(5) (C++ style) is essentially an example of partial application. You take a binary function, and use partial application to bind the self-reference argument to the parent object to create a unary member function.

>>86
It would be function composition if the language had some way to define the chain as a new function. Mathematically speaking, f(g(5)) isn't function composition, it's just using the function g with the argument 5, and then using the result as the argument to the function f. Now, if you instead did something like h(x) = f(g(x)), that is function composition, because you're defining a chain of functions as a new function. Likewise, m.move_north().move_east() isn't composition, but something like
movable movable::move_northeast() {
return this->move_north().move_east();
}


would be.

>>106
Static analysis means it's done at/before compile time. Smart pointers are basically a form of runtime GC. Rust's main selling point is that the features that make it ``safe" are all done at compile time, thus causing no run-time penalty.

Name: Anonymous 2017-01-31 3:45

Lets see these rust guys implement diffoubly linked lists

Name: Anonymous 2017-01-31 3:46

trips upcoming

Name: ▄︻̷̿┻̿═━一 2017-01-31 3:47

THESE 2nd AMENDMENT TRIPS

Name: Anonymous 2017-04-29 18:56

Rust is very fast.

C:
#include <stdio.h>

int main()
{
int total = 0;
for (int i = 0; i < 100000; i++)
{
for (int j = 0; j < i; j++)
{
total += (j * j == i) ? j : 0;
}
}

printf("%lu\n", total);
return 0;
}
50085
real 8.25
user 8.25
sys 0.00

fn main() {
let mut total: i32 = 0i32;
for i in 1..100_001 {
for j in 1..i {
total += if (j*j) == i {j} else {0i32};
}
}
println!("{}", total);
}
50085
real 2.61
user 2.61
sys 0.00

And it's fair to claim that Rust enforces memory safety unlike C or C++. Reason why C/C++ programs are so vulnerable. The example in the OP just goes to show Rust handles errors better and it trains the programmer to do so.

Rust has a decent dev environment. The cargo is a very good project manager, Rust language server is the combination of Clang format, Clang complete and CPP check, with more features like snippets etc. And lastly, the Rust compiler is very impressive. For a language that's 2 years old it certainly helps produce fast, optimized and safe binaries that C never did. Rust compiler is like GCC+CPP check combined.

So FUCK YOU. Stay confined in your bubble world of baby duck syndrome while you can, I just got sick and tired of edgy C tards like you. No wonder C is dying.

Name: Anonymous 2017-04-30 2:18

Rust would be good if it didn't look like C++.

Name: Anonymous 2017-04-30 11:26

>>113
at least it doesn't look like lisp.

Name: Anonymous 2017-05-01 20:47

>>112
Rust: let mut total: i32 = 0i32;
Symta: Total = 0

Code less, create more.

Name: Anonymous 2017-05-01 21:32

>>115
Symta
Nice shitpost.

Name: Anonymous 2017-05-01 21:57

>>115
Rust has more backing.

Name: Anonymous 2017-05-13 17:14

The future is bright!

Name: Anonymous 2017-05-13 23:17

>>1
At least Rust has figured out how to eliminate the need for significant whitespace in nested generic type declarations.

>>115
I'm not familiar with Symta, however not having to declare variable types means either that you don't know for sure that your variable is represented as a 32-bit signed integer, or that the language uses implicit typing rules which can hurt readability. Either way, it's not really a truly ``synonymous" statement to the Rust variable declaration. I do think having to specify the variable type both in the variable declaration and in the literal being used to initialize the variable is ridiculous. Something like let mut total = 0; is understandably dangerous, since nowhere is the actual data type of the variable explicitly stated. But either let mut total: i32 = 0; or let mut total = 0i32 should be fine. Otherwise you're just being needlessly redundant.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List