DEV Community

Jesse Phillips
Jesse Phillips

Posted on

Is Web Development Windows 3.1?

In the early days of Windows there was a very particular way to code your graphical interface. This was because all of Windows was single threaded. Your application could utilize all the processing time and thus prevent other windows to be unintractable.

The win16 api expected you to call into a special management function to release control so other window processing could take place. The win16 api had some tricks up its sleeve, as it would call this manager method for you when asking it to do something. This way there was less likely to be a rogue app.

Now days you're Windows app will need to us threading in order for your application to allow for it not to "hang". But the rest of the system carries on.

My question then, is Web development like this old Win api? Are we using async, promises everywhere to keep our entire web page functioning rather than our component?

Top comments (1)

Collapse
 
leob profile image
leob

Yes it's sort of like that - Javascript is singe threaded.

The old Win16 way was called "cooperative multitasking", Win32/WinNT switched to "preemptive" multitasking (threads).

So it's sort of ironic that the most popular programming language nowadays, Javascript, uses the "Win16 cooperative" multitasking model (requiring the event loop and callbacks/promises and so on), rather than the more "modern" preemptive multitasking model used by languages like PHP (in conjunction with Apache or Nginx) or Java, which use threads to serve web requests.

Javascript requires this both on the frontend (in the browser) and the backend (node.js).

So why, you ask? Threads (used by PHP and Apache/Nginx, and by Java) carry much more overhead (memory usage and context switching). The "cooperative" model used by Javascript is in principle more efficient, more scaleable and less resource intensive. But (here's the "but") it's more complicated to program - anyone who's worked with callbacks or promises can attest to that.