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
Doh004
Apr 22, 2007

Mmmmm Donuts...

LOOK I AM A TURTLE posted:

I blame stuff like this partly on the relative difficulty of doing little ad-hoc checks for membership in some constant list in C#. In Python, even your average terrible programmer can figure out how to do this:
Python code:
int(DataContext.Params["pageCode"]) in [1000, 1037, etc.]
What's the best way to write that same line in C#? Like this?
C# code:
new int[] { 1000, 1037, etc. }.Contains(int.Parse(DataContext.Params["pageCode"]))
Not to say the Python example is good either, since obviously there should at the very least be a "ValidPageCodes" list and a function call to wrap the check, but at least it would be easy to tell what the actual codes are at a glance.

Pretty much.

I ended up having to determine all of the different sectors, and their corresponding subsectors and put them in their own static lists of ints. So now you can just do

C# code:
insurancePageCodes.Contains(int.Parse(DataContext.Params["pageCode"]))
// or
bondPageCodes.Contains(int.Parse(DataContext.Params["pageCode"]))
Also changed it so we stopped rewriting the int parsing of the pageCode variable and just did it once. I think that annoyed me even more so.

*edit #2* And if I were to actually spend more time on it (if I actually owned the solution) I'd have a valid system setup to determine the correct page codes instead of just going off of integers. But :effort:

Doh004 fucked around with this message at 18:23 on May 31, 2012

Adbot
ADBOT LOVES YOU

epswing
Nov 4, 2003

Soiled Meat

Apparently neither of you read my second sentence.

E: vvv :rolleyes:

epswing fucked around with this message at 18:31 on May 31, 2012

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

epswing posted:

Apparently neither of you read my second sentence.

Sure they did. You said "it's not much of an optimization", and trex pointed out that it might not even be an optimization.

Johnny Cache Hit
Oct 17, 2011

ijustam posted:

This code

:negative:

All the SQL statements are just plain-text strings, with the escaping just changing single quotes into double single quotes (' -> ''). On top of that, all of the SQL statements are written into one string, which is declared at the global scope so every single method shares the same string.

But why change it if it works? :suicide:

:respek:

At my last job they couldn't decide between that approach, and "throw each SQL statement into a table, query for it at runtime, and EXECUTE it".

I think all veteran programmers know exactly which solution they ended up picking - both.

NiceAaron
Oct 19, 2003

Devote your hearts to the cause~

So I needed to query a list of key/value pairs from the database, and of course it turns out that they're stored as a big ol' string in one column of the relevant table, and looks kind of like this:

code:
WECC_RESERVE_RESPONSIBLE_ENTITY]_,_[BPAT}*,*{WECC_RESERVE_RESP_ENTITY_TYPE]_,_[BA}*,*{WECC_RESERVE_MULTIPLIER]_,_[5}*,*{Original Tag]_,_[BPAT_BPATRZOO127_BPAT
Which is a pretty big horror but let me finish. I quickly realized that this string is using a sequence of characters to delimit the key/value pairs, and another sequence of characters to delimit the keys from the values. (I suspect that the original developer didn't think of the brackets as part of the delimiter and was just trying to quote the values, but the brackets don't actually match up correctly, so gently caress it they're part of the delimiter.)

}*,*{

]_,_[

If you're not giggling already then you have a much cleaner mind than me and every coworker I showed this to.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed

pokeyman posted:

Sure they did. You said "it's not much of an optimization", and trex pointed out that it might not even be an optimization.
I'll go a step further and point out that in order for it to be an optimization you'd either have to reuse the data structure between calls or somehow have a hash function that is faster than your equality function. Constructing a one-use hash table is sometimes the simplest thing to do, but it's never the fastest.

PrBacterio
Jul 19, 2000

NiceAaron posted:

}*,*{

]_,_[

If you're not giggling already then you have a much cleaner mind than me and every coworker I showed this to.
I *think* I'm getting the second one but the first one frankly doesn't really look like anything to me :ohdear:

Look Around You
Jan 19, 2009

PrBacterio posted:

I *think* I'm getting the second one but the first one frankly doesn't really look like anything to me :ohdear:

It looks like a lady's torso.

Doc Hawkins
Jun 15, 2010

Dashing? But I'm not even moving!


I see a high owl.

Sinestro
Oct 31, 2010

The perfect day needs the perfect set of wheels.
I saw a stoned dwarf in a barrel. v:v:v

Carthag Tuek
Oct 15, 2005

Tider skal komme,
tider skal henrulle,
slćgt skal fřlge slćgters gang



its an elephant on pcp.

All Hat
Jul 11, 2008

He that is without int among you, let him first cast a long

A man peeking out with boobies on each side of his face. Lucky guy.
It may also be a man with grotesquely large ears. Lucky guy.

darthbob88
Oct 13, 2011

YOSPOS
Not sure just how much of a coding vs business horror this is, but: Ran into a problem at work of a technopolitical nature. Asked for help with it in this post, but the summary is that my code and client code are butting heads and one of them will have to be modified to make everything work. Managed to modify my code to make it fit, but that's not the horror.

The horror is that I mentioned this problem to a carpool buddy, and that my only good options here were break client code or modify my code. He suggested that I break the client code, then explain to the client that it was necessary to make my code work.
:v: The client, being a rational business owner, will totally understand that you, as the expert they hired, know what you're doing better than they do, that this is the best way to make your code work, and they definitely won't resent you suggesting their site is ugly and badly coded.
:eng99: And then after this meeting where they thank me for breaking their site, we'd all ride off on our unicorns to Neverland, to have tea with the Queen of the Fairies.

Hell, I'm a programmer with Asperger's, and I have a better grasp on people than this guy does.

Re: The delimiters, I understood the first one fairly quickly to be a curvy lady's torso, but the second one is a bit more puzzling. Man's torso, possibly with a boner?

pseudorandom name
May 6, 2007

darthbob88 posted:

Re: The delimiters, I understood the first one fairly quickly to be a curvy lady's torso, but the second one is a bit more puzzling. Man's torso, possibly with a boner?

:butt:

Progressive JPEG
Feb 19, 2003

trex eaterofcadrs posted:

Yeah you guys are all talking about serialization, and I've never used it professionally so I was just tossing it out there to see if anyone had experience with it, in a horrible manner of course.

They're wonderful. Protobufs I mean. If you're looking to send stuff over a network or store stuff to disk, there's really not much reason to use anything else. And yes I use them at my jerb all the time.

Ithaqua posted:

I forget if my spirit was too crushed to bother refactoring by that point, but this would've made a lot more sense:
C# code:
public static string ToNonNullString(this string s) 
{
	return s ?? string.Empty;
}

???????

Doctor w-rw-rw-
Jun 24, 2008

beoba posted:

They're wonderful. Protobufs I mean. If you're looking to send stuff over a network or store stuff to disk, there's really not much reason to use anything else. And yes I use them at my jerb all the time.

Interesting. I'd like to know more, but this seems like a job for the Java thread rather than the coding horrors thread, if they're actually good.

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

Doctor w-rw-rw- posted:

Interesting. I'd like to know more, but this seems like a job for the Java thread rather than the coding horrors thread, if they're actually good.

They are available in C++ and python too IIRC.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

beoba posted:

???????

!!!!!!

The refactoring was to replace the poorly-named, stupidly-implemented method with an extension method. In C#, you can extend a type that you don't have source for (like, in this case, string) by making a static method in a static class, and marking the first parameter with the this keyword.

So with the method I defined earlier, you could do:
code:
var foo = "Test string";
var definitelyNotNullFoo = foo.ToNonNullString();
It makes writing fluent code a lot easier, because you can read the order of method execution in order, instead of from the inside out.

Like if you had ThenTheLastThing(ThenOtherThing(DoThing(foo)));, it's way more readable if you can write it as foo.DoThing().ThenOtherThing().ThenTheLastThing();

Bohemian Cowabunga
Mar 24, 2008

So can we bitch about lovely teachers here?..
I am currently studying to become a network engineer and have taken an introductory course in C# on the side. The entire course has pretty much turned into a self-study. We have had zero theory and not turned in a single assignment, but merely worked on whatever we wanted during the classes.

Now we have never actually seen any of this guys own code until now, when he gave us the code our oral exam is based upon.

http://pastebin.com/RYHrAfRb

This guy is being paid to teach programming.

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

Bohemian Cowabunga posted:

So can we bitch about lovely teachers here?..
I am currently studying to become a network engineer and have taken an introductory course in C# on the side. The entire course has pretty much turned into a self-study. We have had zero theory and not turned in a single assignment, but merely worked on whatever we wanted during the classes.

Now we have never actually seen any of this guys own code until now, when he gave us the code our oral exam is based upon.

http://pastebin.com/RYHrAfRb

This guy is being paid to teach programming.

He's obviously just showing you what *not* to do....

Bruegels Fuckbooks
Sep 14, 2004

Now, listen - I know the two of you are very different from each other in a lot of ways, but you have to understand that as far as Grandpa's concerned, you're both pieces of shit! Yeah. I can prove it mathematically.

Bohemian Cowabunga posted:

So can we bitch about lovely teachers here?..
I am currently studying to become a network engineer and have taken an introductory course in C# on the side. The entire course has pretty much turned into a self-study. We have had zero theory and not turned in a single assignment, but merely worked on whatever we wanted during the classes.

Now we have never actually seen any of this guys own code until now, when he gave us the code our oral exam is based upon.

http://pastebin.com/RYHrAfRb

This guy is being paid to teach programming.

Wow, that is extremely uneducated C# - it's about what you'd expect if you gave a high school freshman a copy of winforms for dummies and two days.

Doh004
Apr 22, 2007

Mmmmm Donuts...

Bohemian Cowabunga posted:

So can we bitch about lovely teachers here?..
I am currently studying to become a network engineer and have taken an introductory course in C# on the side. The entire course has pretty much turned into a self-study. We have had zero theory and not turned in a single assignment, but merely worked on whatever we wanted during the classes.

Now we have never actually seen any of this guys own code until now, when he gave us the code our oral exam is based upon.

http://pastebin.com/RYHrAfRb

This guy is being paid to teach programming.

Get your money back. That's horrific.

Sinestro
Oct 31, 2010

The perfect day needs the perfect set of wheels.

Bohemian Cowabunga posted:

So can we bitch about lovely teachers here?..
I am currently studying to become a network engineer and have taken an introductory course in C# on the side. The entire course has pretty much turned into a self-study. We have had zero theory and not turned in a single assignment, but merely worked on whatever we wanted during the classes.

Now we have never actually seen any of this guys own code until now, when he gave us the code our oral exam is based upon.

http://pastebin.com/RYHrAfRb

This guy is being paid to teach programming.

Rubbing a hard drive with a magnet would make better C#. Kill him and burn the corpse.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Bohemian Cowabunga posted:

So can we bitch about lovely teachers here?..
I am currently studying to become a network engineer and have taken an introductory course in C# on the side. The entire course has pretty much turned into a self-study. We have had zero theory and not turned in a single assignment, but merely worked on whatever we wanted during the classes.

Now we have never actually seen any of this guys own code until now, when he gave us the code our oral exam is based upon.

http://pastebin.com/RYHrAfRb

This guy is being paid to teach programming.

That's atrocious. It would be pretty amusing if you refactored it to remove all of the horrors, but then you'd probably get an F for being a snarky bastard.

epswing
Nov 4, 2003

Soiled Meat

Bohemian Cowabunga posted:

So can we bitch about lovely teachers here?..
I am currently studying to become a network engineer and have taken an introductory course in C# on the side. The entire course has pretty much turned into a self-study. We have had zero theory and not turned in a single assignment, but merely worked on whatever we wanted during the classes.

Now we have never actually seen any of this guys own code until now, when he gave us the code our oral exam is based upon.

http://pastebin.com/RYHrAfRb

This guy is being paid to teach programming.

:aaa: holy poo poo man

nielsm
Jun 1, 2009



Looks like PHP written with C# syntax.

gonadic io
Feb 16, 2011

>>=
C# code:
public static bool db = false;// true or false ;
I guess this is the 'teaching' part of the course?

Bohemian Cowabunga
Mar 24, 2008

^^^^Pretty much!


Doh004 posted:

Get your money back. That's horrific.

Being danish I am at least not paying for this, in fact, I get paid for it :denmark:

hieronymus posted:

Wow, that is extremely uneducated C# - it's about what you'd expect if you gave a high school freshman a copy of winforms for dummies and two days.
I have to say I was kinda shocked as well. I have just been following various online books and most of what he does just seem to go against everything I have been reading.

Ithaqua posted:

That's atrocious. It would be pretty amusing if you refactored it to remove all of the horrors, but then you'd probably get an F for being a snarky bastard.

Yeah, it is gonna be hard explaining this code without doing nothing but correcting it.

Zombywuf
Mar 29, 2008

Bohemian Cowabunga posted:

Being danish I am at least not paying for this, in fact, I get paid for it :denmark:

Fill in the blanks in his code and look at it as an opportunity to stick a few hobby projects on Github.

zokie
Feb 13, 2006

Out of many, Sweden

Bohemian Cowabunga posted:

So can we bitch about lovely teachers here?..
I am currently studying to become a network engineer and have taken an introductory course in C# on the side. The entire course has pretty much turned into a self-study. We have had zero theory and not turned in a single assignment, but merely worked on whatever we wanted during the classes.

Now we have never actually seen any of this guys own code until now, when he gave us the code our oral exam is based upon.

http://pastebin.com/RYHrAfRb

This guy is being paid to teach programming.

Haha, saw the "antal" variable and got reminded of my introductory class to Java. Where the teacher programmed in Swedish! He would literally write: hämtaNamn() and ändraNamn(String namn) instead of get/setName(). During our second year C#-course I had to convince some of my course mates that we should program in English :smith: :sweden:

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope
I was just on a user interface course that was previously (the last 10 years or so) been held in Finnish, so of course in the example programs all the variables were in Finnish instead of English.

I felt so sorry for the exchange students.

Zombywuf
Mar 29, 2008

You get to learn two languages for the price of one, where's the problem?

Novo
May 13, 2003

Stercorem pro cerebro habes
Soiled Meat

Munkeymon posted:

I'm assuming the bank's data service (you didn't think Mint logged into their web site and scraped it did you?) can't handle the character and, since Mint can't force the bank to fix their poo poo, they basically say "If you want this to work today, you'll have to change your password so we can [also] log in [using the service your bank gives us to work with]"

Mint's data provider, Yodlee, absolutely does do screen scraping when there is no API available.

Bruegels Fuckbooks
Sep 14, 2004

Now, listen - I know the two of you are very different from each other in a lot of ways, but you have to understand that as far as Grandpa's concerned, you're both pieces of shit! Yeah. I can prove it mathematically.

Zombywuf posted:

You get to learn two languages for the price of one, where's the problem?

I went to Finland once - Finnish is completely unintelligible to (this) native English speaker. I didn't think I knew Swedish at all but I was actually pretty thankful that all the road signs were also written in Swedish because I am completely illiterate in Finnish but occasionally, Swedish has a loan word.

Coffee Mugshot
Jun 26, 2010

by Lowtax
I don't get it. That's how all my professors' code looks at the university I'm at right now. Turns out the people who teach you how to code don't know how to code themselves.

Dicky B
Mar 23, 2004

The codebase I took over at my job was previously worked on by a Polish programmer and is littered with Polish comments and code.

My favorite discovery was a variable named "zmienna".

nielsm
Jun 1, 2009



Dicky B posted:

The codebase I took over at my job was previously worked on by a Polish programmer and is littered with Polish comments and code.

My favorite discovery was a variable named "zmienna".

So did it use Polish notation?
What happens when a Hungarian is taught to program like that?
:haw:

Sinestro
Oct 31, 2010

The perfect day needs the perfect set of wheels.

nielsm posted:

So did it use Polish notation?
What happens when a Hungarian is taught to program like that?
:haw:

szNév

Progressive JPEG
Feb 19, 2003

Doctor w-rw-rw- posted:

Interesting. I'd like to know more, but this seems like a job for the Java thread rather than the coding horrors thread, if they're actually good.

trex eaterofcadrs posted:

They are available in C++ and python too IIRC.

Yeah, base protobuf is effectively a specification of the serialization format and .proto file syntax. On top of that are various per-language generators and libraries which handle manipulating that data. Official ones are C++/Java/Python, but there are apparently a bunch of third party implementations for other languages, too.

<back to horrors>

Adbot
ADBOT LOVES YOU

Munkeymon
Aug 14, 2003

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



Novo posted:

Mint's data provider, Yodlee, absolutely does do screen scraping when there is no API available.

Well, first off http://money.cnn.com/2010/12/02/pf/mint_leaves_yodlee/index.htm

Second, if they weren't actually getting the data themselves, that makes it kind of weird that Mint was telling me to pester my credit union to integrate with Mint (and not Yodlee or whatever) back in 2008 or 9.

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