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.
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
if (condition)
{
multiple();
lines();
}
if (condition)
single_line();
"Sometimes failing a leap of faith is better than inching forward"
- ShinsukeIto
Offline
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
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)
Thanks to: Ernesdo (Current Avatar), Zoey2070 (Signature)
Very inactive, maybe in the future, idk.
Offline
I like to have { and } on new lines because it is easier for me to read. careful you dont want to trigger HG
Offline
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
if()
{
}
thanks zoey aaaaaaaaaaaand thanks latif for the avatar
Offline
I usually follow the style guides of the specific language / project I'm using.
Everybody edits, but some edit more than others
Offline
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
- 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
if(stuff == true)
{
return true;
}
else
{
return false;
}
hypermind code over here
Offline
if(stuff == true)
{
return true;
}
else
{
return false;
}hypermind code over here
Offline
if(!!stuff != !true)
{
ย ย return !!!false;
}
else
{
ย ย return !false;
}
ftfy
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Offline
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
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.
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).
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
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
Real tabs instead of spaces
You know this will trigger a lot of people?
Offline
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
HG wrote:
Real tabs instead of spaces
You know this will trigger a lot of people?
Felling triggered already.
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 operatorReal 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>
}
};
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
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).
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)).
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
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:
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
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
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
▼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
Offline
[ Started around 1732683128.8461 - Generated in 0.119 seconds, 12 queries executed - Memory usage: 1.9 MiB (Peak: 2.2 MiB) ]