logoalt Hacker News

jrdrestoday at 1:09 AM4 repliesview on HN

The code makes me smile, because it's nasty. This isn't like C4, a tiny but complete C compiler which does error checking on its subset. Instead, this is worse than Sector C, which takes every shortcut and just plain assumes everything in the source is right.

This "Python" just plain assumes for keywords: Any "f" is a "for [x] in range[y]" (exactly that, no other for's). Any "w" is a "while". Any "i" is an "if". Any "d" is a "def". Any "p" is a "print("

Nasty, nasty.

(Also nasty is that the code snippets in the article has more comments than the github copy of the "readable" version. You need the article to understand what's going on.)

This is a just a bit too simple for a "Tiny Python". If somebody is willing to allow a few more K's of bytes, I'd love to see at least lists & dicts here--Lisp can do them!


Replies

tveitatoday at 5:50 AM

As they say in TDD, write a test, then write the simplest code that will make it pass.

Clearly supporting multiple functions starting with 'p' would be overengineering.

show 1 reply
erutoday at 1:49 AM

If you are willing to sacrifice performance, you can implement dicts via linear lookup in much less code than a proper hash table.

show 1 reply
adamddev1today at 8:27 AM

Reminds me of the good 'ol Apple II BASIC. You can name your variables whatever you want, but only the first two letters matter.

show 1 reply
kristianptoday at 6:15 AM

> Any "w" is a "while"

Meaning that something as simple as "w = 4" would fail? A little too nasty for my liking. Not a choice I would have made, but admire the amount of work done here and the readability of the article. And it's more human-written code than I've done in a number of months!