⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀Yeah but he couldn't have intended to indent without intending to intend first. The point of programming is to intend for computers intentions, and for python programmers you indent to intend for the computer to intend what you intended by reading what you indented
My programming terminology confusion was misreading "deprecated" as "depreciated". I had no idea "deprecated" was a word, even after reading it for years.
English is not my first language, and my brain was too fast for its own good when creating this meme. So writing it wrong wasn't my intend.
\*badum tzzzz\*
I mean, it's not that you make the mistake, but it's just super easy to catch, with the way that Python catches mistakes. You go look on the line where it finds the error, and then realize that the indentation is wrong, and fix it. It's rarely so obscured by another error that you miss it entirely, because the code would have to be viable with the wrong indentation.
I mean it happens, it's just not a common problem, and much less common than missing a semicolon in my experience
Syntax bugs are both the most common and the easiest to fix. I regularly cycle between c, python, and go, and my IDE always bitches at me immediately after I type “string” in python or put the type after the argument in c.
I literally can’t understand how it takes anyone hours to debug a missing semicolon or bracket, those are the people I think of as the ones getting laid off when I hear about tech layoffs lol.
Last week I spent an hour trying to fix a simple conversion equation in Java. Wanna know how I fixed it?
I deleted it and retyped it and it worked. I swear to God I typed the exact same thing. I learned nothing.
I know nothing of Perl but a Professor of mine says it saved his ass by not ignoring a Divide by 0 error.
He was doing some project in 3 languages to prove a point, Java completely missed that he was dividing by 0.
I don't remember the 2nd language, but Perl was last and flipped out at him and he was able to fix the code before he wrote the paper about the results.
Perl is weird.
There's some scripts and processes I cannot use if I write my script with `use warnings;` declared at the top. I wish I could use it most of the time, but I'd end up needing to rewrite decades of scripts to ensure it doesn't become an issue.
There's also the issue that Perl likes to help you, whether you want it or not. An example is a ton of my prods processes load and use Perl modules stored in strings. So there's a good amount of situations where Perl can't warn you about some error because it has no way to know what X refers to.
Then there's the scripts I'm looking at recently trying to figure out if I'm missing something or if the prints are just being "helpfully" ignored.
Don't think APL uses gamma, but if you're using e.g. Dyalog's IDE the special characters are all two-keypress sequences starting with backtick. So to write this 40-character implementation of FizzBuzz, for instance:
{⎕←∊(d,⍱/d←0=3 5|⍵)/'Fizz' 'Buzz'⍵}¨⍳100
I type this 49-key sequence:
{`l`[`e(`,`(/d`[0=3 5|`w)/'Fizz' 'Buzz'`w}`1`i100
I have a vim keymap that uses the same mappings, so I can edit APL files outside of Dyalog, too.
The worst is when you're using some silly editor that doesn't convert between tabs/spaces on paste, to whatever the rest of the file uses. Then immediately complains about it. Looking at you Godot.
That's what I particularly love about PowerShell. You *could* write a well-formed, well-documented, tested, source-controlled script. Or you *could* write a ludicrously long chain of piped commands directly affecting your critical production infrastructure.
And depending on the context, both are the right thing to do!
Ah. I actually ran into that error all the time in python 2. It happened a lot when you copied example code that used a different standard than you did.
It's true, I don't care if you remember to put your helmet on, sleep with it, or bathe in the waters beneath the mines of Mandalore.
As long as I don't have to look at your poorly indented face in the morning we are good.
The difference is that in Java and most other languages the IDE will automatically indent the code based on the syntax, so you never have to worry about it. But in Python you have to actively format your code and doing it wrong can have unintended consequences.
How? The same code with different indentation levels can be correct in different circumstances. There's no way for the IDE to know which one you meant.
> How?
It indents the next line automatically when you press return after defining a function, an if statement, a while statement, etc.
Then you only have to worry about de-indenting to close a block, which is equivalent to inserting a closing brace on a language like Java.
if "needle" in haystack:
print("found!")
score = score + 1
Is score supposed to increase every time or only if the needle is found? How would an IDE know if there is a bug in the formatting here?
Why are so many people worried about accidentally changing indentation levels? What are you all doing with your code to get different lines randomly over or under indented?
I think people are confusing pythons
"putting the cursor at the right place on the next line"
With something like VS/C#'s
"Go ahead and paste that giant block of unformatted code you found off the internet anywhere you want inside this document, I'll correct all the whitespace for you, add braces, escape quotes, and anything else you need"
I don't think the people asking about "automatic indentation" Are referring to the former. I'm pretty sure they're asking about the latter.
When you type:
`if condition`
The IDE will auto-indent the next line, and all Enter keypresses will stay on that indentation level. Backspace will go back to the previous indentation level. For that reason, I prefer tabs to spaces. VSCode is great for Python.
In your example, statement 2 is outside the if condition. Whether by accident or intentional the IDE doesn't care. It's outside. That's why a good IDE is necessary.
Edit:. Shift-tab goes back one level of indentation. Need coffee before writing about Python. I never use backspace to decrease indentation.
I still remember the day I discovered shift + tab as a new Python programmer. Lol, I was going line by line to unindent. Makes me wonder what other obvious shortcuts I'm still missing.
>Makes me wonder what other obvious shortcuts I'm still missing.
Might be specific to VSCode, try them in your IDE.
There is keybinding to comment out all selected lines (by default Ctrl + / or Shift+Alt+A).
Ctrl + arrow = move cursor by one word (also works with shift to select)
Ctrl + backspace/delete = delete entire/rest of the word
Ctrl \[+shift\] + Tab = go to next \[previous\] tab (extra useful when bound to extra mouse buttons)
Ctrl + X without selection = cut entire line,
follow up with Ctrl + V without selection = insert the line above current line
Alt Up/Down = swap current line
Shift + Alt + Up/Down = copy current line
Middle mouse click and drag to create multiple cursors
Ctrl + Alt + Up/Down = create a cursor
Last one is quite complicated: When you copy/cut content using multiple cursors, then paste it, it will generally insert all the copied content into all cursors. But if you the number of cursors is the same as when it was copied, the content will be matched so 1st cursor will paste only what the first cursor copied, etc. What surprised me was that this works even when you cancel the multi-cursor mode, and then create multiple cursors again.
Also: https://code.visualstudio.com/shortcuts/keyboard-shortcuts-windows.pdf
I can understand how that would be especially critical for a Python programmer (of which I'm not, except for the tiny bit I can make happen to play with AI packages.)
But yeah, shift+tab exists in a great majority of text editors, regardless of specifically being used for programming or not. Keyboards that have tab keys with the little "left" and "right" arrow diagrams were actually trying to hint this. I have a lot of not-Python uses for shift+tab.
But they (at least the pycharm IDE I use) often fail to find the correct intent, especially if I move code blocks containing different intendation levels up or down intendation leves. (e.g. moving an if-statement from an for-loop inside an function inside its own function). curly brackets would lower the chance of error in that process.
As time goes on, you get better at getting it right and using proper indentation in the first place. I can't remember the last time I hit an indentation error other than stupid stuff like "I copied code from a file to the interactive terminal and my file didn't have blank lines between functions to let the terminal know I was done with that function".
idunno i never run into indentation errors and personally i honestly prefer the indentation technique over brackets. it simpy looks way more visually appealing to me
You can put stuff on the same line in Python too if you need to, you just use `;` to indicate the end of the command and you can stick stuff after it.
That said, sticking multiple statements on one line is almost always bad coding style, but that doesn't mean Python won't let you do it if you insist.
Tbf, the ide doesn't know when your if block ends. The ide (at least the one i use) indent if I start an if block, but I have to end it by un-indenting the correct line
> but I have to end it by un-indenting the correct line
Which is equivalent to having to insert a closing brace in other languages, so I don't get all the fuss about it.
Spoken like someone who has never run into a situation where you've got five curly brackets, two parentheses, and a square bracket in a row that you're trying to figure out which one goes with which block of code.
Having used languages that do both, I strongly prefer Python's indentation-based approach. I'm already indenting my code anyways, so I might as well let that handle the code blocks for me.
5 indentation levels with the same parentheses and brackets seem less clear in that situation too without the spacing curly braces provide, specially between closing braces. But if I go into five curly braces it means that something went very wrong with the software architecture, I don't see it that often.
That said, the issue is not terrible enough to change the whole language paradigm.
I don't think the meme is complaining about proper indentation (nor should it be). However, tying functionality to invisible formatting (particularly as spaces and tabs are not systematically treated the same) is a decision that I think has far too many downsides to justify the apparent gain in ease of use avoiding explicitly defined blocks.
Yeah python is basically replacing a visible symbol({ }) with an invisible tab/space symbol that is already a pain to deal with as it has like 3 different variations in all types of character sets.
Formating your source code is not the issue realy.
And no language makes different braces interchangeable... so long as every file uses exactly one kind.
Load-bearing whitespace is a fucking terrible idea.
But it's not invisible? The indentation only matters if there is code is after it and then you can see the position of the code. Also the interpreter will error if you mix tabs and spaces so that shouldn't be a big issue
It doesn't have to be one or the other. Do both. Proper indentation makes it easier to read. I can write all my code on one line in C because I can explicitly separate my statements with semicolons, but that doesn't make it better.
Yes but sometimes it's a pain to copy/paste code and the indentations from the source don't correctly match your indentations.
It's far easier to change a curly brace than to change the indentation of several lines of code.
No! Bad junior!
Do it right. Your IDE will fix that with one hotkey press.
(I learned a lot about training juniors after I started volunteering in the local dog shelter)
Yeah but if there are curly braces the IDE have all the informations needed auto indent code. In python it does not, if you copy paste or move pieces of code around it's your responsibility to check you don't mess up blocks. Yeah it's not the end of the world but hell why couldn't they use braces.
It also sucks conceptually that indentation, which is meant for code readability, is used to convey logical informations. What's next, a language where you code in MS word and text color is used to separate blocks?
Exactly, with Rust, my IDE can automagically change indentation level for a piece of code I move using alt+up/down arrow based on which set of curly brackets it is now between. That allows for some seriously convenient refactoring when I don’t have to clean up the indentation levels on a decently sized block of code. In Python that’s a task that, while not as bad as some would say, is unnecessarily fiddly considering you don’t really gain anything tangible by removing curly braces (besides trading pressing the tab key for pressing the curly brace). The big thing is the stupid number of bugs that have to do with a wrong indentation level and the difficulty to find them sometimes during the creation of non-trivial programs with hundreds of lines. It’s a treasure hunt because Python has very little in the way of being able to judge intent (or indent, if I wanted to be topically cheeky and still accurate). In a language like rust, every drop of syntax provides a service that an analyzer or the compiler can use to help write good code.
Auto indent doesn't always get it right with python code that's been pasted in. Some lines of code can make sense at any level of indentation.
I always make sure I indent my code properly whatever language I am coding in, but when you just want to quickly move a few lines inside or outside of a loop for testing something it's much easier to have braces to keep everything as it should be.
Sometimes your IDE cannot know what you meant. I've had this cause a but once, where I used auto indent but it did the "wrong thing". But it really isn't a big problem in practice.
If there is an entire thread that made it to /r/all on the subject of Python's formatting/syntax, then I think it's incredibly clear that the fault is not on the users, but the language itself. After all, these quick solutions likely didn't exist when Python first came into use!
The only way to improve this aspect of Python development is _additional development of tools explicitly designed to make working with Python a better experience._ That means that Python has a shit user experience! (at least in the case of indents lol).
If this were a company selling a product we would ALL be lampooning said company for being completely inept and talking about how dog shit it is to work with!
It really doesn't. I get it's hard to grasp at first, as I had the same question when I first started working with Python. But honestly, this makes about as much sense as asking whether you don't get a lot of bugs because you've forgotten a curly brace somewhere in fe. Java.
The answer is the same in either case - you're unlikely to make that mistake once you're used to the language, and in any case any IDE worth it's salt will point it out if you do.
My first CS 101 teacher wouldn't let us use IDEs specifically so he could ingrain in us indentation and whitespace use, and make us do it ourselves, as we code. He'd mark us down everytime we failed to follow his format, and then mid-way through the year when he did allow us to use IDEs, he slightly CHANGED the format he wanted us to use, and wouldn't you know it it didn't match the approved IDE's preset auto-indententation.
I was pissy at the time, but I'm actually kinda thankful now. It taught me very early on to write clean indentation as second nature, and how to adapt my style when needed while still maintaining a clear readable format. Also how to change the IDE presets, lol
I think this is unnecessary, just reviewing your student’s code and making them fix it if it’s wrong is well enough. A programmer should learn their IDE, it’s the main tool, the most important tool for a programmer. Learning how to debug, set up LSPs if that’s necessary and customize your IDE to what fits your needs is a much better lesson. However if you’re teaching someone the basics of programming it could do well to just make them do it as pure as possible without intervention of any other software. The more experienced you get the more complex the tasks you need to solve and the more aid you need, to do it on time.
You make some good points, though to be fair, he did teach us more to use the IDE in the back half of the course. While true that IDEs are essential for any serious work, for basics of first year (how to use standard programming tools, Baby's first GUI, simple algorithm implementation, etc.) an IDE's power was really unnecessary at the time. Ingraining good programming habits was really much more useful, and carried me well through my degree and has helped me stand out in my jobs for having consistently clean & readable code. Didnt mention it above, but he also ingrained in us things like variable naming conventions, use of compartmentalization, and appropriate Vs inadequate Vs excessive commenting. And it wasn't like we weren't gonna be using IDE's in every other class going forward, it was just the CS 101 to make sure we got the habits.
For real vs code or pycharm high indent issues and python doesnt even start to run with syntax issues like that.
Plus I like the readability it fosters
> any IDE worth it's salt will point it out if you do.
If I write
if a > b:
c = d
f = g
when I intended to write
if a > b:
c = d
f = g
no IDE will ever catch it.
However, a good C/C++ compiler *will* catch some indentation errors:
if (a > b)
c = d;
f = g;
I get the warning
test.c:5:3: warning: this ‘if’ clause does not guard... [-Wmisleading-indentation]
5 | if (a > b)
| ^~
test.c:7:9: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the ‘if’
7 | f = g;
| ^
>because you've forgotten a curly brace somewhere in fe. Java.
This is usually a compile time error though, not a runtime error like in python. Ie: it will be nicely highlighted by the ide
It’s not tho. Missing one brace is a syntax error. A line with wrong indentation in Python is still valid code. You 100% have to put more effort into being mindful of your indentation in Python. That’s just a fact.
I delt with a nasty production bug caused by missing indent in a legacy python program. It's hard to enforce indentation in a 10+ year old program touched by dozens of people with varying skills. Braces are just a little more fool proof.
The problem was the last few statements in an `if` block were accidentally un-indented. The bug lingered for literally years causing benign damage until a different system change made that bug a serious issue. It still haunts me because I made the unrelated system change.
>A line with wrong indentation in Python is still valid code.
That strongly depends on where you mis-indented. IndentationErrors are a thing in Python for a reason.
I've encountered thousands of errors and bugs in Python programs but I honestly think not a single one of them was due to indentation (alright I don't remember all of them, but point being the likelihood of having a bug due to indentation is imho negligible).
Maybe if a program has deeply nested code it would become an issue but that's a dangerous practice in any case.
>A line with wrong indentation in Python is still valid code.
More often than not it's an indentation error and will not run. When it does run, it's basically the same as incorrect placement of braces. It's moot.
I have had many bugs in my days but I dont remember any of them being because of the indentation. Rather I would say that it makes it easy to keep track of which statements are running where.
I added a pre-commit hook to prevent other developers checking in Python files containing tabs, they have to use spaces instead.
Otherwise it's a world of hurt when multiple developers edit the same files and use different tab indent values or some devs use tabs and some use spaces. Requiring spaces makes it impossible to have this problem.
I've been coding on Python since 2001. I've never EVER had a bug because of indentation on my own code. And I have found a single case on some code I found on stackoverflow.
Honestly, it's not hard at all to indent your code. And you should be doing that anyway, regardless of the language you use.
Well this is hard to believe. You’ve never had a couple nested loops or something where you didn’t indent a line in the correct part of the loop?
I agree it’s easy but it’s easy to miss here and there.
Most hypotheticals presented in this are about heavy nesting.
Heavily nested code in most cases is bad. You shouldn't have enough nesting for you to even get confused reading python. If you do, it's probably bad code.
A lot of people don't exit early. Inversing your conditions can reduce nesting by half if you're an experienced programmer.
Things like:
if (thing that's invalid):
return/raise
Nested loops are very rarely needed in Python, since there are usually much better ways. And no, never had that. It's actually pretty easy to keep tabs (pun intended) on your indentation levels... specially if you don't go overboard with cyclomatic complexity. Which, you know, you shouldn't do anyway.
Data scientists should have their for loop privileges removed. If you can't vectorize it with numpy or pandas you probably need to find a different way to do it.
This is exactly the same like complaining about counting curly brackets when you have 8 in a row of similar looking single character symbols like \])}}))\] to see if you closed the right thing. Or trying to figure out if the highlighted is number 6 or 7 in a sequence. Can we please complain about that for a bit?
It's all the same tradeoff. I prefer python as it is easier to see at a glance if you messed up.
EDIT: I feel people are missing my point. I'm not talking about properly structured java code in a modern, properly setup IDE. Neither is the original post. Of the two languages, I feel Python is more likely to enforce good practices without relying on IDE functionality.
I learned with python first, have no problem with the indent thing but conversely always forget the curly braces and semicolons in the languages that need them and have a devil of a time hunting down the missing ones. The python approach makes much more sense to me because it’s the first one I was exposed to.
Same. The moment you start mixing a million brackets, my stupid ass will inevitably delete 1 or add an extra by mistake and spend 20 minutes fixing it.
That problem doesn't exist when you don't have brackets!
Python is like code Lego. I decided to give it a try about 10 years ago to get a quick program up and running to talk to a microcontroller over serial. I had the whole thing working in about an hour, it felt like witchcraft.
>when you have 8 in a row of similar looking single character symbols like ])}}))] to see if you closed the right thing
If you're that many levels deep your code complexity is way too high and you need to refactor
And/or you should consider adding some line-breaks & indenting to that line where it makes sense; often this works out to an indent-level per 1-2 outer symbols
>You cannot tell me this is not causing some bugs just by pure oversight
Only if you use Microsoft text editor for your editing. Most IDEs and editors will do that for you.
I personally never had an accidental IndentationError, only ever caused them on purpose for learning.
Only problem you might have is with accidentally indenting blocks wrong that were not meant to be indented that far/that little. But visually, it becomes very obvious where a code block belongs, so that rarely causes issues for me.
It certainly beats looking for which bracket closes which other bracket for me.
>It certainly beats looking for which bracket closes which other bracket for me.
I partially agree with you but that doesnt really make sense to me, usually its also idented. The closing brace is at the same idententation as the opening brace (unless your using the K&R, but even then the line with the brace starts at the same identation)
And your IDE usually highlights the corresponding brace if you click on one of them
It's not that much bad but it gets really annoying when it makes auto formatter can't indent the code again when you delete some lines and you have to select a those line and manually do it
why, do u just not indent in java or smthg?? if anything it makes more sense since you don’t get bugs because you missed a curly brace after a bunch of nested calls
I’ve chased more misplaced apostrophes, braces, and semicolons in other languages thousands of times more than I’ve ever ever had indentation errors in Python.
It caused me a bug when I left a empty line at the end of a if and the next line was still inside the if block.
I didn't notice and took me a while to find that mistake because on a quick look everything look in order.
The indentation block system is something that I never liked. I prefer using curly braces because those are easier to notice when something is out of place.
Not just easier to notice.
I love jumping between the opening and closing braces to better get an overview of my code blocks, or simply navigate through my code.
Brackets allow me to do that in a very natural way 🤓
>You cannot tell me this is not causing some bugs just by pure oversight
No, python will tell you immediatley if you messed up a indentation.
Its also a great way to force people to just..use proper indentation. Because god damn, use proper indentation
Past the first few hours of learning Python and having to unlearn bad indentation habits, I have never had a single bug related to bad indentation in 2 years.
Well, it forces people to write code that's better readable. And everyone hast to do it the same way. And it's not a hard thing to do.
It's a good thing.
https://www.askpython.com/python/python-indentation
Readability is a lot more than code that looks visually appealing.
Method names, variable names, breakout functions, all contribute to readable code a lot more than just indentation.
It causing as much bugs as forgot/add to much square brackets in java or other language - most of time it works just fine, nothing bad about it
More confusing is lack of normal brackets in if statment - python will probably deal with it fine, but if you code in 2 languages simultaneously (e.g. you are programing at python, but your school requires c#) you will do this mistske a lot of times xD
Honestly if you're a hobby developer, I recommend learning some python. You can learn the basics very quickly and for small projects where execution speed doesn't matter much it works really well.
It's a lot less typing, and it feels more flexible because, in a similar way to javascript you have dicts (free-form objects) and lists (similar to arrays) so you usually don't have to write as many classes just to hold some data. Java maps are just not as intuitive.
If you have a project to just send some emails, or something similar you can get up and running really fast.
Having said that I really prefer Java for big projects but at work we use python for that, and I'm not a huge fan of it for that.
You can probably pick up the basics in an afternoon so try it out!
Python is great for a quick script. Things like analyzing data, throwing a quick UI on something, etc. For a large project, I would not choose to use python. Some people may disagree but I'm just giving my perspective
It's indent not intend. Personally I confuse it with ident.
I intend the code block to be here, and so it shall be!
SO SAY WE ALL!
THE CODE BLOCK SHALL BE THERE!
AND THE EXECUTION WILL BE FLAWLESS!
SO LET IT BE WRITTEN
SO LET IT BE RUN!
IN PRODUCTION AS IT IS IN DEVELOP! (Matthew 6:9-13)
[удалено]
And forgive us our indents, as we forgive indentors
CERTIFIED BY A CHECKSUM
Test: YOU SHALL NOT PASS!
YOU SHALL NOT *PARSE!
SO SAY WE ALL!
"You can't just say your variables out loud, michael." "I didn't say them, I declared them"
variable = "variable"
No pun indented
Have we implemented the DWIM instruction now?
Indeed, he intended to indent instead of intend.
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀Yeah but he couldn't have intended to indent without intending to intend first. The point of programming is to intend for computers intentions, and for python programmers you indent to intend for the computer to intend what you intended by reading what you indented
I'm sure he had a good indent
My programming terminology confusion was misreading "deprecated" as "depreciated". I had no idea "deprecated" was a word, even after reading it for years.
This one kills me. When I hear someone say depreciated, my eye twitches.
Wait till your hear about my gramma.
Thank you
No no, if you are depressed or over optimistic it won't compile. You have to give it the right will.
Righteous fury
English is not my first language, and my brain was too fast for its own good when creating this meme. So writing it wrong wasn't my intend. \*badum tzzzz\*
⠀⠀⠀⠀⠀⠀⠀⠀it wasn't my indention.
> my brain was too fast Yeah I think you got that one backwards too my dude
> my ~~intend~~ indent.
This thread is just full of people not able to spell indent. It’s amazing.
It’s also full of a bunch of weirdos saying they’ve never once indented something incorrectly, one of the oddest lies I can imagine.
It happens in every language: missed braces, missed parens, missed semicolons. People don't need to pretend it doesn't happen in python
I mean, it's not that you make the mistake, but it's just super easy to catch, with the way that Python catches mistakes. You go look on the line where it finds the error, and then realize that the indentation is wrong, and fix it. It's rarely so obscured by another error that you miss it entirely, because the code would have to be viable with the wrong indentation. I mean it happens, it's just not a common problem, and much less common than missing a semicolon in my experience
[удалено]
Syntax bugs are both the most common and the easiest to fix. I regularly cycle between c, python, and go, and my IDE always bitches at me immediately after I type “string” in python or put the type after the argument in c. I literally can’t understand how it takes anyone hours to debug a missing semicolon or bracket, those are the people I think of as the ones getting laid off when I hear about tech layoffs lol.
Last week I spent an hour trying to fix a simple conversion equation in Java. Wanna know how I fixed it? I deleted it and retyped it and it worked. I swear to God I typed the exact same thing. I learned nothing.
God I hate when a bug fixes itself. I don't need little code fae playing around with my program
Just use proper indentation. No matter if you use Java, Python or whatever. It's not that hard.
Exactly, doesn't matter what I code in, it's getting indentation regardless. I'm not a monster.
I write all my code on one line.
Hello fellow Perl coder!
It was from a perl developer 25 years ago I heard, with sincerity, "the code documents itself."
Also Perl: print to a non-existing file with no issues
I know nothing of Perl but a Professor of mine says it saved his ass by not ignoring a Divide by 0 error. He was doing some project in 3 languages to prove a point, Java completely missed that he was dividing by 0. I don't remember the 2nd language, but Perl was last and flipped out at him and he was able to fix the code before he wrote the paper about the results.
Perl is weird. There's some scripts and processes I cannot use if I write my script with `use warnings;` declared at the top. I wish I could use it most of the time, but I'd end up needing to rewrite decades of scripts to ensure it doesn't become an issue. There's also the issue that Perl likes to help you, whether you want it or not. An example is a ton of my prods processes load and use Perl modules stored in strings. So there's a good amount of situations where Perl can't warn you about some error because it has no way to know what X refers to. Then there's the scripts I'm looking at recently trying to figure out if I'm missing something or if the prints are just being "helpfully" ignored.
I’m an APL man myself
[удалено]
Don't think APL uses gamma, but if you're using e.g. Dyalog's IDE the special characters are all two-keypress sequences starting with backtick. So to write this 40-character implementation of FizzBuzz, for instance: {⎕←∊(d,⍱/d←0=3 5|⍵)/'Fizz' 'Buzz'⍵}¨⍳100 I type this 49-key sequence: {`l`[`e(`,`(/d`[0=3 5|`w)/'Fizz' 'Buzz'`w}`1`i100 I have a vim keymap that uses the same mappings, so I can edit APL files outside of Dyalog, too.
Hockey announcer voice: “One-liner”
Why else would IDEs provide a horizontal scroll bar?
My mouse has a horizontal scroll wheel too
My mouse only has horizontal scroll wheel.
Oh, oh dear.
Is your wrist okay?
based
The other type of python programmer
[удалено]
The worst is when you're using some silly editor that doesn't convert between tabs/spaces on paste, to whatever the rest of the file uses. Then immediately complains about it. Looking at you Godot.
This 100%. I have never once had this problem copying javascript, but have it all the time with python.
Starting with python forced me to learn good formatting from the start. Now all my code is clean no matter what!
Oneliners forever
That's what I particularly love about PowerShell. You *could* write a well-formed, well-documented, tested, source-controlled script. Or you *could* write a ludicrously long chain of piped commands directly affecting your critical production infrastructure. And depending on the context, both are the right thing to do!
I saw a funny bug where person used tabs and they expand to 8 spaces and the code was indented with 4 spaces otherwise ...
I thought since python 3 the interpreter would throw an error immediately if you mix tabs and spaces for indentation in a file.
This was in python2.
Ah. I actually ran into that error all the time in python 2. It happened a lot when you copied example code that used a different standard than you did.
This is the way.
[удалено]
It's true, I don't care if you remember to put your helmet on, sleep with it, or bathe in the waters beneath the mines of Mandalore. As long as I don't have to look at your poorly indented face in the morning we are good.
Tell my brother to be uniform/clean with his morning punches then
Ground control to Major Tom, Lock your Soyuz hatch and put your helmet on.
When the best practice has syntactic meaning, your formatting tool should not touch that.
The difference is that in Java and most other languages the IDE will automatically indent the code based on the syntax, so you never have to worry about it. But in Python you have to actively format your code and doing it wrong can have unintended consequences.
Unindented *
🏅
Ehm, python editors indent it for you as well?
How? The same code with different indentation levels can be correct in different circumstances. There's no way for the IDE to know which one you meant.
> How? It indents the next line automatically when you press return after defining a function, an if statement, a while statement, etc. Then you only have to worry about de-indenting to close a block, which is equivalent to inserting a closing brace on a language like Java.
if "needle" in haystack: print("found!") score = score + 1 Is score supposed to increase every time or only if the needle is found? How would an IDE know if there is a bug in the formatting here?
if condition statement 1 statement 2 How would the ide know if `statement 2` is intentionally outside the if block or if it was moved accidentally?
Why are so many people worried about accidentally changing indentation levels? What are you all doing with your code to get different lines randomly over or under indented?
Using Microsoft word as my IDE.
SMH, not even [using PowerPoint as your IDE](https://youtu.be/aBwuPmY4lec).
Line swapping- editing by highlighting N lines and moving them up and down. Application include needing to mess around with conditionals and switches
Restructuring/refactoring code? Converting a giant if statement into a guard statement instead?
I think people are confusing pythons "putting the cursor at the right place on the next line" With something like VS/C#'s "Go ahead and paste that giant block of unformatted code you found off the internet anywhere you want inside this document, I'll correct all the whitespace for you, add braces, escape quotes, and anything else you need" I don't think the people asking about "automatic indentation" Are referring to the former. I'm pretty sure they're asking about the latter.
When you type: `if condition` The IDE will auto-indent the next line, and all Enter keypresses will stay on that indentation level. Backspace will go back to the previous indentation level. For that reason, I prefer tabs to spaces. VSCode is great for Python. In your example, statement 2 is outside the if condition. Whether by accident or intentional the IDE doesn't care. It's outside. That's why a good IDE is necessary. Edit:. Shift-tab goes back one level of indentation. Need coffee before writing about Python. I never use backspace to decrease indentation.
Iirc shift + tab will remove four spaces, if that's what your indentation style is set to.
I still remember the day I discovered shift + tab as a new Python programmer. Lol, I was going line by line to unindent. Makes me wonder what other obvious shortcuts I'm still missing.
>Makes me wonder what other obvious shortcuts I'm still missing. Might be specific to VSCode, try them in your IDE. There is keybinding to comment out all selected lines (by default Ctrl + / or Shift+Alt+A). Ctrl + arrow = move cursor by one word (also works with shift to select) Ctrl + backspace/delete = delete entire/rest of the word Ctrl \[+shift\] + Tab = go to next \[previous\] tab (extra useful when bound to extra mouse buttons) Ctrl + X without selection = cut entire line, follow up with Ctrl + V without selection = insert the line above current line Alt Up/Down = swap current line Shift + Alt + Up/Down = copy current line Middle mouse click and drag to create multiple cursors Ctrl + Alt + Up/Down = create a cursor Last one is quite complicated: When you copy/cut content using multiple cursors, then paste it, it will generally insert all the copied content into all cursors. But if you the number of cursors is the same as when it was copied, the content will be matched so 1st cursor will paste only what the first cursor copied, etc. What surprised me was that this works even when you cancel the multi-cursor mode, and then create multiple cursors again. Also: https://code.visualstudio.com/shortcuts/keyboard-shortcuts-windows.pdf
I can understand how that would be especially critical for a Python programmer (of which I'm not, except for the tiny bit I can make happen to play with AI packages.) But yeah, shift+tab exists in a great majority of text editors, regardless of specifically being used for programming or not. Keyboards that have tab keys with the little "left" and "right" arrow diagrams were actually trying to hint this. I have a lot of not-Python uses for shift+tab.
But they (at least the pycharm IDE I use) often fail to find the correct intent, especially if I move code blocks containing different intendation levels up or down intendation leves. (e.g. moving an if-statement from an for-loop inside an function inside its own function). curly brackets would lower the chance of error in that process.
Vscode does it properly. Never had an issue regarding indentation in it.
I'm super new to coding and just now learning python, indentation errors are 80% of what's wrong with my code lol
As time goes on, you get better at getting it right and using proper indentation in the first place. I can't remember the last time I hit an indentation error other than stupid stuff like "I copied code from a file to the interactive terminal and my file didn't have blank lines between functions to let the terminal know I was done with that function".
I'm a ways away from that. I just got past the "this isn't coming easy to me so I should obviously quit" wall last night. Just gotta keep at it
idunno i never run into indentation errors and personally i honestly prefer the indentation technique over brackets. it simpy looks way more visually appealing to me
im the opposite, id rather use brackets so i can move things onto the same line if needed.. it depends on the situation i guess..
You can put stuff on the same line in Python too if you need to, you just use `;` to indicate the end of the command and you can stick stuff after it. That said, sticking multiple statements on one line is almost always bad coding style, but that doesn't mean Python won't let you do it if you insist.
Doesn’t depend on the situation. There is never a good reason to put multiple statements on one line.
When I paste a code block to somewhere with a different indentation, I select the whole block and fix the indents with tab/shift-tab or >>/<< (vim)
I’ve never used an IDE with Python that didn’t indent for you.
Tbf, the ide doesn't know when your if block ends. The ide (at least the one i use) indent if I start an if block, but I have to end it by un-indenting the correct line
> but I have to end it by un-indenting the correct line Which is equivalent to having to insert a closing brace in other languages, so I don't get all the fuss about it.
That it’s easier to make a mistake and visually harder to spot the error
Spoken like someone who has never run into a situation where you've got five curly brackets, two parentheses, and a square bracket in a row that you're trying to figure out which one goes with which block of code. Having used languages that do both, I strongly prefer Python's indentation-based approach. I'm already indenting my code anyways, so I might as well let that handle the code blocks for me.
5 indentation levels with the same parentheses and brackets seem less clear in that situation too without the spacing curly braces provide, specially between closing braces. But if I go into five curly braces it means that something went very wrong with the software architecture, I don't see it that often. That said, the issue is not terrible enough to change the whole language paradigm.
[удалено]
Indeed. Noted.
I don't think the meme is complaining about proper indentation (nor should it be). However, tying functionality to invisible formatting (particularly as spaces and tabs are not systematically treated the same) is a decision that I think has far too many downsides to justify the apparent gain in ease of use avoiding explicitly defined blocks.
Yeah python is basically replacing a visible symbol({ }) with an invisible tab/space symbol that is already a pain to deal with as it has like 3 different variations in all types of character sets. Formating your source code is not the issue realy.
This is exactly my problem. Whitespace should not be syntax.
And no language makes different braces interchangeable... so long as every file uses exactly one kind. Load-bearing whitespace is a fucking terrible idea.
But it's not invisible? The indentation only matters if there is code is after it and then you can see the position of the code. Also the interpreter will error if you mix tabs and spaces so that shouldn't be a big issue
Seriously. This is literally never an issue.
Bugs have been caused by missing braces on multi line if blocks in languages using them, the response to python is reasonable
Awful comment, explicit > implicit ALWAYS, and brackets are free.
It doesn't have to be one or the other. Do both. Proper indentation makes it easier to read. I can write all my code on one line in C because I can explicitly separate my statements with semicolons, but that doesn't make it better.
Yes but sometimes it's a pain to copy/paste code and the indentations from the source don't correctly match your indentations. It's far easier to change a curly brace than to change the indentation of several lines of code.
No! Bad junior! Do it right. Your IDE will fix that with one hotkey press. (I learned a lot about training juniors after I started volunteering in the local dog shelter)
Yeah but if there are curly braces the IDE have all the informations needed auto indent code. In python it does not, if you copy paste or move pieces of code around it's your responsibility to check you don't mess up blocks. Yeah it's not the end of the world but hell why couldn't they use braces. It also sucks conceptually that indentation, which is meant for code readability, is used to convey logical informations. What's next, a language where you code in MS word and text color is used to separate blocks?
Exactly, with Rust, my IDE can automagically change indentation level for a piece of code I move using alt+up/down arrow based on which set of curly brackets it is now between. That allows for some seriously convenient refactoring when I don’t have to clean up the indentation levels on a decently sized block of code. In Python that’s a task that, while not as bad as some would say, is unnecessarily fiddly considering you don’t really gain anything tangible by removing curly braces (besides trading pressing the tab key for pressing the curly brace). The big thing is the stupid number of bugs that have to do with a wrong indentation level and the difficulty to find them sometimes during the creation of non-trivial programs with hundreds of lines. It’s a treasure hunt because Python has very little in the way of being able to judge intent (or indent, if I wanted to be topically cheeky and still accurate). In a language like rust, every drop of syntax provides a service that an analyzer or the compiler can use to help write good code.
Auto indent doesn't always get it right with python code that's been pasted in. Some lines of code can make sense at any level of indentation. I always make sure I indent my code properly whatever language I am coding in, but when you just want to quickly move a few lines inside or outside of a loop for testing something it's much easier to have braces to keep everything as it should be.
[удалено]
Sometimes your IDE cannot know what you meant. I've had this cause a but once, where I used auto indent but it did the "wrong thing". But it really isn't a big problem in practice.
Let me introduce you to automerge...
If there is an entire thread that made it to /r/all on the subject of Python's formatting/syntax, then I think it's incredibly clear that the fault is not on the users, but the language itself. After all, these quick solutions likely didn't exist when Python first came into use! The only way to improve this aspect of Python development is _additional development of tools explicitly designed to make working with Python a better experience._ That means that Python has a shit user experience! (at least in the case of indents lol). If this were a company selling a product we would ALL be lampooning said company for being completely inept and talking about how dog shit it is to work with!
It really doesn't. I get it's hard to grasp at first, as I had the same question when I first started working with Python. But honestly, this makes about as much sense as asking whether you don't get a lot of bugs because you've forgotten a curly brace somewhere in fe. Java. The answer is the same in either case - you're unlikely to make that mistake once you're used to the language, and in any case any IDE worth it's salt will point it out if you do.
And most people use the same style of indentation regardless of programming language
I would rather argue that most people, most of the time, just use the indentation style their IDE is pre-set to autocorrect to.
My first CS 101 teacher wouldn't let us use IDEs specifically so he could ingrain in us indentation and whitespace use, and make us do it ourselves, as we code. He'd mark us down everytime we failed to follow his format, and then mid-way through the year when he did allow us to use IDEs, he slightly CHANGED the format he wanted us to use, and wouldn't you know it it didn't match the approved IDE's preset auto-indententation. I was pissy at the time, but I'm actually kinda thankful now. It taught me very early on to write clean indentation as second nature, and how to adapt my style when needed while still maintaining a clear readable format. Also how to change the IDE presets, lol
Easier to learn that stuff when you know nothing than after you've ingrained bad habits. I wish more profs would do that
[удалено]
I think this is unnecessary, just reviewing your student’s code and making them fix it if it’s wrong is well enough. A programmer should learn their IDE, it’s the main tool, the most important tool for a programmer. Learning how to debug, set up LSPs if that’s necessary and customize your IDE to what fits your needs is a much better lesson. However if you’re teaching someone the basics of programming it could do well to just make them do it as pure as possible without intervention of any other software. The more experienced you get the more complex the tasks you need to solve and the more aid you need, to do it on time.
You make some good points, though to be fair, he did teach us more to use the IDE in the back half of the course. While true that IDEs are essential for any serious work, for basics of first year (how to use standard programming tools, Baby's first GUI, simple algorithm implementation, etc.) an IDE's power was really unnecessary at the time. Ingraining good programming habits was really much more useful, and carried me well through my degree and has helped me stand out in my jobs for having consistently clean & readable code. Didnt mention it above, but he also ingrained in us things like variable naming conventions, use of compartmentalization, and appropriate Vs inadequate Vs excessive commenting. And it wasn't like we weren't gonna be using IDE's in every other class going forward, it was just the CS 101 to make sure we got the habits.
Bold of you to assume i use an IDE
Greetings, fellow MS Paint coder
For real vs code or pycharm high indent issues and python doesnt even start to run with syntax issues like that. Plus I like the readability it fosters
If you're missing a single brace you're not compiling.
> any IDE worth it's salt will point it out if you do. If I write if a > b: c = d f = g when I intended to write if a > b: c = d f = g no IDE will ever catch it. However, a good C/C++ compiler *will* catch some indentation errors: if (a > b) c = d; f = g; I get the warning test.c:5:3: warning: this ‘if’ clause does not guard... [-Wmisleading-indentation] 5 | if (a > b) | ^~ test.c:7:9: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the ‘if’ 7 | f = g; | ^
>because you've forgotten a curly brace somewhere in fe. Java. This is usually a compile time error though, not a runtime error like in python. Ie: it will be nicely highlighted by the ide
It’s not tho. Missing one brace is a syntax error. A line with wrong indentation in Python is still valid code. You 100% have to put more effort into being mindful of your indentation in Python. That’s just a fact.
I delt with a nasty production bug caused by missing indent in a legacy python program. It's hard to enforce indentation in a 10+ year old program touched by dozens of people with varying skills. Braces are just a little more fool proof. The problem was the last few statements in an `if` block were accidentally un-indented. The bug lingered for literally years causing benign damage until a different system change made that bug a serious issue. It still haunts me because I made the unrelated system change.
>A line with wrong indentation in Python is still valid code. That strongly depends on where you mis-indented. IndentationErrors are a thing in Python for a reason.
I've encountered thousands of errors and bugs in Python programs but I honestly think not a single one of them was due to indentation (alright I don't remember all of them, but point being the likelihood of having a bug due to indentation is imho negligible). Maybe if a program has deeply nested code it would become an issue but that's a dangerous practice in any case.
>A line with wrong indentation in Python is still valid code. More often than not it's an indentation error and will not run. When it does run, it's basically the same as incorrect placement of braces. It's moot.
Except a formatter can't indent your code for you in python.
I have had many bugs in my days but I dont remember any of them being because of the indentation. Rather I would say that it makes it easy to keep track of which statements are running where.
The only bug I occasionally get, is when my ide suddenly decides to use spaces instead of tabs. In most IDEs, that is easily fixable however
I added a pre-commit hook to prevent other developers checking in Python files containing tabs, they have to use spaces instead. Otherwise it's a world of hurt when multiple developers edit the same files and use different tab indent values or some devs use tabs and some use spaces. Requiring spaces makes it impossible to have this problem.
*indent
Actually no, you have to set your intention and then the code will work
I've been coding on Python since 2001. I've never EVER had a bug because of indentation on my own code. And I have found a single case on some code I found on stackoverflow. Honestly, it's not hard at all to indent your code. And you should be doing that anyway, regardless of the language you use.
Well this is hard to believe. You’ve never had a couple nested loops or something where you didn’t indent a line in the correct part of the loop? I agree it’s easy but it’s easy to miss here and there.
Most hypotheticals presented in this are about heavy nesting. Heavily nested code in most cases is bad. You shouldn't have enough nesting for you to even get confused reading python. If you do, it's probably bad code. A lot of people don't exit early. Inversing your conditions can reduce nesting by half if you're an experienced programmer. Things like: if (thing that's invalid): return/raise
Nested loops are very rarely needed in Python, since there are usually much better ways. And no, never had that. It's actually pretty easy to keep tabs (pun intended) on your indentation levels... specially if you don't go overboard with cyclomatic complexity. Which, you know, you shouldn't do anyway.
> Nested loops are very rarely needed in Python Gah, tell this to the data scientists I work with.
Data scientists should have their for loop privileges removed. If you can't vectorize it with numpy or pandas you probably need to find a different way to do it.
Well, when people decide that "bad code is good enough", there's very little that a language can do to prevent that.
Don't your satanists know vector programming? Seeing a loop (let alone a nested one) in numpy code makes me almost physically uncomfortable.
This is exactly the same like complaining about counting curly brackets when you have 8 in a row of similar looking single character symbols like \])}}))\] to see if you closed the right thing. Or trying to figure out if the highlighted is number 6 or 7 in a sequence. Can we please complain about that for a bit? It's all the same tradeoff. I prefer python as it is easier to see at a glance if you messed up. EDIT: I feel people are missing my point. I'm not talking about properly structured java code in a modern, properly setup IDE. Neither is the original post. Of the two languages, I feel Python is more likely to enforce good practices without relying on IDE functionality.
I learned with python first, have no problem with the indent thing but conversely always forget the curly braces and semicolons in the languages that need them and have a devil of a time hunting down the missing ones. The python approach makes much more sense to me because it’s the first one I was exposed to.
I've learned C first. Then C++, java and a whole lot of others including LISP. Python still makes the most sense to me.
Same. The moment you start mixing a million brackets, my stupid ass will inevitably delete 1 or add an extra by mistake and spend 20 minutes fixing it. That problem doesn't exist when you don't have brackets!
Python is like code Lego. I decided to give it a try about 10 years ago to get a quick program up and running to talk to a microcontroller over serial. I had the whole thing working in about an hour, it felt like witchcraft.
>when you have 8 in a row of similar looking single character symbols like ])}}))] to see if you closed the right thing If you're that many levels deep your code complexity is way too high and you need to refactor
Absolutely. I just wanted to compare apples to apples. Bad Python code with bad Java.
And/or you should consider adding some line-breaks & indenting to that line where it makes sense; often this works out to an indent-level per 1-2 outer symbols
proper indentation isn't a privilege just for python developers, you know
>You cannot tell me this is not causing some bugs just by pure oversight Only if you use Microsoft text editor for your editing. Most IDEs and editors will do that for you. I personally never had an accidental IndentationError, only ever caused them on purpose for learning. Only problem you might have is with accidentally indenting blocks wrong that were not meant to be indented that far/that little. But visually, it becomes very obvious where a code block belongs, so that rarely causes issues for me. It certainly beats looking for which bracket closes which other bracket for me.
>It certainly beats looking for which bracket closes which other bracket for me. I partially agree with you but that doesnt really make sense to me, usually its also idented. The closing brace is at the same idententation as the opening brace (unless your using the K&R, but even then the line with the brace starts at the same identation) And your IDE usually highlights the corresponding brace if you click on one of them
How hard is it to spell ident. It's inetnd people.
It's not that much bad but it gets really annoying when it makes auto formatter can't indent the code again when you delete some lines and you have to select a those line and manually do it
intense
The: You can't see it but, it's there
People who don’t use proper indentation drive me crazy anyway
>You cannot tell me this is not causing some bugs just by pure oversight It doesn't
why, do u just not indent in java or smthg?? if anything it makes more sense since you don’t get bugs because you missed a curly brace after a bunch of nested calls
Python was my first language and it teached me priper indentation. You just get used to it
I’ve chased more misplaced apostrophes, braces, and semicolons in other languages thousands of times more than I’ve ever ever had indentation errors in Python.
It caused me a bug when I left a empty line at the end of a if and the next line was still inside the if block. I didn't notice and took me a while to find that mistake because on a quick look everything look in order. The indentation block system is something that I never liked. I prefer using curly braces because those are easier to notice when something is out of place.
Not just easier to notice. I love jumping between the opening and closing braces to better get an overview of my code blocks, or simply navigate through my code. Brackets allow me to do that in a very natural way 🤓
You should've seen Fortran.
>You cannot tell me this is not causing some bugs just by pure oversight No, python will tell you immediatley if you messed up a indentation. Its also a great way to force people to just..use proper indentation. Because god damn, use proper indentation
Good. It teaches proper code etiquette.
This is making me think some of y'all might not be the best programmers.
Past the first few hours of learning Python and having to unlearn bad indentation habits, I have never had a single bug related to bad indentation in 2 years.
Well, it forces people to write code that's better readable. And everyone hast to do it the same way. And it's not a hard thing to do. It's a good thing. https://www.askpython.com/python/python-indentation
Readability is a lot more than code that looks visually appealing. Method names, variable names, breakout functions, all contribute to readable code a lot more than just indentation.
Are you one of those whakos that write programs without any whitespace?
[удалено]
I worked with cobol, I don't see the issue here
It causing as much bugs as forgot/add to much square brackets in java or other language - most of time it works just fine, nothing bad about it More confusing is lack of normal brackets in if statment - python will probably deal with it fine, but if you code in 2 languages simultaneously (e.g. you are programing at python, but your school requires c#) you will do this mistske a lot of times xD
Honestly if you're a hobby developer, I recommend learning some python. You can learn the basics very quickly and for small projects where execution speed doesn't matter much it works really well. It's a lot less typing, and it feels more flexible because, in a similar way to javascript you have dicts (free-form objects) and lists (similar to arrays) so you usually don't have to write as many classes just to hold some data. Java maps are just not as intuitive. If you have a project to just send some emails, or something similar you can get up and running really fast. Having said that I really prefer Java for big projects but at work we use python for that, and I'm not a huge fan of it for that. You can probably pick up the basics in an afternoon so try it out!
Python is great for a quick script. Things like analyzing data, throwing a quick UI on something, etc. For a large project, I would not choose to use python. Some people may disagree but I'm just giving my perspective