if (conditional) {
}
orif (conditional)
{
}
the occupation of lesser men
The second one.
>work
#2 is in the coding standard.
>home
>>only program at home when moving a game or interviewing.
>>>modding, use either or both. Who gives a shit.
>>>interview, try and look up companies std, default to the Google std if it can't be found. #1 for the most part.
https://google.github.io/styleguide/cppguide.html
>>59704159
#1 is the coding standard in everything but C#.
Nobody gives a shit what google has to say.
>>59703721
Whatever the coding standard says.
Either is readable, but I personally prefer the first, it is more compact.
If I am the one who makes the standard, the curly brace should only be on a separate line if it severs a purpose, like when you initialize a class.
Ex:example::example() :
_value_a(),
_value_b()
{
//stuff
}
looks a lot better thanexample::example() :
_value_a(),
_value_b() {
//stuff
}
orexample::example() : _value_a(), _value_b() {
//stuff
}
>>59703721
sauce?
>>59703721
> a ? b : c
Out of the way plebians, patrician coming through.
Ternary if supported.
Otherwise use what the language itself suggest using.
If the language itself has no style guidelines,
fall back to the first one posted.
>>59704159
>Google style guides
Not when they recommend this for HTML: https://google.github.io/styleguide/htmlcssguide.html#Optional_Tags
>>59704186
>
>>59703721
The second one is compulsory where you are rated by your "output" and "productivity".if (conditional) {
//stuff
} else { // save more v-space
/other stuff
}
>>59706184
>pajeet metrics
Leave.
>>59703721
I found the elder god tier:if(conditional){ some_shit_here(); other_shit();}
>not using higher order conditionalsif (!(err = (a > b) ? func1(a) : func2(b)))
>>59703721
Literally doesn't matter.
>>59706377
I'd fire any "programmer" daring to submit this to review.
>>59706466
What's wrong with it?
It kills many birds in one stone and would be written in 5 + 10 lines if it was written the retard way like you suggest.
>using if
>not ternary operator
plebs
you guys dont know anything// simple program to test if 1 + 1 = 2 is true
#include <iostream>
enum Booleans : bool { T = true, F = false};
void isTrue(Booleans statement, Booleans* output) {
if (statement == Booleans::T) {
*output = Booleans::T;
} else { if (statement == Booleans::F) {
*output = Booleans::F;
}
}
}
using number = int;
number main(int argc, char * * argv) {
char stringFalse[6] = {'F','A','L','S','E','\0'};
char stringTrue[5] = {'T','R','U','E','\0'};
Booleans temp;
Booleans statement;
if (1 + 1 == 2) {
statement = Booleans::T;
} else {
if (1 + 1 != 2) {
statement = Booleans::F;
}
}
isTrue(statement, &temp);
if (temp == Booleans::T) {
std::cout << (std::string(stringTrue)).c_str() << std::endl;
} else {
if (temp == Booleans::F) {
std::cout << (std::string(stringFalse)).c_str() << std::endl;
}
}
system("pause");
return -1;
}
>>59706774
Everything, and if you can't see it, you do not belong in the field.
>>59707242
yeah ok neet boy
>>59707279
>posts unreadable unmaintainable prone-to-bugs code
>>59703721
first one.
>>59707242
> hard to read
> hard to debug
> hard to handle errors
> not flexible
did I miss anything?
>>59707363
Improper use of the ternary operator and the implication that both functions return 0 as success.
>>59706297
>>59704590
These
>>59707482
these manga guides are so trash
i didn't expect any rigor, but the information density is SO LOW that they resort to dumping entire pages worth of material without the cute drawings so the reader can catch up because they can't into pacing.
if (conditional)
{
}
>Not giving tab to the brackets
Shiggty
if conditional is True:
#stuff
>>59703721
#1
The latter looks like two separate blocks. In the first one it basically reads "here is the condition, start the block. It just reads better
The only thing that jumps out to me as being weird is the fact that the ending brace has its own line while the first one doesn't
>>59708110
That actually makes sense
>{
Into the trash it goes.
>>59706774
4 lines vs 1 line in pure C
>>59703721
>when you realize it doesn't matter because it compiles to the same assembly
>>59709460
Why don't you write all your code on one single line then?
>>59703721
First
Second is only for functions, methods, classes, or objects.
>>59709753
> Implying I don't
The one that doesn't mindlessly waste lines.
I'm writing, not scrolling down a stupid facebook-esque site that never ends.
>>59705273
>inconsistent brace spacing
>>59704416
>Either is readable, but I personally prefer the first, it is more compact.
compact is less readable you dingus
>>59709753
I do.
>>59708110
Fuck off GNU
>>59704416
Personally I use second for class/method/function definitions and first for everything else. Makes it extra clear.
>>59710265
This guy gets it.
>>59703721
First one, because it works better with code folding and doesn't waste vertical space, though by that argumentif (condition) {
foo();
bar();
baz(); }
would be the best.
Personally though, I think what would be the most aesthetic isif condition do
foo()
bar()
baz()
end do
>>59707212// simple program to test if 1 + 1 = 2 is true
#include <iostream>
#include <map>
enum Booleans : bool { T = true, F = false};
void isTrue(Booleans statement, Booleans* output) {
if (statement == Booleans::T) {
*output = Booleans::T;
} else { if (statement == Booleans::F) {
*output = Booleans::F;
}
}
}
using number = int;
namespace c_plus_plus_standard_namespace = std;
using Booleans_to_c_string_map_type = c_plus_plus_standard_namespace::map<Booleans, char*>;
number main(number argc, char * * argv) {
char stringFalse[6] = {'F','A','L','S','E','\0'};
char stringTrue[5] = {'T','R','U','E','\0'};
Booleans temp;
Booleans statement;
Booleans_to_c_string_map_type boolean_to_c_string_map;
boolean_to_c_string_map[Booleans::T] = stringTrue;
boolean_to_c_string_map[Booleans::F] = stringFalse;
if (1 + 1 == 2) {
statement = Booleans::T;
} else {
if (1 + 1 != 2) {
statement = Booleans::F;
}
}
isTrue(statement, &temp);
if (temp == Booleans::T) {
c_plus_plus_standard_namespace::cout << (c_plus_plus_standard_namespace::string(boolean_to_c_string_map[Booleans::T])).c_str() << c_plus_plus_standard_namespace::endl;
} else {
if (temp == Booleans::F) {
c_plus_plus_standard_namespace::cout << (c_plus_plus_standard_namespace::string(boolean_to_c_string_map[Booleans::F])).c_str() << c_plus_plus_standard_namespace::endl;
}
}
system("pause");
return -1;
}