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
Zombywuf
Mar 29, 2008

tef posted:

*producer puts thing on shared queue* *releases semaphore* *producer spins until it can acquire semaphore, reads queue*

if you're using mutexes, condition variables or semaphores it is likely you're doing something wrong - there should be some nice concurrent data structure like a queue you can use instead.

it will probably have less bugs than the homebrew queue.

*implements threaded queue with a threaded queue* :2bong:

Adbot
ADBOT LOVES YOU

POKEMAN SAM
Jul 8, 2004

Zombywuf posted:

*implements threaded queue with a threaded queue* :2bong:

FYI, there is a ConcurrentQueue in .NET 4.0 for those of you who don't know: http://msdn.microsoft.com/en-us/library/dd267265.aspx

Zombywuf
Mar 29, 2008

So I'm trying to debug a unit test in visual studio 2010. I've set a breakpoint on every single loving line and it still bombs out by throwing an exception without hitting a breakpoint somehow. So I need to tell it to break on exceptions.

http://msdn.microsoft.com/en-us/library/d14azbfh.aspx

I'd forgotten just how much of a pile of poo poo this is.

Why did I volunteer to do some .Net development?

EDIT: goddamnit visual studio, I have jumped through your loving hoops, why you no break at breakpoint?

Zombywuf fucked around with this message at 20:59 on Nov 14, 2011

NotShadowStar
Sep 20, 2000
My limited attempts at C# development made me realize that most testing frameworks were fragile hokey metaprogramming attempts that made debuggers really confused. The only testing framework that was worth a poo poo was ones that tried to avoid that and just mocked a new instance using the interface definition.

Molog
Mar 4, 2004
Title text
I haven't ran into any problems debugging unit tests. Are you sure you are debugging the unit test and not just running it?

Dr Monkeysee
Oct 11, 2002

just a fox like a hundred thousand others
Nap Ghost

NotShadowStar posted:

My limited attempts at C# development made me realize that most testing frameworks were fragile hokey metaprogramming attempts that made debuggers really confused. The only testing framework that was worth a poo poo was ones that tried to avoid that and just mocked a new instance using the interface definition.

I ran into some weird edgecase in VS 2005 trying to determine how some unit test scaffolding was failing. You know all those attributes you use like [TestClass] and [TestMethod] and [TestCleanup]? Turns out MSTest does some hosed up syntactic analysis of the actual .cs file instead of using reflection to interrogate those attributes like any sane .NET code would.

I don't know if this is still true in VS 2008 or 2010 but that one blew my mind back then.

Zombywuf
Mar 29, 2008

It seems to be due to the project files being on a remote directory which Visual Studio considers untrusted. I had to set it to trust it to load it, but I can't find the setting to trust it enough to debug it.

Microsoft, misunderstanding security since forever.

TasteMyHouse
Dec 21, 2006
code:
    pei = getbits(1);
pspare:
    if (pei) {
        /* extra info for possible future backward compatible additions */
        getbits(8);  /* not used */
        pei = getbits(1);
        if (pei) goto pspare; /* keep on reading pspare until pei=0 */
    }
ಠ_ಠ

Beef
Jul 26, 2004
While loop is for loosers.

Jonnty
Aug 2, 2007

The enemy has become a flaming star!

TasteMyHouse posted:

code:
    pei = getbits(1);
pspare:
    if (pei) {
        /* extra info for possible future backward compatible additions */
        getbits(8);  /* not used */
        pei = getbits(1);
        if (pei) goto pspare; /* keep on reading pspare until pei=0 */
    }
ಠ_ಠ

Haha, a post about goto being used improperly (for once) AND a redundant if. Lovely.

Opinion Haver
Apr 9, 2007

Jonnty posted:

Haha, a post about goto being used improperly (for once) AND a redundant if. Lovely.

e: whoops

Zombywuf
Mar 29, 2008

So yeah, I copy the folder to my VMs local drive and it breaks on breakpoints fine.

And the test throws a different exception.

EDIT:
BindingFailure was detected
Message: The assembly with display name 'Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel' failed to load in the 'LoadFrom' binding context of the AppDomain with ID 1. The cause of the failure was: System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel' or one of its dependencies. The system cannot find the file specified.

:suicide:

Zombywuf fucked around with this message at 14:04 on Nov 15, 2011

Beef
Jul 26, 2004
Reminds me of drudging through half a page of STL template syntax to get at the actual error.

Zombywuf
Mar 29, 2008

Beef posted:

Reminds me of drudging through half a page of STL template syntax to get at the actual error.

At least that would contain the actual error.

The worst part is that after throwing that the unit test passed.

Then I added more unit tests and it stopped throwing the exception.

TasteMyHouse
Dec 21, 2006
code:
typedef int Int;


WHY

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope

TasteMyHouse posted:

code:
typedef int Int;


WHY

Maybe he was editing code in Word and was getting pissed off by auto-capitalization.

PDP-1
Oct 12, 2004

It's a beautiful day in the neighborhood.

TasteMyHouse posted:

code:
typedef int Int;


WHY

The author of this book on C# insists on using Int32 everywhere instead of int because apparently having the shorter version defined in the language spec as 32 bits is not a good enough guarantee that it will actually be 32 bits wide. The keyword int can represent different width integers in other languages you see, so if you try to run your C# code through a COBOL compiler you may get errors.

That book is an ok read in general but the author spergs out about stuff constantly, sometimes to the point that the editor clearly moved big blocks of text into "Jeff's Ignorable Opinion" callout boxes just to preserve the reader's sanity.

ninjeff
Jan 19, 2004

PDP-1 posted:

if you try to run your C# code through a COBOL compiler you may get errors.
What good is that? M$ needs to get a new language designer as Anders is obviously not pulling his weight. Really makes you wonder how many other languages C# won't compile as, in the year of our lord 2011 no less.

TasteMyHouse
Dec 21, 2006

PDP-1 posted:

The author of this book on C# insists on using Int32 everywhere instead of int because apparently having the shorter version defined in the language spec as 32 bits is not a good enough guarantee that it will actually be 32 bits wide. The keyword int can represent different width integers in other languages you see, so if you try to run your C# code through a COBOL compiler you may get errors.

That book is an ok read in general but the author spergs out about stuff constantly, sometimes to the point that the editor clearly moved big blocks of text into "Jeff's Ignorable Opinion" callout boxes just to preserve the reader's sanity.

This is C++ code.

Dr Monkeysee
Oct 11, 2002

just a fox like a hundred thousand others
Nap Ghost

PDP-1 posted:

The author of this book on C# insists on using Int32 everywhere instead of int because apparently having the shorter version defined in the language spec as 32 bits is not a good enough guarantee that it will actually be 32 bits wide. The keyword int can represent different width integers in other languages you see, so if you try to run your C# code through a COBOL compiler you may get errors.

That book is an ok read in general but the author spergs out about stuff constantly, sometimes to the point that the editor clearly moved big blocks of text into "Jeff's Ignorable Opinion" callout boxes just to preserve the reader's sanity.

He also pimps his own libraries constantly, sometimes to the detriment of explaining how the original thing his library replaces actually works under the hood which is the whole point of the book. It does have a couple really good chapters about threading though.

evensevenone
May 12, 2001
Glass is a solid.

TasteMyHouse posted:

This is C++ code.

obviously it's so he can typedef short Int; if he ever needs to move to an embedded platform.


anyway
code:
            if strcmp('talk',comm) == 1
it's like enums for matlab.

Modern Pragmatist
Aug 20, 2008

evensevenone posted:

obviously it's so he can typedef short Int; if he ever needs to move to an embedded platform.


anyway
code:
            if strcmp('talk',comm) == 1
it's like enums for matlab.

Are you referring to the fact that the behavior is opposite of that of most languages?

Also

Smugdog Millionaire
Sep 14, 2002

8) Blame Icefrog

PDP-1 posted:

The author of this book on C# insists on using Int32 everywhere instead of int because apparently having the shorter version defined in the language spec as 32 bits is not a good enough guarantee that it will actually be 32 bits wide. The keyword int can represent different width integers in other languages you see, so if you try to run your C# code through a COBOL compiler you may get errors.

The advice I remember from the book was that you should make sure you name your methods as DoSomethingWithInt32 instead of DoSomethingWithInt because Int32 is a CLS type and int is a language keyword, not guaranteed to mean the same thing in another language calling your code.
Which is good advice that I agree with, but it isn't super important because I expect 100% of programmers targeting .NET to assume int=Int32.

evensevenone
May 12, 2001
Glass is a solid.

Modern Pragmatist posted:

Are you referring to the fact that the behavior is opposite of that of most languages?

Also

I'm bitching about the fact that a) matlab does have enums and b) even if it didn't (they are kinda new), this is a pretty dumb way to do them.

I don't really care that strcmp is backwards of C which is kind of backwards to begin with.

dancavallaro
Sep 10, 2006
My title sucks

evensevenone posted:

I'm bitching about the fact that a) matlab does have enums and b) even if it didn't (they are kinda new), this is a pretty dumb way to do them.

I don't really care that strcmp is backwards of C which is kind of backwards to begin with.

What? Matlab's strcmp only tells you if the strings are equal or not. strcmp(str1,str2) in every other language returns 0 if they're equal, something < 0 if str1 < str2, and something > 0 if str1 > str2. What alternative do you propose?

evensevenone
May 12, 2001
Glass is a solid.
Nothing. The C way is probably the best.


anyway, using strings as enums is dumb.

PDP-1
Oct 12, 2004

It's a beautiful day in the neighborhood.

Smugdog Millionaire posted:

The advice I remember from the book was that you should make sure you name your methods as DoSomethingWithInt32 instead of DoSomethingWithInt because Int32 is a CLS type and int is a language keyword, not guaranteed to mean the same thing in another language calling your code.
Which is good advice that I agree with, but it isn't super important because I expect 100% of programmers targeting .NET to assume int=Int32.

True, and I understand his argument on naming conventions when you're writing stuff that could be called from outside. If you look at his code examples however, he uses Int32 inside of his classes with the argument that people reading the code may be confused by the less-specific int keyword. That goes past the point of careful coding practices and into crazy spergtown in my mind.

ninjeff posted:

What good is that? M$ needs to get a new language designer as Anders is obviously not pulling his weight. Really makes you wonder how many other languages C# won't compile as, in the year of our lord 2011 no less.

Just wait until the Roslyn compiler services go live - you'll be able to copy/paste code between C#, VB, and Managed COBOL projects seamlessly! :2bong:

Dr Monkeysee
Oct 11, 2002

just a fox like a hundred thousand others
Nap Ghost

Smugdog Millionaire posted:

The advice I remember from the book was that you should make sure you name your methods as DoSomethingWithInt32 instead of DoSomethingWithInt because Int32 is a CLS type and int is a language keyword, not guaranteed to mean the same thing in another language calling your code.
Which is good advice that I agree with, but it isn't super important because I expect 100% of programmers targeting .NET to assume int=Int32.

He does say this and it's definitely good advice (in fact it's part of the Microsoft Framework Design Guidelines) but he also rails against the basic C# type keywords which is... okay I can kinda see his point but relax buddy.

There are quite a few portions of the book that swerve into "this is how I would have designed C# if somebody asked me and by the way I'd like to point out that no one asked me" territory. What's odd is I don't remember the second edition of the book having these weird asides; it was only the third edition after .NET 3.5 he apparently got all fussy about C# syntax.

Dr Monkeysee fucked around with this message at 23:49 on Nov 15, 2011

w00tz0r
Aug 10, 2006

I'm just so god damn happy.
code:
struct Item
{
    pair<Item, int> GetContext();

    int foo;
    int bar;
    int baz;
};

pair<Item, int> Item::GetContext()
{
    return make_pair(this, foo);
}

// later
context_list.push_back(item->GetContext());

// later
std::pair<Item, int>::iterator it = context_list.begin();
while (it != context_list.end())
{
    // operate on it->second;
    // operate on it->first->bar;
    // operate on it->first->baz;

    ++it
}
I can't even begin to think of why he thought this was necessary. :(

Bozart
Oct 28, 2006

Give me the finger.

evensevenone posted:

Nothing. The C way is probably the best.


anyway, using strings as enums is dumb.

To be fair, matlab doesn't really have strings at all which I've already mentioned is hosed Up.

MasterSlowPoke
Oct 9, 2005

Our courage will pull us through
Just did this right now.

code:
if (Updown.Value != Upgrade.Count)
{
   Updown.Value = Upgrade.Count;
}
This didn't work, due to an event triggered when the Value of an Updown is changed. On a larf, I changed this to:

code:
while (Updown.Value != Upgrade.Count)
{
   Updown.Value = Upgrade.Count;
}
And it works. I have no idea why calling the code multiple times results in a different answer.

NotShadowStar
Sep 20, 2000
Shrodinger's Collection.

apseudonym
Feb 25, 2011

From when I was TAing intro to data structures:
code:
public boolean contains(Object o)
 {
  int no = 0;
        int yes = ourList.size - 1;
        int maybe;
  
  while( no <= yes )
      {
          maybe = ( no + yes ) / 2;

          if( (ourCompare.compare((E) o, ((E)ourList.items[maybe]))) > 0 )
              no = maybe + 1;
          else if( (ourCompare.compare((E) o, ((E)ourList.items[maybe]))) < 0 )
              yes = maybe - 1;
          else if ((ourCompare.compare((E) o, ((E)ourList.items[maybe]))) == 0)
           return true;

      }  
  return false;
 }

Orzo
Sep 3, 2004

IT! IT is confusing! Say your goddamn pronouns!
Haha, worst binary search variable names ever. Also runs a comparer of unknown complexity 3 times per iteration...

darthbob88
Oct 13, 2011

YOSPOS

Orzo posted:

Haha, worst binary search variable names ever. Also runs a comparer of unknown complexity 3 times per iteration...

Eh. I might have used variable names like that when I was a student, just for a laugh. Granted, I'd have no idea what they were when I examined them later, nor would the grader understand it, but it'd be funny. The comparator would be a bigger concern; even as a student, I understood that you want to avoid doing things like that more than once. Would it be so hard to do it right?
code:
int comparison = (ourCompare.compare((E) o, ((E)ourList.items[maybe])));
if (comparison > 0) ...etc

HappyHippo
Nov 19, 2003
Do you have an Air Miles Card?

apseudonym posted:

code:
maybe = ( no + yes ) / 2;

This is amazing.

tef
May 30, 2004

-> some l-system crap ->
can anyone spot the bug in the binary search?


answer

tef fucked around with this message at 19:52 on Nov 16, 2011

Orzo
Sep 3, 2004

IT! IT is confusing! Say your goddamn pronouns!
There's no bug, it's by design...the variable is called 'maybe' because maybe it overflows, maybe it doesn't.

evensevenone
May 12, 2001
Glass is a solid.
That's clearly the main problem with that code.

Adbot
ADBOT LOVES YOU

Thermopyle
Jul 1, 2003

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

tef posted:

can anyone spot the bug in the binary search?


answer

The worst part about being self-taught/un-educated in programming is that I've noticed this bug several times, but thought I just didn't understand what was really going on.

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