Lol I'm sure there's someone out there using Word as their IDE especially considering it has more IDE features than Notepad which some beginners start with
I'll be honest, I actually did that in my first programming lesson. Teacher told us to use our favourite text editor, so I booted up Word (might have been OpenOffice. Memory's a bit fuzzy by now), wrote the assigned program, did all syntax highlighting by hand, then took an embarrassing amount of time to figure out why the compiler was throwing all those funky errors my classmates weren't getting >.>
Why would you ever want whitespace to hold meaning in code? Brackets and semicolons were given to us by God so that we could type an entire program on a single line.
You can still use semicolons in Python. I do it all the time to condense space, such as when initializing a bunch of process variables or usually in a loop adding to the end of the conditional outcome (e.g. blFoo=True; continue) makes enough sense.
One rule is never combined this with functional code and print/logging statements.
invisble characters, that are also used to make code more readable can alter the behavior of my code or even invalidate it entirely? sounds like a good idea to me
Counterpoint: semantic whitespace is acceptable when in its in the first 6 columns, but becomes so unacceptable for columns 7+ that even lexing should be unaffected if all whitespace were entirely stripped out.
LOL when I dabbled in Python very lightly (riggings for Source Filmmaker, back when it first came out), I just used Notepad++, as I didn't want another IDE
Indentation is such a stupid mechanism for identifying code blocks. It's one thing for configuration files like YAML to do it, but not a programming language.
I'd always figured it was/thought of it as an error tolerance that worked well enough that some people started leaning on it. The whole no-semicolons JavaScript thing just seems really hipsterish. Explicitness is a virtue.
In JS, semicolons are technically required but automatically inserted. There are a couple edge cases where they get inserted in surprising places, which is generally worse than python's approach.
E.g. the following function doesn't return a value:
function foo() {
return
some_long_complex_expression();
}
(It's because a semicolon gets inserted after the return). At least in typescript, this would typically show a type error, as long as the function's return type annotation isn't void.
It was a revelation when I started programming. "What, it doesn't have to be this way? A language can be native, statically compiled and high level at the same time and not suck ass? We can do better as a species?"
Odin is also a high level native language! Well, not as high level as Go since it's manual memory management but definitely easier than C. I'd recommend checking it out I love it personally
Even YAML is kinda questionable with big complex config files. Like, the spec is like 10x the size of JSON to account for all the sugar and the edge cases.
It does look nice though, and I guess it acts as a forcing function to refactor stuff.
I think that's a universal problem with all formats. What's needed is to break up configuration into subfolders and files so things can be logically separated. But if it's not done well it becomes a PITA to maintain and the end result is to just shoehorn everything into a single file.
I don't like it, but I kinda get it. Indentation is already part of every coding style guide, so adding explicit scoping symbols is kind of redundant information.
..Until you have a mix of spaces and tabs and chaos reigns
Also, having braces at the beginning and end of a block just makes my brain happy.
Nice. In C and C++, I've insisted on my teams' code to always use braces, even for a single line statement. It's a PITA debugging when somebody else a year later adds to that single line, forgetting the braces.
My take is that whitespace shouldn't be relevant. It's only purpose should be to separate non-whitespace characters that matter. Even newlines shouldn't matter.
Whitespace is for making it easier for humans to read the code. So are comments, so is documentation, so is syntactic sugar. The redundancy is a feature. Braces are explicit block separators, but whitespace makes identifying those blocks easier.
If your code could be broken by a tab instead of 4 (or 2 or 8 or 5) spaces, your language is fundamentally flawed.
I tend to agree and always include some kind of whitespace-skip rule in DSL grammars. It lets you use whitespace to taste while the block separators are formally defined. But, I kinda get why someone might want to just use whitespace if they were going to anyway. (Until something that looks correct isn't >.>)
I had a bug a Python bug a few years ago where I had an if-else block nested inside an if block, but the else was an indentation short and I didn't notice, was wondering why some cases didn't do what I expected. Wouldn't happen with braces.
Granted I was still learning Python then so I imagine I would immediately notice the bug were I to encounter it today.
Copy pasting Python is a huge PITA. Doing edits like deleting 1 of X nested if statements sucks. You can delete 1 tab on every line, except if you have some empty lines and you delete a line feed and you always have some empty lines. Python is just way harder to move code around in than a braced language.
Having to think about whitespace and formatting styles is a mental overhead and I refuse to do it. Just give me an autoformatter gosh dang it! Except well, you can't in Python.
i feel like that only makes sense if theres like. a good reason in favor of the indentation. if it takes extra skill to reach baseline functionality then like, why does it?
I think I can pull a similar point between typescript and javascript, you don't really need to type things, so javascript does the job, so does indentations do the job perfectly well. Typescript / braces help making it safer for a little tiny bit of extra work
It's less cognitive load too, imo. Proponents of regular JavaScript will argue that unit tests buy you more safety than explicit typing does, and that's broadly true, but anything that explicit typing would stop you from doing involves mixing similar but ontologically different things, which means having to think about what the thing you're looking at might be at runtime and accounting for all the permutations thereof. And I just think it's easier to think about things with typing.
You can easily count scoping symbols. Not indentation. You can make an argument that if your code is so indented that this becomes a problem then you have bigger problems but I still think indentation is a horrible option is one of the thinks that I most dislike about python
I mean, yeah, most languages use scoping symbols. All I'm doing is throwing the Python folks a bone by acknowledging that every style guide for pretty much every language prescribes indentation for scopes, and I can see how you don't strictly need that and explicit scoping symbols.
What I’m trying to say is that is much easier to count symbols to know how many levels deep inside a block you are then trying to estimate the indenting
I'd rather have it at the end of the line, not the beginning though. I find putting all your language blockage before your statement just makes it feel weird.
Semi colon at the end of the line is easy. 4 groups of indentations? Better hope you've got a good IDE.
True, but you don't control the code you inherit and getting stakeholders to give you time to properly refactor is not an easy task. You end up doing it where you can as you can.
My big issue with it is if tabs get mixed with spaces the interpreter has an aneurysm. Most modern IDEs can detect and preemptively protect you from it, but a tool shouldn't be needed to shield you from a design flaw in the language.
I swear I'm not aiming for a flamewar here, but...
I've always found it odd that Python standards (PEP and all) settled on space-based indentation. If there's any language where a one-character indentation indicator makes sense, it's a language where indentation is significant.
Because it's very common for tabs to be rendered as 1-8 spaces. There's no good reason for a line of python code to exceed the recommended 79 columns, and having tabs that are 8 spaces wide by default is extremely annoying to people like me who like having multiple source file windows opened on the same screen (to reduce eyestrain).
Making 4 spaces the default guarantees files look identical in all editors. By the way, I've never seen a python code editor that didn't default to 4 spaces or have a feature that automatically fixes the indentation.
That's not a problem. You can render them at any width - and in fact, there's no reason for the width to be defined in spaces, you could say that a tab is 38mm if you so choose - but they are still, logically, *one indentation level*.
U my friend are the reason the show Silicon Valley had this running gag but srsly use TABS it’s just a matter of IDE-Settings for example to make it look right just for u and others can work with it normally or in their own special ways^^
I used to hate the idea too, but there's something nice about not having braces everywhere. The funny part is that Python makes the code look cleaner while somehow giving a single whitespace character the power to ruin your entire day. That's a pretty wild trade-off.
Everything not indented by 4 whitespaces should raise a syntax error.
Using indentation is fine, the issue in Python is that that the syntax does not explicitly require one specific method. There is only the recommendation in PEP8.
However, with linters and IDEs this essentially became a non issue, even more now with llms.
To be fair, indentation does make Python code easier to read once you're used to it. The real crime is that one accidental space can turn a perfectly good afternoon into a debugging session.
It's a fairly common mistake that happens when you're learning the language and most of the people on this subreddit are cs students in university or most of the content that makes its way to the top is for the reason that jokes need to be fairly accessible to hit a wide audience.
You have to be familiar enough with the IDE to use those features and also pay attentions to the warnings/errors the IDE gives you. I've seen PRs where it's clear the programmer completely ignored any errors the IDE produced.
I mean, if someone is so digitally illiterate that they can't understand "red squiggly line under stuff means you need to take a second look", they should be in a different line of work.
Like, I get that you do have to look for stuff like that and it won't physically slap you in the face, but that's just basic "paying attention to what you're doing" stuff.
I mean, it's more that I believe that anyone who's having those sorts of issues isn't really an experienced programmer worth their pay. If you can't see the squiggly red line in the IDE and look for why the IDE is telling you that's a bad line, you should find another line of work.
Not just python, basically any programming language benefits from proper indentation.
Almost every editor also automatically indents code for you.
I'm a C++ dev myself, and in that language indentation is optional. However, since the editors will automatically indents code for you, that generally means that the brackets around e.g. functions are superfluous: you can just look at the indentation to see when a function ends.
Why? Nearly every styling convention in every language uses it anyway. Python just cuts out the middle man, reduces unnecessary syntax and makes indentation the go-to scope identifier.
You're still using indentation to make stuff readable anyway, might as well make it do some work.
See here you are wrong. I do not indent it. I put the curly squiggles around it and some magic genie aligns it nicely for me to read better. You got it the wrong way around.
Except well it doesn't. I want to copy past an if statement at the end of another if statement. How does formatter know whether to nest the statement or not?
Braced language, if you want the if statement nested, just paste it before the end brace. If you want it not nested, just paste it after. And if for some reason the tabs get pasted wonky, doesn't matter.
Python, you have to do the tabbing yourself before the magic genie can work.
Except well it doesn't. I want to copy past an if statement at the end of another if statement. How does formatter know whether to nest the statement or not?
Are you asking about something like this?
if thing_a: if thing_b: pass
Python absolutely allows you do do this, there's no syntactical problem here.
Code wise this isn't great practice though, so I would be asking you in code-review to justify why you're doing single-line nesting like this. Especially when it can logically collapse anyways.
if thing_a and thing_b: pass
But doing single-liners in python are usually reserved for self-contained statements like lambdas anyways because otherwise they often get abused to do squirrelly stuff that is better-off broken-out.
This set up, I just don't want to indent manually and don't have to in braced languages. Autoformatters are way more convenient in braced languages than Python
I have another comment in a different thread. It boils down to humans and computers just working differently. Reducing syntax is not always a good thing. If you truly want that, go program in assembly. Code is for humans to understand, so it needs to be designed to work best for humans. Humans need redundancy, abstraction, and explanations. It's why documentation and comments exist. Syntactic sugar isn't necessary, but languages are still of it. Every loop is just a while, but most languages have do-while and multiple types of for loop.
Forcing white space to have syntactic meaning is like making comments have effects. Imagine if there was a language where every function required comments at the beginning. The comments aren't optional, they are mandatory. Not only that, but the only way to set default values for parameters was in the comments.
Sure? But sometimes it is a good thing, and I haven't heard an argument yet that explains why tabs specifically being part of the syntax is a bad thing. We're already going out of our way to do it in the vast majority of cases. Why not kill two birds with one stone?
If you truly want that, go program in assembly.
I don't see the connection at all here to what I said. Assembly is the extreme end of human conforming to the machine.
Python is very much the opposite of that, where it is machine conforming to the human. I.e. the machine must read my formatting and natural logical statements which nearly resemble normal English sentences. Both of those things are a primary a benefit to me and are what the machine uses to perform static analysis.
White space is by definition invisible. We should not be giving invisible characters meaning. The whole tabs vs spaces debate is exactly why. You cannot tell the difference so it causes problems. If the code could be broken because you used the wrong invisible character, that's bad language design.
Making code indentation dependant also makes modifying the code to go to different levels a pain. Let's say you have code that you've already written. You want to make that code part of an if block. With braces, you just write the if statement and an open brace before the code and a closing braces at the end. If you want to adjust the indentation to match the new code, you just let the IDE automatically adjust the indentation. If the code is indentation dependent, you add the if statement at the beginning, then you have to go through the code and adjust the indentation yourself. Even if you can use the IDE to adjust the indentation, you need to check that the indentation is adjusted correctly.
Assembly is the extreme example of what a non-redundent language looks like. There are absolutely no instructions that exist purely as a synonym of a different instruction or to condense multiple instructions into one.
Python choosing indentation instead of braces just swaps which is important, not making it redundant. Making python with braces instead of indents would mean that you can still use indents making the code more redundant and easier to understand.
White space is by definition invisible. We should not be giving invisible characters meaning.
If that were true then we'd have no spaces between any keywords and symbols. No we can and should give value to whitespace, it is what delimits every meaningful token. You're making rookie mistakes and over-generalizations.
You have a preference for not using white space and that's fine, weird IMO, but fine; you have other languages to choose from that use less whitespace. But now you're making just-plain wrong statements about linguistic static analysis, though. lol
The value of whitespace is to separate non-whitespace characters from each other. There should be no difference between one space or two between words. If your going to deliberately misinterpret what I am saying, then there is no need to continue this conversation.
If your going to deliberately misinterpret what I am saying, then there is no need to continue this conversation.
You first said whitespace had no value then said it had value in delimiting. That's not me misrepresenting anything, it's me pointing out the fundamentally incorrect things you're suggesting and you indirectly admitting that you misspoke. It usually better to own up to your mistakes and move on but If you're going to get defensive about it, then I agree, there's no point in continuing this.
Honestly if LLMs didn't do everything now I'd say it's laborious minding the curly brackets, and having fights with colleagues over trailing brackets vs compact brackets. But who cares now code isn't for us any more :\
I genuinely can't use python because of this, I hate it. The language itself is great, but the fucking decision to use indentation just blows my mind. Well that, and the inconsistent library and having to use methods with __ prefix to work, and ... wait, maybe I dont like Python that much.
I don't like when the language forces me to do format my code how it wants to function. I can't arbitrarily break lines up and put them at arbitrary indentations to increase readability.
You can pretty arbitrarily break lines up with \, and arbitrary indentations really don't increase readability. Every time I've seen someone use weird indentation that wouldn't be valid in Python, it makes stuff harder to read.
Do you have an example of what you're thinking of that isn't legal syntax in Python.
I can’t think of a single time when arbitrary indentations have increased readability. In fact, at my company, we have auto-formatters that enforce the same indentation level that Python would require in every other bracketed language.
i’m mid-level and after also having worked with both (mixture of python, java, c++, typescript), i really don’t think python is harder to read because of its indentation. but to each their own!
the way the code is written / style matters much more imo. you can have really crappy java code with braces, and you can have really clean python with indentation.
I’ve never found it to be a problem tbh. I already indent the same way when working in languages that use brackets or whatever else.
Not sure what makes it harder to read tbh, I have my editor display vertical lines to show the current indentation level so maybe that’s why. If anything I find pairing brackets easier to mess up than indentation level but really I find both to be fine and of little consequence. The only thing that is annoying to me is someone doing weird and inconsistent formatting with brackets because brackets allow that to be possible.
I feel like every other time i copy a code block I end up having to hit the format button because of some weird text rendering shit where the tabs aren't copied, and having to do that manually is sometimes very annoying.
I 100% agree. The only reason I would ever use YAML over JSON is for comment support. The amount of times I've been off by one space or whatever, and the linter doesnt catch it, because its technically valid syntax for some older version. I fucking hate it.
I'm a senior backend-leaning full-stack engineer for the last 8 years and I mostly agree that whitespace languages are harder to read, but I code in Python the majority of the time and I can't remember the last time that whitespace affected me. The last time might have been looking through someone else's code who had a 200 line method with 3-4 levels of nested logic, but that was going to be an issue regardless of whitespace. When is the last time it has been am issue for you?
I imagine that you find leading whitespace confusing for the same reason that trailing whitespace can be found confusing and that's to be commended, but finding indented code harder to manually read is not the flex that you think it is
Ha-ha, remember, when we were studying 3d graphics basics, on the finish of the year we would present our programs. And used physical size of the monitor and resolution.
And profesor would literally take ruler and measure shapes dimensions on screen asking why it has such size.
Indentation should make it easier to read code, but shouldn't be needed for it to run properly. Refactoring indentation dependent code is my least favorite experience yet as a programmer, and I've used Fortran.
I remember a coworker that used different spacing for indentation, then one day something didn't work because we copied pasted a code. Oh my god what a wasted day.
440
u/tehdlp Oct 17 '26 •
Lies. I make the editor show whitespace then squint angrily.
76
u/ElectrSheep Oct 18 '26
This just shows the importance of using a proper editor. The interface in Word has a ruler already built in (not to mention tab stops).
212
u/CrimsonPiranha Oct 17 '26
Is it the time again? New cs majors finding out about this sub?
34
u/AzureArmageddon Oct 18 '26
All of your IDEs clearly suck.
62
u/chris240189 Oct 17 '26
Rainbow indent
42
u/Ange1ofD4rkness Oct 17 '26
Hope they didn't replace a tab with spaces
13
u/jirka642 Oct 17 '26
There is nothing like reading comments on r/ProgrammerHumor when it comes to getting rid of my impostor syndrome.
268
u/LetUsSpeakFreely Oct 17 '26 edited Oct 17 '26
Indentation is such a stupid mechanism for identifying code blocks. It's one thing for configuration files like YAML to do it, but not a programming language.
88
u/fly123123123 Oct 17 '26
more classic “i’m a new cs major” jokes
if you’re writing long enough methods that you can’t discern where the bodies start and end, you’re doing it wrong. refactor.
8
u/saf_e Oct 17 '26
Ha-ha, remember, when we were studying 3d graphics basics, on the finish of the year we would present our programs. And used physical size of the monitor and resolution.
And profesor would literally take ruler and measure shapes dimensions on screen asking why it has such size.
6
u/coldnitrogen Oct 17 '26
False. You need a vernier callipers for that
6
u/cturnr Oct 17 '26
ruff, or black, flake8.
or run and read errors...
4
u/snoopbirb Oct 17 '26
That's Bertha, our lint lady.
8
u/StickFigureFan Oct 17 '26
Indentation should make it easier to read code, but shouldn't be needed for it to run properly. Refactoring indentation dependent code is my least favorite experience yet as a programmer, and I've used Fortran.
6
u/SuperT0bi Oct 17 '26
I remember spending 4 hrs trying to find why my code wasn't working. One stupid single space....
2
u/sweatierorc Oct 17 '26
2
u/lachlanhunt Oct 17 '26
That's what it feels like working in a repo where the indentation convention is 2 spaces instead of 4.
2
u/Machine2024 Oct 18 '26
I have OCD and align my code perfectly .
But python code looks really bad I hate it and cant read it .
I prefer the code like C++ and PHP . is more readable and clear .
1
u/OperatingAsIntended Oct 17 '26
1
u/tatstytastycakes Oct 17 '26
summon prettier using the magic command and gain 500 mana
1
u/notyoou Oct 17 '26
Inches or Centimeters instead of Tabs or Spaces
1
u/ozfresh Oct 17 '26
1, 2, 3, 4
1
u/FlameableAmber Oct 17 '26
Ahh python you helped learn how to code but I never wish to see you ever again
1
u/christianbro Oct 17 '26
Cursing why it does not run while editing it with Notepad or a shitty text editor that breaks those
1
u/Anund Oct 17 '26
This is the human you're worried AI is replacing.
1
u/greenwhite7 Oct 17 '26
The main metric of the quality btw
1
u/Invisiblecurse Oct 17 '26
I do this when I develop printouts
1
u/Ambivalent-Mammal Oct 17 '26
It's worth it to avoid those mean old braces.
1
u/smallproton Oct 17 '26
This is such a fuckup of the python guys. As if fortran hadn't happened...
1
u/DecalageVersLeRouge Oct 17 '26
In every language which uses brackets, I can get an IDE to find (and select to) the matching bracket and instantly see if they don't match.
Is there a way to do that in Python?
1
u/geekosas Oct 18 '26
I remember a coworker that used different spacing for indentation, then one day something didn't work because we copied pasted a code. Oh my god what a wasted day.
1
u/Kat_Schrodinger1 Oct 18 '26
strategy game player here: how have yall not incorporated grid lines?
something like a toggleable overlay?
1
u/Alacritous13 Oct 18 '26
Bython fixes this.
1
u/Puzzleheaded-Weird66 Oct 18 '26
I vaguely remember notepad++ havung the option of showing the white space character represented by a different character
1
u/SneakyWineBoy Oct 18 '26
Can this still be a thing in the ai/ide era
1
u/Linkk_93 Oct 19 '26
My dumbass with ansible YAML files on a customer jump host with no good editor
1
u/kolloth Oct 17 '26
White space as scope has got to be one of the most brain dead language design decisions
-1
u/davejohncole Oct 18 '26
People who complain about indentation being significant in Python are just telling on themselves for being a bad programmer.
If your code has that much indentation then I never want to be unfortunate enough to have work with your code in any language.
-2
u/00--0--00- Oct 18 '26
Skill issue