Most active commenters
  • sebcat(3)

←back to thread

2024 points randlet | 39 comments | | HN request time: 2.686s | source | bottom
1. theandrewbailey ◴[] No.17516370[source]
Python was my first programming language, ~15 years ago. The bracket- and semicolon-free syntax is beautiful and approachable to this day. Python is my go-to for writing data format conversion scripts. I wrote a random sentence generator in Python 10 years ago that gave me and my friends hours of entertainment.

Thanks, Guido, for the good times!

replies(1): >>17517645 #
2. fit2rule ◴[] No.17517645[source]
I can never get into Python and end up with as much passion as you. For me, its a very powerful and useful language - no doubt about it.

But the aesthetics of a whitespace language just don't jive with my 30+ years of experience writing code. No matter how many times I try over the past few decades, I just can't get passionate about writing Python code. I know its power, and I totally grok its value to our industry - but for me, Lua is just far more elegant, even if it doesn't ship with all of Pythons' goosebridles. Lua is my go-to scripting language; I only ever use Python if I have to - i.e. its enforced on me by others.

I really do try to get over this personal handicap, often enough, but the moment I have to start thinking about indentation I just lose all the passion and it starts feeling like a drag. What a dilemma, because I know it has been used for many, many great things .. I just wish I could get over my aversion to white-space'ing things all the time. I've tried editor after editor (well, expect the Python-specific things), but it just doesn't click.

Ah well.

replies(6): >>17517931 #>>17519165 #>>17519828 #>>17521140 #>>17521516 #>>17535913 #
3. patejam ◴[] No.17517931[source]
The indentation should be almost the same as any other language. Unless you have an aversion to consistent code-style.

Python whitespace was only annoying for me years ago when it still had trouble handling tabs and spaces in the same file, and you would run into literally invisible bugs. I haven't run into that in a long time, though.

replies(2): >>17518007 #>>17520705 #
4. rabidrat ◴[] No.17518007{3}[source]
It's also basically impossible to cut-and-paste code from a web forum. Was that "else" from the inner or the outer "if"?
replies(7): >>17518208 #>>17518298 #>>17518902 #>>17518922 #>>17519764 #>>17521294 #>>17542022 #
5. gerdesj ◴[] No.17518208{4}[source]
That could be considered a feature. At least you have to read what you have copied and pasted.
replies(1): >>17518372 #
6. lamontcg ◴[] No.17518298{4}[source]
Also makes auto formatting very difficult when whitespace indentation doesn't just affect readability but syntax.
replies(1): >>17518642 #
7. rabidrat ◴[] No.17518372{5}[source]
That's cute but I hope no one reading this thinks you are being serious. If they do, to wit:

So many webforums strip leading indents from code. It's not like it looks right on the forum, and then gets inserted into your editor wrong. It's often not right on the source side either. So if you're trying to learn an algorithm from the Python code, you're SOL. This has happened to me.

replies(5): >>17519602 #>>17520400 #>>17521870 #>>17528247 #>>17535193 #
8. sametmax ◴[] No.17518642{5}[source]
Use black. It just works.
9. patejam ◴[] No.17518902{4}[source]
I have problems in a lot of languages copy-pasting code (why are the line numbers being copied!?), but yes this is another problem for this specific language.
10. acdha ◴[] No.17518922{4}[source]
What editor are you using? This just works in VSCode, vim, TextMate, etc.
11. lisper ◴[] No.17519165[source]
Python has open-braces in the form of colons. If you use emacs, you can use the PASS statement as a close-brace and everything will auto-indent properly. Python purists have conniptions when they see this programming style, but I've used it for nearly 20 years and it works for me.
replies(1): >>17520610 #
12. gerdesj ◴[] No.17519602{6}[source]
It isn't cute at all and I am quite serious. It is an accident that Python syntax pitted against sufficiently unsophisticated code displayers causes copy n paste breakage.

However, that breakage does mean that you have to at least read the code a bit. You either get to avoid a potential security flaw or gain a deeper understanding of an algorithm.

Fixing syntax does not break your ability to learn an algorithm but it will get you closer to its description.

With Python you are generally SIL not SOL.

13. int_19h ◴[] No.17519764{4}[source]
How so? If the code was properly indented on the forum, it'll still be properly indented when you paste it. The only thing you'll need to do is to make sure that indentation of the entire pasted block is consistent with whatever's around it... but pretty much any editor these days, at least the ones meant for code, let you easily adjust indentation of an arbitrary selection (just highlight and Tab or Shift-Tab as needed).
14. cutler ◴[] No.17519828[source]
I found Python's indentation style more appealing after working with Clojure for a while. Python is a bit like lisp without the parentheses. In fact you can Clojurify Python with Hy (http://hylang.org) which solves both the indentation problem and the crippled lambdas problem.
replies(1): >>17539554 #
15. Retra ◴[] No.17520400{6}[source]
You're not SOL. You just have to retype or reformat the code. Given that you're trying to learn, you should have started with that step anyhow.

I've been writing Python for years and never had this problem.

16. rrmm ◴[] No.17520610{3}[source]
I usually close blocks with "#end <whatever>". It doesn't automatically format, but it at least makes it clear to me should the formatting get messed up. I keep thinking about changing the emacs mode to respect this, but it never causes enough of an issue to make me do it.
17. gsich ◴[] No.17520705{3}[source]
tabs would be much better, but unfortunately pep8 dictates spaces.
replies(1): >>17521066 #
18. zinckiwi ◴[] No.17521066{4}[source]
For submissions to the language. For your own stuff, knock yourself out and tab away.
19. perfunctory ◴[] No.17521140[source]
I used to have a similar aversion to significant whitespace having learned in compiler classes that space should be insignificant. Over time I learned to appreciate the significant indentation though and now I want a C frontend with similar syntax.
replies(1): >>17521426 #
20. Doxin ◴[] No.17521294{4}[source]
Make sure you copy the whitespace on the first line as well and then it's just a case of indent/dedenting the whole section of pasted code to match.
21. elcritch ◴[] No.17521426{3}[source]
Try Nim, pretty much a Python-esque front-end for C.

Personally I really miss defining for-loop index cars in the for-loop syntax.

22. enriquto ◴[] No.17521516[source]
> but for me, Lua is just far more elegant,

It's curious... Lua is my favorite language due to its elegance, but I would love it even more if it used significant indentation (using tabs, of course) instead of "end" blocks.

replies(2): >>17521701 #>>17523706 #
23. sebcat ◴[] No.17521701{3}[source]
OTOH, I would love Python even more if I could do:

    x = function(x) return x*x end
and not use those awful Python lambdas...

Not that it really matters though, bridges still get built.

replies(3): >>17522056 #>>17522565 #>>17524098 #
24. ◴[] No.17521870{6}[source]
25. aldanor ◴[] No.17522056{4}[source]
Your example is already doable without lambdas:

    def f(x): return x * x
replies(1): >>17522270 #
26. sebcat ◴[] No.17522270{5}[source]
To clarify: the point I was trying to make was that the explicit 'end' in Lua allows for closures that are more nice (subjective) than Python lambdas. Something both JS and Lua got right, but with which Python ended up with a much more limited syntax.
replies(1): >>17523589 #
27. enriquto ◴[] No.17522565{4}[source]
it looks a bit perverse to use the same name for the function and for its argument, but maybe it's just me
replies(1): >>17523106 #
28. sebcat ◴[] No.17523106{5}[source]
Lexical scope, I like it
29. klibertp ◴[] No.17523589{6}[source]
The lambda syntax is not what makes it less nice - it's the fact that they are limited to a single expression. Being indentation-based has nothing to do with that restriction: Nim manages to use indents and to have multiline lambdas at the same time.
30. alexeiz ◴[] No.17523706{3}[source]
You can try moonscript. It compiles to Lua and uses significant indentation.
31. doc_gunthrop ◴[] No.17524098{4}[source]

    x = lambda x: x*x
It doesn't look that bad in comparison...
32. thedirt0115 ◴[] No.17528247{6}[source]
I find this hard to believe. Searching for python copy paste indentation, the first page of results has everything from how to turn it on for various editors to how to turn it OFF for various editors (implying it's built-in to some). If you just gave up 5 seconds after pasting because it didn't look right or work immediately and you didn't even try looking for help... I dunno what to say.
33. bsg75 ◴[] No.17535193{6}[source]
I would suggest this is more of a forum software problem than a Python problem. Stripping indentation damages the readability of code in any language.
34. codezero ◴[] No.17535913[source]
This is way off topic, but I’ve never seen the word goosebridle - googling it comes up with a phrase a wigwam for a goose’s bridle - and there its usage is meant as a rejoinder meaning “none of your business” - I’m curious how it ended up as a word to mean - I’m guessing - flashy features (jeez now I am sure there is a more common word for that) - is this a local thing, or is the etymology on the web wrong, what I’m saying is I’m curious how your usage of the word came about :)
35. armitron ◴[] No.17539554{3}[source]
Python is nothing like Lisp, where did you come up with that?

Three things that are key in Lisp: Symbols, environments and lexical scope. Python has none of these.

replies(2): >>17539891 #>>17541719 #
36. lispm ◴[] No.17539891{4}[source]
Python reminds me more of an object-oriented BASIC. Mostly imperative control flow. Lots of assignments. Lots of state manipulation.
replies(1): >>17541802 #
37. kazinator ◴[] No.17541719{4}[source]
Most of the examples of Python program design that are held up as "Pythonic" can be described as Fortran with dynamic typing.
38. kazinator ◴[] No.17541802{5}[source]
Perhaps the biggest computer science cluster-fuck in Python is that there is no syntactic distinction between instantiating/binding a variable and assigning to it.

Python 3 makes it worse by adding some declarative stupidies nonlocal and global:

https://en.wikipedia.org/wiki/Variable_shadowing#Python

39. LBarret ◴[] No.17542022{4}[source]
yes, but that's so minor compared to the gain of a more readable syntax... really an edge case.