Live data from Hacker News

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

github.com

71–78 of 78 posts

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

#72
post #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.

Yeah the challenge is a lot of fun I have to admit that.

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

#73
Pretty nice. I love awk, but it has serious deficiencies like the lack of datetime handling and Ruby/Perl was always too fringe.

I would like to see a pip package for this sometime but also maybe some consideration for integration with other previous similar attempts or other similar projects which I just learned about today.

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

#74
post #57

Face it - Python just ain't fit for one-liners. Give Perl and Ruby some credit as they were designed for conciseness and the command-line. Python may dominate data science, AI and ML but it's deficiencies bleed through when you try to compose something elegant and concise.

I agree about Perl; haven't done a lot of one liners with Ruby when I was using the language. Perl was made to be really compact to the detriment of being hard to read. I think Python strikes a nice balance, and you can compress it to a point. In discussions like these I always like to bring out my one-liner k-nearest neighbor classifier [1]! Explanation here [2] (better on a desktop).

[1] https://twitter.com/AbhishekGhose/status/500564420733304833?...

[2] http://quipu-strands.blogspot.com/2014/08/knn-classifier-in-...

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

#75
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?

Aye, in general legibility >> compactness. Apart from the intellectual exercise (fun; !work), one-liners imo come in handy in:

>some_complex_tool | 'my one liner' | some_other_complex_tool > result.txt

Not putting the one-liner logic into a separate script avoids an additional lookup for someone learning what is going on, along with any deployment/path/.. dependencies to that separate script.

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

#76

I 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…

You're braver than I -- whenever a shell/terminal indicates to me it expects multiline now, I press, in that order, Ctrl+C, Ctrl+D, Ctrl+Z, and Ctrl+Alt+Del.

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

#77
post #55

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

It forces you to write "good" code. 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.

Nowadays tooling will enforce this "goodness" for most languages. Whitespace blocks were a pain when people mixed tabs and spaces.
Post reply on HN