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.

#1 2017-04-24 01:20:49

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

So what's your coding style?

Just a place where people can discuss the title, if they'd like.

Think CammelCase or not for variables and methods, braces on nl or eol, yes or no braces on single line (if-)statements (or just move straight over to a conditional operator).

Please do mind we want to keep this thread friendly, most likely there's no right or wrong

Offline

#2 2017-04-24 01:48:25

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

Re: So what's your coding style?

if (condition)
{
    multiple();
    lines();
}

if (condition)
    single_line();


"Sometimes failing a leap of faith is better than inching forward"
- ShinsukeIto

Offline

Wooted by: (2)

#3 2017-04-24 01:51:21, last edited by hummerz5 (2017-04-24 01:51:41)

hummerz5
Member
From: wait I'm not a secret mod huh
Joined: 2015-08-10
Posts: 5,853

Re: So what's your coding style?

I've been recently indoctrinated in the world of Java, so Classes, localVariables, MethodNames... CONSTANT_IDENTIFIERS, I suppose I'd just apply those to other places, regardless as to whether or not the language generally approves of that.

My braces are whatever the editor wants me to do... VS I think has me doing brace gets its own line, IntelliJ sticks it at the end of the conditional line.

how about those one-line conditional "blocks" what are those called? Where you do the if w/o actually following it up with a block? yeah I don't roll with those

edit: yeah, what diff did the second time. no.

Offline

#4 2017-04-24 02:28:41, last edited by Vinyl Melody (2017-04-24 02:28:52)

Vinyl Melody
Formerly BananaMilkShake
Joined: 2016-06-19
Posts: 616

Re: So what's your coding style?

if(conditon) {
    multiple();
    functions();
}

if(condition)
    function();

var b1=true, b2=true, b3=true;

And also squeeze everything if possible, so rather than

if(variable == "yes") {
    function();
}

it's

if(variable=="yes")
    function();

Also, slight abuse of #region to make things a bit tidy (but //--\\ , <!--[]--> and --[[]]-- on VS Code when working on JS/HTML/CSS/LUA/LUA+Fake XML)


cb0de83627.png
Thanks to: Ernesdo (Current Avatar), Zoey2070 (Signature)

Very inactive, maybe in the future, idk.

Offline

#5 2017-04-24 02:31:35

John
Member
Joined: 2019-01-11
Posts: 2,011

Re: So what's your coding style?

I like to have { and } on new lines because it is easier for me to read. careful you dont want to trigger HG


PW?scale=2

Offline

#6 2017-04-24 03:00:08

hummerz5
Member
From: wait I'm not a secret mod huh
Joined: 2015-08-10
Posts: 5,853

Re: So what's your coding style?

Vinyl Melody wrote:

And also squeeze everything if possible, so rather than

if (condition){ multiple(); lines(); } var b1=true, b2=true, b3=true; if (condition2){ singleLine(); }

I mean if we use your argument, then we should probably minify.. :b

idk. My biggest qualm with that is when I want to add code inside the condition response. Then I have to add the braces anyway! D:

Offline

Wooted by:

#7 2017-04-24 03:26:01

Xfrogman43
Member
From: need to find a new home
Joined: 2015-02-15
Posts: 4,174

Re: So what's your coding style?

if()
{
}


zsbu6Xm.png thanks zoey aaaaaaaaaaaand thanks latif for the avatar

Offline

#8 2017-04-24 04:05:14

mrjawapa
Corn Man ๐ŸŒฝ
From: Ohio, USA
Joined: 2015-02-15
Posts: 5,840
Website

Re: So what's your coding style?

hummerz5 wrote:

if (condition){ multiple(); lines(); } var b1=true, b2=true, b3=true; if (condition2){ singleLine(); }

this bothers me a lot.


Discord: jawp#5123

Offline

#9 2017-04-24 05:29:59

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

Re: So what's your coding style?

I usually follow the style guides of the specific language / project I'm using.


Everybody edits, but some edit more than others

Offline

#10 2017-04-24 08:01:32, last edited by LukeM (2017-04-24 08:09:58)

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

Re: So what's your coding style?

If in notepad++ then I do this:
if (expression) {
  Thing();
} else if (expression) {
  Thing();
} // Tabs with a size of 2

And if I'm in VS, I do this:
if (expression)
{
    Thing();
}
else if (expression)
{
    Thing();
} // Tabs with a size of 4

I'm not sure why I do it differently...

Also:
functions: DoSomething()
variables: storeSomething
unless it contains something that stands for something:
worldIDthingHere
IDofTheWorld

if (oneLiner) doSomething();
if (oneLiner && longerThan("about half the page"))
  PutOnNewLine("do it again if neccisary", true
    "indent inside brackets", true,
    "more lines here");

Offline

#11 2017-04-24 08:22:50, last edited by Swarth100 (2017-04-24 14:19:16)

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

Re: So what's your coding style?

- Avoid { } for oneline conditionals
- Segment code in chunks for different sections
- Inline if when possible
- Header files must contain all exposed function declarations without variable names
- .c file code must be heavily documented
- I always use multiline comments. I use single '//' for commented out code, so it's easy to lookfor and replace when committing some code.

Offline

#12 2017-04-24 09:58:03, last edited by Gosha (2017-04-24 10:00:07)

Gosha
Member
From: Russia
Joined: 2015-03-15
Posts: 6,211

Re: So what's your coding style?

if(stuff == true)
{
    return true;
}
else
{
    return false;
}

hypermind code over here

Offline

#13 2017-04-24 10:35:09

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

Re: So what's your coding style?

Gosha wrote:

if(stuff == true)
{
    return true;
}
else
{
    return false;
}

hypermind code over here

mind-blowing-amazing-awesome-random-facts-1024x1024.jpg

Offline

Wooted by: (2)

#14 2017-04-24 11:31:49

kubapolish
Banned
From: ฬฬฬฬฬฬฬฬฬฬฬฬฬฬฬฬฬฬฬฬฬฬฬฬฬฬฬฬฬฬ
Joined: 2015-02-19
Posts: 1,024
Website

Re: So what's your coding style?

Gosha wrote:

if(!!stuff != !true)
{
ย  ย  return !!!false;
}
else
{
ย  ย  return !false;
}

ftfy


โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ

Offline

#15 2017-04-24 13:26:27

Gosha
Member
From: Russia
Joined: 2015-03-15
Posts: 6,211

Re: So what's your coding style?

I think you made it too complicated!!!

i think it should like this:


var logic = 0;
goto checker;
answer1:
return stuff;
answer2:
return !stuff;
answer3:
throw new BoolenEqualsToZeroException();
checker:
if(stuff == true)
{
    logic = logic + Math.Pow(logic,0);
}
else if(stuff == false)
{
   logic = logic + 2 - 4;
}
else 
{
   logic = logic + logic * logic + (logic - logic);
}

if(logic > 0)
{
    goto answer1;
}
else if(logic < 0)
{
   goto answer2;
}
else 
{
   goto answer3;
}

ezpz

Offline

Wooted by:

#16 2017-04-24 13:30:01, last edited by den3107 (2017-04-24 13:35:19)

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

Re: So what's your coding style?

hummerz5 wrote:

I've been recently indoctrinated in the world of Java, so MethodNames...

Methods in Java are actually ALWAYS pascalCase.
In C# it's (most of the time, not sure what's "official") CamelCase for public methods/variables, and pascalCase for private ones.

My classmates generally dislike conditional operators ("1 < 2 ? true : false"). And I do too, except when they help me remove variables or duplication.

example

I also prefer tabs to be 4 spaces, in whatever language (I noticed PHP, JS, HTML and CSS are commonly written with 2 space indentation).

Gosha wrote:
if(stuff == true)
{
    logic = logic + Math.Pow(logic,0);
}
else if(stuff == false)
{
   logic = logic + 2 - 4;
}
else 
{
   logic = logic + logic * logic + (logic - logic);
}

But... But... That's not a PLSQL/MySQL/whatever procedure or anything, so HOW!? :c

Offline

Wooted by:

#17 2017-04-24 13:48:46, last edited by drunkbnu (2017-04-24 13:49:25)

drunkbnu
Formerly HG
Joined: 2017-08-16
Posts: 2,306

Re: So what's your coding style?

  • Opening braces at end of line instead of new line

  • Lambda expressions instead of delegates

  • Statements that run only one method don't use braces

  • string.Format instead of string concatenation

  • switch instead of if for long statements

  • Space before opening parenthesis

  • Real tabs instead of spaces

Offline

#18 2017-04-24 14:17:38

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

Re: So what's your coding style?

HG wrote:
  • Real tabs instead of spaces

You know this will trigger a lot of people?

Offline

#19 2017-04-24 14:28:57

drunkbnu
Formerly HG
Joined: 2017-08-16
Posts: 2,306

Re: So what's your coding style?

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.

Offline

Wooted by: (4)

#20 2017-04-24 14:37:51, last edited by Zumza (2017-04-24 14:44:04)

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

Re: So what's your coding style?

Swarth100 wrote:
HG wrote:
  • Real tabs instead of spaces

You know this will trigger a lot of people?

Felling triggered already.



HG wrote:
  • Opening braces at end of line instead of new line

  • Lambda expressions instead of delegates

  • Statements that run only one method don't use braces

  • string.Format instead of string concatenation

  • switch instead of if for long statements

  • Space before opening parenthesis(not on functions calls tho) I'd say spaces between any keyword or operator

  • Real tabs instead of spaces

This list is quite good and I'd say we should complete it with more good stuff.



I'll add:

  • Splitting a line in 2 if it takes too much space

  • Nesting avoidance

E.g. I've seen a lot of people that do:

connection.OnMessage += (sender, message) => {
     if (message.Type == "say") {
          <things>
     }
}; 
CONTENT WARNING

This is how it should be done:

connection.OnMessage += (sender, message) => {
     if (message.Type != "say") return;
     <things>
};

Nesting avoidance


Everybody edits, but some edit more than others

Offline

#21 2017-04-24 15:10:59

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

Re: So what's your coding style?

HG wrote:
  • Real tabs instead of spaces

I actually prefer spaces because they allow me to sub-indent, without having spaces and tabs mixed together everywhere (I think we all can agree that tabs and spaces mixed is the worst kind).

Why sub-indent?
HG wrote:

It's your fault for taking the wrong way from the beginning.

Plenty of IDE's actually default to using spaces instead of tabs. And plenty of the before mentioned plenty, don't even have an option to switch to tabs instead of spaces.
I think the main reason for this is because tab size can differ per system, making some indented stuff a bit strange (namely in complex comments (which, for example, explains how a complex formula works)).

Zumza wrote:

I'll add:

  • Nesting avoidance

connection.OnMessage += (sender, message) => {
     if (message.Type != "say") return;
     <things>
};

I'd actually still be quite triggered with that code (not related to nesting avoidance in general).

You generally want to keep your methods single-purpose.
You currently did two things in that method though: Attaching event handlers AND processing those events.
If you'd attach more event handlers, you do even more stuff in that single method.

Besides: By using a method, you can also simulate events easily, by calling the event handling method. Which in turn could help make some specific things easier to make and reduce code duplication (I must admit I haven't had any need for simulation with EE bots, though I have with Unity).

Also: Nesting avoidance wouldn't, theoretically, reduce cyclomatic complexity (by much). Though our brains would commonly find it easier to read since they can eliminate paths more easily.


Does anybody btw use comment documentation (like javadoc in Java) in their personal projects?

Offline

Wooted by:

#22 2017-04-24 15:14:11, last edited by Zumza (2017-04-24 16:21:02)

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

Re: So what's your coding style?

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.

Looking at you reminds me of this:

den3107 wrote:
Zumza wrote:
connection.OnMessage += (sender, message) => {
     if (message.Type != "say") return;
     <things>
};

I'd actually still be quite triggered with that code (not related to nesting avoidance in general). It's an example to show what I mean by nesting avoidance. I don't recommend anybody to use such a thing for actual message handling.

You generally want to keep your methods single-purpose. This is a good thing to add on the list.

Also: Nesting avoidance wouldn't, theoretically, reduce cyclomatic complexity (by much). Though our brains would commonly find it easier to read since they can eliminate paths more easily.
It does actually remove a lot of nesting when you intend to put multiple checks in the same method. So check A only if A is true go to step B, only if step B is true etc. I've seen a lot of newbies that end up this scenario in if { if { if { etc }}}


Everybody edits, but some edit more than others

Offline

#23 2017-04-24 17:14:11

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

Re: So what's your coding style?

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.

Offline

#24 2017-04-24 17:16:50

drunkbnu
Formerly HG
Joined: 2017-08-16
Posts: 2,306

Re: So what's your coding style?

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.

Offline

#25 2017-04-24 17:19:54, last edited by LukeM (2017-04-24 17:22:43)

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

Re: So what's your coding style?

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

Offline

Wooted by:
den31071493468817657283

Board footer

Powered by FluxBB

[ Started around 1732682113.0056 - Generated in 0.287 seconds, 13 queries executed - Memory usage: 1.9 MiB (Peak: 2.2 MiB) ]