Live data from Hacker News

Do you know that there is an HTML tables API?

christianheilmann.com

41–50 of 206 posts

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

#41

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?

It’s not about the table element, it’s about the API to construct and manipulate that element with a columns and rows interface which is largely superseded by general DOM manipulation.

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

#42

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

Yep, didn’t realize this was unknown by enough web developers to warrant an article.

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

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

Code quality is not bike shedding.

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

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

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

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

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

Usually I'd cosign, but I get it, after a similiar issue I had a couple days ago with a Rust article that was insanely frustrating to deal with.

It's a brain scramble because you can't just read in toto.

Well, you can literally, but, you don't feel like you grok it.

And when you take a second pass you gotta slow down and stop and parse "what's r here? is it relevant? oh rows?"

It's one of those things that's hard to describe because it doesn't sound like much if you got it. And this example is trivial, especially if you're not open to the idea its a problem (r/c = rows/columns) But it's nigh-impenetrable in other scenarios.

You feel like you're barely understanding something that you actually might grok completely.

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

#46
post #28

Earlier quoted context omitted.

A bike-shedding thread on top as usual.

Code quality is not bike shedding.

It is, however, off topic and beside the point. And whether short names are a code quality issue is a rather contested and context-dependent topic.

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

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

Personally I'd make everything const instead of let and use for of instead of forEach, but it's like 10 lines of code it doesn't really matter.

Are you sure this old API does the right thing with for…of?

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

#48
post #20

Earlier quoted context omitted.

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.

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.

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

#49
post #28

Earlier quoted context omitted.

A bike-shedding thread on top as usual.

Usually I'd cosign, but I get it, after a similiar issue I had a couple days ago with a Rust article that was insanely frustrating to deal with. It's a brain scramble because you can't just read in toto. Well, you can literally , but, you don't feel like you grok it. And when you take a second pass you gotta slow down and stop and parse "what's r here? is it relevant? oh rows?" It's one of those things that's hard to…

> It's one of those things that's hard to describe because it doesn't sound like much if you got it. And this example is trivial, especially if you're not open to the idea its a problem (r/c = rows/columns) But it's nigh-impenetrable in other scenarios.

I agree, it's highly context-specific.

In a small demo for a small blog post with basically no complexity? Go ahead, use 1 character variable names, it really isn't difficult.

In the 1000 long CUDA kernel where you barely understand what's going on even though you understand the concepts? I'd be favoring longer descriptive names than one letter names for sure.

Post reply on HN