<?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>Encoding &#8211; Xojo Programming Blog</title>
	<atom:link href="https://blog.xojo.com/tag/encoding/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.xojo.com</link>
	<description>Blog about the Xojo programming language and IDE</description>
	<lastBuildDate>Tue, 02 Mar 2021 17:52:46 +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>
	<item>
		<title>Avoiding Common Programming Pitfalls</title>
		<link>https://blog.xojo.com/2019/02/25/programming-pitfalls/</link>
		
		<dc:creator><![CDATA[Paul Lefebvre]]></dc:creator>
		<pubDate>Mon, 25 Feb 2019 10:00:01 +0000</pubDate>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Learning]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[64-bit]]></category>
		<category><![CDATA[Encoding]]></category>
		<category><![CDATA[HiDPi]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Xojo Programming Language]]></category>
		<guid isPermaLink="false">https://blog.xojo.com/?p=5431</guid>

					<description><![CDATA[Check that you aren't falling for some of the most common programming pitfalls]]></description>
										<content:encoded><![CDATA[<p>Code doesn&#8217;t care whether you are new to programming or an old pro, a citizen developer or the head of engineering, some missteps can catch any of us. Read on to learn some of the most common programming pitfalls and how to avoid them.</p>
<p><span id="more-5431"></span></p>
<h2>Ignoring Encoding</h2>
<p>When working with Strings that come from (or are sent) outside your app, you always need to consider the encoding of the text. These days, UTF8 is the most common encoding for text and probably the one you should use most of the time. But if you&#8217;re getting text from a database or a web service or just another file that you don&#8217;t control, then you&#8217;ll want to use the <a href="https://documentation.xojo.com/api/text/encoding_text/defineencoding.html">DefineEncoding</a> method to set the correct encoding of the incoming text or use <a href="https://documentation.xojo.com/api/text/encoding_text/convertencoding.html">ConvertEncoding</a> to cover the encoding to something you&#8217;d rather be using, such as UTF8.</p>
<p>Kem Tekinay is doing a session on called <a href="https://www.xojo.com/xdc/sessions/info/tekinay/">Decoding Text Encodings</a> at <a href="https://www.xojo.com/xdc">XDC 2019</a> that you won&#8217;t want to miss.</p>
<p><img fetchpriority="high" decoding="async" class="size-medium aligncenter" src="https://upload.wikimedia.org/wikipedia/en/5/54/A2600_Pitfall.png" width="320" height="226" /></p>
<h2>Avoiding Exception Handling</h2>
<p>Some classes <a href="https://documentation.xojo.com/getting_started/debugging/exception_handling.html">raise exceptions</a> when something unexpected happens. If your code ignores these exceptions then this causes your app to display an error message to the user which forces them to quit the app. That&#8217;s not the best experience.</p>
<p>At the very least you should have some code in the App.UnhandledException event for your desktop/web/iOS app so that you will know when these occur. The code do something as simple as log the error to the system log or a file so that you&#8217;ll have it to investigate.</p>
<p>Then you can pinpoint the part of the code where it occurred and add the appropriate <a href="https://documentation.xojo.com/api/code_execution/try.html">Try&#8230;Catch</a> code to deal with it appropriately and gracefully.</p>
<p>As an example, if you call XMLDocument.LoadXML and supply invalid XML, then an XMLException is raised. By catching this exception you can display a message to the user telling them the XML file they selected is invalid and asking them to choose another.</p>
<h2>Skipping Database Error Checking</h2>
<p>Whenever you run a database command it is possible that there was a database error that happened. But you won&#8217;t know about it unless you check the if <a href="https://documentation.xojo.com/api/deprecated/deprecated_class_members/database.error.html">Database.Error</a> is True. Always do this and then display or log the <a href="https://documentation.xojo.com/api/deprecated/deprecated_class_members/database.error.htmlCode">Database.ErrorCode</a> and <a href="https://documentation.xojo.com/api/deprecated/deprecated_class_members/database.error.htmlMessage">Database.ErrorMessage</a>.</p>
<p>This can really help with catching subtle problems, such as a typo in a SELECT statement.</p>
<h2>Ignoring Memory Leaks</h2>
<p>A memory leak in your app is when it keeps reserving memory but never gives it back. Oftentimes this is not noticeable as the increased memory usage is minimal and does not typically affect 64-bit apps. In addition the memory is released when your app quits. But if you have a significant memory leak you should look into figuring out how to eliminate it.</p>
<p>You can determine if your app has a memory leak by checking (using the OS Task Manager or Activity Monitor) if its memory usage increases significantly as the app is used even while you are closing windows or documents that are no longer used.</p>
<p>It is possible you have some objects that are never going Nil and thus not releasing their memory. Normally you don&#8217;t have to worry about setting objects to Nil manually as Xojo uses automatic reference counting (ARC) to clean up memory. But there is a situation, called a <a href="https://documentation.xojo.com/topics/debugging/how_xojo_manages_memory.html">circular reference</a>, that can lead to objects not being set to Nil.</p>
<p>A circular reference means that ObjectA refers to ObjectB and ObjectB refers to ObjectA. Since neither ever has its reference count get to zero, then they cannot be released from memory.</p>
<p>You can either manually set things to Nil to ensure that memory is released or you can make use of the <a href="https://documentation.xojo.com/api/language/weakref.html">WeakRef</a> class to help manage it.</p>
<h2>Fuzzy Graphics in HiDPI</h2>
<p>If you used pictures in older projects then they&#8217;ll only have a single size. When you enabled HiDPI for your project (Shared Build Settings -&gt; Supports HiDPI) then this picture is treated as a 1x size and is scaled in HiDPI screens. This can result in a fuzzy or blurry picture.</p>
<p>Instead you want to start using <a href="https://documentation.xojo.com/getting_started/using_the_ide/image_set_editor.html">Image Sets</a>. When you create an Image Set you have three &#8220;slots&#8221; for 1x, 2x and 3x image sizes. Supplying at least 1x and 2x images will limit unnecessary scaling and cause your images to appear much sharper and clearer. Image Sets are created by default in current versions of Xojo when you add a picture or image to your project. Right click on existing pictures in the project and choose &#8220;Convert to Image&#8221; to convert them to an image so you can add additional sizes.</p>
<h2>Not Updating to 64-bit</h2>
<p>For macOS, you should definitely be updating your projects so they build 64-bit apps. It&#8217;s likely that the version of macOS that is released later this year will no longer support 32-bit apps at all and you&#8217;ll want to be prepared. For many projects you just have to change the Build Architecture setting for the OS from &#8220;x86 32-bit&#8221; to &#8220;x86 64-bit&#8221;. Some projects may require updates to Declares that call OS libraries to ensure they can call the 64-bit version of the library.</p>
<p>It&#8217;s less of a rush on Windows as 64-bit versions of Windows still fully support 32-bit apps. However, on a 64-bit version of Windows, which are becoming increasingly common, you will get better overall performance as the OS does not have to load 32-bit compatibility layers which use up memory and CPU.</p>
<p>On Linux, 64-bit distributions are becoming more and more common and many do not include any built-in support for 32-bit apps. So you&#8217;ll want to be able to distribute a 64-bit app if at all possible.</p>
<h2>Not Checking the Docs</h2>
<p>We are working to consolidate all the documentation into one place and that place is: https://documentation.xojo.com</p>
<p>As part of this process, the docs have been cleaned up, updated and we&#8217;ve improved the categorization to make it easier to find things. This is an ongoing process, of course. But sometimes it will be faster to look up something in the docs than it is to post a question in the <a href="http://forum.xojo.com">forum</a> and wait for replies.</p>
<p>I hope you find some of these tips helpful. At <a href="https://www.xojo.com/xdc/sessions/info/lefebvre/">XDC 2019</a>, I&#8217;ll be covering additional tips in my two sessions: <em>Avoid Troubleshooting Troubles: Effective Debugging Techniques</em> and <em>Virtuous Code Optimization</em>.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
