232 points · by weinzierl · 3y ago · 100 comments
I'm also never sure what magic gets wrapped around the html I type. Does this thing add a DOCTYPE? A header? Or can I define my own header? Etc.
So I made this one, where you edit just a raw html page and see the output right away:
https://no-gravity.github.io/html_editor/
The code is here:
https://github.com/no-gravity/html_editor
One way I often use it is that I copy the whole source (via view source) of a page, paste it into the html_editor, add a <base href="url_of_the_page"> to it and then I can try realtime changes with all the external CSS and JS being loaded just as it is on the original page.
I think it's for this reason you often see those languages split out in code playgrounds. And I also think it's a big part of the initial pushback against css-in-JS libraries such as styled-components or Emotion.
This is why I absolutely love Vue single-file components. AFAIK, there’s no elegant substitute for these in React.
If I want to create a reusable component I need to control the layout tightly, and use media queries for display size.
The user of the component needs to control the colour and cosmetic stuff, while also using media queries, but for dark/light mode.
All four use cases use the same bloody input - CSS! Which means all of the different parties are stepping on each others toes because they may accidentally set a property that needs to be set by a different party.
It's not designed for separation of concerns.
All of the four mentioned use cases are stylistic. So it is desirable to accomplish them in a domain-specific styling language.
Used correctly, conflicting regressions are greatly minified.
It's just the problem with CSS that the vast number of developers don't know about its fundamentals, such as "CSS Specifity"
https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity
This collective lack of knowledge leads to the kind of "monkey patching until it works for me (and breaks for you)" many lament about.
Feel free to give an concrete minimum viable example (including code) where you are struggling with CSS, and I will try to give suggestions.
That is what the web was built as. We were supposed to browse documents like we browsed magazines. Your React monstrosities were hacked on top of that model, turning the browser into an application runtime - which it wasn't meant to be.
It says,
> MOUNTAIN VIEW, Calif. (December 4, 1995) -- Netscape Communications Corporation (NASDAQ: NSCP) and Sun Microsystems, Inc. (NASDAQ:SUNW), today announced JavaScript, an open, cross-platform object scripting language for the creation and customization of applications on enterprise networks and the Internet.
(Emphasis mine)
JavaScript was always meant for building applications.
However, my own personal guidelines are::
* A small project lives all in one file.
* A medium project is organized by what the files are (markup, images, etc).
* A large project is organized by its major components, and how those components are themselves organized depends on _their_ size and what they do.
* Never be afraid to reorganize a project if (and only if) it makes sense.
Video: https://rt.ht/yt (multi-device, live sync without reloads)
Home: https://elefunc.com/#rtcode_io
Playground: https://rtcode.io
Network: https://rtedge.net
---
To import from CodePen:
• https://codepen.io/jkantner/pen/NWEgzoK (original)
• https://rt.ht/codepen.io/jkantner/pen/NWEgzoK (import)
• https://rtcode.io/jkantner/pen/NWEgzoK (import)
Besides that, I like it. Thanks for the links.
Is this a commercial product?
• https://new.rt.ht (try starting fresh here)
If you cannot save your code, just save the URL which encodes the complete state down to the selected text ranges.
Saving/deployed to 275+ Cloudflare locations may not be available globally yet.
It is will be a free playground with commercial features, such as edge-deployed workers which can be developed in-editor:
• https://sw.rt.ht/? (in-editor)
• https://sw.rt.ht (edge-deployed)
Does it matter? (Serious question) Not for a full website where it matters for duplication / caching / performance, but in this context - for the playground.
There is one little quirky js thing you can do to get the script element from inside the script but I doubt many people are doing that.
<div>…</div><script>document.currentScript.previousSibling.…</script>
Provided you care even vaguely about code size (and are ending up with handfuls of kilobytes at most, not multiple megabytes), inlining everything is excellent for performance (seriously, unreasonably effective, way more than most expect), and if it’s stuff that must be done before the document is fully interactive, then doing it immediately like this rather than messing around with DOMContentLoaded event handlers and querying and such is likewise excellent for performance.Now you *have* to elaborate. And what's the problem it solves?
Tbh I also never liked it, for all those reasons you listed.
Ideally it would be a left panel with a treeview list of files with the selected file displayed on the right panel in an editable element.
Output should be a different window which updates on every change.
In a web programming course I created I often referred to and leaned on MDN.
Aside:
DDG lets you search in MDN directly if you prefix a search with !mdn. It's one of the few sites that has a very much usable search feature.
For me, I have blackholed w3schools and boosted MDN in my search engine of choice. It is quite nice to always get the MDN page on a web-dev related query as the top result.
Even searching for "w3schools" directly results in the wikipedia as the top result (which is.. fair enough).
The same search on DDG results is a page full of w3schools & subdomains.
1. MDN's quality is higher, and it's more comprehensive when it comes to new browser specifications, but it's much less comprehensive in general technology/programming topics (e.g. W3Schools covers PHP which many working with e.g. Wordpress will dabble in alongside their HTML/CSS/JS).
2. Tenure. MDN's is much much more recent - W3Schools has been around forever.
W3Schools is a somewhat dodgy website with questionable quality, but it's hard to argue they've had a net-negative impact on educating programmers. I certainly learned a large chunk of my knowledge from W3Schools in the days before MDN docs existed in their current form.
And it sometimes takes months to get things fixed (after reporting or providing PR at https://github.com/mdn/content).
I've learned to always test myself when it comes to pesky/obscure behavior(s) of JS.
If we're talking the best then it has to compete with Qt, Rust, MSDN, cppreference, all of which I would say are better. Definitely in the top 10 though.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
With Rust's
https://doc.rust-lang.org/std/iter/struct.Map.html
I find MDN to be a bit clearer, and they benefit from the in-browser runtime. All the extra detail in the Rust docs (blanket traits etc) were quite intimidating and distracting when I first started learning it.
https://doc.rust-lang.org/std/iter/trait.Iterator.html#metho...
Just look at the official HTML and JavaSc.. nay, ECMAScript specification docs[0][1]. You'd sooner end up with a headache than a functional website if you had no other choice but to use those ;)
Additionally, most initiatives aimed at improving the situation have only resulted in yet more overhead in the form of additional committees with each their own agendas and procedures, or the creation of another new deeply interconnected but otherwise completely separate sibling standard[0][1][3][4], fragmenting things even further.
I used to be quite heavily involved with some of the more meritful of those initiatives, but at some point realised that despite all the time and effort I was putting in, nothing really meaningful/impactful had been achieved or was even anywhere in sight, and it was also becoming too costly on a personal level. Guess that's my justification for having the right to post this rant :)
[0] https://infra.spec.whatwg.org/
[1] https://webidl.spec.whatwg.org/
CSS specs are likewise very readable and extremely useful reference, though they’re less precise than significant parts of the HTML Standard. But if you have questions about how certain things fit together, or corner cases in certain properties, MDN is normally useless while the relevant specs are regularly invaluable. I highly recommend being familiar with reading these specs if you’re doing even mildly unconventional things.
The ECMAScript Language Specification: it’s not like either of the other two; it’s not a document that describes how things are supposed to act or how to use things, but is full code for implementing an ECMAScript engine—just expressed in natural language rather than a more accustomed programming language. I’ve referred to it a number of times when I’ve had nuanced questions about exactly what the engine does in such-and-such a case (the sort that the vast majority of web developers will never need or want to ask), and it’s been useful in such cases once it finally loaded, but it’s very firmly designed for implementers, not users. Covering any of the sort of stuff that MDN covers in documentation was never anywhere near the intended scope of the ECMAScript Language Specification, nor should it have been.
The specs and MDN serve quite different purposes, and something that combined both functions would be poor at both functions. Bemoan not the necessity of either: rejoice rather that you have both!
But really these kind of playgrounds are at least a cousin, if not a direct descendant, of the immediate feedback principle that underlies everything from a REPL to the kind of systems (Symbolics, etc) that allow you to edit running code. Their potential is beautifully illustrated in Brett Victor's famous 'Inventing on Principle' talk: https://www.youtube.com/watch?v=PUv66718DII
Three areas that I'd love to see playgrounds mature beyond teaching beginners CSS:
1) Integrated directly into developer documentation. You can see some of that in systems that are documenting services -- for example, the Google Sheets API documentation has a 'Try this Method' box that lets you post a request to the service on the same page that describes it, but what I really want is something like that when I'm reading the man page of a destructive disk command, or a complex database query, or a low-level C graphics library. That'll require a playground wired to something as big as a VM, maybe.
2) Integrated into textbooks: for the last couple years the astonishing posts from Bartosz Ciechanowski ([Sound](https://ciechanow.ski/sound/), [Bicyle](https://ciechanow.ski/bicycle/)) have demonstrated just how much better a textbook could be if you could interactively play with the concepts you're reading about. Unlike dev docs, the thing you're interacting with doesn't even have to be "real".
3) Most ambitiously: integrated into the input form of bug/issue tracking tools. This is the opposite of play: it means a running system would need to be in cahoots with a playground, so that mature apps could let you record and playback what you saw as a user, allow you to edit irrelevant parts of input and output out and submit a complete here-look-see-it-is-busted asset for analysis. A Stackoverflow of the future would be orders of magnitude more interesting if each question was posed as a broken playground.
For quick JS prototyping I use RunJS a fair bit, but it is purely for JS so I can't test HTML/CSS. I've also tried Quokka for the same use case but it didn't work very well for me either (having to create files in my editor actually felt kinda annoying somehow).
I also do a decent amount of performance benchmarking, but all the websites for that right now are pretty meh (takes a while to figure out how to get libs imported, assuming they actually work, seems many JS benching sites are abandoned). And most of all they only test in my browser. While building the test suite that's good, but once I'm happy with it I'd like to be able to click a button which will bench my suite in Chrome / Firefox / Safari.
Related thoughts: "design systems" / UI component libraries often have interactive documentation sites (e.g. built with Storybook), showcasing variants and providing "knobs" / controls to edit props and see the results in realtime, so lib consumers can see a component working (in isolation) and generate a code fragment copy/pasteable into their own downstream app.
Also, extending your item (3), project maintainers often ask people reporting bugs to provide an MRE (Minimum Reproducable Example) in a standalone repo. I've noticed a few such cases where the maintainers make this much easier by sharing a link to a basic preconfigured codesandbox or stackblitz for exactly this MRE purpose. I think this idea will catch on and become much more common.
Additionally my company won't run their own playground because they can't figure out how to store and audit code people put into it.
It's a set of custom elements and a service worker that populate an iframe with the contents of the code editor with no server, but in a way that looks like real network requests to the iframe.
This means you get a root HTML page and all the right loading behavior and ordering as a real hosted web page. Inspect the iframe with devtools and you see exactly what you wrote, nothing added by the playground.
The elements also support Node-style import specifier resolution, pulling npm dependencies automatically from unpkg.com, TypeScript, and JSX.
And the elements are very configurable. You have drop in a tabbed-editor and preview combo element, or you can separate the preview and editors for each file - which lets you write prose around each.
I did eventually end up building one for myself and made it available [1] that the goal was a clean UI/UX, minimal and instant live feedback loop with no extra calls to the server - just a simple static website. It defaults to a JS playground since it's what I use the most but HTML and CSS can be toggled.
I don't think a reference website should include any sort of feature that can hallucinate incorrect documentation for you on demand.
It's bad enough that they have to include a disclaimer[1] on their upsell page, which states that the "AI Help" may occassionally return incorrect results.
I think most of the hate for current AI tools comes from the fact that people expect the computer from Star Trek which always provides perfect answers.
Edit: So yes, it needs to be made super obvious to users that it might give you wrong answers.
Either it's good at explaining and is right, or is bad at explaining and is wrong.
Applying the logic of it being "right most of the time" seems really bad for a tool applied to a reference documentation website.
Can I has a vim mode please ? I am not returning back to using arrows to move around text
I'd monetize this by adding features and hiding them behind MDN Pro+ (or w/e the subscription is called) in the future. Ala Codepen.