sometimes i start my iterator with = -1. As I only +=1 it with a condition and I know that it will return true on the first cycle. I’ll chuck array[iterator] and need it to be 0 to start with ofc.
I just have no idea how to not do this, but it looks so bad, i need a i8 instead of a u8 at least because of this
I could tell you my recent cenario, but it wouldn’t get us anywhere. because I know that it’s avoidable, but it’d take for me to run a different logic for only first element of my array. which is doable, but it’d make the code like 5 extra lines longer, harder to read/follow. But I just simply choose to put -1 and boom it’s fixed, just works.
another solution would be (without context) is to add one more variable and one more check to my foreach, but that takes more memory and cpu, I usually choose the i = -1, it’s ugly but not as ugly as other solutions would be
I count 13 steps, so it just means you’re gonna trip up on 3 of them…
15 steps. You’re not counting the top, and the bottom is step 0 and we all know counting starts there.
Both of you are nerds.
We are on a programming sub of a federated and open source reddit clone. We are all nerds.
I assume it was meant as a compliment.
(i said it with love)
sometimes i start my iterator with = -1. As I only +=1 it with a condition and I know that it will return true on the first cycle. I’ll chuck array[iterator] and need it to be 0 to start with ofc.
I just have no idea how to not do this, but it looks so bad, i need a i8 instead of a u8 at least because of this
What? My intuition is there’s always gotta be some equivalent nicer refactor that could do away with such an awkward construct.
In what kind of situation would that be totally unavoidable?
I could tell you my recent cenario, but it wouldn’t get us anywhere. because I know that it’s avoidable, but it’d take for me to run a different logic for only first element of my array. which is doable, but it’d make the code like 5 extra lines longer, harder to read/follow. But I just simply choose to put -1 and boom it’s fixed, just works.
another solution would be (without context) is to add one more variable and one more check to my foreach, but that takes more memory and cpu, I usually choose the i = -1, it’s ugly but not as ugly as other solutions would be
thats great unless you want
i
to be an unsigned integeredit: oops u already mentioned that
I hope I never have to see this code.
lucky, I forgot it
sending it asap (when I get home)
That’s accurate. There’s always a few steps not included in the tutorial