Earlier quoted context omitted.
We tried that for a while, yeah? https://coffeescript.org/
And I loved it. So much more convenient than standard JavaScript.
Show HN: Making Python one-liner-fit with the new pwk (Python With Kurly braces)
51–60 of 78 posts
Re: Show HN: Making Python one-liner-fit with the new pwk (Python With Kurly braces)
#52It's a shame Python doesn't natively support easy invocation from command line. It really shoots down a whole class of applications where bash is getting used but Python would be so much better. I've ended up using Groovy for this level of scripting, and it works really well.
It doesn't? If I write this into a file (/tmp/test.py): #!/usr/bin/env python print("Hello, world!") and mark it as executable (chmod +x /tmp/test.py), I can just execute it as /tmp/test.py like I would do with any bash file. If you mean invocation as "execute a command that I'm passing", 'python -c' does exactly that. Even as a complete shell it works including changing directories and using standard python to do fi…
I think that's what xonsh was made for? :)
Re: Show HN: Making Python one-liner-fit with the new pwk (Python With Kurly braces)
#53You 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 extend Exception slip through.)You could probably also make a context manager which takes a function/lambda to define how to handle exceptions etc.
Re: Show HN: Making Python one-liner-fit with the new pwk (Python With Kurly braces)
#54Earlier quoted context omitted.
Suppose you didn't have syntax highlighting. Would the braces be more distracting then?
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…
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 various ways) and I keep wondering why that doesn't describe my own experience as a daily user of Python. Maybe a lot of it is that I tend to avoid more than a couple of levels of indentation like the plague, and therefore it's rare for there to be any confusion about where a particular line of code would "belong".
Re: Show HN: Making Python one-liner-fit with the new pwk (Python With Kurly braces)
#55Can someone help me understand the rationale behind semantic whitespace as a replacement for explicit delimiters? Is it purely aesthetic?
I think it's Python's only real strength. The language is ugly, the interpreter is a genuinely deficient way of making software ("Why use a compiler when you can just write thousands of unit tests to check for syntax errors!?"), and the mechanisms for abstraction are fairly weak - even after all that, n00b Python code is fairly readable.
Re: Show HN: Making Python one-liner-fit with the new pwk (Python With Kurly braces)
#56Earlier 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.
But you're absolutely right, it made my code really hard to reason about. I don't know why this is the case but it was always harder to read my own CS than raw JS. I found myself putting blocks into the CS2JS just to read inner workings.
While it made me less verbose and short-term faster, longer term it made me slower.
Re: Show HN: Making Python one-liner-fit with the new pwk (Python With Kurly braces)
#57Re: Show HN: Making Python one-liner-fit with the new pwk (Python With Kurly braces)
#58I tried a few (not all) of the examples with plain old Python (granted, these are multi-liners, not one-liners, but I think they're easier to read). I'm not sure I see the advantange of curly braces. # --- Example 1 # pwk pwk 'if "braces"=="bad": { print("Be gone!"); exit(99) } else: { print("Howdy!") }' # vs # python python -c 'if "braces"=="bad": print("Be gone!"); exit(99) else: print("Howdy!")' # --- Example 2 pw…
Re: Show HN: Making Python one-liner-fit with the new pwk (Python With Kurly braces)
#59Can someone help me understand the rationale behind semantic whitespace as a replacement for explicit delimiters? Is it purely aesthetic?
You can never have a "goto fail" kind of bug.
Re: Show HN: Making Python one-liner-fit with the new pwk (Python With Kurly braces)
#60Can someone help me understand the rationale behind semantic whitespace as a replacement for explicit delimiters? Is it purely aesthetic?
It's easier to follow a program's execution when you can be sure the whitespace will never lie to you. You can never have a "goto fail" kind of bug.