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.
 
  • Locked thread
Chalks
Sep 30, 2009

HoboMan posted:

wait, List doesn't have it's own Clone method????

It's easy if you've got a list of value types, everything gets complicated once you start dealing with object references though. There's no way for a clone function to instantiate a valid copy of an arbitrary object - even the MemberwiseClone function I mentioned earlier won't work on an object that's got its own object references.

Powerful Two-Hander posted:

im AssId "sqlexception"

I'm AssId "Object reference not set to an instance of an object"

I love FirstOrDefault().SomeFunction() 'cause it lets you error ever so slightly later than you would have with First()

Chalks fucked around with this message at 15:56 on Nov 18, 2016

Adbot
ADBOT LOVES YOU

MrMoo
Sep 14, 2000

raminasi posted:

"greater new york area" always means new jersey. how did you not know the company location before you interviewed?

I've interviewed at their office in Chelsea before and they still have many dev jobs in Manhattan. The job site filter only had "Greater New York City Area" and other NJ listings spelt out the name of the town.


KidDynamite posted:

Yo send this my way

https://www.linkedin.com/jobs/view/...pbw~iv1ctxzw~t4

Bloody
Mar 3, 2013

attempting to teach one of our younger engineers how to debug and problem solve and its uhhh tricky

Jerry Bindle
May 16, 2003
make http://debuggingrules.com/ required reading for everyone imo

Bloody
Mar 3, 2013

oh god yes a general purpose debugging reference i am buying this for every fucker i work with

ulmont
Sep 15, 2010

IF I EVER MISS VOTING IN AN ELECTION (EVEN AMERICAN IDOL) ,OR HAVE UNPAID PARKING TICKETS, PLEASE TAKE AWAY MY FRANCHISE

Bloody posted:

oh god yes a general purpose debugging reference i am buying this for every fucker i work with

leftist heap
Feb 28, 2013

Fun Shoe
people fresh outta school have their minds blown by super simple debugging poo poo. a guy at work was super impressed when i worked backwards from an error by searching for the error message in the code. conditional breakpoints are gonna make his brain shoot out of his ears.

geeves
Sep 16, 2004

I just came across this deep in my company's code base. It's in a job that really hasn't been modified since 2008 - this was added in 2005 for some reason... It's not called, they're all empty objects; they are all just sitting there taking up space.

code:
public void precious() {
  if (!(Skin instanceof Lotion)) {
    It.getHose();
  }
}

public void told() {
  Basket.put(It.lotion());
}

Arcsech
Aug 5, 2008

Barnyard Protein posted:

make http://debuggingrules.com/ required reading for everyone imo

just bought this, will report back

The MUMPSorceress
Jan 6, 2012


^SHTPSTS

Gary’s Answer

leftist heap posted:

people fresh outta school have their minds blown by super simple debugging poo poo. a guy at work was super impressed when i worked backwards from an error by searching for the error message in the code. conditional breakpoints are gonna make his brain shoot out of his ears.

conditional breakpoints never work in vb6 because if the variable you want to break on isn't in scope when you write the breakpoint (that's right, you can't set them without the program already running) it'll either never hit it or just crash randomly.

HoboMan
Nov 4, 2010

geeves posted:

I just came across this deep in my company's code base. It's in a job that really hasn't been modified since 2008 - this was added in 2005 for some reason... It's not called, they're all empty objects; they are all just sitting there taking up space.

code:
public void precious() {
  if (!(Skin instanceof Lotion)) {
    It.getHose();
  }
}

public void told() {
  Basket.put(It.lotion());
}

lmao

Chamook
Nov 17, 2006

wheeeeeeeeeeeeee

Chalks posted:

I love FirstOrDefault().SomeFunction() 'cause it lets you error ever so slightly later than you would have with First()

.FirstOrDefault().ToMaybe().Map(someFunction)

:smug:

Ciaphas
Nov 20, 2005

> BEWARE, COWARD :ovr:


Chalks posted:

It's easy if you've got a list of value types, everything gets complicated once you start dealing with object references though. There's no way for a clone function to instantiate a valid copy of an arbitrary object - even the MemberwiseClone function I mentioned earlier won't work on an object that's got its own object references.


I'm AssId "Object reference not set to an instance of an object"

I love FirstOrDefault().SomeFunction() 'cause it lets you error ever so slightly later than you would have with First()

i feel like every time i use .First() i'm committing some sort of hate crime even when I know i'm gonna get exactly one result back

Ciaphas
Nov 20, 2005

> BEWARE, COWARD :ovr:


leftist heap posted:

people fresh outta school have their minds blown by super simple debugging poo poo. a guy at work was super impressed when i worked backwards from an error by searching for the error message in the code. conditional breakpoints are gonna make his brain shoot out of his ears.

no matter what IDE i've used--sunstudio (ugh), eclipse or VS2013 or VS2015 conditional breakpoints have always given me guff, be it awful performance or just plain not working, so i've given up and done poo poo like adding this to code and recompiling
code:
if (buttCount > 1)
   int xxx = 0; // breakpoint here

leftist heap
Feb 28, 2013

Fun Shoe
i can't help it if people are using terrible languages or ides

raminasi
Jan 25, 2005

a last drink with no ice

Ciaphas posted:

i feel like every time i use .First() i'm committing some sort of hate crime even when I know i'm gonna get exactly one result back

that's why they made .Single()

Ciaphas
Nov 20, 2005

> BEWARE, COWARD :ovr:


loving rear end goblins why am i so terrible

(thanks)

Ciaphas fucked around with this message at 19:50 on Nov 18, 2016

Ciaphas
Nov 20, 2005

> BEWARE, COWARD :ovr:


that's like when I spent an hour trying to work out a nice way to Convert a string like "10001011011110" from base 2 To a base 10 UInt64

Got it down to like three lines of rather clever linq and casting then welped when I saw the one line built in solution

Bloody
Mar 3, 2013


oh neat

Bloody
Mar 3, 2013

i tend to use firstordefault when i think there will probably be multiple things in the ienumerable but i dont care about them. also FirstOrDefault becomes much more tolerable when combined with the ?. and ?? operators

Powerful Two-Hander
Mar 10, 2004

Mods please change my name to "Tooter Skeleton" TIA.


i actually had a conversation today where a data consumer could not understand that my job was not to ensure that the data conformed to their arbitrary expectations i.e. that there would only be one result in a set. i guarantee their offshore devs will just return the first result because they didn't understand my point about exception cases.

this happens all the loving time with 'programme managers' that don't understand that when you do a variable assignment in sql but returned multiple rows in the set the variable will be assigned a 'random' value based on the order of the set. i had a full on argument with a guy that refused to believe that changing a 1 to 1 to a 1 to many relationship would gently caress any existing consumer.

quiggy
Aug 7, 2010

[in Russian] Oof.


Powerful Two-Hander posted:

im AssId "sqlexception"

Chalks
Sep 30, 2009

Bloody posted:

i tend to use firstordefault when i think there will probably be multiple things in the ienumerable but i dont care about them. also FirstOrDefault becomes much more tolerable when combined with the ?. and ?? operators

Yeah, FirstOrDefault is fine and ?. makes it actually really cool to work with - but I always laugh when someone's gone to the trouble of writing "OrDefault" then immediately written code that would crash if the default was ever returned. And when I say someone, it's me 90% of the time.

I usually use the function if I'm going to write some complex object creation code if the value is null, but I must admit I never knew about .Single() or .SingleOrDefault() so now I guess I'm going to start using those instead. I wonder how many latent bugs will be revealed as a result!

Bloody
Mar 3, 2013

unit testing with hardware is dumb and annoying

Potassium Problems
Sep 28, 2001

Chalks posted:

Yeah, FirstOrDefault is fine and ?. makes it actually really cool to work with - but I always laugh when someone's gone to the trouble of writing "OrDefault" then immediately written code that would crash if the default was ever returned. And when I say someone, it's me 90% of the time.

I usually use the function if I'm going to write some complex object creation code if the value is null, but I must admit I never knew about .Single() or .SingleOrDefault() so now I guess I'm going to start using those instead. I wonder how many latent bugs will be revealed as a result!

Keep in mind that both .Single() and .SingleOrDefault() will throw an exception if there's more than 1 element in the collection

Ciaphas
Nov 20, 2005

> BEWARE, COWARD :ovr:


Potassium Problems posted:

Keep in mind that both .Single() and .SingleOrDefault() will throw an exception if there's more than 1 element in the collection

Yeah I just checked my code and about half of my .First() calls could be changed to .Single() but there were a surprising number where I want to explicitly handle cases of 2 or more, or where I really do just want First() and I don't care about row ordering because the values I'm retrieving after the First() are guaranteed the same in every row 'cos of a .Where() or whatever

Still, more tools in the toolbox

Ciaphas
Nov 20, 2005

> BEWARE, COWARD :ovr:


Also I loving hate being stuck on VS2013 because I really really want ?. right now

Jerry Bindle
May 16, 2003

Bloody posted:

unit testing with hardware is dumb and annoying

actually its not even a unit test
“A test is not a unit test if:
- It talks to the database
- It communicates across the network
- It touches the file system
- It can’t run at the same time as any of your other unit tests
- You have to do special things to your environment (such as editing config files) to run it.”
[1] M. Feathers, "A Set of Unit Testing Rules," 2005.


i know what you mean tho i'm struggling with the same kind of thing right now :( concurrency is hard

Bloody
Mar 3, 2013

names are dogmatic it tests one unit of functionality its not my fault that that unit of functionality happens to live 50% on a pc and 50% in an fpga

Chalks
Sep 30, 2009

Potassium Problems posted:

Keep in mind that both .Single() and .SingleOrDefault() will throw an exception if there's more than 1 element in the collection

Yeah, that's why I'm wondering if it'll reveal some pre-existing bugs. In pretty much every situation I use FirstOrDefault I can only have one result unless I've done something stupid like a cross product join or something, so it'll be good to catch any cases where that's happening.

Bognar
Aug 4, 2011

I am the queen of France
Hot Rope Guy

Ciaphas posted:

Yeah I just checked my code and about half of my .First() calls could be changed to .Single() but there were a surprising number where I want to explicitly handle cases of 2 or more, or where I really do just want First() and I don't care about row ordering because the values I'm retrieving after the First() are guaranteed the same in every row 'cos of a .Where() or whatever

Still, more tools in the toolbox

really you should only use .Single() instead of .First() if you need to enforce that there is only one matching element in the collection. .First() bails out after it finds a matching element, but .Single() has to traverse the entire collection.

Bloody
Mar 3, 2013

good news fam looks like its just a concurrency bug

Bognar
Aug 4, 2011

I am the queen of France
Hot Rope Guy
also if you use .Single in linq to sql, it pulls back the entire result set. entity framework is smart enough to just limit to top 2.

Shaggar
Apr 26, 2006
entity framework fuckin sucks

Elysiume
Aug 13, 2009

Alone, she fights.

Barnyard Protein posted:

actually its not even a unit test
“A test is not a unit test if:
- It talks to the database
- It communicates across the network
- It touches the file system
- It can’t run at the same time as any of your other unit tests
- You have to do special things to your environment (such as editing config files) to run it.”
[1] M. Feathers, "A Set of Unit Testing Rules," 2005.


i know what you mean tho i'm struggling with the same kind of thing right now :( concurrency is hard
running what should be a unit test suite that fails because a dependency is down is really frustrating. on a related note, I once found an integration test suite that had every test wrapped in a try/catch that swallowed every exception and validated nothing

leper khan
Dec 28, 2010
Honest to god thinks Half Life 2 is a bad game. But at least he likes Monster Hunter.

Ciaphas posted:

Also I loving hate being stuck on VS2013 because I really really want ?. right now

i can confirm that ?. is cool and good

Chalks
Sep 30, 2009

Bognar posted:

also if you use .Single in linq to sql, it pulls back the entire result set. entity framework is smart enough to just limit to top 2.

Pulling back the entire result set doesn't seem too bad if you're going to thrown an exception anyway if it's more than a single row.

Ciaphas
Nov 20, 2005

> BEWARE, COWARD :ovr:


Shaggar posted:

entity framework fuckin sucks

better than writing raw sql

though this is my first foray into EF so i really don't have a fukken clue what i'm doing

Ciaphas
Nov 20, 2005

> BEWARE, COWARD :ovr:


currently i'm annoyed that i can't seem to set entity class accessibility to internal instead of public without causing nullreferenceexceptions

It compiles fine, but as soon as I do any query involving an association it explodes if every single entity class isn't public

Which is annoying because I want to enforce this poo poo shouldn't be usable outside of the project it's in


At least making the DbContext derived class internal seems to work ok, so that's a start

Adbot
ADBOT LOVES YOU

Ciaphas
Nov 20, 2005

> BEWARE, COWARD :ovr:


On another topic Oracle continues to be literally Hitler, he says as he tries to figure out how to get PL/SQL to call a C++ function from an external dynamic library, or a C function from another external library calling aforesaid C++ function

  • Locked thread