Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
POKEMAN SAM
Jul 8, 2004

Jonnty posted:

Is there any conceivable reason why you might think that was in any way sensible? Some standard return format or something?

When you find 2 lines with horrors in a 3 line function, and notice the third line is a return statement, you kinda just assume it might be horror-free.

Adbot
ADBOT LOVES YOU

Standish
May 21, 2001

the guy who does
code:
string s="";
everywhere and tells me he's "just being sure" when I ask why.

Sprawl
Nov 21, 2005


I'm a huge retarded sperglord who can't spell, but Starfleet Dental would still take me and I love them for it!

Standish posted:

the guy who does
code:
string s="";
everywhere and tells me he's "just being sure" when I ask why.

It gets rid of the default NULL value for the string which can be useful in some languages.

Standish
May 21, 2001

Sprawl posted:

It gets rid of the default NULL value for the string which can be useful in some languages.
Yeah, this is C++.

ColdPie
Jun 9, 2006

Ugg boots posted:

When you find 2 lines with horrors in a 3 line function, and notice the third line is a return statement, you kinda just assume it might be horror-free.

Excuse my stupid question, but is the horror just not using fmod? Not knowing about a poorly-named function doesn't seem like a horror to me, just a lack of familiarity with the standard library which ought to be corrected. I don't think I would blame someone for reimplementing atan2 either, given its name.

POKEMAN SAM
Jul 8, 2004

ColdPie posted:

Excuse my stupid question, but is the horror just not using fmod? Not knowing about a poorly-named function doesn't seem like a horror to me, just a lack of familiarity with the standard library which ought to be corrected. I don't think I would blame someone for reimplementing atan2 either, given its name.

The while blah doesn't really bother me because it at least makes sense intuitively. This makes me cry though:

return toDegrees(toRadians(degrees));

Edit: I just realized that this code doesn't work like fmod. The range of the function is [0, 360] not [0, 360) :D

Jonnty
Aug 2, 2007

The enemy has become a flaming star!

Ugg boots posted:

When you find 2 lines with horrors in a 3 line function, and notice the third line is a return statement, you kinda just assume it might be horror-free.

I'm not criticising you for missing it, I'm trying to work out what sort of logic the guy was using. Anybody?

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

ColdPie posted:

I don't think I would blame someone for reimplementing atan2 either, given its name.

I would. The C standard library is really small. If you don't know C well enough to be able to use documentation when you want a really common function, you don't know it well enough to be getting paid to write code in it.

POKEMAN SAM
Jul 8, 2004

Avenging Dentist posted:

I would. The C standard library is really small. If you don't know C well enough to be able to use documentation when you want a really common function, you don't know it well enough to be getting paid to write code in it.

code:
float MathATan2f (float x, float y) {
    return atan2f(y, x);
}
lol

ColdPie
Jun 9, 2006

Avenging Dentist posted:

I would. The C standard library is really small. If you don't know C well enough to be able to use documentation when you want a really common function, you don't know it well enough to be getting paid to write code in it.

So you'd argue that the library is small enough to just be memorized? I guess I don't disagree. It just seems harsh to me to call it a horror when someone isn't familiar with non-obvious functions like atan2 and fmod.

Jethro
Jun 1, 2000

I was raised on the dairy, Bitch!

ColdPie posted:

So you'd argue that the library is small enough to just be memorized? I guess I don't disagree. It just seems harsh to me to call it a horror when someone isn't familiar with non-obvious functions like atan2 and fmod.
No, he'd argue that the library is small enough that one could search through the documentation. Hence his use of the term "use documentation" not "memorize documentation".

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh
Yeah really, if your knowledge of C is so limited that you don't think "oh hey there's a math.h header I wonder if it has this seemingly-common function I want", you really have no business writing C.

PhonyMcRingRing
Jun 6, 2002
Here's a coding horror I wrote some time ago that I stumbled on yesterday

code:
    Public Shared Function Clamp(ByVal i As Object, ByVal low As Object, ByVal high As Object) As Object

        If CDbl(i) < CDbl(low) Then
            Return low
        ElseIf CDbl(i) > CDbl(high) Then
            Return high
        Else
            Return i
        End If

    End Function
Yeah... I made a Clamp function that accepted any type of object, didn't even type check or use generics, and worst of all, I converted all the values to doubles.

Luckily when I deleted it no errors popped up, so I guess I never actually used it for anything.

Shumagorath
Jun 6, 2001

Otto Skorzeny posted:

This is exactly the sort of trash Perl and Ruby were made to replace

loving come on mang
My hate for shell script knows no bounds. Back in second year we were asked to make a baby version of Make using Bash and I got marks taken off for calling the script recursively to process dependencies.

Mill Town
Apr 17, 2006

Shumagorath posted:

My hate for shell script knows no bounds. Back in second year we were asked to make a baby version of Make using Bash and I got marks taken off for calling the script recursively to process dependencies.

I got bitten the other day by the fact that you can't put spaces around an = when assigning variables in bash. Seriously bash, what the gently caress?

I then went on to write some scripts in PHP instead which is a horror in itself :suicide:

Larz2021
Feb 2, 2001

ColdPie posted:

Excuse my stupid question, but is the horror just not using fmod?


The real horror is actually having to use fmod.

clockwork automaton
May 2, 2007

You've probably never heard of them.

Fun Shoe
code:
void DrivingViewPopups::hideAll(){
   
   showPopups == false;
   popups.at(currentPopup)->beginHide();
}
I just - I just don't even understand how you make this mistake. I taught programming before and the first year students didn't even make this mistake. And this is production stuff. Someone got paid for this. :(

NotShadowStar
Sep 20, 2000
You mean ==? I'm not sure how that even works without a compiler/parse error. But hey even long veterans mix up =/== sometimes when not paying attention and they can be a bitch to find. I blame no language since C having the balls to go back to using := for assignment for visual distinction.

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

NotShadowStar posted:

I'm not sure how that even works without a compiler/parse error.

That's a perfectly legitimate construct in nearly every language with remotely C-like syntax.

qntm
Jun 17, 2009

NotShadowStar posted:

You mean ==? I'm not sure how that even works without a compiler/parse error. But hey even long veterans mix up =/== sometimes when not paying attention and they can be a bitch to find. I blame no language since C having the balls to go back to using := for assignment for visual distinction.

I really used to like my graphing calculator which used "->" as its assignment operator, e.g.

code:
false->showPopUps
well, it could only handle integer variables with a single-character name so it was more like

code:
0->P
Even so, it was "put this value in that box." It made perfect sense to me.

crazyfish
Sep 19, 2002

clockwork automaton posted:

code:
void DrivingViewPopups::hideAll(){
   
   showPopups == false;
   popups.at(currentPopup)->beginHide();
}
I just - I just don't even understand how you make this mistake. I taught programming before and the first year students didn't even make this mistake. And this is production stuff. Someone got paid for this. :(

A static analysis tool might have caught that, but you can't possibly tell me you've never made an == vs = mistake.

mr_jim
Oct 30, 2006

OUT OF THE DARK

crazyfish posted:

A static analysis tool might have caught that, but you can't possibly tell me you've never made an == vs = mistake.

GCC and Clang both print warnings if you use -Wall. If you don't use -Wall, you are an idiot.

code:
$ gcc -Wall test.c
test.c: In function ‘main’:
test.c:4:5: warning: statement with no effect
$ clang -Wall test.c 
test.c:4:7: warning: expression result unused [-Wunused-value]
    i == 0;
    ~ ^  ~
1 diagnostic generated.

NotShadowStar
Sep 20, 2000
Actually I've been noticing a trend lately, and I think it started with Python people where they use assignment all in one line with no spaces like

code:
onething=another
And conditionals spaced out

code:
if onething == another:
For visual distinction.

Of course if your language is cool you could use a little used unicode greek character to really gently caress with people, this would be cool if you could use the c preprocessor to do so.

onthing ͼ another

TOO SCSI FOR MY CAT
Oct 12, 2008

this is what happens when you take UI design away from engineers and give it to a bunch of hipster art student "designers"

NotShadowStar posted:

Actually I've been noticing a trend lately, and I think it started with Python people where they use assignment all in one line with no spaces like

I have never seen Python code which doesn't space out assignments, and the standard formatting guidelines say that the '=' operator should have spaces around it. Some people don't put spaces around '=' for keyword arguments, but they're dumb.

Crazy RRRussian
Mar 5, 2010

by Fistgrrl

clockwork automaton posted:

code:
void DrivingViewPopups::hideAll(){
   
   showPopups == false;
   popups.at(currentPopup)->beginHide();
}
I just - I just don't even understand how you make this mistake. I taught programming before and the first year students didn't even make this mistake. And this is production stuff. Someone got paid for this. :(

I make mistakes like this when I code very tired and/or very drunk. I catch it pretty quickly tho, because obviously assignment doesn't happen. The horror here is that this person never caught it and it didn't generate any bugs in the code, presumably because he didn't catch it right away, which indicates that there was no reason to do assignment and have a chance to make this mistake in first place.

lumberjack4
May 14, 2010

I was refactoring some code one day and saw:
code:
if (myList.Count > 0) { continue;}
else { continue; }
I still make fun of that to this day.

HFX
Nov 29, 2004

lumberjack4 posted:

I was refactoring some code one day and saw:
code:
if (myList.Count > 0) { continue;}
else { continue; }
I still make fun of that to this day.

This can happen if you originally were doing something in one of the clauses and have since removed that behavior.

Scaevolus
Apr 16, 2007

Janin posted:

Some people don't put spaces around '=' for keyword arguments, but they're dumb.
From PEP8:
code:
      Don't use spaces around the '=' sign when used to indicate a
      keyword argument or a default parameter value.

      Yes:

          def complex(real, imag=0.0):
              return magic(r=real, i=imag)

      No:

          def complex(real, imag = 0.0):
              return magic(r = real, i = imag)

A A 2 3 5 8 K
Nov 24, 2003
Illiteracy... what does that word even mean?

Scaevolus posted:

From PEP8:
code:
      Don't use spaces around the '=' sign when used to indicate a
      keyword argument or a default parameter value.

      Yes:

          def complex(real, imag=0.0):
              return magic(r=real, i=imag)

      No:

          def complex(real, imag = 0.0):
              return magic(r = real, i = imag)

Calling people dumb for using a given style and following a standard blindly are both horrors. Your responsibilities as a developer are to do something sane, be consistent about it, and let others do the same. How much horrible bickering would go away if people didn't fight over arbitrary style preferences?

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
That's why there isn't a fight in Python: there's a style guide. Like all style guides, it provides rules that should be followed unless you have an excellent reason not to.

Given this, why is "following a standard blindly" a horror? If you can't be bothered to think about whether you should break a rule, the least confusing thing to do is follow the rule.

A A 2 3 5 8 K
Nov 24, 2003
Illiteracy... what does that word even mean?

pokeyman posted:

That's why there isn't a fight in Python: there's a style guide. Like all style guides, it provides rules that should be followed unless you have an excellent reason not to.

Given this, why is "following a standard blindly" a horror? If you can't be bothered to think about whether you should break a rule, the least confusing thing to do is follow the rule.

Using incorrect indentation and meaningless variable names are bad practices that are worth discouraging. That's what I mean by "be sane". But a guide shouldn't be twice as long as it needs to be so it can encompass things like whether a syntactically unimportant space belongs somewhere or not.

It doesn't make sense to say that one has an excellent reason to prefer Pink Floyd to Led Zeppelin, it's personal and subjective. People who don't like music or who don't like making decisions or forming opinions for themselves can follow someone else's guideline, but others should not have to explain themselves for having their own sense of style.

shrughes
Oct 11, 2008

(call/cc call/cc)

A A 2 3 5 8 K posted:

:words: It doesn't make sense to say that one has an excellent reason to prefer Pink Floyd to Led Zeppelin, it's personal and subjective.

No, you are wrong [1]. We are talking about style guides here, not music.

People do not come with a built-in preference for what they consider good style. The preference is mostly "what they are used to." And thus it makes sense to have and to follow style guidelines, so that everybody is used to the same style.



[1] Also, I am right.

Zombywuf
Mar 29, 2008

shrughes posted:

No, you are wrong [1]. We are talking about style guides here, not music.

People do not come with a built-in preference for what they consider good style. The preference is mostly "what they are used to." And thus it makes sense to have and to follow style guidelines, so that everybody is used to the same style.

All Glory to PEP8

Fehler
Dec 14, 2004

.

Scaevolus posted:

From PEP8:

quote:

The most popular way of indenting Python is with spaces only. The second-most popular way is with tabs only. Code indented with a mixture of tabs and spaces should be converted to using spaces exclusively.

For new projects, spaces-only are strongly recommended over tabs.
What the gently caress? Why would anybody in their right mind encourage space indentation?

Flobbster
Feb 17, 2005

"Cadet Kirk, after the way you cheated on the Kobayashi Maru test I oughta punch you in tha face!"

Fehler posted:

What the gently caress? Why would anybody in their right mind encourage space indentation?

Because then your code doesn't look all retarded if someone uses different tab sizes than you when they view it, and any decent text editor/IDE nowadays will treat a contiguous block of spaces as if it were a tab anyway, so you can't even tell the difference while you're editing.

There's no reason to prefer tab indentation over space indentation nowadays, unless you're worried about MY DISK SPACE

TOO SCSI FOR MY CAT
Oct 12, 2008

this is what happens when you take UI design away from engineers and give it to a bunch of hipster art student "designers"

Flobbster posted:

Because then your code doesn't look all retarded if someone uses different tab sizes than you when they view it, and any decent text editor/IDE nowadays will treat a contiguous block of spaces as if it were a tab anyway, so you can't even tell the difference while you're editing.

There's no reason to prefer tab indentation over space indentation nowadays, unless you're worried about MY DISK SPACE

The entire point of using tabs is so that it'll look different if somebody changes their editor's tab size. Some people like 2-space indentation, some people like 8-space; tabs let them both use whatever size they want.

If your editor treats a block of spaces like tabs, that's the horror.

Mustach
Mar 2, 2003

In this long line, there's been some real strange genes. You've got 'em all, with some extras thrown in.
Tabs vs. spaces: the most important argument in the world.

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



Janin posted:

The entire point of using tabs is so that it'll look different if somebody changes their editor's tab size. Some people like 2-space indentation, some people like 8-space; tabs let them both use whatever size they want.

I was reading Crockford's javascript guides and saw this in his style guide:

quote:

Use of tabs should be avoided because (as of this writing in the 21st Century) there still is not a standard for the placement of tabstops.

and facepalmed irl because way to miss the loving point, man.

king_kilr
May 25, 2007

Janin posted:

The entire point of using tabs is so that it'll look different if somebody changes their editor's tab size. Some people like 2-space indentation, some people like 8-space; tabs let them both use whatever size they want.

If your editor treats a block of spaces like tabs, that's the horror.

That's create, excecpt how do you format this:

code:
var my_crap = func_call(foo,
                        bar)

Adbot
ADBOT LOVES YOU

Vanadium
Jan 8, 2005

With spaces, because that is not indentation.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply