DEV Community

PNS11
PNS11

Posted on

1 2

Let's build: 'load to get faster early web development

When trying stuff out or doing early work on a web site or service it can seem slow and fragmented to restart your application server over and over again.

Instead of churning out all that Ctrl+C or D and possibly also restarting httpGate or nginx at every adjustment you could use a simple little trick that is suitable when testing app modules or just getting started on a project.

dev.l

# libraries for the app server
(load "@lib/http.l" "@lib/xhtml.l" "@lib/form.l") 

(de work () 
    (load "app.l"))

(de go ()
    (server 8080 "!work"))

Once you have this you run and forget about it:

$ pil dev.l -go -wait

Now if you visit localhost:8080 it won't be spectacular.

Enter some GUI boilerplate into "app.l".

app.l

(app) # assuming you want session handling
(action 
    (html 0 "Test bed for savvy gravy" "@lib.css" NIL
        (<h1> NIL "It's alive!")))

Next visit will then look better, and as you work on and save "app.l" and reload localhost:8080 you'll see changes reflected immediately without restarting "main.l".

app.l

(app)
(setq *Awesome T)
(action 
    (html 0 "Test bed for savvy gravy" "@lib.css" NIL
        (if *Awesome
            (<h1> 'awesome "Apparently you're awesome!")
            (<h1> 'notsoawesome "Pretty sure you won't see this!") )))

Using this technique 'in production' isn't a good idea since file I/O performance is about as bad as it gets, but compared to restarting the same script over and over manually while allowing a separation of your development helper functions and globals in "dev.l" from the app code in "app.l" will feel like super powers.

There are of course other ways to achieve this or similar results, you could for example use coroutines or background tasks instead, laying ground for a more sophisticated integrated development and production administration environment. Or whatever it's called when you program your servers by pew-pew:ing messages at objects and watching web services grow out of it.

Next time we'll create a small guestbook application.

Stagling@Patreon for coffee donations, unless you'd perhaps, y'know, like to hire me or something, then I'm sure we could work something out.

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay