by cdrini · 2y ago · 0 comments
A few responses:
1. The spec is too long/complicated: Yeah that's cause graphics is inherently complicated. You can't simplify out the core of the thing you're trying to do. Sure "shapes" are simple, but anything that would be actually useful involves paths (interpolation modes), transforms, groups, blend modes, effects, gradients, masks, stamps, FONTS (don't get me started on fonts!) typography, and on and on. And that's just stationary 2d graphics! Add animations in there and it's a whole other deal. Strip it all out and yes, your spec is shorter. But then you need like 20 different file formats! One for each sub-domain. And good luck trying to make them all work with each other.
The fact that it interoperates with CSS/JS _is a huge plus!_. You can have SVG without these things if you really wanted to, but the fact that they interplay with each other is a testament to good language design on everyone's part here.
Also: The Postscript spec is 920 pages, and the PDF spec from 2008 is 750 pages. Graphics are hard!
2. SVG is verbose because it's XML: XML is pretty compact honestly, especially in SVGs.
Consider:
<rect width="200" height="100" x="10" y="10" />
vs. { "type": "rect", "width": 200, "height": 100, "x": 10", "y": 10 }
And that's me following best practices to have `"` around the values in the XML! It could be even more compact. It's only more verbose I guess when you have closing tags which in SVGs is mostly for the `<g>` element which is literally only one letter :PSo...
<g>
<rect width="200" height="100" x="10" y="10" />
</g>
vs {
"type": "g",
"children": [
{ "type": "rect", "width": 200, "height": 100, "x": 10", "y": 10 }
]
}
XML is really not significantly verbose for uses like this, and the auto-closing `/>` makes it even more compact. And at the end of the day even if it were more verbose, it's not sufficiently more verbose for me to super care.3. Who is SVG for?
It's for both humans and computers and strikes a compromise between the needs of the two. Computers: built in a hugely well-supported language like XML makes it super easy to parse/process computationally. If you wanted to build a renderer that supports just a subset of SVG, that would be a < 1 day task. The more you want to support, the more it would take.
And it's human readable -- or at least as human readable as any textual representation of 2D graphics can be. And that's another piece of inherent complexity here: representing 2D graphics in (effectively 1D) text is _always_ going to be hard to "read", if by "read" we mean understand what it's supposed to be displaying. No text format will be able to get around that.
TLDR: The flaws listed here with SVG are either mostly preference/minutia or complexity inherent to the problem-space itself (2D graphics in a 1D format) that aren't likely overcomeable. Don't get me wrong there are definitely flaws with SVG! But I don't think these are it.
I even like XML as a user of my work’s external vendor’s configs. I edit subsections more than I write it. It is well documented, errors are easy to spot, and the file is git-able. I would honestly hate to see what that company would come up with in JSON or YAML configs so in this case XML is a great fit.
This isn't an issue if you use S expressions, simply because S expressions get rid of the concept of properties. But at that point, you end up with a rectangle with a sub-node called "width", which feels weird as well: the width of a rectangle is clearly a property of the rectangle, not a "child" of it? I'd argue that using S-expressions where each rect node must have x/y/width/height children is just a poor attempt at adding back properties to a syntax which doesn't natively support it.
Are you implying those are optional? They aren't. You can choose between " and ' but you need one of them. You might be confusing HTML rules with XML here? HTML is not XML. (That was XHTML, which failed…)