News for hackers. Stuff that matters.
Re:“I'm basically giving myself a permanent vacation from be... by fit2rule on Thursday July 12, 2018 @03:08PM (#17517645)
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.

Re:“I'm basically giving myself a permanent vacation from be... by patejam on Thursday July 12, 2018 @03:38PM (#17517931)
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.

Re:“I'm basically giving myself a permanent vacation from be... by rabidrat on Thursday July 12, 2018 @03:46PM (#17518007)
It's also basically impossible to cut-and-paste code from a web forum. Was that "else" from the inner or the outer "if"?
Re:“I'm basically giving myself a permanent vacation from be... by gerdesj on Thursday July 12, 2018 @04:11PM (#17518208)
That could be considered a feature. At least you have to read what you have copied and pasted.
Re:“I'm basically giving myself a permanent vacation from be... by rabidrat on Thursday July 12, 2018 @04:34PM (#17518372)
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.

Re:“I'm basically giving myself a permanent vacation from be... by gerdesj on Thursday July 12, 2018 @08:02PM (#17519602)
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.

Re:“I'm basically giving myself a permanent vacation from be... by Retra on Thursday July 12, 2018 @11:47PM (#17520400)
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.

Re:“I'm basically giving myself a permanent vacation from be... by thedirt0115 on Friday July 13, 2018 @09:31PM (#17528247)
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.
Re:“I'm basically giving myself a permanent vacation from be... by bsg75 on Sunday July 15, 2018 @09:43AM (#17535193)
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.
Re:“I'm basically giving myself a permanent vacation from be... by int_19h on Thursday July 12, 2018 @08:44PM (#17519764)
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).
Re:“I'm basically giving myself a permanent vacation from be... by lamontcg on Thursday July 12, 2018 @04:22PM (#17518298)
Also makes auto formatting very difficult when whitespace indentation doesn't just affect readability but syntax.
Re:“I'm basically giving myself a permanent vacation from be... by sametmax on Thursday July 12, 2018 @05:09PM (#17518642)
Use black. It just works.
Re:“I'm basically giving myself a permanent vacation from be... by patejam on Thursday July 12, 2018 @05:47PM (#17518902)
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.
Re:“I'm basically giving myself a permanent vacation from be... by acdha on Thursday July 12, 2018 @05:50PM (#17518922)
What editor are you using? This just works in VSCode, vim, TextMate, etc.
Re:“I'm basically giving myself a permanent vacation from be... by Doxin on Friday July 13, 2018 @04:15AM (#17521294)
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.
Re:“I'm basically giving myself a permanent vacation from be... by LBarret on Monday July 16, 2018 @11:26AM (#17542022)
yes, but that's so minor compared to the gain of a more readable syntax... really an edge case.
Re:“I'm basically giving myself a permanent vacation from be... by gsich on Friday July 13, 2018 @01:26AM (#17520705)
tabs would be much better, but unfortunately pep8 dictates spaces.
Re:“I'm basically giving myself a permanent vacation from be... by zinckiwi on Friday July 13, 2018 @03:18AM (#17521066)
For submissions to the language. For your own stuff, knock yourself out and tab away.
Re:“I'm basically giving myself a permanent vacation from be... by lisper on Thursday July 12, 2018 @06:31PM (#17519165)
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.
Re:“I'm basically giving myself a permanent vacation from be... by rrmm on Friday July 13, 2018 @12:56AM (#17520610)
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.
Re:“I'm basically giving myself a permanent vacation from be... by cutler on Thursday July 12, 2018 @09:04PM (#17519828)
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.
Re:“I'm basically giving myself a permanent vacation from be... by armitron on Monday July 16, 2018 @04:07AM (#17539554)
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.

Re:“I'm basically giving myself a permanent vacation from be... by kazinator on Monday July 16, 2018 @10:52AM (#17541719)
Most of the examples of Python program design that are held up as "Pythonic" can be described as Fortran with dynamic typing.
Re:“I'm basically giving myself a permanent vacation from be... by lispm on Monday July 16, 2018 @05:37AM (#17539891)
Python reminds me more of an object-oriented BASIC. Mostly imperative control flow. Lots of assignments. Lots of state manipulation.
Re:“I'm basically giving myself a permanent vacation from be... by kazinator on Monday July 16, 2018 @11:01AM (#17541802)
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

Re:“I'm basically giving myself a permanent vacation from be... by enriquto on Friday July 13, 2018 @05:12AM (#17521516)
> 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.

Re:“I'm basically giving myself a permanent vacation from be... by sebcat on Friday July 13, 2018 @06:08AM (#17521701)
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.

Re:“I'm basically giving myself a permanent vacation from be... by doc_gunthrop on Friday July 13, 2018 @12:03PM (#17524098)

    x = lambda x: x*x
It doesn't look that bad in comparison...
Re:“I'm basically giving myself a permanent vacation from be... by aldanor on Friday July 13, 2018 @07:47AM (#17522056)
Your example is already doable without lambdas:

    def f(x): return x * x
Re:“I'm basically giving myself a permanent vacation from be... by sebcat on Friday July 13, 2018 @08:22AM (#17522270)
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.
Re:“I'm basically giving myself a permanent vacation from be... by klibertp on Friday July 13, 2018 @11:12AM (#17523589)
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.
Re:“I'm basically giving myself a permanent vacation from be... by enriquto on Friday July 13, 2018 @09:04AM (#17522565)
it looks a bit perverse to use the same name for the function and for its argument, but maybe it's just me
Re:“I'm basically giving myself a permanent vacation from be... by sebcat on Friday July 13, 2018 @10:11AM (#17523106)
Lexical scope, I like it
Re:“I'm basically giving myself a permanent vacation from be... by alexeiz on Friday July 13, 2018 @11:26AM (#17523706)
You can try moonscript. It compiles to Lua and uses significant indentation.
Re:“I'm basically giving myself a permanent vacation from be... by perfunctory on Friday July 13, 2018 @03:36AM (#17521140)
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.
Re:“I'm basically giving myself a permanent vacation from be... by elcritch on Friday July 13, 2018 @04:49AM (#17521426)
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.

Re:“I'm basically giving myself a permanent vacation from be... by codezero on Sunday July 15, 2018 @12:34PM (#17535913)
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 :)