<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Recent changes to Coding_conventions</title><link>https://sourceforge.net/p/hpg-projects/wiki/Coding_conventions/</link><description>Recent changes to Coding_conventions</description><atom:link href="https://sourceforge.net/p/hpg-projects/wiki/Coding_conventions/feed" rel="self"/><language>en</language><lastBuildDate>Fri, 20 Jan 2023 12:13:29 -0000</lastBuildDate><atom:link href="https://sourceforge.net/p/hpg-projects/wiki/Coding_conventions/feed" rel="self" type="application/rss+xml"/><item><title>Coding_conventions modified by Hugh Greene</title><link>https://sourceforge.net/p/hpg-projects/wiki/Coding_conventions/</link><description>&lt;div class="markdown_content"&gt;&lt;p&gt;I am not really picky about what your code looks like in terms of&lt;br/&gt;
indentation. Traditionally, I use two spaces for indentation, I do not&lt;br/&gt;
use braces unless required, and I place braces on their own unindented&lt;br/&gt;
lines unless the code in the braces is three lines or fewer, in which&lt;br/&gt;
case I put the opening brace after the &lt;code&gt;if()&lt;/code&gt;, or other statement.&lt;br/&gt;
Everyone else does the exact opposite of this, so pick your own style&lt;br/&gt;
and you'll fit right in.&lt;/p&gt;
&lt;h2 id="types"&gt;Types&lt;/h2&gt;
&lt;p&gt;What I &lt;em&gt;am&lt;/em&gt; concerned about and have been seeing happen a lot, lately,&lt;br/&gt;
are function and variable type confusion. I'll be succinct, and use&lt;br/&gt;
bullet points.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Always use the type which requires the fewest casts in your&lt;br/&gt;
    code.&lt;/strong&gt; If your function needs a double, take double. If your&lt;br/&gt;
    function needs a float, take float. If your function works for&lt;br/&gt;
    either, Robert has created scalar types for you to choose from based&lt;br/&gt;
    on system. For example, graphics floating point types should default&lt;br/&gt;
    to &lt;code&gt;gs_scalar&lt;/code&gt;. Look around the code; chances are, the correct&lt;br/&gt;
    scalar type is used somewhere.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Never use var or variant.&lt;/strong&gt; This is the rule. The &lt;em&gt;exception&lt;/em&gt; to&lt;br/&gt;
    this rule is, you may use variant when you need to accept either a&lt;br/&gt;
    string or real type, and you may use var if you need tot accept an&lt;br/&gt;
    array of such objects. If you need to accept an array of only reals&lt;br/&gt;
    or only strings, go ahead and use var for now, as ENIGMA does not&lt;br/&gt;
&lt;em&gt;yet&lt;/em&gt; have an array type.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="naming-convention"&gt;Naming convention&lt;/h2&gt;
&lt;p&gt;Another point is naming convention. I am not the underscore-case nazi. I&lt;br/&gt;
don't care what you name your own variables. Our current convention is&lt;br/&gt;
&lt;code&gt;snake_case&lt;/code&gt; for basically everything. This is violated on arbitrary&lt;br/&gt;
occasion without repercussion. However, we are running a user-friendly&lt;br/&gt;
API here, and in user space, functions are &lt;em&gt;expected&lt;/em&gt; to use a&lt;br/&gt;
consistent convention.&lt;/p&gt;
&lt;p&gt;This convention is, again, snake case, with functions partitioned using&lt;br/&gt;
C&lt;br/&gt;
namespaces.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;draw_&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;This is where primarily 2-Dimensional, but also dimensionality-insensitive drawing functions go.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;d3d_&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;This is where functions that specifically concern drawing in 3D go. Some of these functions are renamed versions of functions from &lt;code&gt;draw_&lt;/code&gt;, offered for the convenience of users searching for functions.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;sound_&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;This is where functions go which concern sound resources. There are functions to play sounds and stop sounds from playing by resource ID, but the idea is that functions here specifically concern tangible sound resources.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;audio_&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;This is where all other manner of audio functions go, as related to working with channels and playing instances of sounds.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;display_&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;This is where you will find functions concerning the entire desktop's display, which may contain many windows not related to your program.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;window_&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;This is where you will find functions that concern the window, as managed by the window server, desktop environment, and generically, the window manager.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;screen_&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;This is where you will find functions that concern your program's drawing screen; that is, the region inside the window to which your program renders.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;instance_&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;These functions concern object instances in general. Finding instances, iterating instances, creating and destroying instances.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;collision_&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;These functions concern testing for collisions with instances. They work with not only a position for instances, but also a physical shape. They do not, in general, incorporate dynamics.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;This is not a comprehensive list, but a general list of namespaces which&lt;br/&gt;
seem to run together or are otherwise not obvious.&lt;/p&gt;&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Hugh Greene</dc:creator><pubDate>Fri, 20 Jan 2023 12:13:29 -0000</pubDate><guid>https://sourceforge.net47c549a97c7d91fdae170328aaef7770505197c4</guid></item></channel></rss>