Forum C# Debug.Assert() not allowed?

Debug.Assert() not allowed?

Postby wildbunny » March 14th, 2011, 6:25 pm

Hi guys,

Any particular reason Debug.Assert() is not allowed in sever side?

Cheers, Paul.
wildbunny
 
Posts: 217
Joined: March 9th, 2011, 10:35 am

Re: Debug.Assert() not allowed?

Postby Oliver » March 18th, 2011, 10:39 am

Code checking works via a whitelist, not a blacklist. So, only the classes that are explicitly allowed by us -- we just haven't looked at the Debug class.

I did a quick look and it seems debug.assert will try to show message boxes and do something with a global listeners collection, which are things we'd rather not like to have happen in the game code.

Best,
Oliver
User avatar
Oliver
.IO
 
Posts: 1159
Joined: January 12th, 2010, 8:29 am

Re: Debug.Assert() not allowed?

Postby wildbunny » March 18th, 2011, 11:17 am

Oliver wrote:Code checking works via a whitelist, not a blacklist. So, only the classes that are explicitly allowed by us -- we just haven't looked at the Debug class.

I did a quick look and it seems debug.assert will try to show message boxes and do something with a global listeners collection, which are things we'd rather not like to have happen in the game code.

Best,
Oliver


But by not allowing developers to use the tools they are accustomed to you risk making the platform unattractive?

The Debug namespace contains many things which make our lives as developers easier; i find it hard to believe you've created a server back-end in c# without using Debug.Assert() yourselves, or Debug.WriteLn()?

I urge you to reconsider :)

Cheers, Paul.
wildbunny
 
Posts: 217
Joined: March 9th, 2011, 10:35 am

Re: Debug.Assert() not allowed?

Postby Oliver » March 18th, 2011, 11:42 am

We have to have a locked down environment: We have your code running on our servers, so we can't just allow it to do whatever it wants. There are tons of classes that are off limits: File access, direct socket access, etc. etc. etc. If you want full and complete access to everything, you have to write and maintain your own scalable server infrastructure.

The trade off you get with Player.IO is less wiggle-room, but also you get to skip worrying about scalability and distribution and ops for your game.

Instead of Debug.WriteLine() you should be using Console.WriteLine()

If you want Assert, you can write a small static method yourself that does it? Like so:

Code: Select all
   public class Debug {
      public static void Assert(bool condition) { Assert(condition, null); }
      public static void Assert(bool condition, string caption) {
         if(!condition) {
            Console.Error.WriteLine("Condition "+ (caption!=null?" [" + caption + "] ":" ") + "failed!");
            throw new Exception("Assert Failed");
         }
      }
   }


Best,
Oliver
User avatar
Oliver
.IO
 
Posts: 1159
Joined: January 12th, 2010, 8:29 am

Re: Debug.Assert() not allowed?

Postby TomatoGG » March 30th, 2011, 6:33 am

This is the my version of Debug.Assert that I have been using so far ;)
Two things I like about it :
1. It will only be called in the Debug version, not the Release version
2. The output on the console window will show the entire exception, including stack trace

Code: Select all
internal class MyDebug {
   [Conditional("DEBUG")]
   public static void Assert(bool flag, string text) {
      if (!flag) Console.WriteLine(new Exception(text));
   }
}
TomatoGG
 
Posts: 17
Joined: July 3rd, 2010, 11:15 am

Re: Debug.Assert() not allowed?

Postby wildbunny » March 30th, 2011, 9:26 am

TomatoGG wrote:This is the my version of Debug.Assert that I have been using so far ;)
Two things I like about it :
1. It will only be called in the Debug version, not the Release version
2. The output on the console window will show the entire exception, including stack trace

Code: Select all
internal class MyDebug {
   [Conditional("DEBUG")]
   public static void Assert(bool flag, string text) {
      if (!flag) Console.WriteLine(new Exception(text));
   }
}


Hi Tomato,

But this fails to actually stop the code? Isn't that the primary point of an assert? :)

Cheers, Paul.
wildbunny
 
Posts: 217
Joined: March 9th, 2011, 10:35 am

Re: Debug.Assert() not allowed?

Postby Oliver » April 15th, 2011, 11:44 am

change it to:

if(!flag){
var ex = new Exception(text)
Console.WriteLine(ex);
throw ex;
}

?
User avatar
Oliver
.IO
 
Posts: 1159
Joined: January 12th, 2010, 8:29 am


Return to C#



cron