About the ASCII code difference between lower case and upper case, it was actually very good design. There are exactly 2^5 characters between corresponding letters ('a' and 'A' etc.), which means that it's enough to use bitwise OR to transform from upper-case to lower-case: c | 0b100000 or c | 0x20. Also, it's not very difficult to transform for lower-case to upper-case.
Another great video! I really like what ya'll are doing. I really hope more folks (students and job-seekers especially) find Exercism. I think Exercism does a great service of being a learning tool first and foremost. Keep it up :-)
The Rust solution using an array looks like a really clever idea for performance, but a match statement would be better in pretty much every way. First, as Jeremy pointed out, the array isn't very readable. It's hard to tell what letter maps to what score. A match statement would make that clear. Second, using an array instead of a hash map is smart for performance, but if you use a match statement then the compiler builds the lookup table for you, resulting in the same runtime performance benefit. Third, it looks clever to use `c.to_ascii_lowercase() as usize - 97` to convert to a number that can be used to index into the array, but again, using a match statement lets the compiler do that for you. Fourth, if you use a match statement that maps all non-ascii-lowercase characters to 0, then you don't need to filter for `is_ascii_alphabetic()`. In fact, the `to_ascii_lowercase()` method already contains an `if self.is_ascii_uppercase()`, so the filter is duplicating that check.
23:20 Heh, a-Z is not consecutive in ASCII, that's a bit daft... 25:27 Hold on, lowercase and uppercase are exactly 32 apart? Brilliant! I've done plenty of -'a' and -'A' conversions and fell into the trap of the former and never even considered the latter. In hindsight I've been pretty silly to think they just put some symbols in between the two cases because _they_ were being dumb. :P How much of my code demonstrates this ignorance...?
About the ASCII code difference between lower case and upper case, it was actually very good design. There are exactly 2^5 characters between corresponding letters ('a' and 'A' etc.), which means that it's enough to use bitwise OR to transform from upper-case to lower-case: c | 0b100000 or c | 0x20. Also, it's not very difficult to transform for lower-case to upper-case.
Yeah - we go on to discover that in the next solution we show! :)
I guess you can do xor to get to uppercase, in Python this yields "Z": chr(ord('z') ^ 0x20)
@@nitkonigde1381 I think it's NAND - AND with the bitwise complement of 0x20. XOR toggles between lower case and upper case.
@@iosimion Thanks!
Very cool.
Thanks!
Another great video! I really like what ya'll are doing. I really hope more folks (students and job-seekers especially) find Exercism. I think Exercism does a great service of being a learning tool first and foremost. Keep it up :-)
Thanks so much!
The Rust solution using an array looks like a really clever idea for performance, but a match statement would be better in pretty much every way.
First, as Jeremy pointed out, the array isn't very readable. It's hard to tell what letter maps to what score. A match statement would make that clear.
Second, using an array instead of a hash map is smart for performance, but if you use a match statement then the compiler builds the lookup table for you, resulting in the same runtime performance benefit.
Third, it looks clever to use `c.to_ascii_lowercase() as usize - 97` to convert to a number that can be used to index into the array, but again, using a match statement lets the compiler do that for you.
Fourth, if you use a match statement that maps all non-ascii-lowercase characters to 0, then you don't need to filter for `is_ascii_alphabetic()`. In fact, the `to_ascii_lowercase()` method already contains an `if self.is_ascii_uppercase()`, so the filter is duplicating that check.
Agree with everything you said. It's fascinating though, isn't it :D
Thank you for this, good to know.
23:20 Heh, a-Z is not consecutive in ASCII, that's a bit daft...
25:27 Hold on, lowercase and uppercase are exactly 32 apart? Brilliant!
I've done plenty of -'a' and -'A' conversions and fell into the trap of the former and never even considered the latter. In hindsight I've been pretty silly to think they just put some symbols in between the two cases because _they_ were being dumb. :P How much of my code demonstrates this ignorance...?
Ha! Yes - I enjoyed my learning journey there being so on display 😂
I'd like to see a poll of how many people knew that already. And then I'd like to see a poll of how many people answered truthfully.
Ha. Yes! :D