Originally posted by uid313
View Post
Announcement
Collapse
No announcement yet.
Rust 1.21 Released With Minor Updates
Collapse
X
-
- Likes 1
-
Originally posted by uid313 View Post
Implicit return statements.
- Likes 1
Leave a comment:
-
Originally posted by unixfan2001 View Post
Can you please stop comparing it to Ruby or, at the very least, try to explain why exactly you think it looks like that?
I (and, from the looks of it, quite a few others) just can't see it. The syntax has far more in common with Haskell and similar, functional languages.
Leave a comment:
-
Originally posted by caligula View Post
Now do the same without the typedef. It's cheating. The problem here is, C's syntax is totally backwards. For documenting the type, you're better off writing the comments in Rust. Maybe you can handle it, but there are lots of programmers totally lost with this syntax, yet they are fully able to implement monads in Haskell.
Code:let i = 5; let x = if i == 5 { 3} else { 4 };
Code:int (*return_func) (int) function (int (*input_function) (int) ) { //stuff }
Code:[](int)->int function ([](int)->int input_function) { //stuff }
Note that we are purely discussing syntax here, Rust and basically every other language other than C++ has vastly superior semantics surrounding strings among other things, and both .NET languages and Rust have a superior vocabulary regarding primitive types.
Leave a comment:
-
Originally posted by Luke_Wolf View Postin C
Code:typedef int (*return_func)(int); return_func function(int (*input_function)(int)) { //stuff }
Last edited by caligula; 13 October 2017, 04:51 PM.
- Likes 1
Leave a comment:
-
Originally posted by uid313 View Post
I don't know if that is any useful or good, but that is very confusing for me who are mostly used to the languages of C, C++, C#, Java and PHP.
just wading into code may work okay when you're shifting from one C Family language to another, but Rust is not a C Family language, and even within C family languages it benefits you greatly to at least read some of the docs before you dive in. Impl isn't confusing at all if you use even a minimum of due diligence in learning the language
- Likes 3
Leave a comment:
-
Originally posted by caligula View Post
Try to express (i32 -> i32) -> (i32 -> i32) in C.
Code:typedef int (*return_func)(int); return_func function(int (*input_function)(int)) { //stuff }
Code:std::function<int (int)> function (std::function<int (int)> input){ //stuff }
- Likes 1
Leave a comment:
-
Originally posted by Khrundel View PostIt is a keyword used to add "methods", including associated (i.e. static) to a type.
impl MyType {...} - adds methods to a type "MyType".
impl SomeTrait for SomeType {...} - adds implementation of SomeTrait (i.e. interface) to SomeType. Unlike other languages, where you can only implement interfaces for your type, Rust allows you to add implementation of interfaces from your module to any type, including foreign. So, you can create trait Foo, implement it for i32 (builtin type for 32-bit int), then cast pointer to i32 to pointer to Foo and then use that pointer OOP like way, as if Foo is a base class for i32.
Leave a comment:
-
Originally posted by uid313 View Post
Good point.
I could guess "Impl" was short for Implement, but I still don't know what it does or what it means.
Like is it a class, a interface or a trait or something else?
I wish Rust was more like C, C++, C#, Java, and PHP and that it was less like Ruby.
I (and, from the looks of it, quite a few others) just can't see it. The syntax has far more in common with Haskell and similar, functional languages.
- Likes 1
Leave a comment:
-
Originally posted by uid313 View PostI could guess "Impl" was short for Implement, but I still don't know what it does or what it means.
Like is it a class, a interface or a trait or something else?
impl MyType {...} - adds methods to a type "MyType".
impl SomeTrait for SomeType {...} - adds implementation of SomeTrait (i.e. interface) to SomeType. Unlike other languages, where you can only implement interfaces for your type, Rust allows you to add implementation of interfaces from your module to any type, including foreign. So, you can create trait Foo, implement it for i32 (builtin type for 32-bit int), then cast pointer to i32 to pointer to Foo and then use that pointer OOP like way, as if Foo is a base class for i32.
- Likes 4
Leave a comment:
Leave a comment: