The Build-up
I met Debasis Basu (LinkedIn) at a social event, a few weeks ago.
Debasis is a childhood friend. We studied at the same re...
For further actions, you may consider blocking this person and/or reporting abuse
Tell Debasis this additional thing too: Rust has no undefined behaviour. I'm sure you ran into this with c. It does not happen in Rust
I am trying to learn rust and making basic videos on it. Learning a language was never this tough for me ( not having experience in systems programming might be a reason ), but it is giving that in depth knowledge in every aspect when I m trying to learn new things. And I want to continue that for systems programming.
Thank you for your article. It made me pause to reflect on why I learned Rust.
In addition to your own reasons, I chose to learn Rust after working at some companies who didn't understand that a single point of failure in their systems was unacceptable and other companies that did.
Rust's added strictness makes it much less likely that a bug in my code might escape detection with my tests.
It also ensures that every path has code to handle it or that I have had to intentionally no-op my way past it. Having the compiler force me to contemplate every possible path forces me to consider all failure points..even the ones that will "never happen"..and create the back up code for every closet case.
In short, it points out most single points of failure in my code that I didn't already notice when planning my projects and forces me to include code to recover from or avoid those pitfalls.
That...and Rust is just fun. ;)
When I click on the documentation link you mentioned:
dev.to/nsengupta/%5BThe%20Rust%20P...
it sends me to an non-existing page.
What am I doing wrong, please? Thank you.
I 'Thank' you, twice!
I have edited the blog. Please check once more, and let me know if the problem persists. I will be more careful, the next time.
:-)
You're very welcome! The link works properly now.
I had a similar discussion with a friend who loves C++ and tried to learn Rust, but abandoned it very soon.
He laughed in my face comparing simple things, like a for loop in C++ and one in Rust, pointing out the elegance of the C++ syntax.
in C++
for (int i = 100; i >= 1; i -= 5) { ... }
in Rust
for i in (1..=100).rev().step_by(5) { ... }
in C++ : I thank you
in Rust : you to me do the thanking, but in reverse
What would you answer to this comparison, as I was at a loss of words?
I don’t see anything inelegant in rust for loop: it even intuitively clearer as having semantic parts like range from 1 to 100, rev, step_by…
His reluctant behaviour is just a matter of habit and unwillingness to step out of his comfort zone.
The loop also can be rewritten with while:
let mut i = 100;
while i >= 1 {
i = i - 5;
}
Let me nitpick at the beginning:
That's a 'C' loop, and not a C++ loop, in the strict sense and with my tongue firmly in the cheek. :-)
The loop in Rust can be written in a way that Eugen (dev.to/tsolan) has shown already.
However, in case of Rust code shown by you, the idea is of having an Iterator as a datatype and treat it as that. It is not a
for loop
in that sense. Declaratively speaking, we areAnd, we are not specifying a terminating condition. This is an Iterator and we are declaring what should happen during each iteration. the Iterator understands that when it has gone beyond the lowermost end of the Range, nothing needs to be done! The iteration stops.
Rust playground is here: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021
C playground is here: cplayground.com/?p=pika-seahorse-t...
Honestly, I have done quite some Java (using both OO and FP constructs) and Scala programming and I understand and appreciate the declarative nature of many operations which these propound. Readabiity of a code - a somewhat underrated yet extremely important aspect - increases with right level of declarative-ness. SQL is a great example of declarative programming.
NB: Just to make it clear, I have remained a big fan of C and I only have awe and respect for late Dennis Ritchie and Brian Kernighian. Whatever little I have been able to do in my career so far, I attribute that to the chance exposure to, adoption of and a l-o-n-g association with 'C' programming, from the very early days in my career. 'C' has helped me to sense, what is happening at the critical spot where my code meets the machine.
But, now, I am beyond that 'my language is better than your language' warfare. It is plain silly! :-P
I can't take SVD file and generate peripheral access crate in C in portable way. I have to take vendor locking library and use it in my embedded code, that porting in future is going to be nightmare.
But in the end it's not about what I can or cannot do, but how quick, how reliable and how many security holes I'm going to leave in my solution.
Great post!
The price to pay for being inattentive could be disatrous.
Loved the accidental here
😃 I thought of using ruinous but then, decided against it.
Thanks for your comment.