Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Turbo Pascal Compiler in JavaScript (github.com/lkesteloot)
148 points by mariuz on Feb 20, 2021 | hide | past | favorite | 72 comments


In 1996, I wrote programs in TP 6.0 on a 486DX2/66 with 4 MB RAM. The IDE weighed in at a few megs, compiled my stuff in less than a second, and produced standalone .EXEs that ran on every DOS PC.

In 2021, I'm writing programs for iOS in React Native. I need Xcode that weighs in at ~8GB _compressed_, node.js, and RN plus the whole slew of dependencies. On my 2020 Intel Mac mini w/ 32 GB of RAM, Xcode takes multiple minutes to build just the native part of the project from scratch.

Where, where on earth did I go wrong?


Did your programs in 1996 do anything close to as much as they do now?

It's easy to feel a lot of nostalgia, but those truly were simpler times when we expected a lot less of our computers/programs.


I used excel and word, had windowing operating systems, and databases.

Sure they didn't scale as much or have embedded video, but in terms of "did they do function X"? Yes they all worked fairly well.

The massive horsepower gains are REALLY noticeable in the evolution of games. But outside of that in "productivity"... ye gods we are wasting horsepower to basically do the same crap we used to do.

What is really really exasperating is when any app freezes for multiple seconds. I start counting 4 billion... 8 billion... 12 billion (assuming 4 billion instructions per second). How does that happen with having 1000x the horsepower?

And the RAM we waste these days. Windows ran in 4 MB! And 16GB is too small these days for development?

Moore's law is dying. Software stacks need to start optimizing themselves.


> I used excel and word, had windowing operating systems, and databases. Sure they didn't scale as much or have embedded video ...

Word for Windows almost certainly supported embedded videos. WordPerfect for Windows certainly did, and I seem to recall it being based upon OLE (a Microsoft technology). This was in the Windows 3.1 era.

> ... but in terms of "did they do function X"? Yes they all worked fairly well.

The answer is truly an, "it depends." Some modern software is much more powerful. Other software feels like a throwback to the 8-bit era with a shimmering veneer. I used to think that this was a product of web and mobile development effectively forcing developers to start again from scratch, but I am starting to believe that most modern developers lack the ability to implement features that aren't provided by a framework.


A lot of the RAM usage can be explained by users expecting crisp fonts and icons on 4K screens. That's quite a lot more data than in VGA.


That's true to a point, but... is that just being lazy? Aren't those all in "compressed" vector maps and could be rendered as needed with video hardware?

Don't get me started on icons. Icons, if anything, have gotten progressively worse somehow with more resolution and colors. It's almost like the reduced color palette caused more sudden color transitions and communicated the icon's purpose back in the day.

Which might have underpinned material design... but that entire movement, at least its major expressions (e.g. Windows 8/x) is an utter disaster.


For a lot of software that is not really true, especially on the client side. A lot of LoB software doesn't demand anything more; frontends with a bit of logic on top of a db. The fact that you get a lot of things out of the box does not mean they are required or expected. I guess everything working with a mouse would be the one thing that is expected, but that could be done in '96, just TP for DOS was not the best choice for that. You would take Delphi 2 for that if you were into Pascal.

But sure there is software that does a lot more as well, luckily we did progress.

But don't forget there are millions of (mostly Windows) programs in the world which could've been (and are still!) from that era or long before (Cobol machines in the basement).


Software did less in 1996. That's why it was so much better! :-)


That's actually not a terrible point :).

I do remember WordPerfect (the DOS version) being absolutely incredible... in no small part because you could "reveal codes" (or whatever the name of that feature was). I helped my dad produce a couple of textbooks using WP and the most difficult thing we ever encountered was... printer drivers. (Which is still a pain point today if you're not using Windows/Mac.)


I remember so well being ashamed that PC users were still typing docs in such primitive UIs while I was "desktop publishing" with WYSIWYG on my Atari ST. "Reveal codes" blergh a modern computer should be better than that!

30 years later, I love writing markdown and stay away from GUI rich text editors as much as I can.


As one of those PC users, that could only use Amiga 500 from friends during weekend meetups and demoscene parties, I definitely don't miss those days of only having c:\> to work with.


Frankly, that's a pain point even if you're using Windows or Mac.


Ah. I've been out of the ecosystem for so many years. It used to be simple on those platforms... :/


It’s an exaggeration to say it’s a pain point on Mac for most printers. I’m sure some aren’t supported by the standard flow, but that flow is literally “select your printer which is already identified, agree to download a driver and wait a bit”. It’s as painful as installing a web extension if you don’t have to go find it first.


Well, except your printer now has its own OS, and asks to be connected to the Internet so it can download security updates it wouldn't need if it wasn't connected to the internet.


Huh? This isn’t something I’ve ever heard of from Apple’s distribution of printer drivers. Neither of the Brother printers I’ve used since this system was put in place (Snow Leopard, widely regarded as the high water mark for macOS quality) have required or requested network access other than for availability. Are you talking about something specific that’s well documented or just being paranoid and sharing careless inference?


I was talking about the printers themselves. Back then you just worried about the drivers on your computer, now you have to keep in mind that your printer needs to update its firmware on its own.


But I don’t need to worry about either. My OS vendor distributes it and I trust their distribution model. My printer has no say at all.


We still don't do much more customer-facing, we just do a lot more internally. Just judging actually useful features, I'd put a lot of DOS software on favorable grounds compared to your average immutable functional serverless Kafka-backed hexagonal 12 factor SOLID web app.


They most definitely could do a lot[1].

There was also overlays[2][3] and extended memory (EMS/XMS) which made it possible to use quite a lot of memory.

[1]: https://ilyabirman.net/meanwhile/all/ui-museum-turbo-pascal-...

[2]: http://www.oocities.org/~franzglaser/tpsrc/overlaytxt.html

[3]: https://secondboyet.com/articles/publishedarticles/theslithy...


Yes. I programmed in Turbo Pascal and (later on) Delphi. I am not unfamiliar with these systems.


I agree.

Saving stuff to harddisk with 8.3 file name notation and working on super-crappy monitors is still a dealbreaker, not to mention Git.

I recently wrote a little demo on Amiga 500, 68k Motorola. And it was excruciating.

Today's software development is sometimes unfortunate, but I find the benefits more remarkable than in the 90th.


Isn't lowering your expectations the secret to happiness?


I too work in React Native sometimes.

Most of the React Native code I have seen is just presenting customized widgets to the user, and being a front-end for an API.

It is difficult to compile a RN project from a year ago, and very difficult for a three year old RN project.

By contrast, I wrote a paint program in Java almost 15 years ago, and it ran comfortably on a 486DX4/100 machine. And it will run without any modification on a computer today.

  git clone https://github.com/unqueued/SimplePaint
  cd SimplePaint
  make
  java SimplePaint

Generating a jar file (make jar) creates a distributable that is 26K.

I've written fairly sophisticated business logic in Visual Basic 6, and I remember how much less cognitive load there was developing it. In the early 2000s, it was no problem to interface with a variety of different databases and APIs.

And like Java, most of these programs will probably run on Windows 10 with no modification.

One thing I really miss is how much less room there was for things to go wrong. Even in Visual Basic, the primitive threading support was so much simpler. Even when dealing with data streams from various sockets, handles, and the GUI, I spent maybe 1/10th the time as with React Native.

Of course I appreciate that React Native can do some unique and cool stuff. But I find that in practice what it is used for is stuff which could have been done so much better with other technologies.


I come from that era too.

The tools of the past still work blazingly fast on current PC. But look closely, a database such as postgresl is really light on resources and goes very fast for workloads of the 90's (or event SQLite). A C compiler with make goes fast too. Except your code now runs on a multiprocess operating system with tons of security, crash proof stuff (remember rebooting your PC because an off by one in your C code ?, remember fiddling with CONFIG.SYS to be able to use stuff about 640KB ?). A compressor is way faster than before. Stuff like Maxima are so much better now...

The only thing that has inflated is UI. But as far as UI for coder are concerned, things are good today I think. I use emacs, it still rocks. I use IntelliJ and it's pretty fast + it has code refactoring, code navigation and other wonders. Sometimes I write Jupyter notebooks, have you ever saw that ? It's incredible how much powerful that is to explain ideas. Of course I could do it with pen and papers, but I have so much more comfort to do it now.

So it's not that bleak :-)

One more example, I write demos for Apple 2+ from time to time. And guess what : do I code them on the Apple 2 ? No way, 40x24 display ? floppy disks ? crashing computer ? No git ? No good text editor ? No browser ? Nope, I would never code on an Apple 2+ today. But coding on today's tool with Apple2 as a target, that's waaaaaay better than in the good old days !


Surprisingly, so much of this is typography. I had the same question and started tracking down what 'why is there so much code' question. The answer, nearly always, lead back to being able to use arbitrary fonts and arbitrary languages, chosen dynamically at run time.


Well, TP did have problems going above 64k and needed modules/codeswapping IIRC to get to 640k.

I hit those limits writing a battletech game in Turbo Pascal.

And not exactly doing optimization...

But yeah, Turbo Pascal really makes you wonder where all the horsepower (LITERALLY 1000x more speed or more with multicore and all the branch prediction, spec exec, ops fusion, out of order exec, etc) is going.

And 4MB ram. That fits in CPU cache and then some!

Library bloat is so out of control.


Individual objects were limited to 64k, but you had 640k for your program and the heap, in general. (I had some tweaks to get myself 704k free at the C:\> prompt).


There were many options overcoming memory limitations back then though: overlays, XMS, EMS, even protected mode with BP7.


> Where, where on earth did I go wrong?

Here.

> I'm writing programs for iOS in React Native


"Where, where on earth did I go wrong?"

Try Firemonkey from Delphi. It will allow you to write cross-platform applications, though for iOS/Mac you'd still need XCode, but at least you'll compile in seconds a small/medium application.


How long would it take you to build everything you get from RN and all the libraries in TP6?

From what I remember of TP6 it would take me a few years. Maybe even a decade. Oh and a lot of libraries (like mouse support) used assembly code and prob only worked on a limited numbed of computers.


>How long would it take you to build everything you get from RN and all the libraries in TP6?

Are we talking about the site, or the web browser to view it with? I could probably do either in a month.

Using Lazarus/Free Pascal, about 1 week each.


We’re talking about taking in React code and compiling it to iOS native UI plus the bridge between native APIs and JavaScript.

Obviously to get there you first need to get all the iOS UI kit into Pascal. Then also a compiler from Pascal to iOS binaries.

PS: don’t forget the dev tooling.


Oops... I see the typo now... you wrote RN, and I read HN, Hacker News... ;-)


The author's blog post is quite enjoyable: https://www.teamten.com/lawrence/projects/turbo_pascal_compi...

> My friend Fredrik Fatemi and I spent the summer after high school (1989) writing graphics programs in Turbo Pascal on his 286 PC (with EGA!) in his basement while watching The Princess Bride again and again on his VCR. He recently found some 3½" diskettes with our programs on it. I couldn’t find a good way to run them on my Mac, so naturally I wrote a Turbo Pascal compiler. It’s web based and you can try it here.[1]

[1] https://www.teamten.com/lawrence/projects/turbo_pascal_compi...


> I couldn’t find a good way to run them on my Mac

Dosbox / Boxer


Good thing the author didn't know, ;) we now have a TP compiler in JavaScript!

Sometimes it is awesome when the right person doesn't know something.


A bit offtopic, but I recently discovered Lazarus, and I was pleasantly reminded that the language I learned in high school is still kicking.


Pascal was my first programming language at University (circa 2016). Alas in 2018 they succumbed to student feedback (university admin was big on that) complaining about learning a "dead language".

Missing the point that it is a brilliant teaching language for a beginner to learn fundamental concepts.


Even better than that, it also runs natively on Raspberry Pi, so you can go down at bare metal on embedded projects.


You mean ObjPascal or the IDE?


Lazarus is the IDE. Free Pascal is the language. Both go together in Raspberry Pi without a problem. Create beautiful GUI that can run on touchscreen too. Use a $50 3.5 inch touchscreen + $35 RPi and you can have a beautiful IoT doing whatever you want.


Delphi is also a commercial product still - I use it every day :-)


Can I ask what kind of projects you work on as a Delphi developer today? I loved using it back in the day but I understand the market for it is quite slim now.


I spent two decades as a Delphi contractor. Not doing it anymore, but I still see a lot of control software for industrial machinery and lab equipment (at least those made in EU), POS and kiosk software as well as custom ERP and ERP style software.

I am currently working on NIR spectrometer and I am actually thinking about using Lazarus for driving touch screen instead of web based dashboard.


For example this company uses Delphi on their software products,

https://www.lab-services.nl/en/home

In Germany, there are still conferences with Delphi contents (EKON 24 and BASTA), and some magazines have occasional Delphi content.


A lot of medical software was written in Delphi and still going - it was written by Doctors and grew.


Pascal was quite an accomplishment: a compact, elegant, easy-to-learn, easy-to-read language.

And Wirth's "Compilerbau" (Compiler Construction) booklet (about the size and less than the weight of a bar of chocolate) is a true gem; it makes it all look very simple.


> elegant, easy-to-learn, easy-to-read language.

Compared to C? Yes, obviously.

Compared to languages we have now? Not so much.


Care to tell me an example of one we have now? That Delphi (spiritual successor of Pascal) is not just as elegant? Because I can't think of one.


Obviously, these things are subjective, but... Python? Haskell? Scala? Heck, even modern Java?


Java elegant? Where you actually have the need for an IDE to be on a ultra-wide monitor because otherwise you can't read the name of a class? And you call that elegant?

Python elegant? Probably you meant easy to learn, but elegant is something else entirely. Not to mention is still interpreted (though for the life of me I can't phantom why none writes a compiler for it. Would be a huge advantage)

Haskell is the only one that I would call elegant on this list. But we were talking about modern. Haskell is 30 years old, I would not call that modern. Also Haskel and Lisp can be written (just like C macros if you want) to birth an entire different syntax if that's your kink.


Maybe this would be easier if you shared your definition of 'elegant'.

> Haskell is the only one that I would call elegant on this list. But we were talking about modern. Haskell is 30 years old, I would not call that modern. Also Haskel and Lisp can be written (just like C macros if you want) to birth an entire different syntax if that's your kink.

The only mention of 'modern' in this thread was with respect to Java... you know, the one with record types which eliminate a lot of boilerplate?

I'm not sure why age should count against Haskell, when you agree that it is 'elegant'? I should point out that the Haskell of 30 years ago is very different from Haskell today.

I'm not even sure what we're arguing about at this point.


> or the life of me I can't phantom why none writes a compiler for it. Would be a huge advantage

Pick your poison:

PyPy https://www.pypy.org

Cython https://cython.org

Nuitka https://nuitka.net


I have a problem. For some reason a good mathematician wrote the solution to it in Python. Works great. Now I want to use that solution, which is very complex, tens on thousands of lines in Python, in another language because I also need speed and Python is solving that solution in too much time.

What choices do I have? One would be to rewrite the solution myself using provided Python code as base. Second would be to get the Python code compiled in a .dll(Win)/.so(Lin) and use it.

Can above poisons do that for me? Answer: NO. I tried all 3 already, they do. not. work.

Otherwise I can definitely call Powerpoint2Exe an interpreted language too since it can generate a standalone executable.


Statically compiling general Python code to a high-performance standalone executable is currently not possible.

But to solve the problem you describe, you can:

1) embed CPython in your app to run the Python code (i.e. link with the libpython DLL), and then

2) modify the most performance-critical parts of the Python code so that they can be compiled with Cython or mypyc (or write them in C using the Python C API).


All workarounds for something not needed to do had the OP started with a language with proper AOT support.


> I can't phantom why none writes a compiler for it. Would be a huge advantage

When every variable and field access involves a hash table lookup, the interpreter loop is not the primary performance bottleneck.


> I sorted the five original Pascal programs by complexity and was driven to implement the minimal set of features to see each run in turn.

Subsetting like this is so underrated. In case anyone is wondering why one person could do this without an engineering team, and act like it was so enjoyable ;-)


For Turbo Pascal 5.5, the Web IDE looks pretty much like Turbo Pascal 3.0.

Oh well, cool achievement anyway. Playing with it right now.


It's just a shallow copy and doesn't support the default wordstar keybindings in the editing mode.


^Y delete line, ^KB block begin, ^KK block end, ^KC copy block, ^KY delete block, ^PH for accents.

Amazing, I don't know how many years (decades?) I haven't used it, but some keybindings are still in my memory!


Pascal, the boring tool that just keeps working for decades. I wrote a program to control a large water meter calibration system in the 1980s, using TP7 on MS-DOS. I did graphics and multitasking, along with monitoring the pumps, flow meters, etc.

I was contacted in 2004 when it stopped working... because they had inadvertently swapped the two IO cables when replacing the PC it ran on. Y2K had zero effect on it.


https://www.freepascal.org/

Free Pascal tries to be compatible with Turbo Pascal and is ported to dozens of systems.


That reminds me I should dig out my old TP sources and put them somewhere for others to enjoy. Yes, for sure, the dawn of computing was a simpler time.


> I couldn’t find a good way to run them on my Mac, so naturally I wrote a Turbo Pascal compiler

Of course, it’s the natural thing to do. Amazing, writing a compiler


Niklaus Wirth was annoyed that no recent computers had drivers for his favorite mouse (a gift from his sabbatical at Xerox), so instead of writing a driver, he built a new computer system (CPU architecture on up) that would talk to it...


I still have all of my code from '95-'97. Wrote 3D tetris, and a flight simulator among other things.


I am relearning TP and DOS as a hobby. I would be interested if you decided to share you code.

I lost all of my TP programs from '92-'02 as the result of a dramatic neglicence.


So much pascal in my youth.. my BBS software was pascal and a mix of assembly.. been a long time.


In case anyone is compelled to watch ROSE.PAS to its finale, the caterpillar simply stops moving.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: