5 ms·
> Grid columns and rows are 1 indexed instead of 0, ensuring a coming decade of mistakes due to the mismatch with Javascript (and, y'know, everything else) conv
by wnevets 10y ago
> Grid columns and rows are 1 indexed instead of 0, ensuring a coming decade of mistakes due to the mismatch with Javascript (and, y'know, everything else) conventions for arrays
but consistent with the rest of CSS IIRC, for example nth-child starts at one
- ajross 10y agoTrue enough, but that causes much less damage because except in the rarest situations, you never write code to do random access to an array of children, you just iterate over them without using indices at all. This is opening up a situation where you have a 2D Javascript array for a model and a bunch of components in the layout (a chessboard, imagine). And the coordinates won' t match!
- torrent-of-ions 10y agoWhat is your concern? Code beauty? What kind of programmer can't deal with converting between 0 and 1 based arrays?
- Risord 10y agoIts easy for sure but I think you agree that we don't want random multipliers or string prefixes to array idexes just for fun.
- ajross 10y agoWhat kind of programmer can't remember to check return values of system calls? What kind of programmer can't deal with properly escaping input under the control of the user? What kind of programmer can't deal with keeping array indexes in bounds? (tl;dr: you. And me.)
- torrent-of-ions 10y agoNone of that is like dealing with 0/1 arrays. Almost everything you encounter in real life starts with 1, not 0. If anything it's the 0 based array that should be consider "wrong" and the cause of so many errors. But we use 0 based arrays because of the C/assembly legacy where the 0 means the location of the array with a 0 offset.
- garaetjjte 10y agohttp://www.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/EWD831.html http://www.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/EW...
- kenshi 10y agoWhat kind of programmer hasn't learnt from and embraced the fact that programmers are human and that humans make mistakes?
- brianzelip 10y ago`order` starts at 0. https://developer.mozilla.org/en-US/docs/Web/CSS/order https://developer.mozilla.org/en-US/docs/Web/CSS/order
- chain18 10y ago`order` is a little bit different though as it doesn't set the position. Instead "Elements are laid out in the ascending order of the order value". So an element with order: 1 will move to the end in a group of elements with no order defined, similar to z-index I guess. Example: https://jsfiddle.net/5uvpco6e/ https://jsfiddle.net/5uvpco6e/
- jwarren 10y agoAdditionally, you can count from the last grid divider with minus numbers. You can have -1, but I can imagine some pushback against -0.
- ajross 10y agoLots of languages (c.f. python) do negative indexes with the first one starting from zero. The last element is indeed -1, because the element selected is simply the array-size-modulus of the index. It wraps exactly how you expect, and a few tricks use this. CSS grid's negative indexes, hilarious, don't even get this right. If the first element is 1 then the last must be 0, right? No, it's not. Nor is it -1. It's negative two. Don't ask. I don't know.
- jwarren 10y agoYou're not wrong on the first point, but I imagine consistency with the front and back of the index was on the spec designers minds. I do have to point out that your second point is not correct. Remember it's not grid areas, it's grid dividers. So the final grid line <strong>is</strong> in fact -1. See my very hasty little Codepen: https://codepen.io/jodi/pen/ZeNRJZ https://codepen.io/jodi/pen/ZeNRJZ