This is RegEx, and it's checking for an email address format. So RegEx is a DSL. SQL, as I mentioned in the beginning of the presentation, is also a DSL. These days we're more likely writing it in the form of an ORM, like Prisma or SQLite, something like that. But it's still with us after all these years, just like our good friend Keanu. So SQL is a DSL.
Or this obvious example from the world of React is JSX, which is also a DSL. Okay, so we've established what a DSL is, and that you actually use them quite often. But why? Why would we want to create a new specialized language that only works for a very specific thing, instead of just using those general programming languages that can do all that stuff and more? Well, just like Dwight says, we believe that improvement is possible, at least in the case of building better web apps. Do we really need to be specifying, for example, auth, routing, CRUD operations, and all these things over and over again? No. With DSLs, you can just say what you want, and it happens.
So let's see how. Here's our RegEx example from before. We just said what we want here. We don't really care how it's being validated or in which order, what the mechanisms are. We just say what we want, and we get back the result that we're looking for. So if we weren't using RegEx in this case, and rather just plain JavaScript, for example, then you'd have to write something like this, right? And this is what the how might look like, rather than the what. You have to specify every little detail of the check. It's long, and it's pretty tedious. SQL is also a very interesting example. Again, this is the what. You just have to specify what you want, and you don't care how you get it. On the other hand, in the background is the how. So SQL is a DSL, and you just have to say what you want, and all this happens. Not only is the SQL query engine performing the correct search algorithms for you, but it also knows how to optimize your query for speed, which is pretty amazing that it's able to pack all that knowledge and process into such a short command.
And although this is a simple JSX example, we can imagine how messy this would get with a more complex example, right? So JSX is saving us from having to specify exactly how things should happen. So why do we need a DSL for WebDev, though? I mean, we've got tons of libraries, lots of frameworks that can do all this stuff without a DSL already. Do we really, really need this? Plus, you might be thinking, next year, AI will be able to take care of all that boilerplate for us, right? So what's the point? Well, even with all that, this is a Google search I did yesterday, and despite all the advancements we've made in WebDev, it almost seems to be getting more convoluted than easier, This is a sentiment we hear devs express quite often. So there's a lot that can still be done. Why then would DSLs be the possible solution to all this WebDev messiness? Let's go over three reasons why.
Comments