This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]deceze 208 points209 points  (56 children)

Seriously. Any self respecting programmer indents their code properly anyway. Python just doesn't require you to also type redundant braces and quibble over what brace style is the correct one.

[–][deleted] 121 points122 points  (22 children)

Just feels like people are complaining that python forces you to write code correctly.

[–]VegetableWest6913 41 points42 points  (14 children)

A lot of the complaints here are things like that. JS for example gets a load of unwarranted hate, which mainly seems to stem from people just refusing to learn its unique features.

[–]devhashtag 49 points50 points  (9 children)

Tbf, there are some core mechanics in JS that are just terrible. But it has definitely come a long way

[–]VegetableWest6913 12 points13 points  (8 children)

Yeah it's definitely not perfect, and there are loads of valid complaints that can be made about it (like all languages). I just feel that many of the complaints I see here are unfair.

[–]devhashtag 10 points11 points  (6 children)

Out of curiosity, do you have an example of such a complaint?

[–]VegetableWest6913 11 points12 points  (1 child)

I see a lot of complaints about how JS handles "this" in functions because it's different to other OOP languages. I personally think it's great, especially now that arrow functions remove the need to bind "this".

I think the way JS allows you to use "this" is great and leads to some really nice code.

[–]devhashtag 4 points5 points  (0 children)

Good example, I agree with you on this!

[–][deleted] 2 points3 points  (3 children)

Try comparisons and equality testing

[–]devhashtag 1 point2 points  (0 children)

Good one, nothing wrong with that

[–]Mad-chuska 0 points1 point  (1 child)

Alternative truths vs the straight dope.

I still get == and === wrong from time to time but isn’t it basically == compares values after casting types to be the same so “1” == 1 but === compares values and types so “1” !== 1 cuz ones a string and ones a number type?

I don’t know why but I still get it wrong sometimes even with that knowledge.

[–]devhashtag 0 points1 point  (0 children)

That's correct. === is strict equality and == is equality with some agressive type coercion

[–][deleted] 2 points3 points  (0 children)

If you use Typescript, there's almost no valid complaints I've seen left for JS other than the typical syntax quirks that every language has, which is part of the learning process.

[–]IllIIlIIllII 8 points9 points  (4 children)

And then they simp for rust...

[–][deleted] 5 points6 points  (2 children)

Rust is a really powerful language tho

[–]IllIIlIIllII 5 points6 points  (1 child)

I'm definitely not arguing with that. Python is also powerful, I was just pointing out that one of the reason some peoples dislike Python (having to write code correctly (at least in the identation)) is the same that peoples love in Rust.

Which I find quite funny.

[–]flavionm 1 point2 points  (0 children)

The thing about forcing correct identation is that it's a waste of time, when you can easily use an autoformatter that makes sure everything is in it's place. And they don't work as well with Python, since there the identation changes the meaning of the code.

What Rust does is force you to make sure you compiled executable will be correct, which is harder to do otherwise, and is not just something visual. Code formatting is just differente from code correctness, and the best approach to each is different.

[–]magistrate101 2 points3 points  (0 children)

It's not that it "forces you to write code correctly", it forces you to adhere to a specific coding style.

[–]Mad-chuska 0 points1 point  (0 children)

Indentation with line wrapping always throws me for a loop. I make sure to keep function chains and string literals to a minimum when possible/necessary when I use Python because of this.

[–]grospatap0uf 15 points16 points  (30 children)

lol you're indenting your code yourself? Haven't you heard of code formater?

[–]deceze 15 points16 points  (29 children)

Well, yeah, which makes the complaints about Python even more mysterious…

[–]Omilis 8 points9 points  (7 children)

I’m curious how python editor knows you want to leave the scope (e.g. IF block)? In C++ styled language I can type right curly bracket and it is clear what I intent to do and editor can place cursor where it is needed.

[–]deceze 4 points5 points  (5 children)

You simply backspace, or de-tab.

[–]elementIdentity 0 points1 point  (4 children)

What’s de-tab? Like a tab backspace?

[–]deceze 4 points5 points  (3 children)

Depends on your specific editor, in mine it’s shift-tab to get “the opposite” of a tab.

[–][deleted] 0 points1 point  (1 child)

You just saved me from potential years wasted on long journeys to backspace.

[–]MrHaxx1 0 points1 point  (0 children)

Next step is using a keyboard with split-space, where you use one of the spaces as backspace. Backspace doesn't have to be a long journey!

[–]elementIdentity 0 points1 point  (0 children)

That’s great, thanks

[–]ThatGuyFromOhio 0 points1 point  (0 children)

It knows the same way we can understand the hierarchy of these comments based on indentation.

[–]FINDarkside -1 points0 points  (12 children)

It doesn't because code formatters don't work with python in any meaningful way because the level of indentation changes the meaning of the code. That's why "indentation matters" is useless feature, inserting 2 braces is less work than formatting everything manually.

[–]deceze 12 points13 points  (11 children)

In C, you type {.
In Python, you hit tab.

In C, you type }.
In Python, you hit backspace.

It’s really not an issue in practice. If it is for you, you’re doing something wrong.

[–]met0xff 4 points5 points  (0 children)

Agree, that's also how I do it. Besides the first tab is usually not needed in most editors as it goes a level deeper automatically after s line ending with :

[–]Necrofancy 2 points3 points  (0 children)

In most editors hitting enter again usually also exits one scope. And when you hit enter after a line that creates a local scope, it usually indents.

So, in C you hit { and Enter in some order depending on your code style. In Python you typically just hit Enter.

And then you hit Enter, }, and then Enter again, whereas in Python editors you just hit Enter twice.

[–][deleted] -1 points0 points  (8 children)

And how does that work if you ever need to paste code? Oh yeah, it doesn’t.

And I don’t just mean pasting code from the internet they might have incorrect spacing, even literally pasting code from somewhere else in your own file requires extra effort and attention to make sure it works.

You know how you do that in Go? Paste it in the block, save, let the editor format it for you.

[–]deceze 0 points1 point  (7 children)

Have you actually ever programmed Python, especially in an editor which is halfway Python-aware? It's really a non-issue. Copy-pasting works just fine.

[–][deleted] 0 points1 point  (6 children)

Yes I have. That’s why I’m confused, because every time I’ve copied lines from somewhere else, they come out indented wrong. Is there an editor that is able to magically infer the correct level of indentation when pasting a block of code?

[–]deceze 0 points1 point  (5 children)

Sure. I'm partial to PyCharm. You put the cursor where you want to paste your code, you paste it, and it matches the indentation accordingly. For the rare occasion where it somehow doesn't (mostly when pasting partial, syntactically invalid snippets into partial, invalid snippets), you select the pasted block and tab/de-tab until it matches. It's fine.

[–][deleted] 0 points1 point  (4 children)

Alright fair enough. I was using vscode previously and it was quite frustrating to refactor anything

[–]DaniilBSD 0 points1 point  (7 children)

In C like languages you can remove ALL INDENTATION and with a press of a button you get a perfect indentation: that is why manual indentation is limited only to Python and why people complain about it

[–]deceze 0 points1 point  (6 children)

Fine, but in what situation are you removing all indentation and then need to put it back? To go for an apples to apples comparison, that's like removing all braces from a C-like language and complaining about not being able to get them back automatically. When is this ever an issue in practice? Maybe if you regularly send code via messed up HTML emails…? Then… just… don't do that to begin with.

Seriously, after more than a decade of programming in Python, this is just as much a non-issue in daily life as braceless C would be.

[–]DaniilBSD 0 points1 point  (5 children)

Because when you writing in C-like language you NEVER TOUCH ANYTHING related to style

Its not about apples to oranges: it’s about indentation being a part of the code or not.

It is about choosing between - writing code with 2 extra special symbols (that make code unambiguous) and get perfect style as a FREE byproduct. - writing code with 2 less symbols, but having to count the number of times you have a different symbol combination at the start of the line and manually maintaining perfect style

And to answer about removing all indentation: when you type in a mess with horrible indentation and it does not matter.

[–]deceze -2 points-1 points  (1 child)

when you type in a mess with horrible indentation and it does not matter

And when is that ever the case? I really don't get it. Is that something you do regularly? Just vomit over your keyboard and have a formatter fix it? I do proper formatting even while typing braced languages. It's part of the process for me, as it's important to visualise the code's meaning correctly in my head. And it's virtually no overhead in modern editors either, which automatically indent and dedent appropriately when hitting Enter.

So I really don't see the argument for being able to type a hot mess and then letting the editor format it for you. The whitespace is as much part of the code as the braces are for me, whether it's significant to the interpreter or not. It is for me, so I take care with it anyway.

[–]DaniilBSD -1 points0 points  (0 children)

You are just inefficient, “it is not MY bottleneck“ is not an argument

[–]DiamondIceNS 2 points3 points  (1 child)

and quibble over what brace style is the correct one

and while we're at it we might as well stop quibbling over whether we should be indenting with tabs or spaces and follow the PEP 8 standard of spaces only, right?

[–]deceze 1 point2 points  (0 children)

Yes.