Indent equals how many spaces
Case 1 If two spaces are used before both the print statement then result is fine Case 2 If one tab is used before both the print statement then again result is ok Case 3 If one tab is used for one print statement and 2 spaces are used to another print statement then result is throwing error. When using a hanging indent the following should be considered; there should be no arguments on the first line and further indentation should be used to clearly distinguish itself as a continuation line.
Found this in the Python Style Guide :. Python 2 code indented with a mixture of tabs and spaces should be converted to using spaces exclusively. When invoking the Python 2 command line interpreter with the -t option, it issues warnings about code that illegally mixes tabs and spaces. When using -tt these warnings become errors.
These options are highly recommended! A single tab may or may not be 2 or 4 spaces, by default it varies from editor or the environment being used, there are also options to set the spaces in tabs, in settings or preferences. So, it depends on the editor or environment used. Is this the case? The only leading space characters precede the Books lines, because this is literal text content, not code, these space characters must be preserved. With virtual formatting you choose the indentation width to suit the environment and indentation style without affecting any characters in the source file.
You can even set the indentation width to 0, if you need a flattened view of the code as shown below:. To contrast this with space character formatting, the same XSLT opened in an editor without virtual formatting is transformed by that editor's auto-formatter to this:.
The larger blank yellow blocks in the screenshot above clearly show the space characters added by the formatter of the conventional editor. Unfortunately, these now can't be distinguished from real content so the XSLT would have to be modified to correct this issue.
XSLT is possibly an extreme case, but this principle holds true for many programming languages: Characters should be used for content and an alternative method sought when it comes to formatting. Not mentioned until now: There are languages Python, Haskell where indentation matters.
But 1 character counts as 1 character, be it a space or a tab so the indentation seen by the compiler may not be the same one you see on the screen if you use tabs. Therefore, in languages like Haskell, spaces are a must. In all others, it's a matter of personal taste and nowadays not a great deal - every decent editor has a " leading tabs to spaces" and " leading spaces to tabs" command. I used to use spaces, but I've been using tabs lately purely because that's what Eclipse was set to when I finally noticed.
All of the other developers on my team use Eclipse, so it made sense to standardise on tabs when we realised we'd already been using them for ages and there was no reason to bother changing to spaces. I've been surprised by how much of a non-issue it has been. Setting the displayed tab size to 3 or 5 characters in your IDE greatly simplifies distinguishing between code sections that are indented by spaces almost always 4 these days and those that are indented by tab.
Plenty of arguments have been given already, but nobody mentioned where we could be headed in the future. Ideally code should be considered data, and not be stored in any specific text formatting. Any developer can apply his own preferred view. Furthermore, this view shouldn't be limited to just text , but can include tables, color pickers and mathematical formulas.
This idea isn't too far-fetched. Yes this is possible with editor plugins, but working on text directly adds so many unnecessary complexities, as opposed to the approach MPS takes. As opposed to tabs and spaces, there are little disadvantages which can be mentioned for working directly on abstract syntax trees.
All that is needed is for the technology to mature to a commercially viable product. The first signs of this are showing up.
Largely built upon MPS, a commercial actionscript editor, Realaxy was created. I'd love to see one of the big players jump on the concept of this technology and see what happens! If you are a team of one, pick whatever you personally like. Consider what the default behavior of your favorite editor, but pick whatever you like. In my various jobs I've used two spaces, four spaces, eight spaces, tabs, spaces-and-tabs, I think I may have also used one space.
I tell my editor what to do then I don't think about it again, the editor works out the details. The only other thing is to make sure you pick a smart editor. Emacs or vi? Now that's a holy war I'm willing to fight Sign up to join this community. The best answers are voted up and rise to the top. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams?
Learn more. Tabs versus spaces—what is the proper indentation character for everything, in every situation, ever? Asked 11 years, 2 months ago. Active 9 years, 8 months ago. Viewed k times. Read this first — finnw. Whatever you choose, it must be used by the whole team but not when one uses tabs others spaces. The edit was removed, but hopefully this comment will remain: Instead of indentation characters, why not use the left-margin instead?
I really don't think there should be an "accepted" answer here. The fact the the answer with fewer votes is actually first is testament to that: why should the asker get a special power i. Active Oldest Votes. Spaces A tab could be a different number of columns depending on your environment, but a space is always one column. Your second paragraph is wrong; the answer is 4!
Daenyth - perhaps if you are using a curly-brace language. Everyone can set it to his taste and be happy. Show 8 more comments. Tabs Now, of course, consistency matters more than either one, and a good IDE makes the differences negligible. That said, the point of this thread is to be a holy war, so: I prefer tabs: They're a character specifically meant for indentation They allow developers with different preferences in indentation size to change how it's the code looks without changing the code separation of data and presentation for the proverbial win!
It's impossible to half-indent something with tabs. So when you copy code from some website that used 3 spaces into your 4-space indented file, you don't have to deal with misalignment. What about copying that 3-space indented code into your tab-indented file, which you have set your tabs to 3 spaces?
When you send your code to your compatriots they wonder why that function has such bad indentation! Tabs are not originally meant for indentation, they are meant for tabulation , and do a dreadful job at it Timwi: Wikipedia seems to say that they are meant for moving the cursor to the next of a set of fixed columns.
Doesn't sound like tabulation was the primary function. Also, I was referring to the post-typewriter era. Check for yourself. Another benefit of this approach - fewer keypresses when using arrow keys for left-right navigation. Show 13 more comments. Peter Boughton. Yes yes yes yes yes. One hundred percent yes. This lets everyone set their own tab width while preserving tabular formatting.
If you're worried about keeping within 80 columns as you probably should be! Honestly, is this so difficult? Yes, but don't use spaces to line up within a line.
Your colleagues may be using a proportional font so your ASCII art is going to look weird on their screens. Add a comment. Tabs allow mistakes to be more noticeable , it's annoying to micro manage to spaces. Spaces should be used where tabs are completely useless. Perhaps that you need to upgrade :p? MaR: Noticable mistakes is true, the width of a tab is larger.
Tabs are consistent as a single Tab is an indentation, while you otherwise have to define how many spaces you will use for an indentation. Customization is an advantage. You are using tabs in the first place, so it's more productive. Seems you can't even give a good reasoning why it is impractical, haters gonna hate Optional: Download our practice document. Watch the video below to learn more about how to use indents and tabs in Word.
In many types of documents, you may want to indent only the first line of each paragraph. This helps to visually separate paragraphs from one another. It's also possible to indent every line except for the first line , which is known as a hanging indent. A quick way to indent is to use the Tab key. If you can't see the Ruler, select the View tab, then click the checkbox next to the Ruler.
In some cases, you may want to have more control over indents.
0コメント