Live data from Hacker News

Show HN: Making Python one-liner-fit with the new pwk (Python With Kurly braces)

github.com

61–70 of 78 posts

Re: Show HN: Making Python one-liner-fit with the new pwk (Python With Kurly braces)

#61
post #21

Earlier quoted context omitted.

Suppose you didn't have syntax highlighting. Would the braces be more distracting then?

> Suppose you didn't have syntax highlighting. That might be a bit TOO contrived, at least for me. I could see this coming up for someone working with jurassic hardware not under their control though. Anyway, to play along. I think curly braces help tell what is happening in long source files with deep nesting. But also you could just render whitespace characters as something visible to count them to judge indentatio…

> jurassic hardware

Like the late 1980s, when Guido was creating Python?

Re: Show HN: Making Python one-liner-fit with the new pwk (Python With Kurly braces)

#62
post #21

Earlier quoted context omitted.

Suppose you didn't have syntax highlighting. Would the braces be more distracting then?

No, I think braces are even more useful when you don't have syntax highlighting.

Interesting. I find them distracting. I thought the cruft might be more distracting when it doesn't fade into the background via syntax highlighting.

Re: Show HN: Making Python one-liner-fit with the new pwk (Python With Kurly braces)

#63
post #53

> (To the best of my knowledge, there is as of 2020 no purely pythonic way to write one-lined try-blocks.) You can do this using contexlib. For example the following in pwk: try: { print(os.listdir("/"+s.strip())) } except: pass Can be written in pure Python as: with contextlib.suppress(Exception): print(os.listdir("/"+s.strip())) (Assuming contextlib is imported, and you're okay with letting things which don't exten…

`contextlib.suppress(BaseException)` is possible if you really want to (although both this and the bare except clause should be avoided anyway).

Re: Show HN: Making Python one-liner-fit with the new pwk (Python With Kurly braces)

#65
post #33

Earlier quoted context omitted.

And I loved it. So much more convenient than standard JavaScript.

CoffeeScript code bases are the scariest code bases on the planet, the nightmares. To me CoffeeScript inherited all the inconsistencies of JavaScript, then made the syntax inconsistent as well. It least it had optional chaining.

JavaScript has optional chaining now! https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...

Re: Show HN: Making Python one-liner-fit with the new pwk (Python With Kurly braces)

#66
post #64

I really don't understand the love of one liners. Yes it's cool to see how much can be done in one line but it's so much harder to read. Isn't legibility far better than compactness?

It depends on the context. I like one-liners because it's much easier to iterate over a command line and building them is a bit of a personal challenge since it's not worth writing a script or saving to a file.

I don't know about most people, but interactively I use short flags and when writing Bash scripts I try hard to use long flags and will often break things up specifically for clarity.

Re: Show HN: Making Python one-liner-fit with the new pwk (Python With Kurly braces)

#67
post #41

Can someone help me understand the rationale behind semantic whitespace as a replacement for explicit delimiters? Is it purely aesthetic?

If you haven't read Landin's "The Next 700 Programming Languages", you should. I don't know if it's still outside the ACM paywall, but you'll find it in a web search if not. It introduced the offside rule -- not actually what Python has -- inspired by mathematical notation. Note "it can be mixed freely with [...] punctuation" (e.g. Haskell). The paper talks about "physical representations", relevant to syntax highlig…

I just finished reading it the other day: https://www.cs.cmu.edu/~crary/819-f09/Landin66.pdf I got there from Erik Meijer's excellent "Confessions of a Used Programming Language Salesman: Getting the Masses Hooked on Haskell": http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.72....

Re: Show HN: Making Python one-liner-fit with the new pwk (Python With Kurly braces)

#68
post #64

I really don't understand the love of one liners. Yes it's cool to see how much can be done in one line but it's so much harder to read. Isn't legibility far better than compactness?

Only advantage I can think of is that you can just paste it in a shell prompt, if you're not comfortable with making a script, changing permissions, etc.

Re: Show HN: Making Python one-liner-fit with the new pwk (Python With Kurly braces)

#70

Earlier quoted context omitted.

No they'd be even more useful. I say that from experience: when I was first learning to program I found C much easier than python for this exact reason, and I was not using syntax highlighting. That might be because I was much more prone to nesting back then. These days I get annoyed when I have two levels of indentation inside a function and treat three as a reminder to refactor. But when I started programming I'd b…

this is interesting, both because I've had a somewhat similar experience (my code is now much less indented than it was 10 years ago), and also because it does seem to hold some explanatory power for why some people seem to react so violently to Python's semantic whitespace. I hear the argument quite frequently that semantic whitespace makes it hard to move code around (or that it causes code to get messed up in vari…

Maybe they are using some arcane programming tool from the 80s...

'{}' has the advantage that it expresses structure in a single line - copy a block of code from one place to another and your editor can throw it almost anywhere and the structure is preserved...

Modern day text editors all preserve indent wonderfully and can indent/outdent as a matter of course...but to some troll insisting on using ed or notepad or Microsoft Word I can see the difficulty.

Post reply on HN