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
Progressive JPEG
Feb 19, 2003

TheresaJayne posted:

I recently had to update our unit tests that had become out of date about 2 years ago.

I came across these tests.

assertTrue(expectedValue == result);


:freakout:

Why not just use assertEquals(expectedValue,result);
FWIW I vaguely remember some case where GTest's assertEquals not working when assertTrue(x == y) did. Not sure what exactly it was though.

Adbot
ADBOT LOVES YOU

Flobbster
Feb 17, 2005

"Cadet Kirk, after the way you cheated on the Kobayashi Maru test I oughta punch you in tha face!"
Well in JUnit, assertEquals calls .equals rather than evaluating ==, so those two lines are different if the first object overrides it. But if you strictly need to check ==, that's what assertSame is for.

So I don't think there's really a legitimate reason to ever do assertTrue(x == y).

Plorkyeran
Mar 22, 2007

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

Progressive JPEG posted:

FWIW I vaguely remember some case where GTest's assertEquals not working when assertTrue(x == y) did. Not sure what exactly it was though.
There's plenty of cases where assertEquals simply won't compile while assertTrue(x == y) will, because assertEquals prints more useful information when it fails and gtest doesn't bother to do so only when it's actually possible.

Progressive JPEG
Feb 19, 2003

That sounds right, it's been several months since I last used it so I wasn't sure of the reason

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope

MononcQc posted:

  • Alternatively some projectors are super lovely and will display reds as black or dark brown and I try to make sure this isn't messed up

I'm already crying because I'm going to make a presentation about JPEG compression on a university course. "When you compare these two images, you can clearly see the compression artifacts" *both images look like identical low-contrast mess*

And that's the best-case scenario

raminasi
Jan 25, 2005

a last drink with no ice

TheresaJayne posted:

I recently had to update our unit tests that had become out of date about 2 years ago.

I came across these tests.

assertTrue(expectedValue == result);


:freakout:

Why not just use assertEquals(expectedValue,result);

In xUnit.net Assert.Equals requires that its arguments be the same type so you can't use it to test implicit conversions.

MononcQc
May 29, 2007

Wheany posted:

I'm already crying because I'm going to make a presentation about JPEG compression on a university course. "When you compare these two images, you can clearly see the compression artifacts" *both images look like identical low-contrast mess*

And that's the best-case scenario

I don't know how large your class is, but it should be possible to make printouts or to put them online as a backup.

Pass the printouts around (and tape copies next to the doors so anyone can see them while going on after the course), and host them over easy-to-type-in links so students with laptops can just open the URLs and see the results.

Dren
Jan 5, 2001

Pillbug
...and find hosting that doesn't recompress your jpegs.

Maluco Marinero
Jan 18, 2001

Damn that's a
fine elephant.

MononcQc posted:

When I gave week-long classes teaching Erlang, I'd also just make my own fully workable virtualbox machines, and I'd carry them with virtual box installers around so that people who inevitably came unprepared didn't need to take an hour to get up and running.

It's going well most of the time now.

Yeah. Me and two others did a one day workshop in getting up and running with Django, Rails or Node, and they chose which on the day. Had about 20 people, wide variety of introductory levels, first year uni, late high school, hobbyists. With a mix of windows and Mac we decided a stack of USBs with Vagrant, VirtualBox and our prebuild box would be the most reliable way to get going. Is still took about an hour to get everyone going so we could star developing, but still a drat site better than working directly on installing native onto heaps of windows machines.

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope

MononcQc posted:

I don't know how large your class is, but it should be possible to make printouts or to put them online as a backup.

That's... not a bad idea. The presentation is not super-important, but it is part of the course requirements. Everybody gets to do one about some subject.

UraniumAnchor
May 21, 2006

Not a walrus.

MononcQc posted:

[*] Have a contingency plan in case power goes out entirely -- I've had to give a presentation during hurricane Irene where we had no power and before generators were going (or knowing how long they'd be going), we had to keep going. It's always in the back of my mind now.

I have to admit I'm curious what the presentation was about that it was this important.

MononcQc
May 29, 2007

UraniumAnchor posted:

I have to admit I'm curious what the presentation was about that it was this important.

I was hired by a company to go give a day-long presentation on Erlang at a developer retreat. Basically they had 3 days of internal conferences including hackathons, planning for the future products, etc. and the last day was about seeing something that would be new for everyone. They used to have them on different languages / stacks / ideologies, and that year it was on Erlang.

We were deep in the woods, about halfway through between Scranton and NYC, at a spa-resort and the thing had been planned for months. Then Irene kicked in, and we lost power entirely (no hot water, no nothing), and no actual civilization for more than 1-2 hours either way, with an entire company having nothing else to do.

We started with just a whiteboard and printouts (that my employer would ship before each training session). Printouts contain all of the slides of the presentation in black & white, exercises, plus the documentation for the things we'll use. Someone who hired us also got free copies of an Erlang book, so we had plenty of stuff to go through to some extent. Eventually they turned the generators back on, fortunately not too late in the day, and we managed to get to do some interesting stuff in there.

I'm guessing it would have been fine for their employees not to have the presentation, but I was paid to do it damnit!

Polio Vax Scene
Apr 5, 2009



ikanreed posted:

Those are certainly not as bad as the entirely real a.ToString()!="false".

These are all over the place in my project. Whatever chucklefuck put these in absolutely loved them. I could tab over to visual studio right now and find one in ten seconds. And it's not just bools either, I'll see things like x.ToString()=="1". God help me I swear one time I found one that was x.ToString()=="null". THAT DOESNT EVEN WHAT :psyboom:

ManoliIsFat
Oct 4, 2002

I'm real confused as to why anyone would even think to do that? Are these plain objects that they "know" are ints or bools, and instead of checking type and casting, they're just calling .ToString()?

ikanreed
Sep 25, 2009

I honestly I have no idea who cannibal[SIC] is and I do not know why I should know.

syq dude, just syq!

Manslaughter posted:

These are all over the place in my project. Whatever chucklefuck put these in absolutely loved them. I could tab over to visual studio right now and find one in ten seconds. And it's not just bools either, I'll see things like x.ToString()=="1". God help me I swear one time I found one that was x.ToString()=="null". THAT DOESNT EVEN WHAT :psyboom:

The stupid data source actually returned "null" for one remote call, instead of "" or null in at least one place in my app. And since library we're using actually boxes the strings, I'm ashamed to admit to using that line once.

But it really was "null", so its not my fault. Really.

Dr Monkeysee
Oct 11, 2002

just a fox like a hundred thousand others
Nap Ghost

TheresaJayne posted:

I recently had to update our unit tests that had become out of date about 2 years ago.

I came across these tests.

assertTrue(expectedValue == result);


:freakout:

Why not just use assertEquals(expectedValue,result);

This drives me bonkers far more than it should. Using a more generic assert when a specific one is available is INSANE CODING.

Xcode 5 updated the SenTest framework to XCTest and it added a bunch of mirrored asserts that were missing before (e.g. STAssertEqualObjects() had no STAssertNotEqualObjects()) and it was like a cool breeze wafted over me when I saw those new asserts.

ManoliIsFat posted:

I'm real confused as to why anyone would even think to do that? Are these plain objects that they "know" are ints or bools, and instead of checking type and casting, they're just calling .ToString()?

In my experience it's actually the opposite. They don't know what the type is but they sure know .ToString() works!

In my shop we've had a few HTML jockeys get pressed into writing actual C# code and we had to beat that practice out of them. They basically didn't understand how a static type system worked and therefore didn't trust it. ToString() gave them something familiar so it became the defacto way to work with any variable (fortunately they were also all quick studies so after a few code-review sessions this particular coding horror vanished).

Dr Monkeysee fucked around with this message at 00:28 on Oct 9, 2013

Crazy Mike
Sep 16, 2005

Now with 25% more kimchee.
I'm trying to understand/refactor a WPF emailer app that a former coworker left us with. It is quite verbose at over 2300 lines in the main window code consisting of gems such as
code:
            if (checkBoxSendMail.IsChecked == true)
            {
                refMailOptions.SendEMail = true;

            }
            if (checkBoxSendMail.IsChecked == false)
            {
                refMailOptions.SendEMail = false;
            }

            if (checkBoxBCCToKOFAX.IsChecked == true)
            {
                refMailOptions.BCC_To_KOFAX = true;
            }
          if (checkBoxBCCToKOFAX.IsChecked == false)       
            {
                refMailOptions.BCC_To_KOFAX = false;
            }

            // Set the Include Note Option
            if (checkBoxIncludeNote.IsChecked == true)
            {
                refMailOptions.Insert_Note = true;
            }
            else
            {
                refMailOptions.Insert_Note = false;
            }
and
code:

            Int32 liSelectedEmailType;


            myreader = cmdGetEmailTypeID.ExecuteReader();

            Boolean boolHasRows;
            boolHasRows = myreader.HasRows;

            if (boolHasRows == true)
            {
                myreader.Read();
                liSelectedEmailType = Convert.ToInt32(myreader[0]);
                myreader.Close();
                connection.Close();
                return liSelectedEmailType;
            }
            else
            {
                myreader.Close();
                connection.Close();
                return -1;
            }

and of course making six calls to the database when one would suffice.
code:
 private void EnableControlsPerAuthorization(string commonName)
              {                 
                  Boolean lbSendEmails;
                  Boolean lbLoadSchedule;
                  Boolean lbInsertNote;
                  Boolean lbReplaceText;
                  Boolean lbBCCKofax;
                  Boolean lbHTMLSetting;

                  lbSendEmails = GetSendEmailsAuthorization(commonName);
                  lbLoadSchedule = GetScheduleAuthorization(commonName);
                  lbInsertNote = GetInsertNoteAuthorization(commonName);
                  lbReplaceText = GetReplaceTextAuthorization(commonName);
                  lbBCCKofax = GetBCCKofaxAuthorization(commonName);
                  lbHTMLSetting = GetHTMLSettingAuthorization(commonName);
with each method differing in only the column selected...
code:
                  
        private Boolean GetSendEmailsAuthorization(string lsCommonName)

            {
                 // Function that checks the PERMISSIONS table to determine if the current user is authorized to Send Emails
                    string lsSqlCmd = "";
                    string lsSendEmails = "N";
                    Boolean lbSendEmails = false;

                    lsSqlCmd = "Select send_emails from dbo.PERMISSIONS  where login_Name = " + "'" + lsCommonName + "'";

                    bool connectionIsOpen;

                    connectionIsOpen = (myConnection.State == System.Data.ConnectionState.Open);
                    if (!connectionIsOpen)
                    {
                        myConnection.Open();
                    }

                    
                    SqlCommand cmdIsAuthorized = new SqlCommand(lsSqlCmd, myConnection);
                    SqlDataReader localDataReader;


                    localDataReader = cmdIsAuthorized.ExecuteReader();

                    Boolean boolHasRows;
                    boolHasRows = localDataReader.HasRows;
                  
                    if (boolHasRows == true)
                    {
                        localDataReader.Read();
                        lsSendEmails = Convert.ToString(localDataReader[0]);
                        if (lsSendEmails == "Y")
                        {
                            lbSendEmails = true;
                        }
                        else
                        {
                            lbSendEmails = false;
                        }


                    }
                    else
                    {
                        lbSendEmails = false;
                    }

                    localDataReader.Close();
                    myConnection.Close();
                    return lbSendEmails;
                  
                

                }
As a junior programmer, seeing this produced by a senior programmer sparks a sense of job security.

EntranceJew
Nov 5, 2009

Crazy Mike posted:

As a junior programmer, seeing this produced by a senior programmer sparks a sense of job security.

This is what I'm going through now, a few guys were brought on after me but they quit in less than two to three months. I was dumbfound when people turned to me asking why modules I produced didn't work after someone else pushed in-development code to production.

shrughes
Oct 11, 2008

(call/cc call/cc)

Ithaqua posted:

Consulting horror:

I went to a presentation my coworker was giving at another company's office. He had the presentation stored online on Google Docs, first tried doing the presentation in a weird tiling window manager, and then when he went to desktop mode, we saw the Ubuntu update program telling him there were 500 updates available. Then he did everything slowly as if he was really uncomfortable using computers. If his laptop didn't have a VGA port I don't think he'd have known to worry about that.

Doctor w-rw-rw-
Jun 24, 2008

Crazy Mike posted:

As a junior programmer, seeing this produced by a senior programmer sparks a sense of job security.

It's a common mistake to assume ability to code makes for a senior programmer. Sometimes people are better at managing people or projects (ideally) or were around longer than smarter people that left.

When I started iOS development near the very beginning of my career as a professional developer, I realized within two months I was already producing much better code (in terms of conceptualization / maintainability / correctness / optimization) than my boss, the project lead, even though he'd been at it for a year and a half and had been an engineer for much longer.

Didn't mean I knew the first thing about managing a project or a team, which only looks easy when you don't have to do it or think about it. It's way harder a skill to detect and healthily and reliably nurture than the ability to code and the value of good management is that it can act as a large multiplier to team productivity in the ideal case.

Doctor w-rw-rw- fucked around with this message at 09:22 on Oct 9, 2013

dwazegek
Feb 11, 2005

WE CAN USE THIS :byodood:
code:
for (int i = 1; i <= variableWithNameThatsTooLong.Count / 11; i++)
{
  int? foo = variableWithNameThatsTooLong.Where(le => le.Id == i && le.key == "foo").First().Value == string.Empty ? null
  : (int?)int.Parse(variableWithNameThatsTooLong.Where(le => le.Id == i && le.key == "foo").First().Value.ToString());

  int? bar = variableWithNameThatsTooLong.Where(le => le.Id == i && le.key == "bar").First().Value == string.Empty ? null
     : (int?)int.Parse(variableWithNameThatsTooLong.Where(le => le.Id == i && le.key == "bar").First().Value.ToString());

  int? qux = variableWithNameThatsTooLong.Where(le => le.Id == i && le.key == "qux").First().Value == string.Empty ? null
     : (int?)int.Parse(variableWithNameThatsTooLong.Where(le => le.Id == i && le.key == "qux").First().Value.ToString());

  //some thing repeated 4 more times for different keys

  bool isPublic = bool.Parse(variableWithNameThatsTooLong.Where(le => le.Id == i && le.key == "LeIsPublic").First().Value.ToString() == "false" ? "FALSE" : "TRUE");
  
  //more code
}
I don't know what I hate most about this code.

The guy who wrote this also has an unhealthy obsession with dictionaries, the entire codebase is littered with methods that take Dictionary<string, string>, Dictionary<string, object> or Dictionary<int, object> as parameters. Which is great, because there's no loving way to determine what data I need to give to a method without reading through the code.

Of course, he never uses a dictionary when its use would actually be justified, like loading an entire set of data in one query and storing it in a dictionary for fast lookups, instead he'll just fire off 500 separate database queries.

dwazegek
Feb 11, 2005

WE CAN USE THIS :byodood:
During a recent change, we added functionality to allow the user to select whether certain processing steps should be skipped for certain items. Instead of implementing this in any sane way, a parameter of type Dictionary<int, bool> was added to a whole bunch of methods. Each method would then check if the item's id was was present in the dictionary, and if the value associated with it was true.

To reduce some boilerplate code, I mentioned that it might be easier to just pass the ids of items that needed to be skipped, then you'd only need to test if the id was present.

Apparently someone decided to follow my suggestion and this hideous code:
code:
private Dictionary<int, bool> getSkipItems(FormCollection fromCollection)
{
  Dictionary<int, bool> skipItems = fromCollection.AllKeys.Where(k => k.EndsWith("__SkipItem"))
    .ToDictionary(k => int.Parse(k.Split('_')[0]), v => bool.Parse(fromCollection[v].Split(',')[0]));
  return skipItems;
}
was changed to this masterpiece:
code:
private List<int> getSkipItems(FormCollection fromCollection)
{
  Dictionary<int, bool> skipItems = fromCollection.AllKeys.Where(k => k.EndsWith("__SkipItem"))
    .ToDictionary(k => int.Parse(k.Split('_')[0]), v => bool.Parse(fromCollection[v].Split(',')[0]));
  skipItems = skipItems.Where(kvp => kvp.Value == true).ToDictionary(key => key.Key, value => value.Value);
  List<int> keyList = new List<int>(skipItems.Keys);
  return keyList;
}

dwazegek fucked around with this message at 13:48 on Oct 9, 2013

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

Doctor w-rw-rw- posted:

It's a common mistake to assume ability to code makes for a senior programmer. Sometimes people are better at managing people or projects (ideally) or were around longer than smarter people that left.

This is fairly common across all industries. My gut feeling is that most of it comes down not to being better at managing people, but to being competent enough to not get fired and then staying at one company long enough to accrue promotions through sheer force of seniority.

Macichne Leainig
Jul 26, 2012

by VG
Today I am looking at a string property wherein the value is nullable, the setter is a ternary operator that checks if the value to set is null, and if it is, set it to an empty string.

I can partially understand the reasoning, but this is data logic in a property where this is all taken care of when saved to the SQL server? The property is used once in the actual UI, so I'm unsure why they didn't just String.Empty there. Because this is royally loving up our code in other places that search on all non-null values - you can imagine how expensive it is to search thousands of records thousands of times for empty strings.

Dessert Rose
May 17, 2004

awoken in control of a lucid deep dream...
Re: nullable values in C#:

code:
if (nullableBool.GetValueOrDefault(false)) { ...

Doctor w-rw-rw-
Jun 24, 2008

Thermopyle posted:

This is fairly common across all industries. My gut feeling is that most of it comes down not to being better at managing people, but to being competent enough to not get fired and then staying at one company long enough to accrue promotions through sheer force of seniority.
I've definitely seen that be the case, but my current boss is both one of the best iOS devs I've ever known as well as the best boss I've ever had. Sometimes, team or company leadership has real leadership qualities. Strange, but true.

Dessert Rose posted:

Re: nullable values in C#:

code:
if (nullableBool.GetValueOrDefault(false)) { ...
Needs clarification. "Optional" (i.e. Scala's Optional) types are a good thing that help avoid NPEs.

Polio Vax Scene
Apr 5, 2009



Dessert Rose posted:

Re: nullable values in C#:

code:
if (nullableBool.GetValueOrDefault(false)) { ...

Heh, you wish Microsoft was smart enough to pass me nullable bools (also sometimes it's nice to know when something is null vs false)

As a bonus to this discussion, here is something I literally alt tabbed and copy-pasted from code that has been live for a few years now.
code:
entity.Attributes["-removed-"].ToString().ToUpper() == "TRUE"

Dessert Rose
May 17, 2004

awoken in control of a lucid deep dream...

Doctor w-rw-rw- posted:

Needs clarification. "Optional" (i.e. Scala's Optional) types are a good thing that help avoid NPEs.

Nullable types are value types, so you can't get a NPE from that. An int? is actually a struct that has some fields in it that tell the runtime whether it should be treated as null, and the ability to say "int? == null" is syntactic sugar for "!int?.HasValue".

By the way, this implementation definitely belongs in the coding horrors thread.

Munkeymon
Aug 14, 2003

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





Maybe (probably) I'm the horror, but I can't figure out why the framework is adding an encoded new line on the end of an IP6 address (but not the IP4 ones!). Can't wait to see what else I run into.

Edit: I guess this is some sort of hosed up variation on mapped IP4 addressing? Why?

Munkeymon fucked around with this message at 19:59 on Oct 9, 2013

Dr Monkeysee
Oct 11, 2002

just a fox like a hundred thousand others
Nap Ghost
I don't know why it's there but I've always seen newlines on Ipv6 addresses and it never seems to cause any problems so welp

pseudorandom name
May 6, 2007

fe80 is a link-local address, %10 is the zone index (on Windows, Unix uses %eth1 and the like). The zone index is which link (network interface) that link-local address is local to.

Munkeymon
Aug 14, 2003

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



Then I'm the horror again today

gently caress

Edit: actually, using % in the new IP address standard when it's already a known reserved character in URIs is kind of a horror, too.

Munkeymon fucked around with this message at 20:49 on Oct 9, 2013

Macichne Leainig
Jul 26, 2012

by VG
Can I complain about bugs that people create in this thread? Because today I got this in my bucket:

quote:

Steps to Reproduce: It happens occasionally - see if you can determine the issue.

Isn't that your loving job to determine what causes it as a QA?

I suppose if the code itself is poo poo I'll throw that in the thread too.

Macichne Leainig fucked around with this message at 21:08 on Oct 9, 2013

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

Munkeymon posted:

Edit: actually, using % in the new IP address standard when it's already a known reserved character in URIs is kind of a horror, too.

The % syntax wasn't for URIs. Naturally, that didn't stop anyone from using it.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Protocol7 posted:

Can I complain about bugs that people create in this thread? Because today I got this in my bucket:


Isn't that your loving job to determine what causes it as a QA?

I suppose if the code itself is poo poo I'll throw that in the thread too.

That's a bug work item that gets bounced right back to the tester with a note saying "Please provide explicit steps to reproduce"

Munkeymon
Aug 14, 2003

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



pokeyman posted:

The % syntax wasn't for URIs. Naturally, that didn't stop anyone from using it.

I know? I meant that because of someone's poor choice of reserved character, constructing a URI with an IP6 address that contains a zone identifier is now just that much more annoying because you have to remember to escape the % with %25 so now your Windows zone identifier looks even more like line noise: http://fe80::abcd%251/:psyduck:

zeekner
Jul 14, 2007

Munkeymon posted:

I know? I meant that because of someone's poor choice of reserved character, constructing a URI with an IP6 address that contains a zone identifier is now just that much more annoying because you have to remember to escape the % with %25 so now your Windows zone identifier looks even more like line noise: [url]http://fe80::abcd%251/:psyduck:[/url]

If you failed to unescape that string, wouldn't you end up with an invalid zone id? That's pretty bad.

Smugdog Millionaire
Sep 14, 2002

8) Blame Icefrog

Dessert Rose posted:

Nullable types are value types, so you can't get a NPE from that. An int? is actually a struct that has some fields in it that tell the runtime whether it should be treated as null, and the ability to say "int? == null" is syntactic sugar for "!int?.HasValue".

By the way, this implementation definitely belongs in the coding horrors thread.

I don't see the problem with the way "nullable" value types were added. Do you have a preferred alternative implementation?

raminasi
Jan 25, 2005

a last drink with no ice

Dessert Rose posted:

Nullable types are value types, so you can't get a NPE from that. An int? is actually a struct that has some fields in it that tell the runtime whether it should be treated as null, and the ability to say "int? == null" is syntactic sugar for "!int?.HasValue".

By the way, this implementation definitely belongs in the coding horrors thread.

Wait, what??

Smugdog Millionaire posted:

I don't see the problem with the way "nullable" value types were added. Do you have a preferred alternative implementation?

You could make the "nullable" values actually nullable and not confuse the balls out of people like me!

Adbot
ADBOT LOVES YOU

Dessert Rose
May 17, 2004

awoken in control of a lucid deep dream...

Smugdog Millionaire posted:

I don't see the problem with the way "nullable" value types were added. Do you have a preferred alternative implementation?

I mean, all the dirty parts are hidden from me, so I don't really care about the oddities, but it has some leaky bits (like the fact that a nullable type is never truly null)

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