Check out my courses: https://nickchapsas.com Become a Patreon and get source code access: …
44 Comments
Leave a Reply
You must be logged in to post a comment.
Check out my courses: https://nickchapsas.com Become a Patreon and get source code access: …
You must be logged in to post a comment.
Everybody knows Sasha Grey's live coding streams are epic.
All about presentation is perfect. There is a great effort on your videos.
Funny enough, haven't used arrays and indexes for a while now. I haven't needed them. Sure I use IEnumerables all the time, sometimes they are arrays, but I don't remember having the need to access elements by index.
For the array range indexing, I find it helps to imagine that the .. represents the elements you are pulling from, and I imagine that the ^ is just a fancy negative sign and I'm pulling elements from a circular array
Personally I find two dots perfectly readable because it's how you often use it in maths, I think everybody would recognise it if it would be hand written. BUT not really when it's two dots and one number. And mixing ^ and .. is not very readable too. I sometimes see it in code, but I forget it exists and don't use unless something reminds me of this option. I bet that if we would have it from start, and everyone at the beginning would try to use it, make tutorials with it etc. it would become a default option.
Ah yes, I love watching Sasha code :^)
I don't have a personal preference here. Whatever works with what I have is going to be my option, e.g.: arrays I will default to range notation, enumerables where I'm probably already using Linq will probably follow with Skip/Take/etc.
I'm a little disappointed with the lowered code in the Substring example though… to be fair I would probably normally just use the parameters in the Substring overloads though.
I hope we can override the .. operator in the future lol
The range operator is also present in that exact way in Rust, so for me it's very readable.
Which programming does Sasha Grey uses? Asking for a friend.
Python made this much more readable.
For the slice thing, it looks similar to like python. Other langs also have this and its super useful, ima use this all the time now.
im a lot newer to coding and substring always confused me so when i learned about the indexing it was a lot simpler to understand
Any time most dev's I know I need to mess with regex, there's a fair chance they'll to bust out notes / documentation as it is just not intuitive. Powerful and effective but annoying as hell at the same time. Not feeling a burning need for array interaction to start down that path too.
This notation is used in MatLab and in image processing in general, so probably they decided to adopt it too. I personally like it.
It feels like these are interfaces to the same method, but don't really add any more 'meat'…
Index and range operators are available via Intellisense. You don't even need to learn them. Just do your normal code. VS will suggest the optimal code by itself. Very useful.
Index Operator. Very useful for cleaner and concise code but a technical burden for other devs.
Python programmers extensively use range indexing and negative index
This is quite easy to read for someone who knows rust, python or matlab. Although I prefer pythons notation to rust's and c#'s.
I feel 2..4 reads so much better then the other method, I read it as index the values between the indices 2 and for, or get the items in the range of 2 to 4
If you ever did python it feels natural
Rust is the only language I know that does slices well and always explicit and clear.
Given a vector `v`, let's say defined `let mut v = vec![1, 2, 3, 4, 5]`:
1. `&v[2..4]` – Immutable slice, freezes v while it exists.
2. `&mut v[2..4]` – Mutable slice, `v` can only be modified through this mutable slice as long as it exists.
3. `v[2..4].to_vec()` – Create a copy of the slice as a new vec.
I don't think there is a "get nth from the end" function, but `v[v.len() – 4]` isn't too bad.
`v.iter().rev().nth(4)` is also possible and seems to be `O(1)` in a small test I did, but I don't know if that's always true.
The sooner we leave behind zero indexing, the better.
I use the range syntax frequently. However, I only really use it on spans, where there isn't really any copy happening. On strings and arrays I either use `.ToSpan()` first, or I use the explicit methods to make the copy obvious
as a C# programmer who have been using Python for years, actually I really love this feature. Unfortunately it can only be used on arrays, not lists
I like the range operator, I think of it like Regex, it's powerful once you have a grasp on it.
I wanted to use this syntax yesterday, but couldn't remember if the second number was the length or the end position +1. Tried googling and looking in the MS docs, but couldn't find it because I didn't know it was called a range indexer. As it turns out, where I was using it, it was easier to think in terms of position and length, so I wound up using Substring()
In D this is the way to go. Slices, foreaches, substrings (which are slices) in a compact form.
Idk, to me this is very readable and much cleaner than a big chain of function calls.
Gotta disagree with this video. I use Ranges and slices all the time and they make things so much nicer. As far as "not knowing what it does" after you spend 3 minutes to learn it then you know what it does, and it will be familiar to anyone who uses Python, which is almost every dev I know.
It saddens me to see C# going down the Java path … new functionality, continuously added, and the core language implementing wrappers … like a Js library.
i dont think there are arrays with negative sizes? so why they dont change twitchStreamers[-4] to go reverse
🤣 I posted about this on LinkedIn just days before this video came out. You went into way more detail and this is a video, but so weird to see someone else asking about the range operators.
"^4" is completely unintuitive. If I saw that somewhere, I would have to look it up. Definitely a thumbs down from me.
"2..4" seems intuitive enough. Bash range operators have the same syntax, so it makes sense. Gets an "okay I guess" from me.
None of these were really needed though. I feel like this was just added so the devs can say "Look at our cool features".
It is actually very natural to me. Remind me of math
the index [2..4] doesnt read nicely, I agree with that… but based on all the languages I've experienced, I would have guessed that's exactly what this would do
I love the .. slice operator in Ruby and others been using it for years it's great and clear. For last we would use negative so -2.. good times
Was using this features for long time 🙂
I think the reason is simply because most blogs etc. don't write much about it
Thanks for the video, it is definitely a useful feature
Yeah, I hate these features. If I wanted to write Perl I would write Perl.
The lasttwo example is confusing to read atm, but the rest seems pretty nice. C# already has a few features like this (symbol syntax) like ??= or ternary operators in general and this seems no different. Have definitely seen similar code in Python, etc, so I think it'll eventually become standard
I hate this notation, especially last two. It's weird code!
I'm not a fan of syntax sugar that is hard to read. If an engineer has to stop to understand your code, time & money have been wasted.
P.S. Sasha Grey codes?
Although I am not using it currently in C#, but it looks pretty powerful specially if u code with python. back in the day when I was coding with python this syntax was a saver and I think that's why it got introduced in C#