Live data from Hacker News

Do you know that there is an HTML tables API?

christianheilmann.com

151–160 of 206 posts

Re: Do you know that there is an HTML tables API?

#151
post #28
post #15

Interesting, but the JavaScript examples hurt: let table = [ ['one','two','three'], ['four','five','six'] ]; let b = document.body; let t = document.createElement('table'); b.appendChild(t); table.forEach((row,ri) => { let r = t.insertRow(ri); row.forEach((l,i) => { let c = r.insertCell(i); c.innerText = l; }) }); Use full words for variable names!

A bike-shedding thread on top as usual.

I understand the frustration (probably no one feels it more than we do, because it's our job to help discussion stay meaningful). But please don't respond by posting like this.

It takes time for the contrarian dynamic to work itself out (https://hn.algolia.com/?dateRange=all&page=0&prefix=true&que...), and once that happens, the original problem subsides but and the secondary problem (shallow objection to the objection) sticks out like a sore thumb.

It's usually enough to downvote (or, in egregious cases) flag a post that shouldn't be at the top. In really egregious cases, emailing hn@ycombinator.com is also a fine idea.

From the guidelines: "Please don't sneer, including at the rest of the community." - https://news.ycombinator.com/newsguidelines.html

Re: Do you know that there is an HTML tables API?

#152

Earlier quoted context omitted.

Declarative frameworks build on the imperative DOM API.

And, not a single one of the declarative frameworks use the HTMLTableElement API!

So how they do they talk to the browser to add a row to the table? Do you know of any API other than DOM used for this?

Re: Do you know that there is an HTML tables API?

#155
post #44

Earlier quoted context omitted.

It’s normal to use short names for things with short scopes.

Yes, and the reason for why that's OK is that the context is just few lines. But this is borderline due to the amount of variables. In just 4 lines you have r, row, t, ri, l, i and c. The full variables names are so short anyway that personally I'd write them out. Code does evolve and there's a risk of this suffering as a result.

rowIndex isn’t that short.

Re: Do you know that there is an HTML tables API?

#156

Earlier quoted context omitted.

My rule of thumb: only using single letter variables in one-liners (and never if it spills to another line), or for something that is conventionally represented as such. So for example: ```python bar = [foo(e) for e in elements] ``` or, using `x`, `n`, `s` and similar when they represent just that, a generic variable with a number, string, etc. I think there is a Code Complete chapter about it.

Yeah, I'm not GP, but my exceptions to this rule are `i` for "iterator" in `for` loops and `e` for "event" in event listeners.

Don’t use ‘i’ (looks like 1), use ‘j1’, etc - helps set you up if you need a nested loop someday. Of course, at that point better naming would probably be best.

Re: Do you know that there is an HTML tables API?

#157

Earlier quoted context omitted.

Yes, and the reason for why that's OK is that the context is just few lines. But this is borderline due to the amount of variables. In just 4 lines you have r, row, t, ri, l, i and c. The full variables names are so short anyway that personally I'd write them out. Code does evolve and there's a risk of this suffering as a result.

rowIndex isn’t that short.

shortness is in the eye of the beholder… program with spring framework long enough and rowIndex sounds like abbreviation. :)

Re: Do you know that there is an HTML tables API?

#158
post #125
post #101

The trouble is not populating it. The trouble is that tables, even though structured semantically, give you absolutely no functionality. There are no search, filter, sort, or selection features that you get.

Compared to what? What gives you all that, and what prevents you from having it with tables?

countless plugins for use in countless frameworks. We should have all that built-in by now. like we finally have a functioning date picker.

Re: Do you know that there is an HTML tables API?

#159
post #23

It is similar as with buttons ( https://news.ycombinator.com/item?id=45774182 ). Not sure when it was (10-15 years ago), but at some point everything became s. So, instead of semantic markup, HTML became a UI toolbox.

That's because the DOM is mostly used as a render target instead of a semantic document.

I think semantic HTML is a great idea but it's kind of jaded to expect it at this point.

It also doesn't help that semantic elements have styling. That right there gives people good reason to use a neutral container as a baseline. In fact I would go as far as to say that having both div and span is a bad design decision. They are just aliases for css `display` values.

Re: Do you know that there is an HTML tables API?

#160
post #104

Earlier quoted context omitted.

HTML tables are cognitively if not officially deprecated these days. I made my 1996 resume in HTML using a table for layout and it was indistinguishable from the Word version when printed. Made by editing the HTML by hand too! Tables are great. I don't doubt that CSS stuff is more capable, but the old ones are still useful.

I think the problem was that tables were always supposed to be for things that look like actual tables in the output - for that purpose they are not deprecated. What is discouraged is using tables as invisible layout grids - and that was their primary de-facto usecase before CSS and grid layouts. But that had always been a hack, even though a necessary one.

Tables are probably still useful for layout in HTML emails (for advertising). I haven't had to work with HTML emails in probably 20 years, but I doubt much has changed about what is and isn't allowed in HTML emails.
Post reply on HN