Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3405086
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T05:27:44+00:00 2026-05-18T05:27:44+00:00

I am currently developing a small AI framework ( genetic algorithms / neural networks)

  • 0

I am currently developing a small AI framework ( genetic algorithms / neural networks) in C#, for a university project.

My first concern is developing a reusable framework, so I am designing everything to be pretty modular. I know I am paying off a price for this (performance), but I feel that I have more to gain than to lose with it (preferable to have code twice as slow than have to lose twice as much time later trying to find impossible to find bugs and losing lots of time trying to add new things that are hard to introduce in a monolithic block of code).

I would like to have lots of checks on different parts of my code, assertions, basically. Check if when running method X I am indeed in a correct state, etc. Those kind of assertions are useful when developing, but I’d like them to stay away from release code (that is, when I decide that I’ll want to leave this working for the night to get my final research results).

I can see several ways of accomplishing this:

  1. System.Diagonists.Assert family of methods.
  2. Code Contracts
  3. Having if (x) then throw InvalidStateException() surrounded by #if DEBUG / #endif

How would you do it and why?

I am also aware of Unit-Tests (I am using them), but I’d also like to have some kind of assertions on the code, too.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T05:27:45+00:00Added an answer on May 18, 2026 at 5:27 am

    You could use a static method like this:

    [Conditional("DEBUG")]
    public static void Assert(bool condition, string message)
    {
        if (!condition)
            throw new InvalidStateException("Assertion failed: " + message);
    }
    

    And assert like so, assuming the method is defined in a class called Util:

    Util.Assert(a == b, "a == b");
    

    Calls to this method will only be emitted by the compiler when the DEBUG symbol is set, thanks to the ConditionalAttribute. So you don’t need to wrap such calls in any #if directives. This will lead to less code clutter.

    (Note that the method itself will still be compiled. This allows you to use such methods in different assemblies!)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In the small application that I'm currently developing for a customer I need to
Greetings, Currently developing small web service application where response from web service (using CXF
I'm currently developing a small customer relationship and invoice management system for my client.
I'm using Windows XP and currently, I'm developing a small win form application so
We are currently developing a server whereby a client requests interest in changes to
I was currently developing a desktop application in C# using mono and testing in
I am currently developing an approval routing WCF service that will allow an user
I am currently developing a Rails application using a database that was designed before
I'm currently developing for a handheld device running Windows XP Professional (not Tablet PC
I'm currently developing a PHP application that's using an Access database as a backend.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.