Editing Documentation/Maemo For Symbian Developers Guide/Maemo and Symbian OS Concepts

Warning: You are not logged in. Your IP address will be recorded in this page's edit history.
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision Your text
Line 15: Line 15:
=== Naming guidelines ===
=== Naming guidelines ===
-
Symbian OS naming conventions like class names prefix (<code>C</code>, <code>M</code>, <code>R</code>, or <code>T</code>), function leave indication (<code>L</code> suffix) are left behind when programming for Maemo platform. In Maemo, the developer is given more freedom and there are no mandatory prefixes in class names. Although there are no strict rules to be followed, Maemo has some programming guidelines that should be considered. Some examples are given below:
+
Symbian OS naming conventions like class names prefix (<span><font face="monospace">C</font></span>, <span><font face="monospace">M</font></span>, <span><font face="monospace">R</font></span>, or <span><font face="monospace">T</font></span>), function leave indication (<span><font face="monospace">L</font></span> suffix) are left behind when programming for Maemo platform. In Maemo, the developer is given more freedom and there are no mandatory prefixes in class names. Although there are no strict rules to be followed, Maemo has some programming guidelines that should be considered. Some examples are given below:
-
Descriptive, lower-case names should be used for variables and functions. Underscores (_) can be used to indicate word boundaries. Non-static and unnecessary global names should be avoided. If it is absolutely necessary to employ a global variable, type or function, one should use a prefix specific to the library or module where the name is, for example <code>gtk_widget_</code>.
+
Descriptive, lower-case names should be used for variables and functions. Underscores (_) can be used to indicate word boundaries. Non-static and unnecessary global names should be avoided. If it is absolutely necessary to employ a global variable, type or function, one should use a prefix specific to the library or module where the name is, e.g. <span><font face="monospace">gtk_widget_</font></span>.
Static memory (variables) should be preferred to dynamic memory, when the needed memory size is not large and/or is used regularly in the program. Static memory does not leak, a pointer to static memory is less likely to cause a segmentation fault, and using static memory keeps the memory usage more constant.
Static memory (variables) should be preferred to dynamic memory, when the needed memory size is not large and/or is used regularly in the program. Static memory does not leak, a pointer to static memory is less likely to cause a segmentation fault, and using static memory keeps the memory usage more constant.
-
Local variables should always be favoured over global variables, that is the visibility of a variable should be kept at a minimum. Global variables should not be used to pass values between functions: this can be performed with arguments. Note: Global variables require extra care when programming with threads. Thus, these should be avoided.
+
Local variables should always be favoured over global variables, i.e. the visibility of a variable should be kept at a minimum. Global variables should not be used to pass values between functions: this can be performed with arguments. Note: Global variables require extra care when programming with threads. Thus, these should be avoided.
=== Runtime type information ===
=== Runtime type information ===
Line 29: Line 29:
=== Exceptions ===
=== Exceptions ===
-
Symbian/C++ developers are familiar with concepts like ''leaving'' and ''trap harness'' because standard [http://www.cplusplus.com/doc/tutorial/exceptions/ C++ exceptions] did not exist when Symbian OS was originally developed. Only from Symbian OS v9 onwards C++ were exception mechanisms supported, although they still should not be mixed with Symbian/C++ code. In Maemo the standard C++ exceptions (<code>try</code>, <code>catch</code>, <code>throw</code>) are available.
+
Symbian/C++ developers are familiar with concepts like ''leaving'' and ''trap harness'' because standard [http://www.cplusplus.com/doc/tutorial/exceptions/ C++ exceptions] did not exist when Symbian OS was originally developed. Only from Symbian OS v9 onwards C++ were exception mechanisms supported, although they still should not be mixed with Symbian/C++ code. In Maemo the standard C++ exceptions (try, catch, throw) are available.
=== Cleanup stack ===
=== Cleanup stack ===
-
A Symbian/C++ specific concept that is not available in the Maemo platform. Similar functionality can be achieved by using [[:wikipedia:Auto_ptr|auto_ptr]] class which is also available for Symbian v9 onwards. <code>auto_ptr</code> is a [[:wikipedia:Smart_pointer|smart pointer]] implementation in [[:wikipedia:Standard_Template_Library |C++ Standard Template Library]], and it is a good way to prevent memory leaks in case of exceptions ([http://maemo4mobile.garage.maemo.org/snippet_autoptr.html view example]).
+
A Symbian/C++ specific concept that is not available in the Maemo platform. Similar functionality can be achieved by using [http://en.wikipedia.org/wiki/Auto_ptr auto_ptr] class which is also available for Symbian v9 onwards. <span><font face="monospace">auto_ptr</font></span> is a [[:wikipedia:Smart_pointer|smart pointer]] implementation in [[:wikipedia:Standard_Template_Library |C++ Standard Template Library]], and it is a good way to prevent memory leaks in case of exceptions ([http://maemo4mobile.garage.maemo.org/snippet_autoptr.html view example]).
For more information on using the <code>auto_ptr</code>, see the article [http://www.gotw.ca/publications/using_auto_ptr_effectively.htm Using auto_ptr Effectively].
For more information on using the <code>auto_ptr</code>, see the article [http://www.gotw.ca/publications/using_auto_ptr_effectively.htm Using auto_ptr Effectively].
Line 91: Line 91:
[[:wikipedia:String.h|The C-style NULL-terminated character arrays and methods]] can be used to store strings only. They are not as safe because they can cause buffer overflow. They can only be used with character set based on ASCII. One advantage is that it is guaranteed to work on any platform which supports C.
[[:wikipedia:String.h|The C-style NULL-terminated character arrays and methods]] can be used to store strings only. They are not as safe because they can cause buffer overflow. They can only be used with character set based on ASCII. One advantage is that it is guaranteed to work on any platform which supports C.
-
=== NULL-terminated character arrays using GLib ===
+
=== NULL-terminated character arrays using Glib ===
GLib is extensively used in the Maemo platform, so it is good practice to use the [http://library.gnome.org/devel/glib/stable/glib-String-Utility-Functions.html GLib-provided types and methods if using character arrays], although nothing prevents the developer from using other types.
GLib is extensively used in the Maemo platform, so it is good practice to use the [http://library.gnome.org/devel/glib/stable/glib-String-Utility-Functions.html GLib-provided types and methods if using character arrays], although nothing prevents the developer from using other types.

Learn more about Contributing to the wiki.


Please note that all contributions to maemo.org wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see maemo.org wiki:Copyrights for details). Do not submit copyrighted work without permission!


Cancel | Editing help (opens in new window)