Live data from Hacker News

I recommend CGI instead of web frameworks

halestrom.net

31–40 of 89 posts

Re: I recommend CGI instead of web frameworks

#31

I love the simplicity of CGI, it was ~2002 when I read about it in a book on Linux and had my first server-side generated HTML output a couple of minutes later. But: It has no place in todays world except of educational use. Especially the fact, that every HTTP request would spawn a full new process makes it unfeasible for any serious webapp.

> It has no place in todays world except of educational use. That's overly strong. I will create a CGI app every now and then. I can use basically any language I want. Not a lot of thought has to go into it. As the article says, it's a simple approach that makes sense for those of us that aren't so familiar with web development (we're usually making those apps for ourselves). In particular, the "you can never have to…

Definitely overly strong. I don't personally use CGI because I've got a whole toolbox of pre-built starters that can scale if needed. Still, I've worked many projects that needed a simple, infrequently used microservice to do something that couldn't be done inside of an enterprise management system (read SAP, CRM, Salesforce). CGI would be an easy to maintain and perfectly acceptable solution.

Re: I recommend CGI instead of web frameworks

#32
There's an important point I haven't seen discussed yet: I don't believe it's possible to write secure web apps without a templating engine with safe-by-default XSS handling (i.e. interpolated text is sanitized, unless explicitly marked as trusted HTML somehow), which implies some amount of a web framework or at least a web-specific library.

Re: I recommend CGI instead of web frameworks

#33
post #17

CGI really is a beautiful abstraction. The reason we stopped using it 15+ years ago was performance: forking a new process for every incoming web request just didn't make sense on ~2000 era hardware. I wonder how true that is today, given that our machines have vastly more RAM and CPU? If you squint at them the right way AWS Lambda functions are pretty similar to the CGI model.

What are typical process creation times nowadays on Linux?

I see that starting up a Python interpreter and running a Python program (or Ruby or whatever…) might be slow, but how far can I get with a golang, C or ocaml binary?

I don't know, but I'd expect the Linux people to have optimized that to death.

Re: I recommend CGI instead of web frameworks

#34
post #8

I'll always have a soft spot for Classic ASP[0]. Makes me dream of a simpler time developing CRUD apps. [0] https://en.wikipedia.org/wiki/Active_Server_Pages

I really wish I’d had a chance to use ASP in an environment doing it properly, rather than the cowboy atmosphere of a tiny web agency. If I understand correctly the idea was that you’d use a proper language for your core business logic which then gets compiled into DLLs loaded by your ASP application, which could then use VBScript for the simple template logic.

Sadly I was at an agency which (I suspect like many other places) just threw stuff like establishing database connections straight into the templates, and had ludicrously complex stuff being done in VBScript, a language designed for light automation.

Re: I recommend CGI instead of web frameworks

#35
post #8

I'll always have a soft spot for Classic ASP[0]. Makes me dream of a simpler time developing CRUD apps. [0] https://en.wikipedia.org/wiki/Active_Server_Pages

Just use long variable names please. Had to debug an ASP site written in 2019 that used classic three letter variable names for everything and it was rough.

Re: I recommend CGI instead of web frameworks

#36
post #17

CGI really is a beautiful abstraction. The reason we stopped using it 15+ years ago was performance: forking a new process for every incoming web request just didn't make sense on ~2000 era hardware. I wonder how true that is today, given that our machines have vastly more RAM and CPU? If you squint at them the right way AWS Lambda functions are pretty similar to the CGI model.

The problem has got worse rather than better; the machines are approximately 1 million times more capable in terms of raw MIPS, but the runtime startup cost of the languages used has increased, so the wall clock time to start a request has gone up.

2000 era CGI tended to be in Perl or PHP. Even then Java made an appearance, with a long-lived host process, e.g. Websphere.

One advantage which the author gets right is that CGI consumes no resources while not serving requests, so you can have a lot of different CGI programs on the same machine. It also plays nicely with multi-user systems, so an ISP could host a lot of different customers on one box. We could serve CGIs from several hundred users off a 128MB Pentium system, for significantly less resources than one Slack instance.

Re: I recommend CGI instead of web frameworks

#37
post #17

CGI really is a beautiful abstraction. The reason we stopped using it 15+ years ago was performance: forking a new process for every incoming web request just didn't make sense on ~2000 era hardware. I wonder how true that is today, given that our machines have vastly more RAM and CPU? If you squint at them the right way AWS Lambda functions are pretty similar to the CGI model.

It's unusable today, more so than it was a decade ago:

- modern frameworks have a much higher startup time (see Python imports, Java VM and other). CGI was fine to run a perl script with no dependencies.

- it prevents any form of caching. caching is very important for many use cases.

- it requires to open a fresh connection with every request, to the database and elsewhere (too bad if you thought you could use redis for caching).

- SSL is everywhere and it has a notable overhead on initialization, meaning you really wish you could reuse connections. (Not just the databases but to other API services)

Speaking from experience, I've inherited the CGI platform at JP Morgan (the largest US bank), that went back to 2006 and approached a thousand running applications at some point. It works and it was still the easiest way to deploy any application in 5 minutes 2 decades later but the drawback are real. It's only for short scripts that can tolerate a 5 second startup time and zero caching.

https://thehftguy.com/2020/07/09/the-most-remarkable-legacy-...

Re: I recommend CGI instead of web frameworks

#39
Like writing C in a simple console-based editor and compiling it with cc on the command line, writing raw CGI scripts like this is a great way to start and learn underlying principles. You can build some simple, even useful things and understand every bit of what is happening.

It doesn't scale to what we do on the web today, of course.

It's a good place to start. Not a good place to stay.

Re: I recommend CGI instead of web frameworks

#40

This text seems like it is stuck in time. I wouldn't be able to do most of the stuff I am doing without libraries and frameworks. It would simply take so much time redoing the same shit that others have done before so I couldn't finish my task at hand and solve the problems I actually care about. Plus, just look at this dudes website. Sure it works just fine but it's nearly impossible to read on my large screen. It f…

> Plus, just look at this dudes website. Sure it works just fine but it's nearly impossible to read on my large screen. It feels like it was designed for an older CRT screen and has never been updated since.

Using the browser's Reader View mode I can read the website beautifully just fine. In fact, this is my preferred way of reading articles on the web, because I get consistent and controlled styles.

> I wonder how people like this can survive in todays world with the requirements people have on web software. You will sooner or later be out competed by a guy using a web framework.

Not everyone doing webdev is competing to get a job or gig as a webdev. There are people who makes their own sites for various purposes, i.e. they are their own webdev customers. And if you're suggesting these people to "require more", it looks to me you start to meddle with how they run their business (which might benefit from your suggestions, but also maybe not).

Post reply on HN