Live data from Hacker News

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

github.com

61–70 of 71 posts

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

#61
post #57
post #52

Earlier quoted context omitted.

The problem is that in the year 2024 there are no real technical arguments against tabs. I suspect very few people saw any tab mangling system ever in their lives or even at all. We are like monkeys from the anecdote about bananas and waterhose. All the population has been replaced multiple times and waterhosse is long dead, but we are still afraid to touch the forbidden fruit.

Technical argument against tabs: they don’t play well with auto-formatters that enforce a specific line width.

Valid concern, thanks. Though I'm interested how such automatic formatting works with spaces.

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

#62

Earlier quoted context omitted.

Yeah I once saw a great talk at a functional programming conference by a Scala compiler developer, making the point that programming language semantics should be specified at the AST level, with syntax entirely up to the user's whim. I consider this to be both totally sensible and completely impractical :)

I tried using Idea for Scala 3 where indents are meaningful. I prefer size 4 tabs for indents. There were four knobs for adjusting indents and until I adjusted all of them the IDE was messing up my indents in subtle ways. If leading editors have trouble abstracting indentation from its textual representation I have zero hopes for them being able abstract even such simple element of AST as a block.

Agreed. I think it would require a lot of work on tooling to make this idea work, for fairly little gain. I still think it's an elegant idea though.

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

#63

Earlier quoted context omitted.

I feel like your conclusion is backwards based on your argument... > I also have the benefit of the compiler screaming at me if I forget a brace, pointing to the exact error including telling me when indentation is suggesting a brace is missing! What the compiler is telling you here is that the braces are superfluous, because the indentation is already describing the structure correctly. So why bother? My take is tha…

It's much easier to navigate to the end of a codeblock in the editor with vim. I can't do the same without braces. I admit this is an irrelevant argument if you're outside the vim echo chamber...but it's a pretty big echo chamber

I use vim, and yes, this is a very specific annoyance. But I just go to the beginning of the next block.

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

#64

Earlier quoted context omitted.

I don't relate to this at all . I don't understand how you refactor, in either python or C or anything else, without fixing indentation after you move code around. Yes, in C you don't have to fix the indentation in order to get it to compile and run, but that doesn't mean you don't have to fix the indentation! You can't just leave it inconsistent, that's insanity.

Of course you can leave it inconsistent! If whitespace is insignificant, you can move things around however you want and use (frequent) runs of a code formatter to clean things up for you. If whitespace is significant, it must be fixed manually line by line.

Code formatters work just fine in python. If you're running a code formatter frequently, that is not "leaving it inconsistent".

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

#65
post #59
post #12

Earlier quoted context omitted.

Not being able to nest multiline lambdas into function arguments where they are called makes you have to read a lot of code backwards.

That has nothing to do with significant indentation. Other languages with significant indentation (Nim, CoffeeScript) support multi-line function literals.

Because of Python's prominence and the divisiveness of significant indents, there is a large amount of misattribution of "whatever Python's syntax choices are" to "must be needed by significant indentation". E.g., whenever I go from Nim back to Python, I get annoyed that `t = 0; for e in x: t += e` is illegal in Python (Yes, I know `sum()` exists - it's just another easy syntax example to amplify your lambdas one.)

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

#66
post #29
post #14

Earlier quoted context omitted.

Literate programming tools that weave/tangle code and documentation don't play well with significant whitespace. Not a problem for me, but I think it's on a valid line of complaints.

I very strongly disagree. The most successful implementation of literate programming is the Jupyter Notebook, formerly called iPython Notebook. Even when you write it as raw markdown, there's no issue mixing documentation with triple-backtick code blocks. Maybe you're thinking of mixing Python with HTML? Python based HTML templating can be ugly, and the significant indentation of Python is a very poor mix for replaci…

I thought tools like jupyter and rmarkdown are better described as narratives[0] (lab notebooks and report generators) separate from and almost antagonistic to literate programming[1]. At least as I've been exposed to them, notebooks don't easily facilitate code reuse -- libraries aren't written in notebooks but could be written with literate programming tools.

[0]: https://khinsen.wordpress.com/2015/09/03/beyond-jupyter-what... [1]: http://www.literateprogramming.com/

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

#67

Earlier quoted context omitted.

I tried using Idea for Scala 3 where indents are meaningful. I prefer size 4 tabs for indents. There were four knobs for adjusting indents and until I adjusted all of them the IDE was messing up my indents in subtle ways. If leading editors have trouble abstracting indentation from its textual representation I have zero hopes for them being able abstract even such simple element of AST as a block.

Agreed. I think it would require a lot of work on tooling to make this idea work, for fairly little gain. I still think it's an elegant idea though.

I think we might get it implemented some day but it's gonna be approached from the side of visual programming. Those systems just need to relax a bit and allow some structure inside their little rectangles. Then the internal structure will be able to easily have multiple views and editors.

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

#68
post #49

Earlier quoted context omitted.

I do wish it had lambdas. That's largely mitigated by the fact you can define functions pretty much anywhere. Instead of: def my_func(): another_func(lambda: ...) you can write def my_func(): def inner(): ... another_func(inner) Sure, it's creating a function, naming it, then immediately throwing it away, but gets the job done with minimal extra boilerplate.

That's what I meant by backwards though. Especially in UI OnClick code etc., I'd rather know the context that this happens on click of whichever object it is, but instead I have to write the clicked code before the code that registers it with the object, whose name has more relevant info, and then I end up having to name an extra thing too and keep the name in sync

One trick for this is to use the decorator syntax, e.g.:

   @foo.on_click
   def foo_clicked(): ...
Of course, for this, foo.on_click needs to be a callable function rather than a property.

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

#69
post #14

Earlier quoted context omitted.

Literate programming tools that weave/tangle code and documentation don't play well with significant whitespace. Not a problem for me, but I think it's on a valid line of complaints.

Which ones? Org mode's babel works fine with it. If you do something like this (loose, not precise babel syntax): >= if 1 == 1: print('1 == 1, shocking!') >= def foo(): > It will generate properly indented code when tangled as in: def foo(): if 1 == 1 print('1 == 1, shocking!') Note that it puts in precisely two extra spaces for each line in the tangled `body`, which is the amount used in the block named `function` w…

I stand corrected! I'm guessing my own bad formatting lead me astray at some point. I tried to come up with a pathological example that'd break with noweb just now and had no luck.

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

#70

Earlier quoted context omitted.

Of course you can leave it inconsistent! If whitespace is insignificant, you can move things around however you want and use (frequent) runs of a code formatter to clean things up for you. If whitespace is significant, it must be fixed manually line by line.

Code formatters work just fine in python. If you're running a code formatter frequently, that is not "leaving it inconsistent".

If we’re talking about pasted code not having the proper indentation, that’s a major difference between languages with and without significant whitespace. A formatter can fix that in C, but not in Python. Additionally, manual fixing of the indentation is required first.
Post reply on HN