Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rust via its Core Values #19

Merged
merged 2 commits into from Jun 8, 2016
Merged

Rust via its Core Values #19

merged 2 commits into from Jun 8, 2016

Conversation

@IanWhitney
Copy link
Owner

@IanWhitney IanWhitney commented Apr 1, 2016

No description provided.

@IanWhitney IanWhitney force-pushed the rust_via_its_core_values branch from 0b47feb to 48f4919 Apr 1, 2016
@respeccing
Copy link

@respeccing respeccing commented Apr 1, 2016

and sticks to its core vales

Loading

@IanWhitney IanWhitney force-pushed the rust_via_its_core_values branch from 48f4919 to 58b4f24 Apr 2, 2016
- You try to use the 5th element of a 2-element array
- You try to call a method on Nil
- Two functions mutate a variable at the same time, leaving it an uncertain state
- You forget to free some memory
Copy link

@durka durka Apr 3, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Memory leaks are annoying, but totally safe! And Rust doesn't prevent them.

Loading

Copy link
Owner Author

@IanWhitney IanWhitney Apr 3, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the clarification. As someone who mostly works with GC'd languages, I found it hard to pick good examples. I'll remove that line.

Loading

Copy link

@durka durka Apr 3, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could replace it with an example of use-after-free.

Loading

@phoe
Copy link

@phoe phoe commented Apr 4, 2016

Hey, thanks for inspiration. I'm going to write a post in a very similar style - but for the underused, very unadvertised and very fun and powerful language called Common Lisp.

Loading


{% rp_highlight rust %}
fn same_length(s1: String, s2: String) -> bool {
s1.len() == s2.len()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a small nitpick. String.len() returns the number of bytes in the string, not the number of characters. Should this be changed to String.chars().count()?

Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it matter in this case though? Or am I missing something?

Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I think you're right @respeccing . The post never mentions anything about length vs. counting chars. I made an incorrect assumption. My apologies.

Loading

Copy link
Owner Author

@IanWhitney IanWhitney Apr 5, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's good to keep in mind though. That is the sort of thing I just assumed worked the same as in Ruby, but it doesn't. Thanks!

Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All good, no worries.
I figured, since it's just comparing the lengths, it doesn't matter the unit, as long as it's the same unit for both.
s1.len() == s2.len()
vs.
s1.chars().count() == s2.chars().count()

That is actually good information for I didn't know about the distinction(looking it up currently). Thanks!

EDIT: https://play.rust-lang.org/?gist=39c77e5d0ae546b30520dfc35cb43b71&version=stable&backtrace=2

Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it does matter which unit we use: https://play.rust-lang.org/?gist=5d3174958c76718508f6ab4566084829&version=stable&backtrace=2
With len these are not equal, whilst with chars().count() they are!
I stand corrected in my assumption

EDIT: plus, I can't think of them as units ( because utf-8 has variable(not fixed) number of bytes )

Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@respeccing - Thanks a ton for making the playpen! This clearly brings forth any issues with using len() in place of chars().count().

Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @brandonio21 for this great eye opener! Much appreciated!

Loading

@cadeon
Copy link

@cadeon cadeon commented Apr 5, 2016

Excellent, excellent post. Makes me want to rewrite one of my pieces of writing considering Rust-
http://taotedev.com/2016/01/29/3-state-v-action/

Loading

@IanWhitney IanWhitney merged commit 2526e1b into master Jun 8, 2016
@IanWhitney IanWhitney deleted the rust_via_its_core_values branch Jun 8, 2016
@rmcsharry
Copy link

@rmcsharry rmcsharry commented Sep 28, 2016

A superb post that makes its point clearly and succinctly - that understanding core principles is key to properly understand a language. So true and you nailed it!

Loading

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

7 participants