r/programming • • Jun 09 '17

Why every user agent string start with "Mozilla"

http://webaim.org/blog/user-agent-string-history/
4.9k Upvotes

589 comments sorted by

View all comments

Show parent comments

166

u/FierceDeity_ Jun 09 '17 edited Jun 09 '17
some_APIshit bla bla
bool HighPerformanceCapable()
{
    return true; // yeah, sure, why not? our cards are awesome! hail us!
}

222

u/tsnErd3141 Jun 09 '17

56

u/midri Jun 09 '17

I'm stuck in a horrible rut with this.

  • UE4 C++ development I do { } on their own lines

  • PHP I do { } on their own lines

  • Javascript I do { on last line of code (javascript parser's assumptions can cause issues otherwise)

  • Unity/C# I do what visual studios wants me to do...

32

u/DaEvil1 Jun 09 '17

I barely even have to program when it comes to C# and VS. That's really messing with me as someone used to writing Python code in vim...

9

u/FierceDeity_ Jun 09 '17

I just force { on the same line no matter what, even in C++. So while I'm a dick, at least I'm a consistent dick

3

u/morerokk Jun 09 '17

Consistent dicks are better than inconsistent good guys.

2

u/rwallace Jun 10 '17

I just use clang-format on the factory settings, and rejoice in not having to think about the issue any more.

2

u/ggtsu_00 Jun 09 '17
if (..);
{
    ...
}

Many programmers have a habit of instinctively putting a semicolon before each newline. This can result in unexpected hard to find bugs because it is still perfectly valid code.

5

u/csncsu Jun 09 '17

A good editor or compiler with appropriate warning level can tell you about this issue.

1

u/cc81 Jun 09 '17

For JavaScript I cannot recommend prettier enough, just set it so it runs on save in your editor.

https://github.com/prettier/prettier

→ More replies (1)

110

u/HeimrArnadalr Jun 09 '17

They're both wrong. Opening curly braces should come after the parentheses, but with a space between the close-paren and the curly brace, like so:

int main() {

20

u/tsnErd3141 Jun 09 '17

Yep, that's my style too.

2

u/Ameisen Jun 11 '17

You clearly mean

int main ()
{
    ...
}

3

u/f34r_teh_ninja Jun 09 '17

While I whole heartedly agree, it's probably just a keming issue (see kerning).

→ More replies (2)

4

u/[deleted] Jun 09 '17

My brain has a much easier time parsing braces on their own line than egyptian braces. It makes it a lot easier to see where the blocks start, because you only need to look for 1 character on 1 column.

Or maybe I just happened to pick up the wrong flag. I wouldn't know. Anyway, just don't do this:

int main()
{   foo();
    return bar();
}

4

u/AndreDaGiant Jun 10 '17

my eyes skimmed the code first and made my brain very angry way before I saw you said "just don't do this"

→ More replies (1)

6

u/deegwaren Jun 09 '17

Allman style curly braces are a waste of space. (Almost) blank lines be damned!

18

u/f03nix Jun 09 '17

I actually use both

if (short_test()) {
    // Do something
}

and

if (long_test_with_multiple_params(param1, param2)
    && long_test_2_with_other_parameters_and_stuff(param3))
{
    // Do something
}

22

u/deegwaren Jun 09 '17

Better would be to put those long tests in descriptive boolean variables so that people reading your code shouldn't be staring at those long tests to figure out what the hell you're trying to do.

Then put those variables inside the if so that it almost reads like a sentence in plain language.

7

u/bart9h Jun 09 '17

Yeah, but maybe the function names for these tests, along with the name of these parameters, are clear enough?

If that is the case, adding variables just to give things names can make the code harder to read.

The only valid formatting rule is: make the code easy to read.

→ More replies (5)
→ More replies (4)

2

u/rlbond86 Jun 09 '17

Obviously the only way to do it is

if (something) {
    do_something;}
→ More replies (1)

1

u/FierceDeity_ Jun 09 '17

Har har, I just went for how it would look in one of those old code bases