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
darthbob88
Oct 13, 2011

YOSPOS
Just came across a piece of my boss's code, and I'm not sure if it's :stonk: horror or :haw: simplicity.

Boss needed to work out how many items are in a given category, like on this page, and all that was really needed was a qualitative answer, whether or not there were more than 20 items in a category. With that in mind how would you get this answer? Personally, I'd use jQuery to count up all the product images on the page and call it good. Quick, easy, usable on many sites.
JavaScript code:
$("img[id*='qv_']").size();
My boss though? He took an arguably simpler route, and just used the "Total Items: <lots>" marker, right under the category name.
JavaScript code:
function getCatTotal() { //find out how many category results there are
		var catTitle = $('#CatTotal');
		if (catTitle && catTitle.length) {
			var total = catTitle.text();
			var begin = total.indexOf('Total Items: ');
			if (begin >= 0) {
				var numResults = parseInt(total.substring(begin + 13));
				if (!isNaN(numResults)) 
					return numResults;
			}
		}
		return 0;
	}
I'm not sure if this is excellent or terrible, and since it's both nonfunctional and obsolete, I don't much care. I do like the simplicity though; "Hmm, how will I work out if this category has more or less than 20 items? I know! I'll just use the label right there, that says how many items this category has." :haw:

Adbot
ADBOT LOVES YOU

pigdog
Apr 23, 2004

by Smythe
What if there are 500 items in the category, but the page is set to display only 20 of them at a time? What if some of the items don't have images associated with them?

Y'all should just get rid of the hardcoded and un-i18nable "Total Items:" and let #CatTotal refer only to the number.

pigdog fucked around with this message at 08:45 on Jun 6, 2012

darthbob88
Oct 13, 2011

YOSPOS

pigdog posted:

What if there are 500 items in the category, but the page is set to display only 20 of them at a time? What if some of the items don't have images associated with them?

Y'all should just get rid of the hardcoded and un-i18nable "Total Items:" and let #CatTotal refer only to the number.

Apparently the site's set to display at least 40 items on a category page, so that's not an issue. AFAIK, all the products have images, so my solution would still work. They may be blanks reading "No Photo Available", but every product has an image. And of course it doesn't really matter anymore, since the new system doesn't care about how many items are in a category.

Site's not ours, we're just scraping it, and it's in English for a mostly English-speaking customer base, so i18n is not a big concern. Apparently #CatTotal referred to the whole tag "Total Items: All of them", hence the need to cut out the number with a substring. I say apparently because the client has since changed it from #CatTotal to something else, so this code doesn't work right anymore, not that we need it as noted above. If we were going to continue using this code, it would be easy enough to scrape the "Total Items: lots" in a way which is still i18n-compatible:
JavaScript code:
var numResults = $("td.cat-titles:first").text().match(/\d+/);
return (!isNaN(numResults))? numResults : 0;

Bhaal
Jul 13, 2001
I ain't going down alone
Dr. Infant, MD
Strange though it sounds, your boss's way is more forward-looking if one day a requirement changes and you need to scrape an exact count instead of just > 20. Not that it's a huge deal either way, plus if you've got no control on their site then any solution is going to have vulnerabilities where a small change would break it. That being said a regex like that would be a better way of going about it, obv.

I can't really share the code as it's far too specific, but pretend you're in PHP and tasked to make a tool that reads in a CSV and does a bunch of stuff with it against some db tables. Basic everyday stuff, right? Well, let's focus on just the "read in a CSV" part, because while you're thinking "in something like PHP that part of the problem has a lifespan of about 4 seconds", our junior programmer has come up with a solution that:
  • Does not use one of the many pre-invented wheels like fgetcsv
  • never at any point fully models a row of data in an array or something, instead choosing giant for loops that bite off a piece one delimiter at a time, making debugging extra challenging
  • Up until recently it parsed strictly on a comma. No quote encapsulating or anything like that
  • Upon barfing on the first quote-encapsulating CSV it encountered, being advised by me and then by the CTO to use a pre-invented wheel like fgetcsv, he instead rewrote the (multiple) bits of code to instead parse on a regex to account for quotes
  • I'm actually not bad with regex, and yet I still have no idea WTF he was trying to accomplish with the one he came up with (hence me not wanting to post the code--it's pretty unique since it is pretty useless
  • His rewrite doesn't work and instead it just mis-parses quote-encapsulating CSVs([blah,"a,b",5] => parses into [blah,"a] [b"] [5])
  • His entire monstrous pile of code that handles all this uses zero associative arrays, one of the actual useful, net-positive features of PHP. He numerically indexes everything and creates a poo poo-ton of variables to map the position of all the business-specific fields in the CSV. I have flashbacks to my early days of reading MUD code written in C circa 1995.
  • You still have to append a dummy row in the CSV that doesn't map to anything on the database side because his parser will include the newline character on the last column.:v:
At this point, explode(',',explode("\n",$csv)) would literally (literally literally, not ironically literally) be a substantial improvement. I think the fact that rest of us are so overtasked is the only reason he's been able to survive here for so long, and the CTO has hinted at this on our last candid discussion (I think he feels stuck on what to do, at least until we get out from under a massive pile of deliverables that has everyone booked solid). We have funds but not dev time to bring on a new hire and get them minimally trained and oriented to start doing stuff in our system, so he stays around and produces more and more "giant nightmare I don't want to think about, but it works if you kick it a few times" features to our web app. I almost want to google up 20 or 30 blog posts about technical debt, print each one, and put them on the CTO's desk.

I technically don't have firing authority over him (besides going to my boss and saying "I quit unless you can him now", which would work but is not exactly healthy), and bad experience at some lovely previous gigs makes me get my dander up when I see anyone get thrown under the bus, so I don't go out of my way to point the finger when his various screwups cause production-level blockages (which the above caused recently). That being said, as far as the throwing under the bus analogy goes, this kid is playing in traffic and I'm starting to count the days for him to get creamed.

Bhaal fucked around with this message at 02:52 on Jun 7, 2012

pigdog
Apr 23, 2004

by Smythe

darthbob88 posted:

Apparently the site's set to display at least 40 items on a category page, so that's not an issue. AFAIK, all the products have images, so my solution would still work. They may be blanks reading "No Photo Available", but every product has an image. And of course it doesn't really matter anymore, since the new system doesn't care about how many items are in a category.
Both your solutions have unnecessary hidden dependencies
Your boss's:
- expects the string "Total Items: <number>" with no regard to i18n

Yours:
- expects every product to have an image
- expects every product to have one image
- expects products without images to have blanks
- expects said images to have ID of "qv_*" (though perhaps that's a firm specification?)
- expects the number of images per page to equal the number of items per category (all products to be displayed at once)
- presumes the question to be whether or not there were more than 20 items in a category, and the actual number to be irrelevant

If that's just one-time scrape, then cool, it doesn't matter terribly much. Yet I feel your original solution involves many more unobvious assumptions, each which have potential to introduce bugs and disparities if the context changed. Even on the link you provided, your solutions would provide different counts already.

Zombywuf
Mar 29, 2008

pigdog posted:

If that's just one-time scrape, then cool, it doesn't matter terribly much. Yet I feel your original solution involves many more unobvious assumptions, each which have potential to introduce bugs and disparities if the context changed. Even on the link you provided, your solutions would provide different counts already.

Web scrapers need constant changing to deal with changes in the data you're scraping. The best solutions are the ones which are the fastest. Count up the images on the site, have a sanity check in the backend and lots of monitoring, move on with your life and deal with changes in the data when they happen.

Personally I'd be tempted to compare the count of img[id*="qv_"] with the count of span.price and error if they were different, but that may be overkill dependent on the context.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Bhaal posted:

I think the fact that rest of us are so overtasked is the only reason he's been able to survive here for so long, and the CTO has hinted at this on our last candid discussion (I think he feels stuck on what to do, at least until we get out from under a massive pile of deliverables that has everyone booked solid). We have funds but not dev time to bring on a new hire and get them minimally trained and oriented to start doing stuff in our system, so he stays around and produces more and more "giant nightmare I don't want to think about, but it works if you kick it a few times" features to our web app. I almost want to google up 20 or 30 blog posts about technical debt, print each one, and put them on the CTO's desk.

I technically don't have firing authority over him (besides going to my boss and saying "I quit unless you can him now", which would work but is not exactly healthy), and bad experience at some lovely previous gigs makes me get my dander up when I see anyone get thrown under the bus, so I don't go out of my way to point the finger when his various screwups cause production-level blockages (which the above caused recently). That being said, as far as the throwing under the bus analogy goes, this kid is playing in traffic and I'm starting to count the days for him to get creamed.

Two things:
1) Is your team doing waterfall? That's your first mistake. In Agile, if someone quits or is fired, you just say "So our next sprint we'll have less points available due to decreased headcount and interviewing efforts; you only get 50 points instead of 70",
2) Firing the weak links spreads the remaining work around more, but in my experience results in a net productivity gain because you're getting poo poo done right on the first try instead of scrambling around trying to put out the fires created by your incompetent co-worker.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug
Just came across this in something. It's not a horror, just... weirdly useless.

C# code:
        public static bool IsEmptyOrNull(this string value)
        {
            return string.IsNullOrEmpty(value);
        }

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."
I dunno man, how are you going to remember method names like that if the conditions aren't ordered alphabetically?

ninjeff
Jan 19, 2004

Internet Janitor posted:

I dunno man, how are you going to remember method names like that if the conditions aren't ordered alphabetically?

Even worse, "IsNullOrEmpty" exposes the order the conditions are checked in (an implementation detail), and that's a BIG no-no. Props to this dev for doing the right thing and futureproofing his code.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug
To be fair, the point of the method was to expose IsNullOrEmpty as an extension method so you could do value.IsEmptyOrNull().

No Safe Word
Feb 26, 2005

With the horror being that IsNullOrEmpty as an extension method makes no sense whatsoever for hopefully obvious reasons (or rather, might as well just be called IsEmptyOrThrowsAnException)

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

No Safe Word posted:

With the horror being that IsNullOrEmpty as an extension method makes no sense whatsoever for hopefully obvious reasons (or rather, might as well just be called IsEmptyOrThrowsAnException)

It won't throw an exception.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
Extension methods are just sugar for static methods, so this can legally be null inside them.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Plorkyeran posted:

Extension methods are just sugar for static methods, so this can legally be null inside them.

The "this" in extension methods is just Microsoft reusing keywords whenever they can -- it's not the same thing as "this" referring to the current class instance.

Mogomra
Nov 5, 2005

simply having a wonderful time
I think extension methods are nice, but really?

Is that just to prevent stuff like:
code:
something.ToString().IsNullOrEmpty();
?

Is that hard to understand or something?

Munkeymon
Aug 14, 2003

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



It just saves someone from typing 'string'. something.IsEmptyOrNull() vs string.IsNullOrEmpty(something)

I guess that could be a little helpful sometimes

Sinestro
Oct 31, 2010

The perfect day needs the perfect set of wheels.
I have had things like that in my code. It just looks a little cleaner.

Sedro
Dec 31, 2008

Munkeymon posted:

It just saves someone from typing 'string'. something.IsEmptyOrNull() vs string.IsNullOrEmpty(something)

I guess that could be a little helpful sometimes
It's not just about typing 'string'. Extension methods let you read things in order of operations rather than inside-out.
Java code:
StringUtils.reverse(StringUtils.trim(StringUtils.defaultIfNull(something, StringUtils.EMPTY)))
versus
C# code:
something.DefaultIfNull(string.Empty).Trim().Reverse()
The other problem is finding the utility methods; if I want a collections method in Java I have to look through Collections, Collections2, CollectionsUtils, Iterables, etc. and classes with those same names in various different packages.

akadajet
Sep 14, 2003

This isn't so much a "coding horror" but a "developer conference horror", but I thought you guys might enjoy shuddering at this.

https://www.youtube.com/watch?v=JUMjxnKzUlQ

windowsazure posted:

This week’s Norwegian Developer’s Conference included a skit that involved inappropriate and offensive elements and vulgar language. We apologize to our customers and our partners and are actively looking into the matter.
I bet.

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

akadajet posted:

This isn't so much a "coding horror" but a "developer conference horror", but I thought you guys might enjoy shuddering at this.

https://www.youtube.com/watch?v=JUMjxnKzUlQ

I bet.

I think you could have just said "Developer's Conference" and "had a skit" and that would have been enough.

Strong Sauce
Jul 2, 2003

You know I am not really your father.





Yeah that bit about "micro" and "soft" not relating to my PENIS was kinda of awkward and weird but I'm more offended by the dance number, specifically that developers at a conference want something like that.

ymgve
Jan 2, 2004


:dukedog:
Offensive Clock

Strong Sauce posted:

Yeah that bit about "micro" and "soft" not relating to my PENIS was kinda of awkward and weird but I'm more offended by the dance number, specifically that developers at a conference want something like that.

No, it's the conference planners that think developers want it.

how!!
Nov 19, 2011

by angerbot
Hot girls dancing in hot pants is not a horror. You nerds.

Jonnty
Aug 2, 2007

The enemy has become a flaming star!

how!! posted:

Hot girls dancing in hot pants is not a horror. You nerds.

Nice job being the problem with the IT industry there. Perhaps you'd like to enlighten us with your views on how harmless booth babes are next?

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

akadajet posted:

This isn't so much a "coding horror" but a "developer conference horror", but I thought you guys might enjoy shuddering at this.

https://www.youtube.com/watch?v=JUMjxnKzUlQ

I bet.

is the music supposed to be a parody of scooter

Doctor w-rw-rw-
Jun 24, 2008

how!! posted:

Hot girls dancing in hot pants is not a horror. You nerds.

Jonnty posted:

Nice job being the problem with the IT industry there. Perhaps you'd like to enlighten us with your views on how harmless booth babes are next?

Y'know, the "penis" line was incredibly awkward, but it didn't look at all like the performance went out of its way to sexualize the women or indeed make any commentary on gender or sexuality at all. I mean, from the looks of it (video quality not high enough to tell), they were wearing sweaters. Certainly not bikinis. "Sensual" or "arousing" are the last two words I would ever use to describe that dance - which, given the context, is a good thing. "Hot girls dancing in hot pants" certainly *could be* a horror, but this one seems somewhat unoffensive...albeit tacky.

So while I'm with you (Jonnty) on the IT/etc industry having to be more sensitive in addressing sexuality/gender issues, having no sense of humor isn't going to fix the problem, either, it's just going to deprive truly oversexualized and demeaning content of its fair share of outrage, creating a glut of unnecessary outrage instead. And then people will just ignore the problem altogether.

Doctor w-rw-rw- fucked around with this message at 05:16 on Jun 9, 2012

how!!
Nov 19, 2011

by angerbot

Jonnty posted:

Nice job being the problem with the IT industry there. Perhaps you'd like to enlighten us with your views on how harmless booth babes are next?

No, but you could you please enlighen me as to who is being harmed by booth babes in the first place? Are you being harmed by booth babes?

Malloc Voidstar
May 7, 2007

Fuck the cowboys. Unf. Fuck em hard.
Yeah it's totally not harmful at all to women to be reduced to sex objects used to sell goods and for that to be the most prominent presence of women at trade shows

het
Nov 14, 2002

A dark black past
is my most valued
possession
So we've got an assessment that we send out to applicants for our programming positions. It's just 5 more-or-less simple everyday problems that we've actually run into. Some are easier than others, but none of them are what I would consider difficult.

One of them involves taking a netmask and providing the CIDR number for it, in any language the applicant prefers. This should be trivially easy (even if you don't know what a netmask or CIDR block is; it's just simple bitmaps at the end of it). But this applicant who has 15 years of programming experience submitted a solution in C (this is a bit of a red flag when the problem involves text parsing) where his algorithm was this:

  • Loop 4 times over the following code:
  • Seek to the next '.' in the string or the end of the string given by the variable i
  • Get the quad value by computing (str[i-3] - '0') * 100 + (str[i-2] - '0') * 10 + (str[i-1] - '0')
Note I didn't mention checking whether the characters in question were a digit.
  • Starting at the 8th bit, check to see if it's set, if so, >> and check the next one
  • if a zero is found, set a flag. If you find a 1 after this point, error out.
  • Go back to the first statement assuming no out of order 0 was found
Note that this ignores values over 255.

The end result is that the following netmasks were considered valid: 511.255.255.0 (a /24), 2255.87255.32511.0 (/24), and 255.255.255.fart (a /30 apparently??)


The funny thing is that after viewing other submissions, I probably should have given him credit for actually knowing characters are numbers.

(also for the love of god stop talking about booth babes)

Star War Sex Parrot
Oct 2, 2003

Aleksei Vasiliev posted:

Yeah it's totally not harmful at all to women to be reduced to sex objects used to sell goods and for that to be the most prominent presence of women at trade shows
We don't need this derail in the god drat programming forum.

Zombywuf
Mar 29, 2008

Otto Skorzeny posted:

is the music supposed to be a parody of scooter

Microsoft's never ending struggle to be relevant.

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.

Zombywuf posted:

Microsoft's never ending struggle to be relevant.

I was at the mall cause I needed a power supply from the Apple store and I finally got around to seeing one of those Microsoft stores. There were something like 6 people in their huge sprawling store, and the Apple store which was about half the size was more like 45-50 customers. Microsoft really has to figure out wtf they are doing with regards to the consumer cause it looks shameful.

the talent deficit
Dec 20, 2003

self-deprecation is a very british trait, and problems can arise when the british attempt to do so with a foreign culture






xml is my xtc

Axel Rhodes Scholar
May 12, 2001

Courage Reactor

Star War Sex Parrot posted:

We don't need this derail in the god drat programming forum.

Maybe not in this thread but apparently basically every programming forum/conference/mailing list does need this derail, over and over and over. I bet a CoC 'women in computer science' thread would go well :)

also here is a coding horror, in commemoration of the ipv6 world launch this week:
code:
uint32 ip;
:rant:

ToxicFrog
Apr 26, 2008


dazjw posted:

Maybe not in this thread but apparently basically every programming forum/conference/mailing list does need this derail, over and over and over. I bet a CoC 'women in computer science' thread would go well :)

If the "women in gaming" threads are anything to go by it would be one page of discussion, five pages of trolling by MRA shitheads, and then a trip to the gas chamber. :(

quote:

also here is a coding horror, in commemoration of the ipv6 world launch this week:
code:
uint32 ip;
:rant:

:suicide:

Meanwhile, I'm working on an embedded system where the standard library functions all have an "iap_" prefix, except for the ones that have an "Iap_" prefix or an "IAP_" prefix or no prefix at all. Yeah, tame compared to most of the stuff posted in this thread, but it wears on me.

Look Around You
Jan 19, 2009

dazjw posted:

Maybe not in this thread but apparently basically every programming forum/conference/mailing list does need this derail, over and over and over. I bet a CoC 'women in computer science' thread would go well :)

also here is a coding horror, in commemoration of the ipv6 world launch this week:
code:
uint32 ip;
:rant:

I thought IPv6 was supposed to have launched like 5 times already and every year it's "no this time it's different!". There was a kid in one of my CS classes that legitimately said that when my professor expressed doubt that the switch was going to happen anytime soon.

Doctor w-rw-rw-
Jun 24, 2008

Look Around You posted:

I thought IPv6 was supposed to have launched like 5 times already and every year it's "no this time it's different!". There was a kid in one of my CS classes that legitimately said that when my professor expressed doubt that the switch was going to happen anytime soon.

Comcast has IPv6 running on one set of hardware, and are working on their Cisco hardware next. The delay has been because the full stack of software AND hardware has to be migrated, tested, and deployed. There was 6to4, - which didn't guarantee that the IPv6 address that was an alias of your IPv4 address actually had a route on the IPv6 internet, then there was 6rd - which put that ball in the ISP's court, rather than a random tunnel broker - to expedite IPv6 deployment, and then there's, finally, normal IPv6.

So from a backbone perspective it's there; from a ISP perspective, it means hardware, software, and deployment need to be upgraded, along with new consumer devices (routers/modems) that support it (for the vast majority of users).

So it's gotten closer every time but random person A accessing random site B needs each link along the way to work, and until *that* is true, I don't think we can consider IPv6 to have been "switched to". When it's there, though, IPv4 will probably become legacy quickly (as in, several months to a few years, hah) and supported primarily for old devices' sake.

Doctor w-rw-rw- fucked around with this message at 20:40 on Jun 9, 2012

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe

Doctor w-rw-rw- posted:

So from a backbone perspective it's there; from a ISP perspective, it means hardware, software, and deployment need to be upgraded, along with new consumer devices (routers/modems) that support it (for the vast majority of users).

Comcast is looking at adding infrastructure to do the translation at the CO rather than at the home, so you talk IPv4 to the CO, and it talks IPv6 to the backbone.

Adbot
ADBOT LOVES YOU

Look Around You
Jan 19, 2009

Doctor w-rw-rw- posted:

Comcast has IPv6 running on one set of hardware, and are working on their Cisco hardware next. The delay has been because the full stack of software AND hardware has to be migrated, tested, and deployed. There was 6to4, - which didn't guarantee that the IPv6 address that was an alias of your IPv4 address actually had a route on the IPv6 internet, then there was 6rd - which put that ball in the ISP's court, rather than a random tunnel broker - to expedite IPv6 deployment, and then there's, finally, normal IPv6.

So from a backbone perspective it's there; from a ISP perspective, it means hardware, software, and deployment need to be upgraded, along with new consumer devices (routers/modems) that support it (for the vast majority of users).

So it's gotten closer every time but random person A accessing random site B needs each link along the way to work, and until *that* is true, I don't think we can consider IPv6 to have been "switched to". When it's there, though, IPv4 will probably become legacy quickly (as in, several months to a few years, hah) and supported primarily for old devices' sake.

Oh, yeah, it's exactly that reason why what that kid said is kind of ridiculous. There's so much more going into the switch than most people realize and people who think it's as simple as flipping a switch are retarded and have no idea how much actually has to go into it.

That being said ISPs are horrible about using government funds for what they're actually supposed to be used for, but that isn't exactly a new thing.

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