Live data from Hacker News

Show HN: Python with do..end in place of strict indentation

github.com

1–10 of 71 posts

Re: Show HN: Python with do..end in place of strict indentation

#2
Sorry, I have to ask...

Does it support also braces? :)

IIUC the source is writen as a long heresting and then executed.

Does it have the same speed than normal Python?

Does it suppont numpy, numba and other similar packages that use jit?

Can a function inside the modified code call a function outside? (It may be helpful for porting conde one function at a time.)

Is it possible to do something similar with a decorator instead of a herestring?

Re: Show HN: Python with do..end in place of strict indentation

#3

Sorry, I have to ask... Does it support also braces? :) IIUC the source is writen as a long heresting and then executed. Does it have the same speed than normal Python? Does it suppont numpy, numba and other similar packages that use jit? Can a function inside the modified code call a function outside? (It may be helpful for porting conde one function at a time.) Is it possible to do something similar with a decorato…

> Does it also support braces? No :)

> the source is written as a long herestring and then executed that's correct but only for single file modules. you can actually have a python like structure comprising entirely of dopy files and it will be compiled in place or in temp dir and executed as a normal python package with distributed source

> Does it have the same speed than normal Python It's just a transpiler so the code is actually executed by the python interpreter itself. So same speed as python with an extra build step

> Does it support numpy, numba, other packages that use jit? Not now

> Can a function inside the modified... Certainly

> Is it possible to do something similar with a decorator instead of a herestring? Could you explain?

Re: Show HN: Python with do..end in place of strict indentation

#4

Sorry, I have to ask... Does it support also braces? :) IIUC the source is writen as a long heresting and then executed. Does it have the same speed than normal Python? Does it suppont numpy, numba and other similar packages that use jit? Can a function inside the modified code call a function outside? (It may be helpful for porting conde one function at a time.) Is it possible to do something similar with a decorato…

(This sort of thing has been done before, and of course it will never make its way into the official Python distribution; but it's always fun to see.)

>Is it possible to do something similar with a decorator instead of a herestring?

No, this is a fundamental change to Python syntax. To apply a decorator to existing Python code, the decorated code has to compile first, creating a Python object (generally either a function object or "type" i.e. class object) which is passed to the decorator (which is really just a higher-order function with special syntactic support).

But of course, you could write the code to preprocess in a separate file with a different extension, and then have actual Python code which reads and preprocesses it and then evals the result. (The internals could also be written differently, in terms of AST manipulations using the "compiler services" part of the standard library. But this way is probably easier.)

On Linux, you could also have a top-level script which does those steps for a specified input filename, and then specify that script in the shebang line for the Dopy code file.

Re: Show HN: Python with do..end in place of strict indentation

#7
Anyone who can't see past Python's indentation-based syntax is a person who doesn't understand Python.

(Both literally and figuratively!)

When "significant whitespace" is at the top of someone's complaints about Python, I'm immediately done hearing about their superficial criticism of the language.

Re: Show HN: Python with do..end in place of strict indentation

#8
post #7

Anyone who can't see past Python's indentation-based syntax is a person who doesn't understand Python. (Both literally and figuratively!) When "significant whitespace" is at the top of someone's complaints about Python, I'm immediately done hearing about their superficial criticism of the language.

Yeah. It avoids the problem of indentation disagreeing with code structure and reduces visual clutter and... that's it.

Re: Show HN: Python with do..end in place of strict indentation

#9
post #7

Anyone who can't see past Python's indentation-based syntax is a person who doesn't understand Python. (Both literally and figuratively!) When "significant whitespace" is at the top of someone's complaints about Python, I'm immediately done hearing about their superficial criticism of the language.

When I hear someone complain about the whitespace thing, it sends a message to me that they do not format their code well and just go willy-nilly on their indentation.

If you're properly indenting code, then it always works as intended. Proper indentation doesn't come from a desire to make the code work, it comes from a desire to make it readable. It just happens that readable means correct in Python's case.

It literally takes me zero thought to get indentation right. If you can't tell when to start or end indentation level, then I'd question if you know when you need to use an open/close brace in other languages.

I mean, yeah, sometimes copy/pasting code doesn't work precisely as intended, but all you have to do is select the code, hit Tab or Shift-Tab, and any sane editor will add/subtract an indentation level to the code.

Re: Show HN: Python with do..end in place of strict indentation

#10
post #7

Anyone who can't see past Python's indentation-based syntax is a person who doesn't understand Python. (Both literally and figuratively!) When "significant whitespace" is at the top of someone's complaints about Python, I'm immediately done hearing about their superficial criticism of the language.

Agreed. I find such complaints very strange, as most people already follow Python-like indentation rules quite strictly in most other languages, but need to add delimiters as well. Indentation is the clearest indication of code structure, so when it's not significant it still looks significant, leading to bugs like:

  if(condition)
      do_thing1();
      do_thing2(); //not in the if!
  do_thing3();
Post reply on HN