TIL (about the Dark Arts of HTML)
-
@Bulb said in TIL (about the Dark Arts of HTML):
But does it have actual semantic significance? That is, is there an application that, upon seeing application/epub+zip will say that it has no clue what epub is, but it does know what a zip is, so it will offer the user to open it as a zip archive?
Also, how do you reduce image/svg+xml to application/xml without already knowing that format?I guess the closest thing there is for that is RFC6838: you're not supposed to use a +suffix unless the suffix itself is already declared as a media type. Dunno how rigorous IANA is about rejecting applications to register
example/something+xml
for something that isn't actually XML, but there'd probably at least be discussion.
-
@Bulb said in TIL (about the Dark Arts of HTML):
The formats that have the same prefix before / often don't share anything, so that's not useful.
My point is that you can add more qualifiers to the MIME type, whether via
/
,+
, or some other legal character. Probably+
for consistency with what everyone's done so far. But truth be hold I have not read the RFC so I don't know what restrictions it applies.The whole point is moot though. The application consuming a file should try and parse its contents, probably looking for some magic number in a well known position, file extensions be damned. After all, everyone's doing defensive coding, right?
-
Well, I think the higher specificity is useful.
To answer the preceding points…
application/epub vs application/epub+zip - you sort of need the qualifier in case you ever wanted to support application/epub+tgz or application/epub+7z.
When you have a bundle that comprises a thing, being able to denote the container type is useful if you’re ever going to support more types of things - for ePub it’s maybe not that useful but encouraging the behaviour of “I have some data in a format, but it’s wrapped in another format” is useful to be able to convey.
image/svg+xml is a weird case because in that case XML isn’t so much a container as the same format - an SVG is a legal XML file, but obviously not always the other way around. Personally I’d be fine here with image/svg on its own but I get why it has the +xml qualifier - and the fact it is specifically an image rather than a generic XML blob is why you need the separation from application/xml.
Video is, as remarked, a shitshow. But even there, ability to reflect “I have this content in this format, wrapped in this container” would be valuable.
-
@Arantor I think for both
+xml
and+zip
it's more "Applications which generically handle the + format can do something sensible with this". Generic zip handling applications can extract resources fromapplication/foo+zip
. XML processing tools can ingest any+xml
file.
-
@PleegWat true, but it’s still useful to know the container format, if anything that’s why it’s useful to explicitly know the container format because you know other tools may be able to open it.
-
@Zecc said in TIL (about the Dark Arts of HTML):
The application consuming a file should try and parse its contents, probably looking for some magic number in a well known position, file extensions be damned.
That's the most practical approach, also because it does not depend on everybody agreeing on anything. It is even implemented in most cases (though not in Excel, as evidenced by the comment that started this discussion).
@Arantor said in TIL (about the Dark Arts of HTML):
application/epub vs application/epub+zip - you sort of need the qualifier in case you ever wanted to support application/epub+tgz or application/epub+7z.
When you have a bundle that comprises a thing, being able to denote the container type is useful if you’re ever going to support more types of things - for ePub it’s maybe not that useful but encouraging the behaviour of “I have some data in a format, but it’s wrapped in another format” is useful to be able to convey.
Yes, that is useful. But I was talking about a different—admittedly not very common, but very useful—use-case, where, in absence of a specific handler, the document may be usefully treated as another type. A
.drawio.png
file is a diagrams.net (draw.io) diagram that can be edited in that application, but it is also a valid PNG image that can be displayed by any browser or image viewer.image/svg+xml is a weird case because in that case XML isn’t so much a container as the same format - an SVG is a legal XML file, but obviously not always the other way around. Personally I’d be fine here with image/svg on its own but I get why it has the +xml qualifier - and the fact it is specifically an image rather than a generic XML blob is why you need the separation from application/xml.
Where I've seen such suffix to be useful is if you want to have a generic validator in front of the application to protect from malformed, and possibly malicious, inputs. Usually such applications simply take
application/xml
andapplication/json
, but sometimes there is a reason to further distinguish different inputs and thenapplication/bflmpsvz+xml
vs.application/bflmpsvz+json
comes in handy.Video is, as remarked, a shitshow. But even there, ability to reflect “I have this content in this format, wrapped in this container” would be valuable.
… It would have been possible to define the formats like
video/v8+matroska
orvideo/h265+mp4
to encode both the codec and the container, but nobody did and even the mime-types for the containers are not consistent, so we've got to keep all the shreds.
-
@Bulb Video generally deals with separate codecs for audio and video though.
-
@PleegWat there could be more
+
or other separators as needed. But someone would have to specify the naming and then all the people would have to update their clients and servers to understand it and they ain't going to because they don't like each other or simply because lazy.
-
@PleegWat said in TIL (about the Dark Arts of HTML):
@Bulb Video generally deals with separate codecs for audio and video though.
I don't really know, FFMPEG does it for me.
-
TIL "Pie Day", March 14th, is also Albert Einstein's birthday.
-
@Bulb said in TIL (about the Dark Arts of HTML):
It would have been possible to define the formats like video/v8+matroska or video/h265+mp4
Apropos, a recent with video mime-type:
We switched the video output from MP4 to Matroska (still the same codec, just different container), because if the generation was stopped, the partially written MP4 was not playable, but the partially written Matroska (
.mkv
) was. Except the video is supposed to play in browser too, and setting the ‘correct’ mime type,video/matroska
(orvideo/x-matroska
) did not work. What did work was setting the mime type tovideo/mp4
. Then it played in Chrome-based browsers and Safari (Firefox apparently does not support Matroska at all, only its WebM subset).
-
@Zecc said in TIL (about the Dark Arts of HTML):
TIL "Pie Day", March 14th, is also Albert Einstein's birthday.
It's also Stephen Hawking's deathday.
-
I'm surprised no one corrected me when I typed Pie instead of Pi.
-
@Zecc said in TIL (about the Dark Arts of HTML):
I'm surprised no one corrected me when I typed Pie instead of Pi.
We accept both flavors here.
-
@Watson said in TIL (about the Dark Arts of HTML):
@Bulb said in TIL (about the Dark Arts of HTML):
But does it have actual semantic significance? That is, is there an application that, upon seeing application/epub+zip will say that it has no clue what epub is, but it does know what a zip is, so it will offer the user to open it as a zip archive?
Also, how do you reduce image/svg+xml to application/xml without already knowing that format?I guess the closest thing there is for that is RFC6838: you're not supposed to use a +suffix unless the suffix itself is already declared as a media type. Dunno how rigorous IANA is about rejecting applications to register
example/something+xml
for something that isn't actually XML, but there'd probably at least be discussion.what stops me from writing whatever on my mime headers?
-
@sockpuppet7 said in TIL (about the Dark Arts of HTML):
@Watson said in TIL (about the Dark Arts of HTML):
@Bulb said in TIL (about the Dark Arts of HTML):
But does it have actual semantic significance? That is, is there an application that, upon seeing application/epub+zip will say that it has no clue what epub is, but it does know what a zip is, so it will offer the user to open it as a zip archive?
Also, how do you reduce image/svg+xml to application/xml without already knowing that format?I guess the closest thing there is for that is RFC6838: you're not supposed to use a +suffix unless the suffix itself is already declared as a media type. Dunno how rigorous IANA is about rejecting applications to register
example/something+xml
for something that isn't actually XML, but there'd probably at least be discussion.what stops me from writing whatever on my mime headers?
Nothing, but you usually want to set something that will make the client behave the way you want. Which sometimes requires setting something that makes no sense, see above.
-
@Zecc said in TIL (about the Dark Arts of HTML):
I'm surprised no one corrected me when I typed Pie instead of Pi.
I thought you were making fun.
-
TIL by default most people are using the seam ripper tool upside down...
-
TIL there's a thing for ripping seams.
-
@Zecc I've usually seen it included in the accessories for a sewing machine. So you can fix your mistakes.
-
@Bulb Skillful as I am, my mistake would be trying to use a sewing machine in the first place.
-
@Zecc I did a couple of times. It ain't hard.
-
@Zecc said in TIL (about the Dark Arts of HTML):
TIL there's a thing for ripping seams.
The fields of computers and sewing intersect with the threadripper.
-
We had a combined class here when I was at school, “design and technology” which rotated through a whole bunch of disciplines, including home economics (cooking, food storage, food hygiene, preservation), textiles (including using a sewing machine), woodwork, metalwork, electronics, product design, packaging design, all sorts of things.
The idea being that you do a rudimentary in everything and specialise for your final two years in a single discipline. (I did electronics, my final project was building a motion based alarm card that you could fit into a desktop PC, with a physical key for the backplate to turn it off. I could have drawn power from the mobo but I just had it battery backed instead.)
-
@Atazhaia said in TIL (about the Dark Arts of HTML):
@Zecc said in TIL (about the Dark Arts of HTML):
TIL there's a thing for ripping seams.
The fields of computers and sewing intersect with the threadripper.
It all started with programmable looms.
-
@Carnage I have visited a textile manufacturer still using old-school looms programmed with punched tapes. Interesting to see work.
-
@Atazhaia Glad to hear there are still people who don't fix what ain't broken out there.
-
@Carnage said in TIL (about the Dark Arts of HTML):
It all started with programmable looms.
I'm Bobbin Threadbare. Are you my mother?
-
@Zecc said in TIL (about the Dark Arts of HTML):
@Carnage said in TIL (about the Dark Arts of HTML):
It all started with programmable looms.
I'm Bobbin Threadbare. Are you my mother?
Lady Cygna is nowhere to be found. Perhaps by weaving the Transcendence draft you might rectify this.
-
@Bulb said in TIL (about the Dark Arts of HTML):
I did a couple of times. It ain't hard.
-
Ladies and gentlemen, default parameters in JavaScript:
Parameters are still set left-to-right, overwriting default parameters even if there are later parameters without defaults.
function f(x = 1, y) { return [x, y]; } f(); // [1, undefined] f(2); // [2, undefined]
But what actually got me visiting this reference page was this:
Parameters defined earlier (to the left) are available to later default parameters
The code I saw using this feature:
function handler(event, el=event.currentTarget) {
That's actually pretty cool.
PS: don't get me started on the weirdness of making function calls inside argument initializers. I had to check myself whether they always ran or not (they don't):
-
@Zecc So... if there is a default, the call does "Is this actual parameter
undefined
? Yes? Evaluate the default expression and use that instead." That's quite a contrast to what Python does!
-
@dkf But is there a difference between explicitly passing undefined and not passing anything at all?
-
@dkf said in TIL (about the Dark Arts of HTML):
@Zecc So... if there is a default, the call does "Is this actual parameter
undefined
? Yes? Evaluate the default expression and use that instead." That's quite a contrast to what Python does!It's a pretty badass take that retains compatibility with the early days where there were no default initializers, so you'd have to do a assign-if-undefined dance at the start of function. I'm impressed.
-
@PleegWat said in TIL (about the Dark Arts of HTML):
@dkf But is there a difference between explicitly passing undefined and not passing anything at all?
I don't think there is. There is a difference between passing undefined or null or other falsy values, of course.
-
@Zecc That's where JS switches from being designed to being one with the crack pipe.
-
@dkf said in TIL (about the Dark Arts of HTML):
That's quite a contrast to what Python does!
Well, the Python way is quite unintuitive. And the technical explanations why it needs to work the way it works don't really sound convincing either.
-
*laughs in PHP*
We have it these days so that mandatory arguments can’t come after optional ones, that if you want to accept null you can expressly indicate this in the type hint, and that you can even call a function with parameters out of order as long as you respect the required parameters and name your args.
Legal PHP:
function myfunc(int $a, string $b) { … }myfunc(b: "thing", a: 3);
-
@topspin said in TIL (about the Dark Arts of HTML):
Well, the Python way is quite unintuitive.
The Python way is to do something expedient that has a simple surface and with deeply behaviour once you start trying to use it for real unless you do something horrible and non-intuitive. And then, when users complain, to explain that this is all implicit in the semantics of the language, which to the users has all the vibes of "It's your fault we're breaking your kneecaps with sledgehammers. You made us do this, haha!"
-
@dkf said in TIL (about the Dark Arts of HTML):
The Python way is to do something expedient that has a simple surface and with deeply behaviour once you start trying to use it for real unless you do something horrible and non-intuitive.
What's your beef with the python default args implementation? That it evaluates them when the function definition is evaluated, instead of at call time? I'll give you that that can be a bit unintuitive at the beginning, but it does make sense IMHO when I think about it. Most of the time it's really a non-issue, and when it is an issue it takes all of an additional
if
block to resolve, so your take on it seems a wee bit hyperbolic.But then, I do have the impression that the things you seem to hate so much about python are mostly the exact things that I like about it. My feeling is that you tend to (have to?) use python when it's really not the best choice of language for the job.
-
@Arantor said in TIL (about the Dark Arts of HTML):
*laughs in PHP*
We have it these days so that mandatory arguments can’t come after optional ones, that if you want to accept null you can expressly indicate this in the type hint, and that you can even call a function with parameters out of order as long as you respect the required parameters and name your args.
Legal PHP:
function myfunc(int $a, string $b) { … }myfunc(b: "thing", a: 3);
I've done that in pl/sql in the past. Function with 20 or so boolean arguments, all defaulting to false, and typical usage required at most one or two to be set to true.
-
@Carnage said in TIL (about the Dark Arts of HTML):
@Atazhaia said in TIL (about the Dark Arts of HTML):
@Zecc said in TIL (about the Dark Arts of HTML):
TIL there's a thing for ripping seams.
The fields of computers and sewing intersect with the threadripper.
It all started with programmable looms.
And ends up with Fox firing a bullet in a circle that shoots everyone in the head including herself.
Spoiler warning
The previous was a spoiler for a movie from 2008
But you would only know if you saw the movie
-
@topspin said in TIL (about the Dark Arts of HTML):
@dkf said in TIL (about the Dark Arts of HTML):
That's quite a contrast to what Python does!
Well, the Python way is quite unintuitive. And the technical explanations why it needs to work the way it works don't really sound convincing either.
They don't, because in C++ it works correctly (i.e. the expression is called for each call where the parameter is defaulted).
-
@Bulb said in TIL (about the Dark Arts of HTML):
They don't, because in C++ it works correctly
In C++ a function definition is not an executable piece of code, so there is no other "logical" time when to evaluate default argument definitions.
In python it's essentially an assignment that gets executed when the interpreter encounters it. When doing so, it also executes the expressions for default arguments. That's the most straight-forward way to do it, otherwise it would have to muck around with the function body (or worse, the call site).
Not saying it couldn't be done, but it wouldn't be as straight-forward and the way it actually works makes sense to me.
-
@ixvedeusi said in TIL (about the Dark Arts of HTML):
What's your beef with the python default args implementation?
They're values, and if you happen to use mutable values (like lists, sets or dicts) then you get the potential for accidental modification at a distance. The syntax for an immutable "list" (i.e., a sequence) is reasonable for all cases... except the most common ones. An immutable set is worse, and immutable maps are disgusting.
The design of the language makes it easier to do the wrong thing than the right one. Is that the mark of a good language? I don't think so!
-
@dkf Oh I would by no means call it the mark of a good language. It's a pitfall that you have to know about and work around. But as language pitfalls go it just seems like a rather minor one, working around it is generally easy, and I find the reasoning behind it acceptable.
But then, I write C++ for a living so I may have gotten a bit numb when it comes to language pitfalls...
-
@ixvedeusi said in TIL (about the Dark Arts of HTML):
@Bulb said in TIL (about the Dark Arts of HTML):
They don't, because in C++ it works correctly
In C++ a function definition is not an executable piece of code, so there is no other "logical" time when to evaluate default argument definitions.
Variable bindings, even file-scoped ones, are executable piece of code though, so it wouldn't be surprising either way.
In python it's essentially an assignment that gets executed when the interpreter encounters it. When doing so, it also executes the expressions for default arguments. That's the most straight-forward way to do it, otherwise it would have to muck around with the function body (or worse, the call site).
Executing a function definition means compiling the body, not running the body, so it would still make more sense to compile the argument initialization, not run parts of it.
-
@ixvedeusi said in TIL (about the Dark Arts of HTML):
otherwise it would have to muck around with the function body (or worse, the call site).
Not saying it couldn't be done, but it wouldn't be as straight-forward and the way it actually works makes sense to me.But that's already what it is doing at that exact moment. It's saying here's a function which has this name, these parameters with these names (which are basically part of the call signature because of named arguments), etc., and it has the following "text" as code. Besides syntax, the function isn't evaluated, so why should default arguments be evaluated at that point? The code to execute them might as well be stored along with the other information that make up the function.
-
Florence Lawrence was a Canadian-American stage performer and film actress. She is often referred to as the "first movie star", and was long thought to be the first film actor to be named publicly until evidence published in 2019 indicated that the first named film star was French actor Max Linder.
Besides her film career, Lawrence is credited with designing the first "auto signaling arm", a predecessor of the modern turn signal, along with the first mechanical brake signal. She did not patent these inventions, however, and as a result she received no credit for, nor profit from, either one.
-
TIL the definition of a Sybil attack, a.k.a. sockpuppets: generate a bunch of entities, drown out/outvote everyone else.
And then I learned what an inverse Sybil attack is: when many entities pretend to be just one, like Pythagoras or boomzilla.