Live data from Hacker News

Do you know that there is an HTML tables API?

christianheilmann.com

31–40 of 206 posts

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

#31
post #20

Earlier quoted context omitted.

I was just about to comment the same. I’m sure people have a good reason for it (or at leafy _a_ reason), but single-letter variable names always struck me as optimizing for the wrong thing. As someone who likes to program in Haskell, I feel this pain very strongly. :)

Do you always feel this is the case? To me the go to single letter variables are very readable. Used so widely my eyes parse them like other symbols: =, &, +, etc.

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.

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

#32

Phew, this post single handedly made me feel old this morning. I started dabbling with the web just over 20 years ago but have mainly been working on the backend the past 10-15 years. I had no clue that nowadays programmers don’t know about this, so I assume it’s supplanted by modern frameworks or modern JS/CSS

Same. I use this all the time, have for decades. Had no idea other people didn’t.

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

#33

I was using it just half a year ago, after either reading MDN or reading what AI suggested. Which means, this API is not obscure and not forgotten. Using `rows` and `cells` is very convenient for keyboard navigation across table cells. https://github.com/ClickHouse/ClickHouse/blob/master/program...

The worst thing on the modern web is people using divs for table data. What do you mean this table isn’t sortable? M365 Admin is the worst offender I’ve come across on this. Just terrible table implementations on almost every page.

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

#35
post #19

Earlier quoted context omitted.

Really? The variable name lengths? Not that the code is clearer as: const te = document.createElement('table'); document.body.appendChild(te); [ ['one', 'two', 'three'], ['four', 'five', 'six' ], ].forEach((r, i) => { const re = te.insertRow(i); r.forEach((c, j) => { re.insertCell(j).innerText = c; }) }); My personal stance on short variable names is that they are fine as long as their scope is very limited, which is…

Looks like your code inserts a new row for every cell.

Cheers! Fixed.

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

#36
post #32

Phew, this post single handedly made me feel old this morning. I started dabbling with the web just over 20 years ago but have mainly been working on the backend the past 10-15 years. I had no clue that nowadays programmers don’t know about this, so I assume it’s supplanted by modern frameworks or modern JS/CSS

Same. I use this all the time, have for decades. Had no idea other people didn’t.

Just a catchy title. Not abandoned etc. This is the only API available to manipulate HTML table tags.

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

#37
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.

I think it was inevitable. Most of the funded content on the web is marketing/sales-driven, and companies paying for marketing content want it to be displayed in a specific way.

It’d be interesting to have a parallel DocBook web for technical content, where consumers of that content could apply their own styles to render it in a way that’s best for them.

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

#38
I used this for a small tool I was making to see stable Diffusion images in a table to compare images on different set of parameters, had lots of rows and columns. I needed to regenerate tables quickly, I vaguely remember this API being much slower than making rows/cells via strings. The reason I found was that each call using this API updates DOM and with string it's all in one go (or something similar).

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

#39

Phew, this post single handedly made me feel old this morning. I started dabbling with the web just over 20 years ago but have mainly been working on the backend the past 10-15 years. I had no clue that nowadays programmers don’t know about this, so I assume it’s supplanted by modern frameworks or modern JS/CSS

Thank you for confirming I am not... crazy, just old then. I was staring at the code for minutes, trying to spot something unusual that I missed. So, this really just about the `` element, or do I actually not see something?

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

#40
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!

I was just about to comment the same. I’m sure people have a good reason for it (or at leafy _a_ reason), but single-letter variable names always struck me as optimizing for the wrong thing. As someone who likes to program in Haskell, I feel this pain very strongly. :)

In real ok, but in this short example it‘s pretty obvious what t,b, r and c mean
Post reply on HN