Back to News
Advertisement
Advertisement

⚡ Community Insights

Discussion Sentiment

80% Positive

Analyzed from 682 words in the discussion.

Trending Topics

#space#python#whitespace#code#more#language#nasty#tiny#https#tab

Discussion (28 Comments)Read Original on HackerNews

jrdres31 minutes ago
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!

teddyhabout 2 hours ago
For those who actually need something like this in production, there is Snek: <https://sneklang.org/> “Snek is a tiny embeddable language targeting processors with only a few kB of flash and ram.
jrdresabout 1 hour ago
Yes, but compiling or modifying Snek from source is very challenging. I wish it was one single C file for an example base like Posix, instead of many files for many platforms plus a custom parser in Python (Lola).
anitilabout 1 hour ago
This is really cool! It's so fun to see what you can achieve and what's optional. I have seen the 'single character variable' limitation in some other minilangs before, but using the source itself as the target of function calls and loops is new to me. It does make a lot of sense but I wouldn't have thought of that.
tempodoxabout 2 hours ago
This seems to be in the same spirit as Justine Tunney's SectorLISP. Very cool.

https://justine.lol/sectorlisp/

gabrielsroka36 minutes ago
Or sectorC

https://github.com/xorvoid/sectorc

Edit: I wonder if sectorC could compile python1024

hankbondabout 2 hours ago
Good use of free will and well-written. Very nice walkthrough austin!
Scubabear68about 2 hours ago
I was very disappointed that this is “interpreting” some tiny made up language.

This is not Python, or even within three orders of magnitude of Python.

stingraycharles2 minutes ago
Yeah the amount of Python code that would work here is probably not a lot more than this specific FizzBuzz example. Lots of shortcuts taken, which I guess is understandable.
SPBSabout 1 hour ago
It’s true, the title should have said “Python-like”
benatkin8 minutes ago
I like python subset. However, many don't see it that way.
happycubeabout 1 hour ago
TBF the fizzbuzz code works just fine in CPython.
benatkin6 minutes ago
Indeed, for some code, CPython and this interpreter produce identical output. I gave it an upboat.
TZubiriabout 2 hours ago
A lot of criticism of python often mentions the whitespace as lexical scope tokens, and that criticism is usually posited by users of the language.

As implementer of an interpreter, did you feel that whitespace for lexical scoping made the job of writing the lexer significantly more complex?

nomelabout 2 hours ago
And, there are multiple white space symbols!

<space><space><tab><space>

is different than

<space><tab><space><space>

So you also have to track the actual sequence of counts of white space used for each level, rather than just a simple count.

rmunnabout 2 hours ago
Or you just forbid mixing spaces and tabs in the same indentation sequence, the way most whitespace-sensitive languages seem to end up doing. Or you make a slightly more reasonable rule: spaces may follow tabs, but no tabs may follow a space. That's at least unambiguous.
fc417fc802about 1 hour ago
But it also feels arbitrary and annoyingly restrictive. On top of that there are at least 25 whitespace codepoints in UTF. Should your language really be opinionated about when, where, and in what order (for example) the "mongolian vowel separator" appears?
jubilantiabout 2 hours ago
> <space><space><tab><space> is different than <space><tab><space><space>

in my view, both are the same, both `is` (or ===) an IndentationError raise

fc417fc802about 1 hour ago
It's just a stack containing strings at the end of the day. Really not a big deal.
TZubiriabout 1 hour ago
Right, pointers to strings but yeah. Essentially the whitespace count specifies the stack depth at which a line is to be executed. A decrease in stack depth means all superior levels are terminated.

Doesn't affect function call stacks though.

TZubiriabout 1 hour ago
For a 1024 byte implementation (and even way more complex impl.) You would just force one whitespace char, and definitely no mixing.
zephenabout 1 hour ago
> that criticism is usually posited by users of the language.

Uhhh, no. Sure, it's posited by people who feel they are are forced to use it, but it's basically unlearning other syntax.

Here's a study about people with no experience. They do better with python:

https://www.researchgate.net/publication/262256894_An_Empiri...

When the scala language made whitespace optional, it was very divisive, but now it's extremely well accepted.

mbirth27 minutes ago
At a former workplace where most stuff was done in PHP, some colleagues used whitespace very liberally. Like, indentation was just a random amount of whitespace, every line slightly different. Sometimes 2 or more spaces between keywords, etc.

After that experience Python code is like eye-bleach to me.

TZubiriabout 1 hour ago
I meant users of languages ( application programmers) as opposed to compiler programmers, not python programmers specifically, so I'm including devs that use other languages and see in python a tool that they would consume.
ni5argaabout 2 hours ago
the blog post is pretty well-written! loved how he wrote about the the code-golfing part.