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
zombienietzsche
Dec 9, 2003
code:
(C#)
if (cp.IsLocked.ToString().Equals("1"))
First reaction: why is he using .Equals, we have == overloaded for a reason...

Second reaction: oh god IsLocked is a bool...

Adbot
ADBOT LOVES YOU

RussianManiac
Dec 27, 2005

by Ozmaugh

meinstein posted:

code:
(C#)
if (cp.IsLocked.ToString().Equals("1"))
First reaction: why is he using .Equals, we have == overloaded for a reason...

Second reaction: oh god IsLocked is a bool...

Lol yea. Good points. It looks like a very bad Java programmer tried to learn C#

GROVER CURES HOUSE
Aug 26, 2007

Go on...

meinstein posted:

code:
(C#)
if (cp.IsLocked.ToString().Equals("1"))
First reaction: why is he using .Equals, we have == overloaded for a reason...

Second reaction: oh god IsLocked is a bool...

Better yet, that statement will always return false. :v:

megalodong
Mar 11, 2008

A novel implementation of str_replace(" ", "", $str):
code:
function trimall($str)
{
  for ($i = 0; $i < strlen($str); $i++)
  {
    if (($c = substr($str, $i, 1)) != " ")
    {
        $ret .= $c;
    }
  }
  return $ret;
}

king_kilr
May 25, 2007
Does $ret implicitly get set to "" when something is concatinated to it (and it doesn't already exist).

gibbed
Apr 10, 2006

king_kilr posted:

Does $ret implicitly get set to "" when something is concatinated to it (and it doesn't already exist).
Yes, but you'll also get a warning (unless you're dumb and have warnings set to something other than E_ALL).

king_kilr
May 25, 2007

gibbed posted:

Yes, but you'll also get a warning (unless you're dumb and have warnings set to something other than E_ALL).

... that's the real coding horror.

zootm
Aug 8, 2006

We used to be better friends.

megalodong posted:

A novel implementation of str_replace(" ", "", $str):
I knew a guy who did something near-identical to this (in Java) when I was at uni. I suggested the single-line version and he just kinda looked stunned, then said he'd "maybe think about doing it that way later". Oh, well.

Yakattak
Dec 17, 2009

I am Grumpypuss
>:3

My AP Computer Science teacher has this awful habit of using nondescript parameter variables, like the following:
code:
public Class ClassName(String n, int a)
He actually asked me why I used parameters like the following:
code:
public Class ClassName(String newName, int newAge)

Haquer
Nov 15, 2009

That windswept look...

Yakattak posted:

My AP Computer Science teacher has this awful habit of using nondescript parameter variables, like the following:
code:
public Class ClassName(String n, int a)
He actually asked me why I used parameters like the following:
code:
public Class ClassName(String newName, int newAge)

I'm guilty of using nondescript variables, but only in situations like so:
code:
for (int i = 0; i < MAX; i++)
Which can lead to bad code, but I still catch myself doing it.

But it's funny that he asked you why you had descriptive variable names. I've yet to have somebody ask me that.

Alligator
Jun 10, 2009

LOCK AND LOAF
Hardly a coding horror, though.

In college (UK college that is, so not university) we did a very simple programming module and my teacher was very strict about using Hungarian notation (ugh). Even for a loop counter he'd use names like intI, intJ and intK.

I had no other exposure to programming so when I went to university and realised that hardly anyone uses hungarian notation I was pretty astounded because I assumed it was the way variables were named. It took me a while to get used to reading variable names without prefixes and to stop myself adding them.

Captain Capacitor
Jan 21, 2008

The code you say?
I'm guilty of nondescript variables in two ways: Loop variables and isolated variables in methods/procedures under 5 lines or so (for example, getters/setters).

What's the general opinion on short variable names that are explained/in limited context?

code:
def averageLoginCount():
  q = query = User.objects.all()
  q = q.filter(firstname__contains='y')
  q = q.aggregate(Avg('login_count'))
  return q

jandrese
Apr 3, 2007

by Tiny Fistpump
It's fine until you realize you need to do something else in that loop and suddenly the lines are separated by several other lines of code, then your context can be lost and you have people seeing q = q.filter(firstname__contains='y') all by its lonesome somewhere and wondering WTF q is.

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

Captain Capacitor posted:

What's the general opinion on short variable names that are explained/in limited context?

code:
def averageLoginCount():
  q = query = User.objects.all()
  q = q.filter(firstname__contains='y')
  q = q.aggregate(Avg('login_count'))
  return q

I can't promise this is the "general" opinion, but nobody should have a problem with it unless they were uptight and/or unable to determine by context where guidelines do and don't make sense so they rigidly follow and repeat them as often as possible because it's how they judge their worth as a developer. In which case they'd devise a scenario in which these 5 lines of code get pasted into a critical section of a nuclear power plant monitoring system that is maintained by idiots. Almost all guidelines can be replaced by common sense.

chocojosh
Jun 9, 2007

D00D.

Captain Capacitor posted:

I'm guilty of nondescript variables in two ways: Loop variables and isolated variables in methods/procedures under 5 lines or so (for example, getters/setters).

What's the general opinion on short variable names that are explained/in limited context?

code:
def averageLoginCount():
  q = query = User.objects.all()
  q = q.filter(firstname__contains='y')
  q = q.aggregate(Avg('login_count'))
  return q

I'm wondering why you do q = query = ... Is it to set the value to both q (local var) and query (object var)?

For local variables, I fairly often create objects from the initials of the class name, such as:
FlipTransition ft = new FlipTransition();
MemoryStream ms = new MemoryStream();

Some people have gone "uggggh I don't like it", but my coworkers do similar things and for local variables in short functions it tends to not be a problem.

Jonnty
Aug 2, 2007

The enemy has become a flaming star!

chocojosh posted:

I'm wondering why you do q = query = ... Is it to set the value to both q (local var) and query (object var)?

For local variables, I fairly often create objects from the initials of the class name, such as:
FlipTransition ft = new FlipTransition();
MemoryStream ms = new MemoryStream();

Some people have gone "uggggh I don't like it", but my coworkers do similar things and for local variables in short functions it tends to not be a problem.

I assumed he was doing it to make it explicit what q actually is, but giving it the value q as well to avoid having to type it out - attributes don't work like that in Python as far as I know.

Avenging Dentist
Oct 1, 2005

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

Captain Capacitor posted:

What's the general opinion on short variable names that are explained/in limited context?

Your particular example is bad because it would actually be clearer as a single statement. But in general, the answer is "think about what you are doing". The notion that coding style needs hard-and-fast rules is pretty silly (though you should apply them consistently in your code).

poopgiggle
Feb 7, 2006

it isn't easy being a cross dominate shooter.


Haquer posted:

I'm guilty of using nondescript variables, but only in situations like so:
code:
for (int i = 0; i < MAX; i++)
Which can lead to bad code, but I still catch myself doing it.

But it's funny that he asked you why you had descriptive variable names. I've yet to have somebody ask me that.

Using i, j, and k as loop indices has been common practice since Fortran. I don't think anyone would say it's bad.

A A 2 3 5 8 K
Nov 24, 2003
Illiteracy... what does that word even mean?
http://search.cpan.org/~bshade/Array-PAT-2.0.0/PAT.pm

Array::PAT - PHP Array Tools - Perl extension for array functions that are built into PHP.

Opinion Haver
Apr 9, 2007

A A 2 3 5 8 K posted:

http://search.cpan.org/~bshade/Array-PAT-2.0.0/PAT.pm

Array::PAT - PHP Array Tools - Perl extension for array functions that are built into PHP.

Is the horror that they all start with array_?

spiritual bypass
Feb 19, 2008

Grimey Drawer

yaoi prophet posted:

Is the horror that they all start with array_?

The next horror on the list is the inconsistent argument lists.

Flobbster
Feb 17, 2005

"Cadet Kirk, after the way you cheated on the Kobayashi Maru test I oughta punch you in tha face!"
The horror is that someone decided to take horror of PHP and combine it with the horror that is Perl.

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

yaoi prophet posted:

Is the horror that they all start with array_?

It's a meta-horror of spreading PHP to other languages, see also: http://phpjs.org/

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip

A A 2 3 5 8 K posted:

http://search.cpan.org/~bshade/Array-PAT-2.0.0/PAT.pm

Array::PAT - PHP Array Tools - Perl extension for array functions that are built into PHP.

Ahahahahahahahahahahahahahaha

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

A A 2 3 5 8 K posted:

http://search.cpan.org/~bshade/Array-PAT-2.0.0/PAT.pm

Array::PAT - PHP Array Tools - Perl extension for array functions that are built into PHP.

Array::PAT posted:

Just as The Beatles say:

This applies to all functions, unless otherwise noted. If you use pass by value, you will recieve a value back, but if you pass a reference to a hash or value, you will receive a reference back. This is to support backwards compatability, it might be removed in later releases.

Forgot about that humdinger. That's from the Yellow Submarine lyrics right?

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

pokeyman posted:

Forgot about that humdinger. That's from the Yellow Submarine lyrics right?

I thought it might be a copy/paste failure but then I thought of how unlikely that would be coming from a PHP enthusiast.

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.
"And in the end, the love you take is equal to the love you pass by value." — John Lennon

Dessert Rose
May 17, 2004

awoken in control of a lucid deep dream...

A A 2 3 5 8 K posted:

I thought it might be a copy/paste failure but then I thought of how unlikely that would be coming from a PHP enthusiast.

:drat:

Sebbe
Feb 29, 2004

pokeyman posted:

Forgot about that humdinger. That's from the Yellow Submarine lyrics right?

It's from Love Me Do, but was removed in a later release, as it was only included for compatibility purposes.

zootm
Aug 8, 2006

We used to be better friends.

Mustach posted:

"And in the end, the love you take is equal to the love you pass by value." — John Lennon
It is actually that quote, although without the funny; from the source:
code:
=begin html
<p><i>"And in the end, the love you take,<br>
is equal to the love you make" - "The End", John Lennon/Paul McCartney (1969)</i></p>

dis astranagant
Dec 14, 2006

Implementing a switch with a for case loop :wtc: uattack is an int assigned in a loop a couple lines above this, by the way.

code:
for (int scount = 0; scount < 5; scount++)
    {
        unarmed_attack.clear();
        miss_verb.clear();
        simple_miss_message = false;
        damage_brand = SPWPN_NORMAL;
        aux_damage = 0;

        switch (scount)
        {
        case 0:
        {
            if (uattack != UNAT_KICK)        //jmf: hooves mutation
            {
                if (!player_mutation_level(MUT_HOOVES)
                        && !player_mutation_level(MUT_TALONS)
                    || coinflip())
                {
                    continue;
                }
            }

            if (you.attribute[ATTR_TRANSFORMATION] == TRAN_ICE_BEAST
                || you.attribute[ATTR_TRANSFORMATION] == TRAN_DRAGON
                || you.attribute[ATTR_TRANSFORMATION] == TRAN_SPIDER
                || you.attribute[ATTR_TRANSFORMATION] == TRAN_BAT)
            {
                continue;
            }

            // Kenku have large taloned feet that do good damage.
            const bool clawed_kick = player_mutation_level(MUT_TALONS);

            if (clawed_kick)
            {
                unarmed_attack = "claw";
                miss_verb      = "kick";
            }
            else
                unarmed_attack = "kick";

            aux_damage = (player_mutation_level(MUT_HOOVES) ? 10
                          : clawed_kick                     ?  8 : 5);
            break;
        }

        case 1:
            if (uattack != UNAT_HEADBUTT)
            {
                if (!player_mutation_level(MUT_HORNS)
                       && !player_mutation_level(MUT_BEAK)
                    || !one_chance_in(3))
                {
                    continue;
                }
            }

            if (you.attribute[ATTR_TRANSFORMATION] == TRAN_SPIDER
                || you.attribute[ATTR_TRANSFORMATION] == TRAN_ICE_BEAST
                || you.attribute[ATTR_TRANSFORMATION] == TRAN_DRAGON
                || you.attribute[ATTR_TRANSFORMATION] == TRAN_BAT)
            {
                continue;
            }

            if (player_mutation_level(MUT_BEAK)
                && (!player_mutation_level(MUT_HORNS) || coinflip()))
            {
                unarmed_attack = "peck";
                aux_damage = 6;
            }
            else
            {
                // Minotaurs used to get +5 damage here, now they get
                // +6 because of the horns.
                unarmed_attack = "headbutt";
                aux_damage = 5 + player_mutation_level(MUT_HORNS) * 3;

                if (you.equip[EQ_HELMET] != -1)
                {
                    const item_def& helmet = you.inv[you.equip[EQ_HELMET]];
                    if (is_hard_helmet(helmet))
                    {
                        aux_damage += 2;
                        if (get_helmet_desc(helmet) == THELM_DESC_SPIKED
                            || get_helmet_desc(helmet) == THELM_DESC_HORNED)
                        {
                            aux_damage += 3;
                        }
                    }
                }
            }
            break;

// snip

            // To add more, add to while part of loop below as well
        default:
            continue;
        }
This entire block can be implemented as something like

code:
switch(uattack)
    case UNAT_KICK:
        if (!form_can_kick())
            break;
        do_stuff();  
        break;
//snip
and so on.

dis astranagant fucked around with this message at 11:17 on Dec 31, 2009

spiritual bypass
Feb 19, 2008

Grimey Drawer

dis astranagant posted:

code:
// Minotaurs used to get +5 damage here, now they get
// +6 because of the horns.

Which programmer hasn't forgotten to add the horn damage at one point or another?

Senso
Nov 4, 2005

Always working
Is this code from Angband or Nethack or a similar roguelike?

ColdPie
Jun 9, 2006

Senso posted:

Is this code from Angband or Nethack or a similar roguelike?

Google only turns up an expired pastebin, so it's probably not from a popular OSS project.

jandrese
Apr 3, 2007

by Tiny Fistpump
Looks like it's out of a game called Dungeon Crawl, and yes, it's a Roguelike. There is apparently even an MMO or something.

The code snippit looks like it is out of the "stone soup" distro in fight.cc.

tombom
Mar 8, 2006
I'm sure this has been posted somewhere around here before, but I haven't seen it.
Spectate Swamp Desktop Search It kind of speaks for itself. He posts a lot and it seems he writes code like this professionally.

spiritual bypass
Feb 19, 2008

Grimey Drawer

That right there is a proclick!
I love the versioning system he's built-in to his file.
What language is that? Looks like it would produce horrors no matter the user.

TheSleeper
Feb 20, 2003
Looks like VB to me.

mr_jim
Oct 30, 2006

OUT OF THE DARK

tombom posted:

I'm sure this has been posted somewhere around here before, but I haven't seen it.
Spectate Swamp Desktop Search It kind of speaks for itself. He posts a lot and it seems he writes code like this professionally.

Even Ulillillia writes clearer code than that.

Adbot
ADBOT LOVES YOU

deedee megadoodoo
Sep 28, 2000
Two roads diverged in a wood, and I, I took the one to Flavortown, and that has made all the difference.


tombom posted:

I'm sure this has been posted somewhere around here before, but I haven't seen it.
Spectate Swamp Desktop Search It kind of speaks for itself. He posts a lot and it seems he writes code like this professionally.

Someone should submit that to TDWTF.

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