I think for a simple website, especially one with spartenweb or zero JS principles, a language with an architecture like PHP or ASP/ASPX fits well, where you just write HTML and server side code in the same file, and you navigate to that file from your URL to load it. For example, wwwroot/path/to/page.php on the server corresponds to https://example.com/path/to/page.php

Problem is, both PHP and ASP are pretty terrible languages, and ASP(X) has the additional dealbreaker of not being open source and only running on Windows servers, so I don’t really want to use any of them (I’ve tried all three), so are there any better web languages or web frameworks that does something similar?

  • Helix 🧬@feddit.de
    link
    fedilink
    arrow-up
    1
    arrow-down
    1
    ·
    edit-2
    3 years ago

    This is a bad idea programming-wise, since you want to separate templates and output due to DRY principle, Separation of Concerns, maybe the MVC programming paradigms and general code cleanliness.

    If you do this wrong with dynamic pages, you open up issues with code injection. At the very least, your code will be hard to read.

    • Aarkon@feddit.de
      link
      fedilink
      arrow-up
      3
      ·
      3 years ago

      Code injection is an issue everywhere as soon as you leave the realm of purely static html. That’s why I’d recommend to use a framework to do this instead of sanitizing every possible input yourself.

      DRY, SoC etc. are all sane principles, but that’s not to say that you can’t have an html template and some dynamic language in the same file. You’d only have to think differently about encapsulation and code reuse. Components are a popular pattern these days, exposing functionality that you want to have in multiple places across your page.

      • Helix 🧬@feddit.de
        link
        fedilink
        arrow-up
        2
        ·
        3 years ago

        Well said. Of course this is not a black and white issue. Some code and design can be mixed but the PHP way of allowing HTML with server side includes, sometimes even based on form input, is just a recipe for disaster. That’s actually why Cake and Laravel don’t even really allow this, or at least make it super hard to do.