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
ohgodwhat
Aug 6, 2005

That wouldn't even work in Python, although I don't know about Perl.

Adbot
ADBOT LOVES YOU

POKEMAN SAM
Jul 8, 2004

Triple Tech posted:

Degrees don't mean poo poo! I wonder what their thought process was that using regexp validation, which is infinitely more robust, was somehow worth less than "multiplying something by one"? Geniuses at work, people.

I think regexps are too hard. One of them used a regexp for something else and the other two were like :dropjaw:.

Lonely Wolf
Jan 20, 2003

Will hawk false idols for heaps and heaps of dough.

ryanmfw posted:

That wouldn't even work in Python, although I don't know about Perl.

It works in the sense that it will always evaluate to True. :downs:

Smackbilly
Jan 3, 2001
What kind of a name is Pizza Organ! anyway?

Ugg boots posted:

I mentioned this in IRC as it was playing out, but I'm sitting in a Computer Science majors computer lab, and there are three guys sitting next to me working on a Perl assignment. I know for a fact they're not freshmen or sophomores but even if they were, ugh.

So, they have to take input into their program and want to validate and make sure the user enters in a number (as opposed to something else.)

Their solution?

Store the input in a temp variable. Multiply the temp variable by 1. Make sure the temp variable is the same as the input.

Also this quote "You could also use a regular expression but that'd be a pain in the rear end."

Ugh.

They're missing the part where the human is supposed to do the thinking and planning, and the computer is supposed to do the simple things as quickly as possible. They're trying to have the humans do simple things as quickly as possible without the thinking and planning, and it doesn't really work well that way.

OneEightHundred
Feb 28, 2008

Soon, we will be unstoppable!
While it's not really a problem in that particular case, treating values as different types than you expect them to be and depending on coercion to make it work right isn't really a great practice, since it inevitably leads to fuckups when that coercion behaves unexpectedly. i.e. in that case, you're depending on how a value converts to a number rather than how it converts to a string.

A nice example would be the ghetto ternary operator thing in Lua/Python:
a = b and c or d

Shorter than writing:
if b: a = c
else: a = d

.... but you're depending on "c" not converting to "false", which can easily blow up in your face.

limip
Oct 24, 2003
From library code:
code:
BOOL CHyperRunView::SelectTip(CPoint point);

typedef BOOL (CHyperRunView::*TFTrick)(CPoint) const;
int CHyperRunView::OnToolHitTest(CPoint point, TOOLINFO* pTI) const
{
	TFTrick pFunc = (TFTrick)&CHyperRunView::SelectTip;
	BOOL bNewToolTip = (this->*pFunc)(point);
	[... stuff ...]
	return whatever;
}
The only thing I could think of is they ran it through a static analysis tool and it complained about casting away const, but the static analysis tool couldn't deduce that for member function pointers, because that's just the most complex way of casting away const that I can imagine, while still keeping it under a few lines.

From my company's code, and way too often:
code:
std::map<k, v> m;
[...] stuff [...]
if (m.count(some_value))
{
    std::map<k, v>::iterator it = m.find(some_value);
    [...] lots of stuff with it [...]
}
I would say "hooray for C++0x and auto" but that doesn't even seem to be the main issue, since they declare the iterator a few lines later.

Then there are the complaints that VS2008's release mode iterator checking crashes their crappy code. Not that it makes it slow (see above), but that it crashes the code, because, after all, in VS2003 it "worked"! I fear the day when they find out that catch (...) doesn't catch null pointer deferences or stack overflows anymore.

Filburt Shellbach
Nov 6, 2007

Apni tackat say tujay aaj mitta juu gaa!

weaaddar posted:

Plus the whole unreadability of the code is got to be worth points, after all your coding in perl, if its not an exercise to figure out what your doing, it's wrong.

People who write bad Perl should stop writing Perl.

People who write bad English, such as by confusing "your" with "you're"; "is" with "has"; and "its" with "it's", should stop writing English.

inorpo
Oct 27, 2003

Ugg boots posted:


Also this quote "You could also use a regular expression but that'd be a pain in the rear end."



Correct me if I'm wrong but /^\d+$/ seems correct and is pretty clear. I'm missing the logic why on earth they would multiply the input by 1. :psyduck:

Filburt Shellbach
Nov 6, 2007

Apni tackat say tujay aaj mitta juu gaa!
That was my original solution too. It's fine for positive integers, but if you want to match negative numbers or rationals then you need something more complex. I'd just use Scalar::Util::looks_like_number which also matches scientific notation.

They multiplied by 1 because strings that do not look like numbers evaluate to zero in numeric contexts. So "post" * 1 is zero.

inorpo
Oct 27, 2003

Ah, I was only considering positive whole numbers.

ShoulderDaemon
Oct 9, 2003
support goon fund
Taco Defender

Sartak posted:

That was my original solution too. It's fine for positive integers, but if you want to match negative numbers or rationals then you need something more complex. I'd just use Scalar::Util::looks_like_number which also matches scientific notation.

They multiplied by 1 because strings that do not look like numbers evaluate to zero in numeric contexts. So "post" * 1 is zero.

Honestly, as an experienced Perl programmer I'd probably use $var + 0 eq $var, which is only trivially different from the horror. It's fast, it's fairly clear what it's doing, it works for every number format that perl supports, and it doesn't pull in a module. If I was already using Scalar::Util for something else, I'd use looks_like_number unless it's doing something incredibly stupid.

Filburt Shellbach
Nov 6, 2007

Apni tackat say tujay aaj mitta juu gaa!
$var + 0 eq $var misses a lot of numbers you should probably handle, most importantly zero-padded numbers like 007.

Scalar::Util is core as of 5.8 and most of your dependencies probably pull it in anyway. There's little reason not to use it because it's the most clear (the function is well-named), probably the fastest (since it's written in C), and definitely the most thoroughly tested solution.

ShoulderDaemon
Oct 9, 2003
support goon fund
Taco Defender

Sartak posted:

$var + 0 eq $var misses a lot of numbers you should probably handle, most importantly zero-padded numbers like 007.

I guess I'd specifically not want to handle zero-padded numbers because when I see those I expect them to be parsed as octal, and if the program isn't going to do that I'd prefer it to give me a format error rather than silently mis-handle the number. But maybe that's just me.

da keebsta knicca
Sep 12, 2000

Oh Ruutu, you are such a card.
Oh my god. Every day a new thing. MS SQL Database of grad students...

dbo.gender
--------
GenderID
Gender

Has 2 entries obviously.. male and female.

Also have

dbo.citizenship (3 entries)
dbo.city
dbo.country (I can deal with this one I use it in some apps)
dbo.province
dbo.status (fulltime or part time).
dbo.degreeType

The list goes on and on. 37 tables to hold information about a registered grad student in a single faculty...

Triple Tech
Jul 28, 2006

So what, are you quitting to join Homo Explosion?
There could be more genders, like null or pirate.

da keebsta knicca
Sep 12, 2000

Oh Ruutu, you are such a card.
It is a university, we basically have to some times use NULL not to make people angry.

No Safe Word
Feb 26, 2005

Triple Tech posted:

There could be more genders, like null or pirate.

For one of our clients (in the healthcare business) they literally had at least five (and I think it may actually have been seven) options in the gender field. I forget them all, but it was at least: Male, Female, Unspecified and I think there was a "Neither" or "Both" in there somewhere.

Dessert Rose
May 17, 2004

awoken in control of a lucid deep dream...

da keebsta knicca posted:

It is a university, we basically have to some times use NULL not to make people angry.

To be fair, I'd be pretty pissed off if I had both sexes and you forced me to pick one.

DaTroof
Nov 16, 2000

CC LIMERICK CONTEST GRAND CHAMPION
There once was a poster named Troof
Who was getting quite long in the toof

No Safe Word posted:

For one of our clients (in the healthcare business) they literally had at least five (and I think it may actually have been seven) options in the gender field. I forget them all, but it was at least: Male, Female, Unspecified and I think there was a "Neither" or "Both" in there somewhere.

In an application for a county's department of animal control, there was a table for pets' genders that contained Male, Female, Spayed, and Neutered. It seemed reasonable enough until they started using it for the owner's gender, too.

necrobobsledder
Mar 21, 2005
Lay down your soul to the gods rock 'n roll
Nap Ghost

Ryouga Inverse posted:

To be fair, I'd be pretty pissed off if I had both sexes and you forced me to pick one.
I suppose this is also the point where people in older systems would have written in "M T W Th F S Sun" for "Sex?" and we'd need a tuple to store something supposedly simple like one's sex.

Triple Tech
Jul 28, 2006

So what, are you quitting to join Homo Explosion?

DaTroof posted:

In an application for a county's department of animal control, there was a table for pets' genders that contained Male, Female, Spayed, and Neutered. It seemed reasonable enough until they started using it for the owner's gender, too.

Coding horror, shoe-horning a semantically different concept into an existing framework that isn't properly built to address it. Classic.

TSDK
Nov 24, 2003

I got a wooden uploading this one
I've started seeing this rather sub-optimal anti-pattern in a few places recently:
code:
if ( stricmp( "SOME_STRING_1", p_string ) == 0 )
{
    // Do stuff
}
if ( stricmp( "SOME_STRING_2", p_string ) == 0 )
{
    // Do stuff
}
if ( stricmp( "SOME_STRING_3", p_string ) == 0 )
{
    // Do stuff
}
if ( stricmp( "SOME_STRING_4", p_string ) == 0 )
{
    // Do stuff
}
etc...
Because, y'know, we've got nothing better to do with that CPU time other than carry on testing strings after we've already had a positive match.

Zombywuf
Mar 29, 2008

da keebsta knicca posted:

It is a university, we basically have to some times use NULL not to make people angry.

If gender is normalised, this is the horror.

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

TSDK posted:

I've started seeing this rather sub-optimal anti-pattern in a few places recently:
code:
if ( stricmp( "SOME_STRING_1", p_string ) == 0 )
{
    // Do stuff
}
if ( stricmp( "SOME_STRING_2", p_string ) == 0 )
{
    // Do stuff
}
if ( stricmp( "SOME_STRING_3", p_string ) == 0 )
{
    // Do stuff
}
if ( stricmp( "SOME_STRING_4", p_string ) == 0 )
{
    // Do stuff
}
etc...
Because, y'know, we've got nothing better to do with that CPU time other than carry on testing strings after we've already had a positive match.

How many strings are you testing against by the way

shrughes
Oct 11, 2008

(call/cc call/cc)
Codepadded into #cobol:

code:
  for (int b=a; a>0; a--)
  {
    cout << a << "\n";
    myfile << a << "\n";

  } while (a > 0);

Avenging Dentist
Oct 1, 2005

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

shrughes posted:

Codepadded into #cobol:

code:
  for (int b=a; a>0; a--)
  {
    cout << a << "\n";
    myfile << a << "\n";

  } while (a > 0);

What.

LIEUTENANT INTERNET
Jan 24, 2009

by Fragmaster

shrughes posted:

Codepadded into #cobol:

code:
  for (int b=a; a>0; a--)
  {
    cout << a << "\n";
    myfile << a << "\n";

  } while (a > 0);

nice try but it was poorly formatted and part of a do while loop

Avenging Dentist
Oct 1, 2005

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

LIEUTENANT INTERNET posted:

nice try but it was poorly formatted and part of a do while loop

u mad?

LIEUTENANT INTERNET
Jan 24, 2009

by Fragmaster

Avenging Dentist posted:

u mad?

nice try but Id Rather Be JavaProgrammingtm Enterprise Level Scalable Turnkey Networked Future-Proof Java Solutions instead of fooling around with c++

Avenging Dentist
Oct 1, 2005

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

LIEUTENANT INTERNET posted:

nice try but Id Rather Be JavaProgrammingtm Enterprise Level Scalable Turnkey Networked Future-Proof Java Solutions instead of fooling around with c++

Do you indent in Java like you do in C++? :pwn:

dancavallaro
Sep 10, 2006
My title sucks

LIEUTENANT INTERNET posted:

nice try but Id Rather Be JavaProgrammingtm Enterprise Level Scalable Turnkey Networked Future-Proof Java Solutions instead of fooling around with c++

:iceburn:

LIEUTENANT INTERNET
Jan 24, 2009

by Fragmaster

Avenging Dentist posted:

Do you indent in Java like you do in C++? :pwn:

real tabs :colbert:

Avenging Dentist
Oct 1, 2005

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

LIEUTENANT INTERNET posted:

real tabs :colbert:

Look upon your works, ye coder, and despair!

LIEUTENANT INTERNET
Jan 24, 2009

by Fragmaster

Avenging Dentist posted:

Look upon your works, ye coder, and despair!

good thing that isnt me

Avenging Dentist
Oct 1, 2005

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

LIEUTENANT INTERNET posted:

good thing that isnt me

It is now, and nothing you can say will change that.

Dessert Rose
May 17, 2004

awoken in control of a lucid deep dream...
the real wtf is that it actually saves to the file (without asking) and then asks if you want to save the file, but really it's asking "do you not want to delete the file?"

Smugdog Millionaire
Sep 14, 2002

8) Blame Icefrog

LIEUTENANT INTERNET posted:

nice try but it was poorly formatted and part of a do while loop

Mmmmm nope. http://codepad.org/s7b80pWr is that same code autoformatted with VS.

EDIT: Which I just noticed is still not formatted well.

Smugdog Millionaire fucked around with this message at 06:10 on Jan 28, 2009

Mill Town
Apr 17, 2006

nnn==

Mill Town fucked around with this message at 09:58 on Jan 28, 2009

TSDK
Nov 24, 2003

I got a wooden uploading this one

Otto Skorzeny posted:

How many strings are you testing against by the way
Enough to be annoyed at the repeated tests, but not enough to warrant a data structure to map the cases better.

Adbot
ADBOT LOVES YOU

Mill Town
Apr 17, 2006

TSDK posted:

Enough to be annoyed at the repeated tests, but not enough to warrant a data structure to map the cases better.

Data structure hell, just stuff all the strings into a hash set.

Near-constant lookup time, it'll actually perform better than an if-else block.

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