|
That wouldn't even work in Python, although I don't know about Perl.
|
# ? Jan 26, 2009 20:43 |
|
|
# ? Apr 23, 2024 23:18 |
|
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:.
|
# ? Jan 26, 2009 23:48 |
|
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.
|
# ? Jan 27, 2009 01:50 |
|
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. 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.
|
# ? Jan 27, 2009 03:04 |
|
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.
|
# ? Jan 27, 2009 03:58 |
|
From library code:code:
From my company's code, and way too often: code:
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.
|
# ? Jan 27, 2009 04:21 |
|
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.
|
# ? Jan 27, 2009 04:24 |
|
Ugg boots posted:
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.
|
# ? Jan 27, 2009 05:17 |
|
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.
|
# ? Jan 27, 2009 05:18 |
|
Ah, I was only considering positive whole numbers.
|
# ? Jan 27, 2009 05:26 |
|
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. 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.
|
# ? Jan 27, 2009 06:00 |
|
$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.
|
# ? Jan 27, 2009 06:11 |
|
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.
|
# ? Jan 27, 2009 06:35 |
|
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...
|
# ? Jan 27, 2009 20:22 |
|
There could be more genders, like null or pirate.
|
# ? Jan 27, 2009 20:27 |
|
It is a university, we basically have to some times use NULL not to make people angry.
|
# ? Jan 27, 2009 20:29 |
|
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.
|
# ? Jan 27, 2009 20:55 |
|
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.
|
# ? Jan 27, 2009 20:58 |
|
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.
|
# ? Jan 27, 2009 21:04 |
|
Ryouga Inverse posted:To be fair, I'd be pretty pissed off if I had both sexes and you forced me to pick one.
|
# ? Jan 27, 2009 21:09 |
|
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.
|
# ? Jan 27, 2009 21:10 |
|
I've started seeing this rather sub-optimal anti-pattern in a few places recently:code:
|
# ? Jan 27, 2009 21:23 |
|
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.
|
# ? Jan 27, 2009 21:34 |
|
TSDK posted:I've started seeing this rather sub-optimal anti-pattern in a few places recently: How many strings are you testing against by the way
|
# ? Jan 27, 2009 22:10 |
|
Codepadded into #cobol:code:
|
# ? Jan 28, 2009 02:11 |
|
shrughes posted:Codepadded into #cobol: What.
|
# ? Jan 28, 2009 02:21 |
|
shrughes posted:Codepadded into #cobol: nice try but it was poorly formatted and part of a do while loop
|
# ? Jan 28, 2009 02:22 |
|
LIEUTENANT INTERNET posted:nice try but it was poorly formatted and part of a do while loop u mad?
|
# ? Jan 28, 2009 02:24 |
|
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++
|
# ? Jan 28, 2009 02:26 |
|
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++?
|
# ? Jan 28, 2009 02:27 |
|
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++
|
# ? Jan 28, 2009 02:27 |
|
Avenging Dentist posted:Do you indent in Java like you do in C++? real tabs
|
# ? Jan 28, 2009 02:28 |
|
LIEUTENANT INTERNET posted:real tabs Look upon your works, ye coder, and despair!
|
# ? Jan 28, 2009 02:30 |
|
Avenging Dentist posted:Look upon your works, ye coder, and despair! good thing that isnt me
|
# ? Jan 28, 2009 02:33 |
|
LIEUTENANT INTERNET posted:good thing that isnt me It is now, and nothing you can say will change that.
|
# ? Jan 28, 2009 02:35 |
|
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?"
|
# ? Jan 28, 2009 03:51 |
|
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 |
# ? Jan 28, 2009 06:08 |
|
nnn==
Mill Town fucked around with this message at 09:58 on Jan 28, 2009 |
# ? Jan 28, 2009 09:55 |
|
Otto Skorzeny posted:How many strings are you testing against by the way
|
# ? Jan 28, 2009 10:24 |
|
|
# ? Apr 23, 2024 23:18 |
|
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.
|
# ? Jan 28, 2009 10:38 |