<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>trace.assert Archives - Dragonsoft Technology View</title>
	<atom:link href="https://blog.dragonsoft.us/tag/traceassert/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.dragonsoft.us/tag/traceassert/</link>
	<description>Talk about Technologies, Software Architecture and Management</description>
	<lastBuildDate>Tue, 31 Mar 2009 15:15:23 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://blog.dragonsoft.us/wp-content/uploads/2022/04/logo-main-bw-150x150.png</url>
	<title>trace.assert Archives - Dragonsoft Technology View</title>
	<link>https://blog.dragonsoft.us/tag/traceassert/</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">2577970</site>	<item>
		<title>Assert is your friend&#8230; not an end-user&#8217;s</title>
		<link>https://blog.dragonsoft.us/2009/01/15/assert-is-your-friend-not-end-users/</link>
					<comments>https://blog.dragonsoft.us/2009/01/15/assert-is-your-friend-not-end-users/#respond</comments>
		
		<dc:creator><![CDATA[Serguei Dosyukov]]></dc:creator>
		<pubDate>Thu, 15 Jan 2009 22:24:22 +0000</pubDate>
				<category><![CDATA[Delphi]]></category>
		<category><![CDATA[Fun stuff with C#]]></category>
		<category><![CDATA[.net 3.5]]></category>
		<category><![CDATA[assert]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[debug.assert]]></category>
		<category><![CDATA[delphi]]></category>
		<category><![CDATA[trace.assert]]></category>
		<guid isPermaLink="false">http://blog.dragonsoft.us/?p=777</guid>

					<description><![CDATA[<p>As a long time Delphi and C# programmer one become used to some features of the language and may not go deep into &#8220;philosophical&#8221; thinking about such features. This often happen with Asserts&#8230; What is Assert or Assertion? By its definition Assert: state categorically affirm: to declare or affirm solemnly<a class="moretag" href="https://blog.dragonsoft.us/2009/01/15/assert-is-your-friend-not-end-users/"> Read more</a></p>
<p>The post <a href="https://blog.dragonsoft.us/2009/01/15/assert-is-your-friend-not-end-users/">Assert is your friend&#8230; not an end-user&#8217;s</a> appeared first on <a href="https://blog.dragonsoft.us">Dragonsoft Technology View</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>As a long time Delphi and C# programmer one become used to some features of the language and may not go deep into &#8220;philosophical&#8221; thinking about such features. This often happen with <strong>Asserts</strong>&#8230;</p>
<h3>What is Assert or Assertion?</h3>
<p>By its definition <strong>Assert</strong>:</p>
<ul>
<li>state categorically</li>
<li>affirm: to declare or affirm solemnly and formally as true</li>
<li>insist: assert to be true</li>
<li>In Computing (<a href="http://en.wikipedia.org/wiki/Assert" target="_blank">wiki</a>): &#8220;an <strong>assert</strong> is a predicate (i.e., a true–false statement) placed in a program to indicate that the developer <em>thinks</em> that the predicate is always true at that place&#8221;</li>
</ul>
<p>In general, using <strong>assert</strong> in the code proven to be useful in many situations because it &#8220;<a href="http://msdn.microsoft.com/en-us/library/aa326827.aspx" target="_blank">checks for a condition and outputs the call stack if the condition is <strong>false</strong></a>&#8221; and it could help to debug some strange situations in the code.</p>
<h3><a href="http://www.codeproject.com/KB/cpp/assertisyourfriend.aspx" target="_blank">Assert is your friend</a></h3>
<p>This method is for programmers to use. But what happen often when something is convenient, it started to be used excessively. Why it is happening?</p>
<p>Let&#8217;s look at the declaration of <strong>Assert</strong> in C# (3.x). There are two versions of the <strong>Assert()</strong>: <a href="http://msdn.microsoft.com/en-us/library/system.diagnostics.debug.assert.aspx" target="_blank"><strong>Debug.Assert()</strong></a> and <a href="http://msdn.microsoft.com/en-us/library/system.diagnostics.trace.assert.aspx" target="_blank"><strong>Trace.Assert()</strong></a>, both in <strong>System.Diagnostics </strong>namespace.</p>
<pre class="brush: csharp; title: ; notranslate">
// Checks for a condition and outputs the call stack
// if the condition is false

&#x5B;ConditionalAttribute(&quot;TRACE&quot;)]
public static void Assert(bool condition)

&#x5B;ConditionalAttribute(&quot;TRACE&quot;)]
public static void Assert(bool condition, string message)

&#x5B;ConditionalAttribute(&quot;DEBUG&quot;)]
public static void Assert(bool condition)

&#x5B;ConditionalAttribute(&quot;DEBUG&quot;)]
public static void Assert(bool condition, string message)</pre>
<p>As we can see from above code, Assert is to be used for <span style="text-decoration: underline;">Testing</span> and <span style="text-decoration: underline;">Debugging</span> and therefore should not be used as a way to present any information to the <strong>end-user.</strong></p>
<h3>Helping yourself</h3>
<p>As useful as it seems, even then Assert infrastructure may not be used to full extend. In the sample declarations above we can see that logic can be invoked with and without providing any additional information.<br />
Imagine how useful is a message &#8220;Project raised an Assert in line X&#8221; compare to &#8220;Project raised an Assert with the Message in line X&#8221;.<br />
First option gives you idea where something failed, where second actually tells you what went wrongand where. Let&#8217;s use power of the tool-set and provide ourselves with useful information.</p>
<h3>Assert is NOT for an end-user</h3>
<p>I was asked recently (this seems to be a ongoing discussion) &#8211; &#8220;Why a programmer should not be using asserts as a regular approach in code conditions validation even when it comes to a production code?&#8221;</p>
<p>By default, Assert would show a message box with some information and the current Call Stack. This information, while being helpful to the developer, would not tell much to the user.</p>
<p>With custom <span><a id="ctl00_rs1_mainContentContainer_ctl73" onclick="function onclick() { function onclick() { function onclick() { function onclick() { Track('ctl00_rs1_mainContentContainer_cpe285485_c|ctl00_rs1_mainContentContainer_ctl73',this); } } } }" href="http://msdn.microsoft.com/en-us/library/system.diagnostics.tracelistener.aspx"><span style="color: #0033cc;">TraceListener</span></a></span> introduced, message can be hidden from the user and information could be stored, but it is not how it should be used by definition.</p>
<p>If information is expected to be presented to the user in any form, it could be achieved in a form not an exceptional, intended for debugging, situation, but by using regular methods: message box, application log, Windows event log, etc.<br />
Even in the case of component development it is desired to use exceptions (<strong>raise/throw</strong>) to &#8220;bubble&#8221; proper message to the error handling layer.</p>
<blockquote><p>The <span><span class="input">throw</span></span> statement is used to signal the occurrence of an anomalous situation (exception) during the program execution.</p></blockquote>
<h3>Assert is a conditional logic</h3>
<p>Last, final and probably major concern here is that in Release environment Debug and even Trace functionality would be disabled and therefore, any code/logic which depend on Assert() would be suppressed and all the nice validations became worthless (see declaration above)&#8230; and Access Violation errors starting pop up unexpectedly.</p>
<hr/><span style="font-size: 7pt">Copyright &copy; 2026 <strong><a href="https://blog.dragonsoft.us">Dragonsoft Technology View</a></strong>. This Feed is for personal non-commercial use only.</span><p>The post <a href="https://blog.dragonsoft.us/2009/01/15/assert-is-your-friend-not-end-users/">Assert is your friend&#8230; not an end-user&#8217;s</a> appeared first on <a href="https://blog.dragonsoft.us">Dragonsoft Technology View</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.dragonsoft.us/2009/01/15/assert-is-your-friend-not-end-users/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">777</post-id>	</item>
	</channel>
</rss>

<!--
Performance optimized by W3 Total Cache. Learn more: https://www.boldgrid.com/w3-total-cache/?utm_source=w3tc&utm_medium=footer_comment&utm_campaign=free_plugin

Page Caching using Disk: Enhanced 
Lazy Loading (feed)
Minified using Disk
Database Caching 18/85 queries in 0.043 seconds using Disk

Served from: blog.dragonsoft.us @ 2026-04-21 01:46:58 by W3 Total Cache
-->