Official Everybody Edits Forums

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.

#26 2017-04-24 17:22:50

Swarth100
Member
Joined: 2015-07-18
Posts: 305

Re: So what's your coding style?

HG wrote:
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

#27 2017-04-24 17:32:28

Different55
Forum Admin
Joined: 2015-02-07
Posts: 16,575

Re: So what's your coding style?

HG wrote:
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

Wooted by: (5)

#28 2017-04-24 18:39:59

LukeM
Member
From: England
Joined: 2016-06-03
Posts: 3,009
Website

Re: So what's your coding style?

Different55 wrote:
HG wrote:
Swarth100

8 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

Offline

Wooted by:

#29 2017-04-24 19:29:45, last edited by Zumza (2017-04-24 19:31:21)

Zumza
Member
From: root
Joined: 2015-02-17
Posts: 4,656

Re: So what's your coding style?

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

Wooted by:

#30 2017-04-24 20:11:17

Swarth100
Member
Joined: 2015-07-18
Posts: 305

Re: So what's your coding style?

destroyer123 wrote:
Different55 wrote:
HG wrote:
Swarth100

8 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

Wooted by:

#31 2017-04-24 23:50:25

den3107
Member
From: Netherlands
Joined: 2015-04-24
Posts: 1,025

Re: So what's your coding style?

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

#32 2017-04-25 11:35:26

Processor
Member
Joined: 2015-02-15
Posts: 2,246

Re: So what's your coding style?


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

#33 2017-04-26 13:10:21

XxAtillaxX
Member
Joined: 2015-11-28
Posts: 4,202

Re: So what's your coding style?

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.

C#
Python

A lexer, parser and interpreter for the functional scripting language heavily inspired by Furcadian DragonSpeak. DragonSpeak.NET and PythonSpeak.


signature.png
*u stinky*

Offline

Wooted by:

#34 2017-04-26 16:31:08

Koya
Fabulous Member
From: The island with those Brits
Joined: 2015-02-18
Posts: 6,310

Re: So what's your coding style?

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.


Po9cnQh.png

PLNQVL8.png
Thank you eleizibeth ^

1SYOldu.png

I stack my signatures rather than delete them so I don't lose them
giphy.gif

WfSi4mm.png

Offline

Wooted by: (4)

#35 2017-04-26 18:02:10, last edited by Swarth100 (2017-04-26 18:08:19)

Swarth100
Member
Joined: 2015-07-18
Posts: 305

Re: So what's your coding style?

destroyer123 wrote:
Swarth100 wrote:
HG

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.

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.

den3107 wrote:

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

#36 2017-04-26 19:08:47, last edited by XxAtillaxX (2017-04-26 19:11:11)

XxAtillaxX
Member
Joined: 2015-11-28
Posts: 4,202

Re: So what's your coding style?

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.


signature.png
*u stinky*

Offline

Wooted by:

#37 2017-04-26 19:12:04, last edited by LukeM (2017-04-26 19:15:05)

LukeM
Member
From: England
Joined: 2016-06-03
Posts: 3,009
Website

Re: So what's your coding style?

(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

#38 2017-04-26 19:38:39

Koya
Fabulous Member
From: The island with those Brits
Joined: 2015-02-18
Posts: 6,310

Re: So what's your coding style?

XxAtillaxX wrote:
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.


Po9cnQh.png

PLNQVL8.png
Thank you eleizibeth ^

1SYOldu.png

I stack my signatures rather than delete them so I don't lose them
giphy.gif

WfSi4mm.png

Offline

Wooted by:

#39 2017-04-26 19:57:34

XxAtillaxX
Member
Joined: 2015-11-28
Posts: 4,202

Re: So what's your coding style?

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.


signature.png
*u stinky*

Offline

#40 2017-04-26 20:15:30

Koya
Fabulous Member
From: The island with those Brits
Joined: 2015-02-18
Posts: 6,310

Re: So what's your coding style?

XxAtillaxX wrote:
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.


Po9cnQh.png

PLNQVL8.png
Thank you eleizibeth ^

1SYOldu.png

I stack my signatures rather than delete them so I don't lose them
giphy.gif

WfSi4mm.png

Offline

#41 2017-04-26 20:37:12, last edited by LukeM (2017-04-26 20:38:11)

LukeM
Member
From: England
Joined: 2016-06-03
Posts: 3,009
Website

Re: So what's your coding style?

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)

Offline

#42 2017-04-27 00:05:08

Abelysk
Guest

Re: So what's your coding style?

Is Bots and Programming the foreign language thread? I have no idea what's going on.

Wooted by:

#43 2017-04-27 00:43:49

den3107
Member
From: Netherlands
Joined: 2015-04-24
Posts: 1,025

Re: So what's your coding style?

Abelysk wrote:

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

#44 2017-04-27 11:07:56, last edited by Swarth100 (2017-04-27 11:18:04)

Swarth100
Member
Joined: 2015-07-18
Posts: 305

Re: So what's your coding style?

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 Repo

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

#45 2017-04-27 12:15:54

den3107
Member
From: Netherlands
Joined: 2015-04-24
Posts: 1,025

Re: So what's your coding style?

Swarth100 wrote:
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 Repo

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.

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

#46 2017-04-27 14:45:57

Tomahawk
Forum Mod
From: UK
Joined: 2015-02-18
Posts: 2,847

Re: So what's your coding style?

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

#47 2017-04-27 21:07:14, last edited by Zumza (2017-04-27 21:13:39)

Zumza
Member
From: root
Joined: 2015-02-17
Posts: 4,656

Re: So what's your coding style?

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 just do that.

def hello():
    pass

Everybody edits, but some edit more than others

Offline

#48 2017-04-27 21:18:22, last edited by LukeM (2017-04-27 21:19:56)

LukeM
Member
From: England
Joined: 2016-06-03
Posts: 3,009
Website

Re: So what's your coding style?

Zumza wrote:
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

#49 2017-04-27 21:58:43

Zumza
Member
From: root
Joined: 2015-02-17
Posts: 4,656

Re: So what's your coding style?

destroyer123 wrote:

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

#50 2017-04-27 22:39:33, last edited by LukeM (2017-04-27 22:40:03)

LukeM
Member
From: England
Joined: 2016-06-03
Posts: 3,009
Website

Re: So what's your coding style?

Zumza wrote:
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

den31071493468817657283

Board footer

Powered by FluxBB

[ Started around 1732681941.2111 - Generated in 0.365 seconds, 13 queries executed - Memory usage: 1.93 MiB (Peak: 2.26 MiB) ]