Do you think I could just leave this part blank and it'd be okay? We're just going to replace the whole thing with a header image anyway, right?
You are not logged in.
Swarth100 wrote:HG wrote:Swarth100 wrote:HG wrote:
Real tabs instead of spaces
You know this will trigger a lot of people?
It's your fault for taking the wrong way from the beginning.
Tabs exist for a reason. To indent.
My question is simple: how many spaces to a tab?
Cause indented spaced code will always look the same. Tabbed code might differ given multiple authors.
8 spaces to a tab.
I mean I really don't want to get into a tabs vs space debate, as there is no end to those.
8 spaces to a tab make it quite hard for code to not go beyond the 80 char limit/margin.
Also I believe standards for C, C++, Java, Python and many other languages do not indent (by default) with 8 spaces.
Dunno, might just be me, but tabs cannot be sustained as a coding style on projects with multiple contributors.
This said, a proper repo also comes with a linter of some sort to be run, formatting code to a common standard before it is pushed.
Offline
Swarth100 wrote:HG wrote:Swarth100 wrote:HG wrote:
Real tabs instead of spaces
You know this will trigger a lot of people?
It's your fault for taking the wrong way from the beginning.
Tabs exist for a reason. To indent.
My question is simple: how many spaces to a tab?
Cause indented spaced code will always look the same. Tabbed code might differ given multiple authors.
8 spaces to a tab.
Anything more than 4 spaces per tab is just showing off.
"Sometimes failing a leap of faith is better than inching forward"
- ShinsukeIto
Offline
The number of spaces increases exponentially by the level of indentation you are at.
As it had been pointed out, you can edit the length of a tab.
The tab key was made specifically made for indentation so it makes sense to use it for indenting your code.
The source code files that use tabs are smaller in size.
You can parse the tabs faster than spaces.
// case closed
break;
Everybody edits, but some edit more than others
Offline
Different55 wrote:HG wrote:▼Swarth1008 spaces to a tab.
Anything more than 4 spaces per tab is just showing off.
Or you are used to using notepad as an IDE
I am sorry for your pain
Offline
About the tabs vs spaces thing:
I use the tab button on my keyboard (not spam space like a... nvm...), thought my IDEs (Visual Studio, Notepad++ and NetBeans) simply place 4 spaces instead of a "tab character". So I guess that generally speaking, there wouldn't be any big issues, if the IDE is set up correctly for the project.
I btw also use shift-tab to un-indent, so that's not a problem either.
Offline
Mostly these for C#: https://msdn.microsoft.com/en-us/library/ff926074.aspx
I have never thought of programming for reputation and honor. What I have in my heart must come out. That is the reason why I code.
Offline
It's fairly apparent the majority of people posting here are most familiar with the C# language, in which I personally follow 1TBS rather than the default Allman style within Visual Studio.
I'd highly recommend following the adage, "When in Rome, do as the Romans do." however, when contributing to projects that aren't your own, with your code style closely resembling theirs.
I've recently grown a preference towards languages with syntax similar to Python, with conventions akin to PEP8 with a few minor trivial differences throughout.
I've become aware of the benefits static typing has for initial readability in comparison to dynamic typing, which a well designed and intuitive structure alleviates.
It's always been an utmost importance for me to develop and seek cleanliness in my projects, especially the ones I've published.
I've slowly started to get a grasp on consistency surrounding verb/noun usage in naming, which is, as well, too often overlooked.
As part of my continued learning of Python, I had fully ported a few basic projects from C# to Python. I'll let the source code speak for itself.
A random pronounceable word generator for memorable link shortener generation.
A lexer, parser and interpreter for the functional scripting language heavily inspired by Furcadian DragonSpeak. DragonSpeak.NET and PythonSpeak.
*u stinky*
Offline
I like indents
I hate indents defining the route of the code, I looked at Python after I started with C# and everything working on indents just seems cluttered; I just like brackets so I know that it wont break because of formatting.
Thank you eleizibeth ^
I stack my signatures rather than delete them so I don't lose them
Offline
Swarth100 wrote:▼HGMy question is simple: how many spaces to a tab?
Cause indented spaced code will always look the same. Tabbed code might differ given multiple authors.
Thats the advantage of tabs, the user can change how they look based on preference, with spaces you would need to use a find and replace if you wanted it to look different, and that could break things if multiple spaces are used in strings, with tabs you can just go into settings and change the size, and then it will automatically change the look of all tabbed text documents to your liking
Also, to answer the question: I usually use 2 spaces to a tab, because I like to program things while having multiple windows open, so like to keep the code as narrow as possible, while still being easy to read
Again, my only concern is how you ensure that every single contributor will use tabs.
If even just one of them uses tabs, and the IDE you use isn't set up as everyone else's the code won't be formatted.
If you use github or gitlab you will have to modify the configuration files of the repo to make sure tab size is rendered properly.
You will need to run a linter to format your code before you push it, making sure that not even a single space is present by mistake.
There is a significant problem for code that wraps beyond the 80 char right margin. How can that be handled nicely?
I don't want to sound picky or anything, but really do yourself (and future project co-workers) a favor and map your tabs to spaces.
Also remap your CapsLock to Ctrl, but that's a different topic.
About the tabs vs spaces thing:
I use the tab button on my keyboard (not spam space like a... nvm...), thought my IDEs (Visual Studio, Notepad++ and NetBeans) simply place 4 spaces instead of a "tab character". So I guess that generally speaking, there wouldn't be any big issues, if the IDE is set up correctly for the project.
I btw also use shift-tab to un-indent, so that's not a problem either.
Tab places the indent level of spaces. Shift+Tab removes said amount of spaces.
Offline
XxAtillaxX wrote:I like indents
I hate indents defining the route of the code, I looked at Python after I started with C# and everything working on indents just seems cluttered; I just like brackets so I know that it wont break because of formatting.
Isn't the very definition of clutter that of which is unneeded and excessive? I think that would apply much more towards curly brackets as opposed to indents.
I'm sure there's still plenty of misconceptions and outright falsehoods regarding Python. I have yet to make a single mistake as a result of improper indentation, even despite my lack of experience.
*u stinky*
Offline
(In reply to Swarth100)
The same thing could be said for spaces couldnt it? How can you ensure that everyone will use them, if one person uses tabs, then that formatting may not be correct if all of the IDEs are not formatted the same
Tabs are specifically for indenting, so why not use them?
Offline
Koya wrote:XxAtillaxX wrote:I like indents
I hate indents defining the route of the code, I looked at Python after I started with C# and everything working on indents just seems cluttered; I just like brackets so I know that it wont break because of formatting.
Isn't the very definition of clutter that of which is unneeded and excessive? I think that would apply much more towards curly brackets as opposed to indents.
I'm sure there's still plenty of misconceptions and outright falsehoods regarding Python. I have yet to make a single mistake as a result of improper indentation, even despite my lack of experience.
Curly brackets are like hugs in your code that make sure things stay in place and stops potential confusion.
Thank you eleizibeth ^
I stack my signatures rather than delete them so I don't lose them
Offline
Curly brackets are like hugs in your code that make sure things stay in place and stops potential confusion.
I think they are unnecessary in modern times, with the small benefit of readability being easily replicable with a well-designed structure in Python.
I much prefer cleanliness with formatting code rather than unnecessary delimiters to chunk things together.
*u stinky*
Offline
Koya wrote:Curly brackets are like hugs in your code that make sure things stay in place and stops potential confusion.
I think they are unnecessary in modern times, with the small benefit of readability being easily replicable with a well-designed structure in Python.
I much prefer cleanliness with formatting code rather than unnecessary delimiters to chunk things together.
Can definitely respect that viewpoint. It might be that the person teaching me Python at school was learning it at the same time and only knew COBOL so I have negative connotations with Python and anything Python-like.
Thank you eleizibeth ^
I stack my signatures rather than delete them so I don't lose them
Offline
Offline
Is Bots and Programming the foreign language thread? I have no idea what's going on.
Is Bots and Programming the foreign language thread? I have no idea what's going on.
We're just talking how we format our code. So where/how we use certain things, like how we capitalize stuff (variables in CamelCase, or pascalCase).
Regarding the indentation "Python-wise vs curly brackets":
What can I say... I like the best of both world.
Generally speaking, everything in my code is indented Pythoin-wise, just exceptions (like long if-statements, which I span over multiple lines) would break, if C#/Java dropped the curly brackets.
Offline
(In reply to Swarth100)
The same thing could be said for spaces couldnt it? How can you ensure that everyone will use them, if one person uses tabs, then that formatting may not be correct if all of the IDEs are not formatted the same
Ehmm,.... that's why nobody ever uses the tab '\t' character when indenting code.
Hopeless discussion, one day you will understand.
Do you want a quick example?
Cheeck out lines 150-154, 159-161 and 163-167.
This amazing team mate decided to indent using tabs. His IDE made him visualise tabs with an indent level of 2.
Too sad gitlab (if not configured differently) visuaises tabs as 8 spaces.
Result? Unreadable code that had to be forcepushed upon.
Offline
destroyer123 wrote:(In reply to Swarth100)
The same thing could be said for spaces couldnt it? How can you ensure that everyone will use them, if one person uses tabs, then that formatting may not be correct if all of the IDEs are not formatted the same
Ehmm,.... that's why nobody ever uses the tab '\t' character when indenting code.
Hopeless discussion, one day you will understand.Do you want a quick example?
▼Code from my Pintos group RepoCheeck out lines 150-154, 159-161 and 163-167.
This amazing team mate decided to indent using tabs. His IDE made him visualise tabs with an indent level of 2.
Too sad gitlab (if not configured differently) visuaises tabs as 8 spaces.Result? Unreadable code that had to be forcepushed upon.
Tabs or spaces, you get the same problem: If the IDE's aren't setup correctly, you'll get stuff like that.
When using tabs, make sure your IDE doesn't reformat them into spaces.
When using spaces, make sure you use the same amount of spaces.
I actually had one guy in a project that always auto-formatted his code (he first wrote barely indented code *shudders* and then let VS auto-indent it for him), and he used 2 space indentation while the rest used 4 (he also put brackets on EOL while the rest used NL).
Conclusion: IDE not set up correctly: you'll alwaysget the same git problems (unless setting up the git correctly, but in my experience that's more trouble than changing a couple IDE settings).
Offline
Wasn't this thread for simply stating your coding style, and not arguing about something entirely subjective and case-specific?
My style's pretty simple for C languages. "CamelCase" for class and struct names, but "camelCase" for all variables and method names. Brackets as follows:
if (something) singleLine(...);
if (something)
{
multipleLines();
...
}
Curly brackets go on their own line unless there's nothing inside them. The IDE handles my indents - as long as they're not tiny or massive I'm fine with them.
One bot to rule them all, one bot to find them. One bot to bring them all... and with this cliché blind them.
Offline
One advantage of using curly brackets is that it is easier to have empty code blocks, which things like python dont seem to like (im not really sure why... but im guessing that there is a reason)
While I totally don't see the point in having empty code blocks, I wanted to put out for the record that in Python you have the "pass" keyword which does absolutely nothing but letting you just do that.
def hello():
pass
Everybody edits, but some edit more than others
Offline
destroyer123 wrote:One advantage of using curly brackets is that it is easier to have empty code blocks, which things like python dont seem to like (im not really sure why... but im guessing that there is a reason)
While I totally don't see the point in having empty code blocks. I wanted to put out for the record that in Python you have the "pass" keyword which does absolutely nothing but letting you make empty code blocks.
def hello(): pass
Oh ok, I guess that I didnt use python enough to be bothered to find a way to do it
Here are the uses ive had:
Its useful for testing, e.g. if you comment out the inside of a code block to see if that is what is causing problems
Sometimes you can do everything you need to do within the while condition, e.g. when making a maze generator, ive had something like this:
while (!Generate()) { }
where Generate is a function which returns true when it has finished
Sometimes I find it useful to lay out all of the possible outcomes of an if in empty code blocks before ive actually written whats needed inside, with comments describing what needs to happen, just so I can remember exactly what I have to do next
Offline
Here are the uses ive had:
Its useful for testing, e.g. if you comment out the inside of a code block to see if that is what is causing problems
Sometimes you can do everything you need to do within the while condition, e.g. when making a maze generator, ive had something like this:
while (!Generate()) { }
where Generate is a function which returns true when it has finished. I don't think ending up with such code in production is a good idea. You'd better replace it with async/await pattern or with an event.
Sometimes I find it useful to lay out all of the possible outcomes of an if in empty code blocks before ive actually written whats needed inside, with comments describing what needs to happen, just so I can remember exactly what I have to do next I this is the exact reason pass keyword exists. pass(fr. to refrain from something)
Everybody edits, but some edit more than others
Offline
destroyer123 wrote:while (!Generate()) { }
where Generate is a function which returns true when it has finished.
I don't think ending up with such code in production is a good idea. You'd better replace it with async/await pattern or with an event.
Oh, this wasnt a multiple thread thing, in this example, Generate made the generator perform one step of the maze generation algorithm. I think I had a step by step generation option, as well as the one where it just generated completely (the example), which is why I couldnt just have the loop in the Generate function
Offline
[ Started around 1732682815.7422 - Generated in 0.156 seconds, 12 queries executed - Memory usage: 1.93 MiB (Peak: 2.26 MiB) ]